This repository was archived by the owner on Nov 7, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
Introducing logical fromUnixTime func #1504
Merged
Merged
Changes from 21 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
5326b4d
Introducing logical fromUnixTime func
pdelewski 234310e
Fixing tests
pdelewski 0fe1f3e
Revert
pdelewski 9baa5ff
Update time functions
pdelewski aa09612
Fixing schema transformer test
pdelewski deb54d7
Fixing opensearch tests
pdelewski f7f7a6a
Fixing terms tests
pdelewski 78b4230
More tests
pdelewski 2024e01
Compare without white characters
pdelewski 2b5e267
Update kibana_sample_data_flights
pdelewski 0a4091b
Updating aggregation request
pdelewski ad1cde5
More updates
pdelewski 8ecb549
More updates
pdelewski d68a2ac
Commenting out clover tests
pdelewski ed1f154
Additional fixes
pdelewski 96b12f8
Adding request_after_transformations.go which contains tests that tak…
pdelewski 2221450
Minor fixes
pdelewski 96802b1
Update `FindTimestampLowerBound` accordingly
mieciu f9feb84
uncomment tests
mieciu c8e7abb
Merge remote-tracking branch 'origin/logical-fromunit-func' into logi…
mieciu 09ea693
Removing some stuff
pdelewski 9028b1e
Review remarks #1
pdelewski eb0ed70
Review remarks #2
pdelewski 92a523e
Review remarks #3, extracting determineBackendConnectorType fun
pdelewski b72bde0
Extracting consts
pdelewski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,11 @@ import ( | |
| "strings" | ||
| ) | ||
|
|
||
| type TransformationsChain struct { | ||
| TransformationName string | ||
| Transformation func(schema.Schema, *model.Query) (*model.Query, error) | ||
| } | ||
|
|
||
| type SchemaCheckPass struct { | ||
| cfg *config.QuesmaConfiguration | ||
| tableDiscovery database_common.TableDiscovery | ||
|
|
@@ -912,8 +917,13 @@ func (s *SchemaCheckPass) convertQueryDateTimeFunctionToClickhouse(indexSchema s | |
| } | ||
| return model.NewFunction("toHour", e.Args[0].Accept(b).(model.Expr)) | ||
|
|
||
| // TODO this is a place for over date/time related functions | ||
| // add more | ||
| case model.FromUnixTimeFunction64mili: | ||
| args := b.VisitChildren(e.Args) | ||
| return model.NewFunction("fromUnixTimestamp64Milli", args...) | ||
|
|
||
| case model.FromUnixTimeFunction: | ||
| args := b.VisitChildren(e.Args) | ||
| return model.NewFunction("fromUnixTimestamp", args...) | ||
|
|
||
| default: | ||
| return visitFunction(b, e) | ||
|
|
@@ -941,10 +951,13 @@ func (s *SchemaCheckPass) convertQueryDateTimeFunctionToDoris(indexSchema schema | |
| return e | ||
| } | ||
| return model.NewFunction("HOUR", e.Args[0].Accept(b).(model.Expr)) | ||
| case model.FromUnixTimeFunction: | ||
| args := b.VisitChildren(e.Args) | ||
| return model.NewFunction("FROM_UNIXTIME", args...) | ||
|
|
||
| // TODO this is a place for over date/time related functions | ||
| // add more | ||
|
|
||
| case model.FromUnixTimeFunction64mili: | ||
| args := b.VisitChildren(e.Args) | ||
| return model.NewFunction("FROM_MILLISECOND", args...) | ||
| default: | ||
| return visitFunction(b, e) | ||
| } | ||
|
|
@@ -1083,7 +1096,7 @@ func (s *SchemaCheckPass) acceptIntsAsTimestamps(indexSchema schema.Schema, quer | |
| } | ||
| } | ||
| if ok { | ||
| if f, okF := model.ToFunction(expr); okF && f.Name == "fromUnixTimestamp64Milli" && len(f.Args) == 1 { | ||
| if f, okF := model.ToFunction(expr); okF && f.Name == model.FromUnixTimeFunction64mili && len(f.Args) == 1 { | ||
| if l, okL := model.ToLiteral(f.Args[0]); okL { | ||
| if _, exists := l.Format(); exists { // heuristics: it's a date <=> it has a format | ||
| return model.NewInfixExpr(col, e.Op, f.Args[0]) | ||
|
|
@@ -1105,7 +1118,7 @@ func (s *SchemaCheckPass) acceptIntsAsTimestamps(indexSchema schema.Schema, quer | |
| if f.Name == "toTimezone" && len(f.Args) == 2 { | ||
| if col, ok := model.ExtractColRef(f.Args[0]); ok && table.IsInt(col.ColumnName) { | ||
| // adds fromUnixTimestamp64Milli | ||
| return model.NewFunction("toTimezone", model.NewFunction("fromUnixTimestamp64Milli", f.Args[0]), f.Args[1]) | ||
| return model.NewFunction("toTimezone", model.NewFunction(model.FromUnixTimeFunction64mili, f.Args[0]), f.Args[1]) | ||
|
||
| } | ||
| } | ||
| return visitFunction(b, f) | ||
|
|
@@ -1119,12 +1132,8 @@ func (s *SchemaCheckPass) acceptIntsAsTimestamps(indexSchema schema.Schema, quer | |
| return query, nil | ||
| } | ||
|
|
||
| func (s *SchemaCheckPass) Transform(plan *model.ExecutionPlan) (*model.ExecutionPlan, error) { | ||
|
|
||
| transformationChain := []struct { | ||
| TransformationName string | ||
| Transformation func(schema.Schema, *model.Query) (*model.Query, error) | ||
| }{ | ||
| func (s *SchemaCheckPass) makeTransformations(backendConnectorType quesma_api.BackendConnectorType) []TransformationsChain { | ||
| transformationChain := []TransformationsChain{ | ||
| // Section 1: from logical to physical | ||
| {TransformationName: "PhysicalFromExpressionTransformation", Transformation: s.applyPhysicalFromExpression}, | ||
| {TransformationName: "WildcardExpansion", Transformation: s.applyWildcardExpansion}, | ||
|
|
@@ -1149,31 +1158,23 @@ func (s *SchemaCheckPass) Transform(plan *model.ExecutionPlan) (*model.Execution | |
|
|
||
| // Section 3: backend specific transformations | ||
| // fallback to clickhouse date functions if no backend connector is set | ||
| if plan.BackendConnector == nil { | ||
|
|
||
| if backendConnectorType == quesma_api.ClickHouseSQLBackend { | ||
| transformationChain = append(transformationChain, struct { | ||
| TransformationName string | ||
| Transformation func(schema.Schema, *model.Query) (*model.Query, error) | ||
| }{TransformationName: "QuesmaDateFunctions", Transformation: s.convertQueryDateTimeFunctionToClickhouse}) | ||
| } else { | ||
| if plan.BackendConnector.GetId() == quesma_api.ClickHouseSQLBackend { | ||
| transformationChain = append(transformationChain, struct { | ||
| TransformationName string | ||
| Transformation func(schema.Schema, *model.Query) (*model.Query, error) | ||
| }{TransformationName: "QuesmaDateFunctions", Transformation: s.convertQueryDateTimeFunctionToClickhouse}) | ||
| } | ||
|
|
||
| if plan.BackendConnector.GetId() == quesma_api.DorisSQLBackend { | ||
| transformationChain = append(transformationChain, struct { | ||
| TransformationName string | ||
| Transformation func(schema.Schema, *model.Query) (*model.Query, error) | ||
| }{TransformationName: "QuesmaDateFunctions", Transformation: s.convertQueryDateTimeFunctionToDoris}) | ||
| } | ||
| } | ||
| transformationChain = append(transformationChain, | ||
| []struct { | ||
|
|
||
| if backendConnectorType == quesma_api.DorisSQLBackend { | ||
| transformationChain = append(transformationChain, struct { | ||
| TransformationName string | ||
| Transformation func(schema.Schema, *model.Query) (*model.Query, error) | ||
| }{ | ||
| }{TransformationName: "QuesmaDateFunctions", Transformation: s.convertQueryDateTimeFunctionToDoris}) | ||
pdelewski marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| transformationChain = append(transformationChain, | ||
| []TransformationsChain{ | ||
| {TransformationName: "IpTransformation", Transformation: s.applyIpTransformations}, | ||
| {TransformationName: "GeoTransformation", Transformation: s.applyGeoTransformations}, | ||
| {TransformationName: "ArrayTransformation", Transformation: s.applyArrayTransformations}, | ||
|
|
@@ -1184,7 +1185,16 @@ func (s *SchemaCheckPass) Transform(plan *model.ExecutionPlan) (*model.Execution | |
| {TransformationName: "BooleanLiteralTransformation", Transformation: s.applyBooleanLiteralLowering}, | ||
| }..., | ||
| ) | ||
| return transformationChain | ||
| } | ||
|
|
||
| func (s *SchemaCheckPass) Transform(plan *model.ExecutionPlan) (*model.ExecutionPlan, error) { | ||
|
|
||
| backendConnectorType := quesma_api.ClickHouseSQLBackend | ||
| if plan != nil && plan.BackendConnector != nil { | ||
| backendConnectorType = plan.BackendConnector.GetId() | ||
| } | ||
pdelewski marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| transformationChain := s.makeTransformations(backendConnectorType) | ||
| for k, query := range plan.Queries { | ||
| var err error | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.