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

[ESQL] Refactor Element Type selection to use a switch #110111

Conversation

not-napoleon
Copy link
Member

Similar to #110036, this creates the opportunity for the compiler to flag this as a place which needs to be changed when we add a data type. It's also fewer lines of code, and makes it explicit which types are not supported.

Ideally, this would also become a property on DataType, but that can't happen until we pull it out of core.

@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-analytical-engine (Team:Analytics)

@elasticsearchmachine elasticsearchmachine added the Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) label Jun 24, 2024
@not-napoleon not-napoleon added auto-merge-without-approval Automatically merge pull request when CI checks pass (NB doesn't wait for reviews!) and removed auto-merge-without-approval Automatically merge pull request when CI checks pass (NB doesn't wait for reviews!) labels Jun 24, 2024
@@ -296,6 +272,6 @@ public static ElementType toElementType(DataType dataType, MappedFieldType.Field
* Returns DOC_VALUES if the given boolean is set.
*/
public static MappedFieldType.FieldExtractPreference extractPreference(boolean hasPreference) {
return hasPreference ? MappedFieldType.FieldExtractPreference.DOC_VALUES : MappedFieldType.FieldExtractPreference.NONE;
return hasPreference ? DOC_VALUES : MappedFieldType.FieldExtractPreference.NONE;
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: might be worth statically importing MappedFieldType.FieldExtractPreference.NONE as well, they're part of the same enum.

Copy link
Contributor

@bpintea bpintea left a comment

Choose a reason for hiding this comment

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

LGTM

@not-napoleon not-napoleon added the auto-merge-without-approval Automatically merge pull request when CI checks pass (NB doesn't wait for reviews!) label Jun 25, 2024
case BOOLEAN -> ElementType.BOOLEAN;
case DOC_DATA_TYPE -> ElementType.DOC;
case TSID_DATA_TYPE -> ElementType.BYTES_REF;
case GEO_POINT, CARTESIAN_POINT -> fieldExtractPreference == DOC_VALUES ? ElementType.LONG : ElementType.BYTES_REF;
// TODO: support forStats for shape aggregations, like st_centroid
Copy link
Contributor

Choose a reason for hiding this comment

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

This comment is out of date, and can be removed. When we do doc-values they will almost certainly also be backed by ByteRefs, so no consideration for fieldExtractPreference is needed (the term forStats was used before we moved to FieldExtractPreference).

…planner/PlannerUtils.java

Co-authored-by: Craig Taverner <[email protected]>
@not-napoleon
Copy link
Member Author

@elasticmachine run elasticsearch-ci/part-3

@not-napoleon
Copy link
Member Author

Test failure reproduces on main, so it's not related to this PR. I opened an issue for it: #110152

@elasticsearchmachine elasticsearchmachine merged commit ae39525 into elastic:main Jun 25, 2024
15 checks passed
@not-napoleon not-napoleon deleted the esql-make-to-element-type-a-switch branch June 25, 2024 15:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Analytics/ES|QL AKA ESQL auto-merge-without-approval Automatically merge pull request when CI checks pass (NB doesn't wait for reviews!) >non-issue Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) v8.15.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants