@@ -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 ))
929944
945+ // TODO this is a place for over date/time related functions
946+ // add more
947+
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,20 +1145,38 @@ 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 }
1149+ // Section 3: backend specific transformations
1150+ if plan .BackendConnector .GetId () == quesma_api .ClickHouseSQLBackend {
1151+ transformationChain = append (transformationChain , struct {
1152+ TransformationName string
1153+ Transformation func (schema.Schema , * model.Query ) (* model.Query , error )
1154+ }{TransformationName : "QuesmaDateFunctions" , Transformation : s .convertQueryDateTimeFunctionToClickhouse })
1155+ }
1156+
1157+ if plan .BackendConnector .GetId () == quesma_api .DorisSQLBackend {
1158+ transformationChain = append (transformationChain , struct {
1159+ TransformationName string
1160+ Transformation func (schema.Schema , * model.Query ) (* model.Query , error )
1161+ }{TransformationName : "QuesmaDateFunctions" , Transformation : s .convertQueryDateTimeFunctionToDoris })
1162+
1163+ }
1164+
1165+ transformationChain = append (transformationChain ,
1166+ []struct {
1167+ TransformationName string
1168+ Transformation func (schema.Schema , * model.Query ) (* model.Query , error )
1169+ }{
1170+ {TransformationName : "IpTransformation" , Transformation : s .applyIpTransformations },
1171+ {TransformationName : "GeoTransformation" , Transformation : s .applyGeoTransformations },
1172+ {TransformationName : "ArrayTransformation" , Transformation : s .applyArrayTransformations },
1173+ {TransformationName : "MapTransformation" , Transformation : s .applyMapTransformations },
1174+ {TransformationName : "MatchOperatorTransformation" , Transformation : s .applyMatchOperator },
1175+ {TransformationName : "AggOverUnsupportedType" , Transformation : s .checkAggOverUnsupportedType },
1176+ {TransformationName : "ApplySelectFromCluster" , Transformation : s .ApplySelectFromCluster },
1177+ {TransformationName : "BooleanLiteralTransformation" , Transformation : s .applyBooleanLiteralLowering },
1178+ }... ,
1179+ )
11331180
11341181 for k , query := range plan .Queries {
11351182 var err error
0 commit comments