Skip to content

Commit 39dedf2

Browse files
committed
WIP Using only 'synthetic' in union types removal to fix fork bug
1 parent dcdbbe0 commit 39dedf2

File tree

2 files changed

+47
-2
lines changed

2 files changed

+47
-2
lines changed

x-pack/plugin/esql/qa/testFixtures/src/main/resources/union_types.csv-spec

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1397,6 +1397,22 @@ event_duration:long | _index:keyword | ts:date | ts_str:
13971397
8268153 | sample_data_ts_nanos | 2023-10-23T13:52:55.015Z | 2023-10-23T13:52:55.015123456Z | 1698069175015123456 | 172.21.3.15 | 172.21.3.15
13981398
;
13991399

1400+
multiIndexInlinestatsOfMultiTypedField
1401+
required_capability: inlinestats_v11
1402+
// https://github.com/elastic/elasticsearch/issues/133973
1403+
FROM apps, apps_short
1404+
| INLINESTATS s = sum(id::integer)
1405+
| SORT name, version
1406+
| LIMIT 5
1407+
;
1408+
1409+
id:unsupported | name:keyword | version:version | s:long
1410+
null | aaaaa | 1 | 210
1411+
null | aaaaa | 1 | 210
1412+
null | aaaaa | 1.2.3.4 | 210
1413+
null | aaaaa | 1.2.3.4 | 210
1414+
null | bbbbb | 2.1 | 210
1415+
;
14001416

14011417
inlineStatsUnionGroup-Ignore
14021418
required_capability: union_types
@@ -1720,6 +1736,33 @@ id:integer | name:keyword | count:long
17201736
14 | mmmmm | 2
17211737
;
17221738

1739+
shortIntegerWideningFork
1740+
required_capability: union_types
1741+
required_capability: casting_operator
1742+
required_capability: union_types_numeric_widening
1743+
required_capability: fork_v9
1744+
1745+
FROM apps, apps_short
1746+
| EVAL x = id::integer
1747+
| FORK (WHERE true) (WHERE true)
1748+
| DROP _fork
1749+
| SORT x ASC, name ASC, version ASC
1750+
| LIMIT 10
1751+
;
1752+
1753+
id:unsupported | name:keyword | version:version | x:integer
1754+
null | aaaaa | 1 | 1
1755+
null | aaaaa | 1 | 1
1756+
null | aaaaa | 1 | 1
1757+
null | aaaaa | 1 | 1
1758+
null | bbbbb | 2.1 | 2
1759+
null | bbbbb | 2.1 | 2
1760+
null | bbbbb | 2.1 | 2
1761+
null | bbbbb | 2.1 | 2
1762+
null | ccccc | 2.3.4 | 3
1763+
null | ccccc | 2.3.4 | 3
1764+
;
1765+
17231766
ImplicitCastingMultiTypedFieldsKeepSort
17241767
required_capability: date_nanos_type
17251768
required_capability: implicit_casting_date_and_date_nanos

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,9 @@ private LogicalPlan resolveFork(Fork fork, AnalyzerContext context) {
812812
// We don't want to keep the same attributes that are outputted by the FORK branches.
813813
// Keeping the same attributes can have unintended side effects when applying optimizations like constant folding.
814814
for (Attribute attr : outputUnion) {
815-
newOutput.add(new ReferenceAttribute(attr.source(), null, attr.name(), attr.dataType()));
815+
newOutput.add(
816+
new ReferenceAttribute(attr.source(), null, attr.name(), attr.dataType(), Nullability.FALSE, null, attr.synthetic())
817+
);
816818
}
817819

818820
return changed ? new Fork(fork.source(), newSubPlans, newOutput) : fork;
@@ -1960,7 +1962,7 @@ private static LogicalPlan planWithoutSyntheticAttributes(LogicalPlan plan) {
19601962

19611963
for (Attribute attr : output) {
19621964
// Do not let the synthetic union type field attributes end up in the final output.
1963-
if (attr.synthetic() && attr instanceof FieldAttribute) {
1965+
if (attr.synthetic()) {
19641966
continue;
19651967
}
19661968
newOutput.add(attr);

0 commit comments

Comments
 (0)