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: fix non-null value being returned for unsupported data types in ValueSources #100656

Merged
merged 2 commits into from Oct 11, 2023

Conversation

astefan
Copy link
Contributor

@astefan astefan commented Oct 11, 2023

Refine (and fix) all cases where an unsupported data type field's values are returned from ValueSources.
Improve unsupported data types handling in TopN by catching non-null values encoding/decoding attempts for unsupported data types.

Fixes #100048

are returned from SourceValues.
Improve unsupported data types handling in TopN
@elasticsearchmachine elasticsearchmachine added the Team:QL (Deprecated) Meta label for query languages team label Oct 11, 2023
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-ql (Team:QL)

@elasticsearchmachine
Copy link
Collaborator

Hi @astefan, I've created a changelog YAML for you.

@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/elasticsearch-esql (:Query Languages/ES|QL)

sources.add(
new ValueSourceInfo(
new UnsupportedValueSourceType(fieldType.typeName()),
new UnsupportedValueSource(null),
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 the actual fix where instead of using null as original source argument, the actual source was still in use.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for explicitly calling this out vs -> null. It would be easy to miss in review.

@@ -380,6 +380,8 @@ private PhysicalOperation planTopN(TopNExec topNExec, LocalExecutionPlannerConte
case "version" -> TopNEncoder.VERSION;
case "boolean", "null", "byte", "short", "integer", "long", "double", "float", "half_float", "datetime", "date_period",
"time_duration", "object", "nested", "scaled_float", "unsigned_long", "_doc" -> TopNEncoder.DEFAULT_SORTABLE;
// unsupported fields are encoded as BytesRef, we'll use the same encoder; all values should be null at this point
case "unsupported" -> TopNEncoder.UNSUPPORTED;
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 a form of double-checking that non-null values are not reaching TopN for unsupported data types.

Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@@ -99,19 +111,7 @@ public static List<ValueSourceInfo> sources(
var fieldContext = new FieldContext(fieldName, fieldData, fieldType);
var vsType = fieldData.getValuesSourceType();
var vs = vsType.getField(fieldContext, null);

if (asUnsupportedSource) {
Copy link
Contributor Author

@astefan astefan Oct 11, 2023

Choose a reason for hiding this comment

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

This was moved earlier in the method because there is no need for all the checks before it, if we know that the data type of the field is definitely an unsupported one. As a consequence, more tests now have warnings added to the response header for cases where we return nulls for unsupported data types.

Copy link
Contributor

@luigidellaquila luigidellaquila left a comment

Choose a reason for hiding this comment

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

LGTM, thanks @astefan!

Copy link
Contributor

@ChrisHegarty ChrisHegarty left a comment

Choose a reason for hiding this comment

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

LGTM

sources.add(
new ValueSourceInfo(
new UnsupportedValueSourceType(fieldType.typeName()),
new UnsupportedValueSource(null),
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for explicitly calling this out vs -> null. It would be easy to miss in review.

@@ -380,6 +380,8 @@ private PhysicalOperation planTopN(TopNExec topNExec, LocalExecutionPlannerConte
case "version" -> TopNEncoder.VERSION;
case "boolean", "null", "byte", "short", "integer", "long", "double", "float", "half_float", "datetime", "date_period",
"time_duration", "object", "nested", "scaled_float", "unsigned_long", "_doc" -> TopNEncoder.DEFAULT_SORTABLE;
// unsupported fields are encoded as BytesRef, we'll use the same encoder; all values should be null at this point
case "unsupported" -> TopNEncoder.UNSUPPORTED;
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@astefan astefan added v8.10.0 auto-backport-and-merge Automatically create backport pull requests and merge when ready labels Oct 11, 2023
@astefan astefan merged commit 29e3d28 into elastic:main Oct 11, 2023
13 checks passed
@astefan astefan deleted the 100048_fix branch October 11, 2023 08:48
@elasticsearchmachine
Copy link
Collaborator

💔 Backport failed

Status Branch Result
8.10 Commit could not be cherrypicked due to conflicts

You can use sqren/backport to manually backport by running backport --upstream elastic/elasticsearch --pr 100656

@astefan astefan added v8.11.0 and removed v8.10.0 labels Oct 11, 2023
astefan added a commit to astefan/elasticsearch that referenced this pull request Oct 11, 2023
… ValueSources (elastic#100656)

* Refine (and fix) all cases where an unsupported data type field's values
are returned from SourceValues.
* Improve unsupported data types handling in TopN

(cherry picked from commit 29e3d28)
elasticsearchmachine pushed a commit that referenced this pull request Oct 11, 2023
… ValueSources (#100656) (#100664)

* Refine (and fix) all cases where an unsupported data type field's values
are returned from SourceValues.
* Improve unsupported data types handling in TopN

(cherry picked from commit 29e3d28)
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-backport-and-merge Automatically create backport pull requests and merge when ready >bug Team:QL (Deprecated) Meta label for query languages team v8.11.0 v8.12.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[ES|QL] Sort returns a bug when the table has unsupportef fields
5 participants