Skip to content
This repository was archived by the owner on Nov 7, 2025. It is now read-only.

Conversation

@trzysiek
Copy link
Member

@trzysiek trzysiek commented Nov 15, 2024

old comment (motivation):
Our error messages for errors encountered while parsing query request isn't as good as Elastic's, I'll try to improve it here. (It's not that unimportant, with invalid query request where Elastic always fails with an error response, we often don't and e.g. return empty results, which might trick the user that queries went fine)

I think I'll split it into few PRs. This might be a good starting point for another one. (update: actually similar small improvement was already merged, but for pipeline aggregations)

new comment (what's been done):
There's really not much going on here.
Clue of this PR is to change our very ugly 400-line func (cw *ClickhouseQueryTranslator) pancakeTryBucketAggregation function into something a bit nicer. And also report errors in more places, to be consistent with Elastic's behaviour.

Quite a few style improvements that I automatically caught in the process, but only some trivial/very local ones, so extracting copy/paste used 5 times into 1 function, consistent naming across parsers of different aggregations, etc. (not much more).

@trzysiek trzysiek force-pushed the report-errors-in-queries-better branch from 1e433b7 to 348e0fe Compare November 16, 2024 14:59
@trzysiek trzysiek changed the title Report errors in queries better Report errors in queries better #1 Nov 16, 2024
github-merge-queue bot pushed a commit that referenced this pull request Nov 17, 2024
Similar to #1006 , but for
pipeline aggregations.

I want to simplify and unify interfaces of our parsers, so all of them
simply return something like `(aggregation, error)`. Code should be
cleaner, and proper returning errors to Kibana much easier.
@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Dec 11, 2024

Deploying quesma with  Cloudflare Pages  Cloudflare Pages

Latest commit: 0a07198
Status: ✅  Deploy successful!
Preview URL: https://9237ddaa.quesma.pages.dev
Branch Preview URL: https://report-errors-in-queries-bet.quesma.pages.dev

View logs

Copy link
Member Author

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

@trzysiek trzysiek force-pushed the report-errors-in-queries-better branch from a2b9125 to 11e7c61 Compare December 11, 2024 14:13
@trzysiek trzysiek force-pushed the report-errors-in-queries-better branch from 11e7c61 to d77bb30 Compare December 11, 2024 14:14
@trzysiek trzysiek force-pushed the report-errors-in-queries-better branch from cde08d8 to df02efd Compare December 11, 2024 14:34
@trzysiek trzysiek changed the title Report errors in queries better #1 Report errors in queries better #1 (in bucket aggregations) Dec 11, 2024
@trzysiek trzysiek changed the title Report errors in queries better #1 (in bucket aggregations) Report errors in queries better #1 (in parsing bucket aggregations) Dec 11, 2024
@trzysiek trzysiek marked this pull request as ready for review December 11, 2024 14:42
@trzysiek trzysiek requested a review from a team as a code owner December 11, 2024 14:42
@trzysiek trzysiek changed the title Report errors in queries better #1 (in parsing bucket aggregations) Report errors in queries better #2 (in parsing bucket aggregations) Dec 11, 2024
} else {
logger.WarnWithCtx(cw.Ctx).Msgf("format specified for date range aggregation is not a string. Using empty. Querymap: %v", dateRange)
}
func (cw *ClickhouseQueryTranslator) parseDateRangeAggregation(aggregation *pancakeAggregationTreeNode, params QueryMap) (err error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder about type signature? Why pass aggregation as argument, shouldn't we just return optional queryType?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, after reading later it become obvious why you did that way.

filtersAggr = bucket_aggregations.NewFiltersEmpty(cw.Ctx)

filtersRaw, exists := queryMap["filters"]
func (cw *ClickhouseQueryTranslator) parseFilters(aggregation *pancakeAggregationTreeNode, params QueryMap) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar, here. Not sure if it's right to pass aggregation here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I understand. It explain later. Keep as ai.

return false, fmt.Errorf("histogram is not a map, but %T, value: %v", histogramRaw, histogramRaw)
}
func (cw *ClickhouseQueryTranslator) pancakeTryBucketAggregation(aggregation *pancakeAggregationTreeNode, queryMap QueryMap) error {
aggregationHandlers := []struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super nice!

@jakozaur jakozaur added this pull request to the merge queue Dec 12, 2024
Merged via the queue into main with commit 5ed84b9 Dec 12, 2024
5 checks passed
@jakozaur jakozaur deleted the report-errors-in-queries-better branch December 12, 2024 11:13
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants