SQL Expressions: Re-implement feature using go-mysql-server (#99521)

* Under feature flag `sqlExpressions` and is experimental
* Excluded from arm32
* Will not work with the Query Service yet
* Does not have limits in place yet
* Does not working with alerting yet
* Currently requires "prepare time series" Transform for time series viz
 
---------

Co-authored-by: Sam Jewell <sam.jewell@grafana.com>
This commit is contained in:
Kyle Brandt
2025-02-06 07:27:28 -05:00
committed by GitHub
co-authored by Sam Jewell
parent 4e6bdce41c
commit d64f41afdc
33 changed files with 1969 additions and 405 deletions
+48
View File
@@ -0,0 +1,48 @@
package expr
import (
"testing"
"github.com/google/go-cmp/cmp"
"github.com/grafana/grafana-plugin-sdk-go/data"
"github.com/stretchr/testify/require"
)
func TestConvertNumericMultiToLong(t *testing.T) {
input := data.Frames{
data.NewFrame("test",
data.NewField("Value", data.Labels{"city": "MIA"}, []int64{5})),
data.NewFrame("test",
data.NewField("Value", data.Labels{"city": "LGA"}, []int64{7}),
),
}
expectedFrame := data.NewFrame("",
data.NewField("Value", nil, []int64{5, 7}),
data.NewField("city", nil, []string{"MIA", "LGA"}),
)
output, err := convertNumericMultiToNumericLong(input)
require.NoError(t, err)
if diff := cmp.Diff(expectedFrame, output[0], data.FrameTestCompareOptions()...); diff != "" {
require.FailNowf(t, "Result mismatch (-want +got):%s\n", diff)
}
}
func TestConvertNumericWideToLong(t *testing.T) {
input := data.Frames{
data.NewFrame("test",
data.NewField("Value", data.Labels{"city": "MIA"}, []int64{5}),
data.NewField("Value", data.Labels{"city": "LGA"}, []int64{7}),
),
}
expectedFrame := data.NewFrame("",
data.NewField("Value", nil, []int64{5, 7}),
data.NewField("city", nil, []string{"MIA", "LGA"}),
)
output, err := convertNumericWideToNumericLong(input)
require.NoError(t, err)
if diff := cmp.Diff(expectedFrame, output[0], data.FrameTestCompareOptions()...); diff != "" {
require.FailNowf(t, "Result mismatch (-want +got):%s\n", diff)
}
}