@@ -14,6 +14,7 @@ import (
1414 "github.com/QuesmaOrg/quesma/platform/parsers/elastic_query_dsl"
1515 "github.com/QuesmaOrg/quesma/platform/schema"
1616 "github.com/QuesmaOrg/quesma/platform/transformations"
17+ quesma_api "github.com/QuesmaOrg/quesma/platform/v2/core"
1718 "sort"
1819 "strconv"
1920 "strings"
@@ -901,7 +902,6 @@ func (s *SchemaCheckPass) applyRuntimeMappings(indexSchema schema.Schema, query
901902func (s * SchemaCheckPass ) convertQueryDateTimeFunctionToClickhouse (indexSchema schema.Schema , query * model.Query ) (* model.Query , error ) {
902903
903904 visitor := model .NewBaseVisitor ()
904-
905905 visitor .OverrideVisitFunction = func (b * model.BaseExprVisitor , e model.FunctionExpr ) interface {} {
906906
907907 switch e .Name {
@@ -926,7 +926,36 @@ func (s *SchemaCheckPass) convertQueryDateTimeFunctionToClickhouse(indexSchema s
926926 query .SelectCommand = * expr .(* model.SelectCommand )
927927 }
928928 return query , nil
929+ }
930+
931+ // it convers out internal date time related fuction to clickhouse functions
932+ func (s * SchemaCheckPass ) convertQueryDateTimeFunctionToDoris (indexSchema schema.Schema , query * model.Query ) (* model.Query , error ) {
933+
934+ visitor := model .NewBaseVisitor ()
935+ visitor .OverrideVisitFunction = func (b * model.BaseExprVisitor , e model.FunctionExpr ) interface {} {
936+
937+ switch e .Name {
938+
939+ case model .DateHourFunction :
940+ if len (e .Args ) != 1 {
941+ return e
942+ }
943+ return model .NewFunction ("HOUR" , e .Args [0 ].Accept (b ).(model.Expr ))
944+
945+ // TODO this is a place for over date/time related functions
946+ // add more
929947
948+ default :
949+ return visitFunction (b , e )
950+ }
951+ }
952+
953+ expr := query .SelectCommand .Accept (visitor )
954+
955+ if _ , ok := expr .(* model.SelectCommand ); ok {
956+ query .SelectCommand = * expr .(* model.SelectCommand )
957+ }
958+ return query , nil
930959}
931960
932961func (s * SchemaCheckPass ) checkAggOverUnsupportedType (indexSchema schema.Schema , query * model.Query ) (* model.Query , error ) {
@@ -1116,21 +1145,46 @@ func (s *SchemaCheckPass) Transform(plan *model.ExecutionPlan) (*model.Execution
11161145 {TransformationName : "FullTextFieldTransformation" , Transformation : s .applyFullTextField },
11171146 {TransformationName : "TimestampFieldTransformation" , Transformation : s .applyTimestampField },
11181147 {TransformationName : "ApplySearchAfterParameter" , Transformation : s .applySearchAfterParameter },
1119-
1120- // Section 3: clickhouse specific transformations
1121- {TransformationName : "QuesmaDateFunctions" , Transformation : s .convertQueryDateTimeFunctionToClickhouse },
1122- {TransformationName : "IpTransformation" , Transformation : s .applyIpTransformations },
1123- {TransformationName : "GeoTransformation" , Transformation : s .applyGeoTransformations },
1124- {TransformationName : "ArrayTransformation" , Transformation : s .applyArrayTransformations },
1125- {TransformationName : "MapTransformation" , Transformation : s .applyMapTransformations },
1126- {TransformationName : "MatchOperatorTransformation" , Transformation : s .applyMatchOperator },
1127- {TransformationName : "AggOverUnsupportedType" , Transformation : s .checkAggOverUnsupportedType },
1128- {TransformationName : "ApplySelectFromCluster" , Transformation : s .ApplySelectFromCluster },
1129-
1130- // Section 4: compensations and checks
1131- {TransformationName : "BooleanLiteralTransformation" , Transformation : s .applyBooleanLiteralLowering },
11321148 }
11331149
1150+ // Section 3: backend specific transformations
1151+ // fallback to clickhouse date functions if no backend connector is set
1152+ if plan .BackendConnector == nil {
1153+ transformationChain = append (transformationChain , struct {
1154+ TransformationName string
1155+ Transformation func (schema.Schema , * model.Query ) (* model.Query , error )
1156+ }{TransformationName : "QuesmaDateFunctions" , Transformation : s .convertQueryDateTimeFunctionToClickhouse })
1157+ } else {
1158+ if plan .BackendConnector .GetId () == quesma_api .ClickHouseSQLBackend {
1159+ transformationChain = append (transformationChain , struct {
1160+ TransformationName string
1161+ Transformation func (schema.Schema , * model.Query ) (* model.Query , error )
1162+ }{TransformationName : "QuesmaDateFunctions" , Transformation : s .convertQueryDateTimeFunctionToClickhouse })
1163+ }
1164+
1165+ if plan .BackendConnector .GetId () == quesma_api .DorisSQLBackend {
1166+ transformationChain = append (transformationChain , struct {
1167+ TransformationName string
1168+ Transformation func (schema.Schema , * model.Query ) (* model.Query , error )
1169+ }{TransformationName : "QuesmaDateFunctions" , Transformation : s .convertQueryDateTimeFunctionToDoris })
1170+ }
1171+ }
1172+ transformationChain = append (transformationChain ,
1173+ []struct {
1174+ TransformationName string
1175+ Transformation func (schema.Schema , * model.Query ) (* model.Query , error )
1176+ }{
1177+ {TransformationName : "IpTransformation" , Transformation : s .applyIpTransformations },
1178+ {TransformationName : "GeoTransformation" , Transformation : s .applyGeoTransformations },
1179+ {TransformationName : "ArrayTransformation" , Transformation : s .applyArrayTransformations },
1180+ {TransformationName : "MapTransformation" , Transformation : s .applyMapTransformations },
1181+ {TransformationName : "MatchOperatorTransformation" , Transformation : s .applyMatchOperator },
1182+ {TransformationName : "AggOverUnsupportedType" , Transformation : s .checkAggOverUnsupportedType },
1183+ {TransformationName : "ApplySelectFromCluster" , Transformation : s .ApplySelectFromCluster },
1184+ {TransformationName : "BooleanLiteralTransformation" , Transformation : s .applyBooleanLiteralLowering },
1185+ }... ,
1186+ )
1187+
11341188 for k , query := range plan .Queries {
11351189 var err error
11361190
0 commit comments