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

QL: Preserve subfields for invalid types #100875

Merged
merged 5 commits into from
Oct 16, 2023
Merged

Conversation

costin
Copy link
Member

@costin costin commented Oct 15, 2023

In certain scenarios, a field can be mapped both as a primitive and
object, causing it to be marked as unsupported, losing any potential
subfields that might have been discovered before.
This commit preserve them to avoid subfields from being incorrectly
reported as missing.

Fix #100869

In certain scenarios, a field can be mapped both as a primitive and
 object, causing it to be marked as unsupported, losing any potential
 subfields that might have been discovered before.
This commit preserve them to avoid subfields from being incorrectly
 reported as missing.

Fix elastic#100869
@elasticsearchmachine
Copy link
Collaborator

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

@elasticsearchmachine
Copy link
Collaborator

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

@elasticsearchmachine
Copy link
Collaborator

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

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!

Copy link
Contributor

@astefan astefan left a comment

Choose a reason for hiding this comment

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

This changes a fundamental behavior in IndexResolver, more specifically: #50823. We decided back then, according to PR's description, that all sub-fields of an unsupported root field to be unsupported as well.

I don't remember exactly why we did this, the code changes there start from the new (back then) "flattened" data type, but the hierarchy of an unsupported root field being marked as unsupported as well, was discovered/discussed/decided in the middle of the PR development.

Please, note one breaking (?) change this PR introduces in SQL, I haven't looked as EQL but likely it's the same:

  • before this PR, query select file.name from "test*" would have complained about file.name not existing in the merged mappings
  • with this PR, the query succeeds and returns the values it finds.

Digging deeper into this issue, I strongly believe the fact that in one case we report the field as missing (from test* | where file.name is not null) but not in an apparently almost identical query from the verification pov (from test* | where file.name is not null | stats count(*)) is the result of #98987. With that PR in place we don't have visibility in the upper hierarchy of file.name unless file is specifically asked in the query. Because of this we are required to re-build the hierarchy from bits and pieces. Without that PR, we get back in field_caps response the full list of file fields and we can decide what's the real (aka useful) hierarchy for file.name.

There are likely many implications/unknowns/concerns here; naming two that I clearly see:

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.

The change to expose the subfields LGTM, but wondering about the considerations when choosing this solution. In the case of #100869, there are three options available:

  • discard everything on any conflict (existing solution, with issues).
  • keep "top" field, if this isn't an object (i.e. file field) and drop subfields (file.name).
  • drop top field (even though not an object) and keep the non-conflicting subfields.

Not sure what the expectation would be in this case. So we can prescribe a solution here, but we're making a choice which might not be always desirable.

Generally, I believe the 1st option would be the most consistent, but practically, the 3rd might be the most practical (even if it seems a bit arbitrary in the case of #100869).

@costin costin changed the title QL: Preserve subfields for unsupported types QL: Preserve subfields for invalid types Oct 16, 2023
@costin
Copy link
Member Author

costin commented Oct 16, 2023

I have updated the PR taking @astefan suggestion - for EQL and SQL the previous behavior is in place, ESQL however changes it and keeps the old properties.

A clarification - this change affects invalid fields not unsupported ones; I used the incorrect terminology in my PR which might have caused confusion. Hierarchies of Unsupported fields are still supported but marked as unsupported so fields do get reported but don't disappear (as is the current case).

@bpintea the current solution keeps all the fields and will allow queries that work on non-conflicting/invalid fields to work while those that touch on invalid ones to report an error (don't use field x, is invalid).
I expect this issue to be a focus for us moving forward in providing means to solve such conflicts at runtime through dedicated functions/commands the user can opt into.

@costin costin added v8.11.1 and removed v8.11.0 labels Oct 16, 2023
@costin costin merged commit 5da8c6c into elastic:main Oct 16, 2023
@costin costin deleted the fix/100869 branch October 16, 2023 22:46
@elasticsearchmachine
Copy link
Collaborator

💚 Backport successful

Status Branch Result
8.11

costin added a commit to costin/elasticsearch that referenced this pull request Oct 16, 2023
In certain scenarios, a field can be mapped both as a primitive and
 object, causing it to be marked as unsupported, losing any potential
 subfields that might have been discovered before.
This commit preserve them to avoid subfields from being incorrectly
 reported as missing.

Fix elastic#100869
elasticsearchmachine pushed a commit that referenced this pull request Oct 16, 2023
In certain scenarios, a field can be mapped both as a primitive and
 object, causing it to be marked as unsupported, losing any potential
 subfields that might have been discovered before.
This commit preserve them to avoid subfields from being incorrectly
 reported as missing.

Fix #100869
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

QL: IndexResolver issue when dealing with dotted fields
5 participants