Skip to content

Fix incorrect nullify with unmapped fields#142300

Merged
idegtiarenko merged 20 commits intoelastic:mainfrom
idegtiarenko:fix_nullify
Mar 9, 2026
Merged

Fix incorrect nullify with unmapped fields#142300
idegtiarenko merged 20 commits intoelastic:mainfrom
idegtiarenko:fix_nullify

Conversation

@idegtiarenko
Copy link
Copy Markdown
Contributor

@idegtiarenko idegtiarenko commented Feb 11, 2026

This change fixes unexpected behavior when some columns are incorrectly nullified when using SET unmapped_fields="nullify";

Fixes: #141870

@idegtiarenko idegtiarenko added Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) :Analytics/ES|QL AKA ESQL v9.4.0 labels Feb 11, 2026
@idegtiarenko idegtiarenko marked this pull request as ready for review February 24, 2026 07:21
@elasticsearchmachine
Copy link
Copy Markdown
Collaborator

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

@elasticsearchmachine
Copy link
Copy Markdown
Collaborator

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

Copy link
Copy Markdown
Contributor

@alex-spies alex-spies left a comment

Choose a reason for hiding this comment

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

Heya, this fixes #141870, right?

Can we maybe add a test suite that runs any spec tests that don't have a SETting and we add SET unmapped_fields="nullify" to it?

That would be a nice invariant that future tests also mustn't break this setting.

@elasticsearchmachine
Copy link
Copy Markdown
Collaborator

Hi @idegtiarenko, I've updated the changelog YAML for you.

# Conflicts:
#	x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/analysis/rules/ResolveUnmapped.java
# Conflicts:
#	x-pack/plugin/esql/qa/server/src/main/java/org/elasticsearch/xpack/esql/qa/rest/EsqlSpecTestCase.java
Comment on lines +57 to +63
// TODO we should implement more generic randomization for SET parameters
return randomBoolean()
&& testCase.expectedWarnings().isEmpty() // avoid shifting warnings positions in source query
&& testCase.expectedWarningsRegex().isEmpty() // regexp might also contain line/position
&& query.startsWith("SET") == false // avoid conflicts with provided settings
? "SET unmapped_fields=\"nullify\"; " + query
: query;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe this should be the default randomization, rather than the single node specific one? What do you think?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

As discussed, this randomization only works if all nodes running the test support the required capabilities. This is generally only true for the single and multi-node tests, not the mixed cluster tests and ccq bwc tests.

Let's also randomize for our multi-node tests, though?

Copy link
Copy Markdown
Contributor

@alex-spies alex-spies left a comment

Choose a reason for hiding this comment

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

Super nice fix, thanks @idegtiarenko ! LGTM, only minor comments. Please address at your own discretion and :shipit:, or let me know if you're out of capacity and I'll take this and foster it into main.

required_capability: optional_fields_nullify_tech_preview
required_capability: optional_fields_fix_unmapped_field_detection

SET unmapped_fields="nullify"; FROM date_nanos | SORT millis ASC | WHERE millis < "2000-01-01" | EVAL nanos = MV_MIN(nanos) | KEEP nanos;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: formatting, in csv tests we normally put every command into a separate line.

Comment on lines +17 to +18
required_capability: optional_fields_nullify_tech_preview
required_capability: optional_fields_fix_unmapped_field_detection
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: if you require optional_fields_fix_unmapped_field_detection, you don't also need to require optional_fields_nullify_tech_preview.

;

keepMapped
required_capability: date_nanos_type
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

That capability is switched on for super long now (since #117080). That's old enough that any bwc test can assume that capability is permanently switched on.

Let's remove it - this test is skipped based on the optional_fields_fix_unmapped_field_detection capability, anyway.

required_capability: optional_fields_nullify_tech_preview
required_capability: optional_fields_fix_unmapped_field_detection

SET unmapped_fields="nullify"; FROM date_nanos | SORT millis ASC | WHERE millis < "2000-01-01" | EVAL nanos = MV_MIN(nanos) | KEEP nanos;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: a small comment on the test would help, e.g. with a link to the issue that we close.
I presume this reproduces because ResolveRefs stops at the WHERE millis < "2000-01-01" and needs to pass control to ImplicitCasting before continuing - and in between, ResolveUnmapped is being run, wrongly assuming that any unresolved refs are due to missing fields that stop ResolveRefs from continuing.

Copy link
Copy Markdown
Contributor

@alex-spies alex-spies left a comment

Choose a reason for hiding this comment

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

Let's backport to 9.3, however. I'll add the labels, esp. the auto-backport one.

@alex-spies alex-spies added auto-backport Automatically create backport pull requests when merged v9.3.2 labels Mar 5, 2026
# Conflicts:
#	x-pack/plugin/esql/qa/server/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/esql/qa/multi_node/EsqlSpecIT.java
#	x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/action/EsqlCapabilities.java
@idegtiarenko idegtiarenko merged commit 1bb4312 into elastic:main Mar 9, 2026
36 checks passed
@idegtiarenko idegtiarenko deleted the fix_nullify branch March 9, 2026 09:45
@elasticsearchmachine
Copy link
Copy Markdown
Collaborator

💔 Backport failed

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

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

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 Automatically create backport pull requests when merged >bug Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) v9.3.2 v9.4.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ESQL: bugs in unmapped_fields="nullify" from spec tests

3 participants