Skip to content

Commit cc4dac3

Browse files
update according to review comments
1 parent 623c4cc commit cc4dac3

File tree

3 files changed

+33
-29
lines changed

3 files changed

+33
-29
lines changed

docs/changelog/127797.yaml

Lines changed: 0 additions & 6 deletions
This file was deleted.

docs/changelog/130026.yaml

Lines changed: 0 additions & 6 deletions
This file was deleted.

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/analysis/Analyzer.java

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ public class Analyzer extends ParameterizedRuleExecutor<LogicalPlan, AnalyzerCon
176176
new ResolveInference(),
177177
new ResolveLookupTables(),
178178
new ResolveFunctions(),
179-
new DateMillisToNanosInEsRelation()
179+
new DateMillisToNanosInEsRelation(IMPLICIT_CASTING_DATE_AND_DATE_NANOS.isEnabled())
180180
),
181181
new Batch<>(
182182
"Resolution",
@@ -1899,26 +1899,42 @@ private static LogicalPlan planWithoutSyntheticAttributes(LogicalPlan plan) {
18991899
* Cast the union typed fields in EsRelation to date_nanos if they are mixed date and date_nanos types.
19001900
*/
19011901
private static class DateMillisToNanosInEsRelation extends Rule<LogicalPlan, LogicalPlan> {
1902+
1903+
private final boolean isSnapshot;
1904+
1905+
DateMillisToNanosInEsRelation(boolean isSnapshot) {
1906+
this.isSnapshot = isSnapshot;
1907+
}
1908+
19021909
@Override
19031910
public LogicalPlan apply(LogicalPlan plan) {
1904-
if (IMPLICIT_CASTING_DATE_AND_DATE_NANOS.isEnabled() == false) {
1905-
return plan;
1906-
}
1907-
return plan.transformUp(EsRelation.class, relation -> {
1908-
if (relation.indexMode() == IndexMode.LOOKUP) {
1909-
return relation;
1910-
}
1911-
return relation.transformExpressionsUp(FieldAttribute.class, f -> {
1912-
if (f.field() instanceof InvalidMappedField imf && imf.types().stream().allMatch(DataType::isDate)) {
1913-
HashMap<ResolveUnionTypes.TypeResolutionKey, Expression> typeResolutions = new HashMap<>();
1914-
var convert = new ToDateNanos(f.source(), f);
1915-
imf.types().forEach(type -> typeResolutions(f, convert, type, imf, typeResolutions));
1916-
var resolvedField = ResolveUnionTypes.resolvedMultiTypeEsField(f, typeResolutions);
1917-
return new FieldAttribute(f.source(), f.parentName(), f.name(), resolvedField, f.nullable(), f.id(), f.synthetic());
1911+
if (isSnapshot) {
1912+
return plan.transformUp(EsRelation.class, relation -> {
1913+
if (relation.indexMode() == IndexMode.LOOKUP) {
1914+
return relation;
19181915
}
1919-
return f;
1916+
return relation.transformExpressionsUp(FieldAttribute.class, f -> {
1917+
if (f.field() instanceof InvalidMappedField imf && imf.types().stream().allMatch(DataType::isDate)) {
1918+
HashMap<ResolveUnionTypes.TypeResolutionKey, Expression> typeResolutions = new HashMap<>();
1919+
var convert = new ToDateNanos(f.source(), f);
1920+
imf.types().forEach(type -> typeResolutions(f, convert, type, imf, typeResolutions));
1921+
var resolvedField = ResolveUnionTypes.resolvedMultiTypeEsField(f, typeResolutions);
1922+
return new FieldAttribute(
1923+
f.source(),
1924+
f.parentName(),
1925+
f.name(),
1926+
resolvedField,
1927+
f.nullable(),
1928+
f.id(),
1929+
f.synthetic()
1930+
);
1931+
}
1932+
return f;
1933+
});
19201934
});
1921-
});
1935+
} else {
1936+
return plan;
1937+
}
19221938
}
19231939
}
19241940

0 commit comments

Comments
 (0)