Skip to content

Conversation

not-napoleon
Copy link
Member

@not-napoleon not-napoleon commented Sep 12, 2025

Relates to #133087

@dnhatn reported that we weren't seeing the performance improvement we expected from the null filters. I added tests and investigated, and it turns out I had forgotten to load the TS metadata from a single filed caps response. This PR includes the tests that help find the problem and the fix.

@not-napoleon not-napoleon added >test Issues or PRs that are addressing/adding tests :Analytics/ES|QL AKA ESQL v9.2.0 labels Sep 12, 2025
@elasticsearchmachine elasticsearchmachine added the Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) label Sep 12, 2025
@elasticsearchmachine
Copy link
Collaborator

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

* Tests for the {@link org.elasticsearch.xpack.esql.optimizer.rules.logical.local.IgnoreNullMetrics} planner rule, to
* verify that the filters are being pushed to Lucene.
*/
public class IgnoreNullMetricsPhysicalPlannerTests extends LocalPhysicalPlanOptimizerTests {
Copy link
Member Author

Choose a reason for hiding this comment

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

Inheriting from LocalPhysicalPlanOptimizerTests seems wrong, but there's no base class between that and MapperTestCase, and this is the strategy ReplaceRoundToWithQueryAndTagsTests uses. This does mean that all the (many) tests in LocalPhysicalPlanOptimizerTests will be re-run in this test class. I recommend refactoring the vaious plannerOptimizer objects into an abstract base class that all three of these classes can inherit their scaffolding from, but such a refactoring is out of scope for this PR, and I will defer to the people who frequently look at this code.

@not-napoleon
Copy link
Member Author

Note to future self: Remember to run test-release on this before merging

@not-napoleon not-napoleon changed the title Esql push down tests for skip null metrics Esql Fix bug with loading TS metadata Sep 12, 2025
@@ -225,7 +225,7 @@ private static EsField createField(
List<IndexFieldCapabilities> rest = fcs.subList(1, fcs.size());
DataType type = EsqlDataTypeRegistry.INSTANCE.fromEs(first.type(), first.metricType());
boolean aggregatable = first.isAggregatable();
EsField.TimeSeriesFieldType timeSeriesFieldType = EsField.TimeSeriesFieldType.UNKNOWN;
EsField.TimeSeriesFieldType timeSeriesFieldType = EsField.TimeSeriesFieldType.fromIndexFieldCapabilities(first);
Copy link
Member Author

Choose a reason for hiding this comment

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

This is the entire bug fix. Everything else in this PR is tests and test scaffolding.

Copy link
Member Author

Choose a reason for hiding this comment

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

These changes are necessary to enable running planner tests that load dimension and metric information from our json schema files. My earlier tests for this feature hard coded a test schema rather than load from json, so I didn't need this before, but we'll want it for many tests going forward.

.get();
List<Doc> sparseDocs = new ArrayList<>();
// generate 100 docs, 50 will have a null metric
// TODO: this is all copied from populateIndex(), refactor it sensibly.
Copy link
Member Author

Choose a reason for hiding this comment

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

I really don't want to refactor this test today, and copying a few dozen lines of test code isn't that big a sin. I'm going to leave this TODO for someone to take on a slow Friday.

@@ -119,14 +119,15 @@ public void testSimple() {
assumeTrue("requires metrics command", EsqlCapabilities.Cap.METRICS_COMMAND.isEnabled());
LogicalPlan actual = localPlan("""
TS test
| STATS max(max_over_time(metric_1))
| STATS max(max_over_time(metric_1)) BY BUCKET(@timestamp, 1 min)
Copy link
Member Author

Choose a reason for hiding this comment

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

Makes sure we're testing this rule and not InferNonNullAggConstraint

@dnhatn dnhatn self-requested a review September 15, 2025 05:40
Copy link
Member

@dnhatn dnhatn 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 Mark!

client().admin().indices().prepareRefresh("sparse-hosts").get();
// Control test
/*
try (EsqlQueryResponse resp = run("""
Copy link
Member

Choose a reason for hiding this comment

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

leftover?

Copy link
Member Author

Choose a reason for hiding this comment

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

probably worth keeping, I just forgot to uncomment it after running the debugger.

boolean isDimension = boolSetting(content.get("time_series_dimension"), false);
boolean isMetric = content.containsKey("time_series_metric");
if (isDimension && isMetric) {
throw new IllegalArgumentException("Field configured as both dimension and metric:" + value);
Copy link
Contributor

Choose a reason for hiding this comment

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

This should never happen here, probably IllegalStateException?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't have a strong opinion, but I chose IllegalArgumentException because this method already throws that on line 133 for other invalid mapping states.

@not-napoleon not-napoleon added the test-release Trigger CI checks against release build label Sep 15, 2025
@not-napoleon not-napoleon enabled auto-merge (squash) September 15, 2025 13:07
@not-napoleon not-napoleon removed the test-release Trigger CI checks against release build label Sep 15, 2025
@not-napoleon
Copy link
Member Author

I feel confidant that the release tests failures are unrelated to this PR, so I'm taking the tag off. I continue to wish we had a better way to do this.

@not-napoleon not-napoleon merged commit 534cdb6 into elastic:main Sep 16, 2025
34 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Analytics/ES|QL AKA ESQL Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) >test Issues or PRs that are addressing/adding tests v9.2.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants