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
Report errors in queries better #2 (in parsing bucket aggregations) #1006
Merged
Merged
Changes from 15 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
b0bef68
Initial
trzysiek bc774cb
Merge branch 'main' into report-errors-in-queries-better
trzysiek f825f79
WIP
trzysiek 348e0fe
WIP2
trzysiek fd01f63
Some code reorganization done
trzysiek 426c30c
Add licence
trzysiek 637b155
Small style
trzysiek 5061fc3
Small improvement
trzysiek 672bba0
Merge branch 'main' into report-errors-in-queries-better
trzysiek 5ef063a
Start of implementation of invalid queries test
trzysiek 52ca3e7
Merge branch 'main' into report-errors-in-queries-better
trzysiek 0a07198
Unify composite aggr
trzysiek 5b599b2
Small last changes
trzysiek 6d5fac5
Merge branch 'main' into report-errors-in-queries-better
trzysiek 7ed955e
Very minor style improvement
trzysiek d77bb30
Simplify code date_range parser
trzysiek a861b28
Very small improvement filters
trzysiek 082cda2
Skip WIP tests
trzysiek df02efd
Last
trzysiek 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,40 +3,32 @@ | |
| package queryparser | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "quesma/logger" | ||
| "quesma/model/bucket_aggregations" | ||
| "unicode" | ||
| ) | ||
|
|
||
| func (cw *ClickhouseQueryTranslator) parseDateRangeAggregation(dateRange QueryMap) (bucket_aggregations.DateRange, error) { | ||
| var err error | ||
| var fieldName, format string | ||
|
|
||
| if field, exists := dateRange["field"]; exists { | ||
| if fieldNameRaw, ok := field.(string); ok { | ||
| fieldName = cw.ResolveField(cw.Ctx, fieldNameRaw) | ||
| } else { | ||
| logger.WarnWithCtx(cw.Ctx).Msgf("field specified for date range aggregation is not a string. Using empty. Querymap: %v", dateRange) | ||
| } | ||
| } else { | ||
| logger.WarnWithCtx(cw.Ctx).Msgf("no field specified for date range aggregation. Using empty. Querymap: %v", dateRange) | ||
| } | ||
| var ranges []any | ||
| var ok bool | ||
| if formatRaw, exists := dateRange["format"]; exists { | ||
| func (cw *ClickhouseQueryTranslator) parseDateRangeAggregation(aggregation *pancakeAggregationTreeNode, params QueryMap) (err error) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder about type signature? Why pass
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, after reading later it become obvious why you did that way. |
||
| var format string | ||
| if formatRaw, exists := params["format"]; exists { | ||
| if formatParsed, ok := formatRaw.(string); ok { | ||
| format = formatParsed | ||
| } else { | ||
| logger.WarnWithCtx(cw.Ctx).Msgf("format specified for date range aggregation is not a string. Using empty. Querymap: %v", dateRange) | ||
| logger.WarnWithCtx(cw.Ctx).Msgf("format specified for date range aggregation is not a string. Using empty. Params: %v", params) | ||
| } | ||
| } | ||
| if rangesRaw, exists := dateRange["ranges"]; exists { | ||
|
|
||
| var ranges []any | ||
| var ok bool | ||
| if rangesRaw, exists := params["ranges"]; exists { | ||
| if ranges, ok = rangesRaw.([]any); !ok { | ||
| logger.WarnWithCtx(cw.Ctx).Msgf("ranges specified for date range aggregation is not an array. Using empty. Querymap: %v", dateRange) | ||
| return fmt.Errorf("ranges specified for date range aggregation is not an array, params: %v", params) | ||
| } | ||
| } else { | ||
| logger.WarnWithCtx(cw.Ctx).Msgf("no ranges specified for date range aggregation. Using empty. Querymap: %v", dateRange) | ||
| return fmt.Errorf("no ranges specified for date range aggregation, params: %v", params) | ||
| } | ||
|
|
||
| intervals := make([]bucket_aggregations.DateTimeInterval, 0, len(ranges)) | ||
| selectColumnsNr := len(ranges) // we query Clickhouse for every unbounded part of interval (begin and end) | ||
| for _, Range := range ranges { | ||
|
|
@@ -47,12 +39,12 @@ func (cw *ClickhouseQueryTranslator) parseDateRangeAggregation(dateRange QueryMa | |
| if fromRaw, ok := from.(string); ok { | ||
| intervalBegin, err = cw.parseDateTimeInClickhouseMathLanguage(fromRaw) | ||
| if err != nil { | ||
| return bucket_aggregations.DateRange{}, err | ||
| return err | ||
| } | ||
| selectColumnsNr++ | ||
| } else { | ||
| logger.WarnWithCtx(cw.Ctx).Msgf("from specified for date range aggregation is not a string. Querymap: %v "+ | ||
| "Using default (unbounded).", dateRange) | ||
| logger.WarnWithCtx(cw.Ctx).Msgf("from specified for date range aggregation is not a string, params: %v "+ | ||
| "using default (unbounded).", params) | ||
| intervalBegin = bucket_aggregations.UnboundedInterval | ||
| } | ||
| } else { | ||
|
|
@@ -63,20 +55,40 @@ func (cw *ClickhouseQueryTranslator) parseDateRangeAggregation(dateRange QueryMa | |
| if toRaw, ok := to.(string); ok { | ||
| intervalEnd, err = cw.parseDateTimeInClickhouseMathLanguage(toRaw) | ||
| if err != nil { | ||
| return bucket_aggregations.DateRange{}, err | ||
| return err | ||
| } | ||
| selectColumnsNr++ | ||
| } else { | ||
| logger.WarnWithCtx(cw.Ctx).Msgf("To specified for date range aggregation is not a string. Querymap: %v "+ | ||
| "Using default (unbounded).", dateRange) | ||
| logger.WarnWithCtx(cw.Ctx).Msgf("To specified for date range aggregation is not a string, params: %v "+ | ||
| "using default (unbounded).", params) | ||
| intervalEnd = bucket_aggregations.UnboundedInterval | ||
| } | ||
| } else { | ||
| intervalEnd = bucket_aggregations.UnboundedInterval | ||
| } | ||
| intervals = append(intervals, bucket_aggregations.NewDateTimeInterval(intervalBegin, intervalEnd)) | ||
| } | ||
| return bucket_aggregations.NewDateRange(cw.Ctx, fieldName, format, intervals, selectColumnsNr), nil | ||
|
|
||
| // TODO: keep for reference as relative time, but no longer needed | ||
| /* | ||
| for _, interval := range dateRangeParsed.Intervals { | ||
|
|
||
| aggregation.selectedColumns = append(aggregation.selectedColumns, interval.ToSQLSelectQuery(dateRangeParsed.FieldName)) | ||
|
|
||
| if sqlSelect, selectNeeded := interval.BeginTimestampToSQL(); selectNeeded { | ||
| aggregation.selectedColumns = append(aggregation.selectedColumns, sqlSelect) | ||
| } | ||
| if sqlSelect, selectNeeded := interval.EndTimestampToSQL(); selectNeeded { | ||
| aggregation.selectedColumns = append(aggregation.selectedColumns, sqlSelect) | ||
| } | ||
| }*/ | ||
|
|
||
| field := cw.parseFieldField(params, "date_range") | ||
| if field == nil { | ||
| return fmt.Errorf("no field specified for date range aggregation, params: %v", params) | ||
| } | ||
| aggregation.queryType = bucket_aggregations.NewDateRange(cw.Ctx, field, format, intervals, selectColumnsNr) | ||
| return nil | ||
| } | ||
|
|
||
| // parseDateTimeInClickhouseMathLanguage parses dateTime from Clickhouse's format | ||
|
|
||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
only very very minor style improvements in this file