SQL Expressions: Add str_to_date function and unskip test (#100226)

This commit is contained in:
Kyle Brandt 2025-02-07 04:51:55 -05:00 committed by GitHub
parent 9da423045e
commit 6dc98dbbcc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 10 deletions

View File

@ -148,27 +148,21 @@ func TestQueryFramesNumericSelect(t *testing.T) {
}
func TestQueryFramesDateTimeSelect(t *testing.T) {
t.Skip("need a fix in go-mysql-server, and then handle the datetime strings (or figure out why strings and not time.Time)")
expectedFrame := &data.Frame{
RefID: "a",
Name: "a",
Fields: []*data.Field{
data.NewField("ts", nil, []time.Time{}),
data.NewField("ts", nil, []*time.Time{
p(time.Date(2025, 2, 3, 3, 0, 0, 0, time.UTC)),
}),
},
}
db := DB{}
// It doesn't like the T in the time string
qry := `SELECT str_to_date('2025-02-03T03:00:00','%Y-%m-%dT%H:%i:%s') as ts`
// This comes back as a string, which needs to be dealt with?
//qry := `SELECT str_to_date('2025-02-03-03:00:00','%Y-%m-%d-%H:%i:%s') as ts`
// This is a datetime(6), need to deal with that as well
//qry := `SELECT current_timestamp() as ts`
f, err := db.QueryFrames(context.Background(), "b", qry, []*data.Frame{})
f, err := db.QueryFrames(context.Background(), "a", qry, nil)
require.NoError(t, err)
if diff := cmp.Diff(expectedFrame, f, data.FrameTestCompareOptions()...); diff != "" {

View File

@ -145,6 +145,9 @@ func allowedFunction(f *sqlparser.FuncExpr) (b bool) {
case "coalesce":
return
case "str_to_date":
return
default:
return false
}