Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance 'sort' field parser to handle various sort formats #139

Merged
merged 2 commits into from
May 17, 2024

Conversation

pivovarit
Copy link
Contributor

@pivovarit pivovarit commented May 17, 2024

Parse shorthand forms of sort fields like:

    "sort": {
        "@timestamp": "desc",
        "_doc": "desc"
    },

and:

 "sort": [
     {
       "@timestamp": "asc"
    },
    {
       "_doc": "asc"
    }
]

Also, rewrote tests to run as separate test cases instead of a single test with a loop

@pivovarit pivovarit marked this pull request as ready for review May 17, 2024 11:42
@pivovarit pivovarit requested a review from a team as a code owner May 17, 2024 11:42
@pivovarit pivovarit requested review from nablaone, jakozaur, mieciu, trzysiek and pdelewski and removed request for a team May 17, 2024 11:42
@pivovarit pivovarit enabled auto-merge (squash) May 17, 2024 11:49
@pivovarit pivovarit force-pushed the parse-map-sort branch 4 times, most recently from d048179 to 88a645d Compare May 17, 2024 13:55
@pivovarit pivovarit force-pushed the parse-map-sort branch 2 times, most recently from 1804a80 to 2ec1aed Compare May 17, 2024 14:07
@pivovarit pivovarit changed the title Enhance 'sort' field parser to handle shorthand maps Enhance 'sort' field parser to handle various sort formats May 17, 2024
@trzysiek trzysiek self-requested a review May 17, 2024 14:30
Comment on lines +1174 to +1204
return sortFields
case map[string]interface{}:
sortFields := make([]string, 0)

for fieldName, fieldValue := range sortMaps {
if strings.HasPrefix(fieldName, "_") && cw.Table.GetFieldInfo(cw.Ctx, fieldName) == clickhouse.NotExists {
// TODO Elastic internal fields will need to be supported in the future
continue
}
if fieldValue, ok := fieldValue.(string); ok {
sortFields = append(sortFields, fmt.Sprintf("%s %s", strconv.Quote(fieldName), fieldValue))
}
}

return sortFields

case map[string]string:
sortFields := make([]string, 0)

for fieldName, fieldValue := range sortMaps {
if strings.HasPrefix(fieldName, "_") && cw.Table.GetFieldInfo(cw.Ctx, fieldName) == clickhouse.NotExists {
// TODO Elastic internal fields will need to be supported in the future
continue
}
sortFields = append(sortFields, fmt.Sprintf("%s %s", strconv.Quote(fieldName), fieldValue))
}

return sortFields
Copy link
Member

Choose a reason for hiding this comment

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

in previous implementation, we do ResolveField. Don't we want to do it in these 2 cases as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is handled at the beginning of each search processing, so we never reach here with nonexistent columns - I will unify that

quesma/queryparser/query_parser_test.go Outdated Show resolved Hide resolved
@pivovarit pivovarit merged commit 63718cc into main May 17, 2024
4 checks passed
@pivovarit pivovarit deleted the parse-map-sort branch May 17, 2024 14:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants