Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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.

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);
}

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