Skip to content
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
f865774
put date date_nanos implicit casting rule behind snapshot
fang-xing-esql Jun 25, 2025
033bf4a
Update docs/changelog/130026.yaml
fang-xing-esql Jun 25, 2025
5c33194
Merge branch 'main' into date-nanos-implicit-casting-behind-snapshot
fang-xing-esql Jun 25, 2025
dbfea50
Merge branch 'main' into date-nanos-implicit-casting-behind-snapshot
fang-xing-esql Jun 26, 2025
623c4cc
Merge branch 'main' into date-nanos-implicit-casting-behind-snapshot
fang-xing-esql Jun 26, 2025
cc4dac3
update according to review comments
fang-xing-esql Jun 26, 2025
d99300c
Merge branch 'main' into date-nanos-implicit-casting-behind-snapshot
fang-xing-esql Jun 27, 2025
19a29cd
Merge branch 'main' into date-nanos-implicit-casting-behind-snapshot
fang-xing-esql Jun 27, 2025
3ac7e58
Merge branch 'main' into date-nanos-implicit-casting-behind-snapshot
fang-xing-esql Jul 1, 2025
12c2693
Merge branch 'main' into date-nanos-implicit-casting-behind-snapshot
fang-xing-esql Jul 1, 2025
921eb11
Merge branch 'main' into date-nanos-implicit-casting-behind-snapshot
fang-xing-esql Jul 1, 2025
2489f5d
Merge branch 'main' into date-nanos-implicit-casting-behind-snapshot
fang-xing-esql Jul 2, 2025
3549595
Merge branch 'main' into date-nanos-implicit-casting-behind-snapshot
fang-xing-esql Jul 2, 2025
b33b12a
Update docs/changelog/130026.yaml
fang-xing-esql Jul 2, 2025
ad4f789
clean up
fang-xing-esql Jul 2, 2025
945efd5
Update docs/changelog/130026.yaml
fang-xing-esql Jul 2, 2025
76b3548
remove/undo changelog
fang-xing-esql Jul 2, 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
6 changes: 0 additions & 6 deletions docs/changelog/127797.yaml

This file was deleted.

6 changes: 6 additions & 0 deletions docs/changelog/130026.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pr: 130026
summary: Ensure date/date_nanos implicit casting rule behind snapshot
area: ES|QL
type: bug
Copy link
Contributor

Choose a reason for hiding this comment

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

This re-appeared - I think you'll have to mark this PR as >non-issue, otherwise the bot will probably insist on the changelog entry.

issues:
- 130003
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@
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.BOOLEAN;
import static org.elasticsearch.xpack.esql.core.type.DataType.DATETIME;
import static org.elasticsearch.xpack.esql.core.type.DataType.DATE_NANOS;
Expand Down Expand Up @@ -175,7 +176,7 @@ public class Analyzer extends ParameterizedRuleExecutor<LogicalPlan, AnalyzerCon
new ResolveInference(),
new ResolveLookupTables(),
new ResolveFunctions(),
new DateMillisToNanosInEsRelation()
new DateMillisToNanosInEsRelation(IMPLICIT_CASTING_DATE_AND_DATE_NANOS.isEnabled())
),
new Batch<>(
"Resolution",
Expand Down Expand Up @@ -1819,10 +1820,6 @@ private static boolean canConvertOriginalTypes(MultiTypeEsField multiTypeEsField

private static Expression typeSpecificConvert(ConvertFunction convert, Source source, DataType type, InvalidMappedField mtf) {
EsField field = new EsField(mtf.getName(), type, mtf.getProperties(), mtf.isAggregatable());
return typeSpecificConvert(convert, source, field);
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 a small refactor.

}

private static Expression typeSpecificConvert(ConvertFunction convert, Source source, EsField field) {
FieldAttribute originalFieldAttr = (FieldAttribute) convert.field();
FieldAttribute resolvedAttr = new FieldAttribute(
source,
Expand Down Expand Up @@ -1902,23 +1899,42 @@ private static LogicalPlan planWithoutSyntheticAttributes(LogicalPlan plan) {
* Cast the union typed fields in EsRelation to date_nanos if they are mixed date and date_nanos types.
*/
private static class DateMillisToNanosInEsRelation extends Rule<LogicalPlan, LogicalPlan> {

private final boolean isSnapshot;

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

@Override
public LogicalPlan apply(LogicalPlan plan) {
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());
if (isSnapshot) {
return plan.transformUp(EsRelation.class, relation -> {
if (relation.indexMode() == IndexMode.LOOKUP) {
return relation;
}
return f;
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;
});
});
});
} else {
return plan;
}
}
}

Expand Down
Loading