Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
216d460
take date date_nanos autocasting out of snapshot
fang-xing-esql Aug 22, 2025
7a7d729
Merge branch 'main' into take-date-nanos-implicit-casting-out-of-snap…
fang-xing-esql Aug 22, 2025
d3001e0
fix test, add missing capabilities
fang-xing-esql Aug 22, 2025
9ad4ca3
Update docs/changelog/133369.yaml
fang-xing-esql Aug 22, 2025
19d1a5a
Merge branch 'main' into take-date-nanos-implicit-casting-out-of-snap…
fang-xing-esql Aug 22, 2025
1ea2b09
update test capabilities
fang-xing-esql Aug 25, 2025
abe317f
Merge branch 'main' into take-date-nanos-implicit-casting-out-of-snap…
fang-xing-esql Aug 25, 2025
b0f29c1
Merge branch 'main' into take-date-nanos-implicit-casting-out-of-snap…
fang-xing-esql Aug 25, 2025
e04e09d
Merge branch 'main' into take-date-nanos-implicit-casting-out-of-snap…
fang-xing-esql Aug 25, 2025
bb6f490
Merge branch 'main' into take-date-nanos-implicit-casting-out-of-snap…
fang-xing-esql Aug 26, 2025
699f22f
update docs
fang-xing-esql Aug 26, 2025
575d24d
Merge branch 'main' into take-date-nanos-implicit-casting-out-of-snap…
fang-xing-esql Aug 26, 2025
180d936
update docs
fang-xing-esql Aug 26, 2025
f3939c4
Merge branch 'main' into take-date-nanos-implicit-casting-out-of-snap…
fang-xing-esql Aug 27, 2025
2d3733f
Merge branch 'main' into take-date-nanos-implicit-casting-out-of-snap…
fang-xing-esql Aug 27, 2025
090f5aa
Merge branch 'main' into take-date-nanos-implicit-casting-out-of-snap…
fang-xing-esql Aug 28, 2025
f5a01f7
fix docs
fang-xing-esql Aug 28, 2025
0f67cb2
fix docs
fang-xing-esql Aug 28, 2025
b84c8fc
Merge branch 'main' into take-date-nanos-implicit-casting-out-of-snap…
fang-xing-esql Aug 28, 2025
eae1032
Merge branch 'main' into take-date-nanos-implicit-casting-out-of-snap…
fang-xing-esql Aug 28, 2025
479ff7a
Merge branch 'main' into take-date-nanos-implicit-casting-out-of-snap…
fang-xing-esql Aug 29, 2025
f9f99e5
update docs according to review comments
fang-xing-esql Aug 29, 2025
42a4e64
Merge branch 'main' into take-date-nanos-implicit-casting-out-of-snap…
fang-xing-esql Aug 29, 2025
8590376
Merge branch 'main' into take-date-nanos-implicit-casting-out-of-snap…
fang-xing-esql Sep 2, 2025
f795674
update doc according to review comments
fang-xing-esql Sep 2, 2025
80c37d0
Merge branch 'main' into take-date-nanos-implicit-casting-out-of-snap…
fang-xing-esql Sep 2, 2025
f454403
Merge branch 'main' into take-date-nanos-implicit-casting-out-of-snap…
fang-xing-esql Sep 2, 2025
7594c57
Merge branch 'main' into take-date-nanos-implicit-casting-out-of-snap…
fang-xing-esql Sep 2, 2025
9e03015
Merge branch 'main' into take-date-nanos-implicit-casting-out-of-snap…
fang-xing-esql Sep 3, 2025
996ab58
Merge branch 'main' into take-date-nanos-implicit-casting-out-of-snap…
fang-xing-esql Sep 3, 2025
5b195fe
add version tag to docs
fang-xing-esql Sep 3, 2025
2b16c15
Merge branch 'main' into take-date-nanos-implicit-casting-out-of-snap…
fang-xing-esql Sep 3, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
import static org.elasticsearch.test.ListMatcher.matchesList;
import static org.elasticsearch.test.MapMatcher.assertMap;
import static org.elasticsearch.test.MapMatcher.matchesMap;
import static org.elasticsearch.xpack.esql.action.EsqlCapabilities.Cap.IMPLICIT_CASTING_DATE_AND_DATE_NANOS;
import static org.elasticsearch.xpack.esql.core.type.DataType.isMillisOrNanos;
import static org.elasticsearch.xpack.esql.qa.rest.RestEsqlTestCase.Mode.SYNC;
import static org.elasticsearch.xpack.esql.tools.ProfileParser.parseProfile;
Expand Down Expand Up @@ -712,9 +711,7 @@ public void testSuggestedCast() throws IOException {
Map<String, Object> results = entityAsMap(resp);
List<?> columns = (List<?>) results.get("columns");
DataType suggestedCast = DataType.suggestedCast(Set.of(listOfTypes.get(i), listOfTypes.get(j)));
if (IMPLICIT_CASTING_DATE_AND_DATE_NANOS.isEnabled()
&& isMillisOrNanos(listOfTypes.get(i))
&& isMillisOrNanos(listOfTypes.get(j))) {
if (isMillisOrNanos(listOfTypes.get(i)) && isMillisOrNanos(listOfTypes.get(j))) {
// datetime and date_nanos are casted to date_nanos implicitly
assertThat(columns, equalTo(List.of(Map.ofEntries(Map.entry("name", "my_field"), Map.entry("type", "date_nanos")))));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ public enum Cap {
/**
* Support implicit casting for union typed fields that are mixed with date and date_nanos type.
*/
IMPLICIT_CASTING_DATE_AND_DATE_NANOS(Build.current().isSnapshot()),
IMPLICIT_CASTING_DATE_AND_DATE_NANOS,

/**
* Support for named or positional parameters in EsqlQueryRequest.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@
import static java.util.Collections.emptyList;
import static java.util.Collections.singletonList;
import static org.elasticsearch.xpack.core.enrich.EnrichPolicy.GEO_MATCH_TYPE;
import static org.elasticsearch.xpack.esql.action.EsqlCapabilities.Cap.IMPLICIT_CASTING_DATE_AND_DATE_NANOS;
import static org.elasticsearch.xpack.esql.core.type.DataType.AGGREGATE_METRIC_DOUBLE;
import static org.elasticsearch.xpack.esql.core.type.DataType.BOOLEAN;
import static org.elasticsearch.xpack.esql.core.type.DataType.DATETIME;
Expand Down Expand Up @@ -192,7 +191,7 @@ public class Analyzer extends ParameterizedRuleExecutor<LogicalPlan, AnalyzerCon
new ResolveLookupTables(),
new ResolveFunctions(),
new ResolveInference(),
new DateMillisToNanosInEsRelation(IMPLICIT_CASTING_DATE_AND_DATE_NANOS.isEnabled())
new DateMillisToNanosInEsRelation()
),
new Batch<>(
"Resolution",
Expand Down Expand Up @@ -1953,41 +1952,23 @@ private static LogicalPlan planWithoutSyntheticAttributes(LogicalPlan plan) {
*/
private static class DateMillisToNanosInEsRelation extends Rule<LogicalPlan, LogicalPlan> {

private final boolean isSnapshot;

DateMillisToNanosInEsRelation(boolean isSnapshot) {
this.isSnapshot = isSnapshot;
}

@Override
public LogicalPlan apply(LogicalPlan plan) {
if (isSnapshot) {
return plan.transformUp(EsRelation.class, relation -> {
if (relation.indexMode() == IndexMode.LOOKUP) {
return relation;
return plan.transformUp(EsRelation.class, relation -> {
if (relation.indexMode() == IndexMode.LOOKUP) {
return relation;
}
return relation.transformExpressionsUp(FieldAttribute.class, f -> {
if (f.field() instanceof InvalidMappedField imf && imf.types().stream().allMatch(DataType::isDate)) {
HashMap<ResolveUnionTypes.TypeResolutionKey, Expression> typeResolutions = new HashMap<>();
var convert = new ToDateNanos(f.source(), f);
imf.types().forEach(type -> typeResolutions(f, convert, type, imf, typeResolutions));
var resolvedField = ResolveUnionTypes.resolvedMultiTypeEsField(f, typeResolutions);
return new FieldAttribute(f.source(), f.parentName(), f.name(), resolvedField, f.nullable(), f.id(), f.synthetic());
}
return relation.transformExpressionsUp(FieldAttribute.class, f -> {
if (f.field() instanceof InvalidMappedField imf && imf.types().stream().allMatch(DataType::isDate)) {
HashMap<ResolveUnionTypes.TypeResolutionKey, Expression> typeResolutions = new HashMap<>();
var convert = new ToDateNanos(f.source(), f);
imf.types().forEach(type -> typeResolutions(f, convert, type, imf, typeResolutions));
var resolvedField = ResolveUnionTypes.resolvedMultiTypeEsField(f, typeResolutions);
return new FieldAttribute(
f.source(),
f.parentName(),
f.name(),
resolvedField,
f.nullable(),
f.id(),
f.synthetic()
);
}
return f;
});
return f;
});
} else {
return plan;
}
});
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4110,7 +4110,6 @@ public void testBucketWithIntervalInStringInGroupingReferencedInAggregation() {
}

public void testImplicitCastingForDateAndDateNanosFields() {
assumeTrue("requires snapshot", EsqlCapabilities.Cap.IMPLICIT_CASTING_DATE_AND_DATE_NANOS.isEnabled());
IndexResolution indexWithUnionTypedFields = indexWithDateDateNanosUnionType();
Analyzer analyzer = AnalyzerTestUtils.analyzer(indexWithUnionTypedFields);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2327,7 +2327,6 @@ public void testMatchFunctionStatisWithNonPushableCondition() {
}

public void testToDateNanosPushDown() {
assumeTrue("requires snapshot", EsqlCapabilities.Cap.IMPLICIT_CASTING_DATE_AND_DATE_NANOS.isEnabled());
IndexResolution indexWithUnionTypedFields = indexWithDateDateNanosUnionType();
plannerOptimizerDateDateNanosUnionTypes = new TestPlannerOptimizer(EsqlTestUtils.TEST_CFG, makeAnalyzer(indexWithUnionTypedFields));
var stats = EsqlTestUtils.statsForExistingField("date_and_date_nanos", "date_and_date_nanos_and_long");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import org.elasticsearch.license.XPackLicenseState;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.xpack.esql.EsqlTestUtils;
import org.elasticsearch.xpack.esql.action.EsqlCapabilities;
import org.elasticsearch.xpack.esql.analysis.Analyzer;
import org.elasticsearch.xpack.esql.analysis.AnalyzerContext;
import org.elasticsearch.xpack.esql.analysis.Verifier;
Expand Down Expand Up @@ -326,7 +325,6 @@ OR CIDR_MATCH(ip0, "fe80::cae2:65ff:fece:feb9") OR host == "beta\"""", matchesRe
}

public void testToDateNanos() {
assumeTrue("requires snapshot", EsqlCapabilities.Cap.IMPLICIT_CASTING_DATE_AND_DATE_NANOS.isEnabled());
IndexResolution indexWithUnionTypedFields = indexWithDateDateNanosUnionType();
plannerOptimizerDateDateNanosUnionTypes = new TestPlannerOptimizer(EsqlTestUtils.TEST_CFG, makeAnalyzer(indexWithUnionTypedFields));
var stats = EsqlTestUtils.statsForExistingField("date_and_date_nanos", "date_and_date_nanos_and_long");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -913,7 +913,7 @@ suggested_type:
- method: POST
path: /_query
parameters: []
capabilities: [suggested_cast, implicit_casting_date_and_date_nanos]
capabilities: [suggested_cast, implicit_casting_date_and_date_nanos, aggregate_metric_double]
reason: "date and date_nanos should no longer produce suggested_cast column"

- do:
Expand Down