Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance unnest support in decoupled mode #17550

Open
wants to merge 113 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 101 commits
Commits
Show all changes
113 commits
Select commit Hold shift + click to select a range
7021b3f
working?
kgyrtkirk Nov 8, 2024
54b057e
x
kgyrtkirk Nov 8, 2024
00837c5
clenaup
kgyrtkirk Nov 9, 2024
314d3f7
some updates
kgyrtkirk Nov 11, 2024
2ceefdc
try-unnestfiled-instead-rowtype
kgyrtkirk Nov 11, 2024
4e0a37a
more wood
kgyrtkirk Nov 11, 2024
e7061ad
more wood
kgyrtkirk Nov 11, 2024
b45b3ba
run trimmer
kgyrtkirk Nov 11, 2024
d38215f
ok-but alon trim should have affected native query - right?
kgyrtkirk Nov 12, 2024
322ec81
make some assert function and fail with that
kgyrtkirk Nov 12, 2024
e8f06bf
make helper method
kgyrtkirk Nov 12, 2024
04ab28f
one way
kgyrtkirk Nov 12, 2024
c49fc27
rename: d1/dbl1
kgyrtkirk Nov 12, 2024
0d03cc5
Revert "rename: d1/dbl1"
kgyrtkirk Nov 12, 2024
d4b4c94
Reapply "rename: d1/dbl1"
kgyrtkirk Nov 12, 2024
7777e48
dbl1/etc
kgyrtkirk Nov 13, 2024
0d07cf1
dbl1/etc
kgyrtkirk Nov 13, 2024
bd72b95
fix some
kgyrtkirk Nov 13, 2024
88e57f9
fix some more
kgyrtkirk Nov 13, 2024
62664e3
fix windowtests
kgyrtkirk Nov 13, 2024
0874843
fix some more
kgyrtkirk Nov 13, 2024
ced72b3
fix nondefault
kgyrtkirk Nov 13, 2024
fc31c8a
update iq files
kgyrtkirk Nov 13, 2024
a1b9f52
Merge remote-tracking branch 'apache/master' into rename-d1-dbl1
kgyrtkirk Nov 13, 2024
247ee17
fixups after merge
kgyrtkirk Nov 13, 2024
1379c9a
Merge branch 'rename-d1-dbl1' into unnest-relfieldtrimmer-unnestfield…
kgyrtkirk Nov 13, 2024
8dfd57f
update test
kgyrtkirk Nov 13, 2024
0d09c18
undo trials; re-introduce expr if needed (will be trimmed in most cases)
kgyrtkirk Nov 13, 2024
96f572e
updates/etc
kgyrtkirk Nov 13, 2024
7d9693b
aa
kgyrtkirk Nov 13, 2024
fbfed8a
update
kgyrtkirk Nov 13, 2024
f4d7ec2
cleanup/enhance rule order to simplify
kgyrtkirk Nov 14, 2024
fd564fd
cleanup/enhance rule order to simplify
kgyrtkirk Nov 14, 2024
9448ed3
enable trim for unnest
kgyrtkirk Nov 14, 2024
9afdfb2
updates
kgyrtkirk Nov 14, 2024
dcdd7d4
fix final test
kgyrtkirk Nov 14, 2024
23e4dab
trim-trim
kgyrtkirk Nov 14, 2024
a075cb9
removal of some projects
kgyrtkirk Nov 14, 2024
12373a8
fix one
kgyrtkirk Nov 14, 2024
6ee980e
update unnest.iq
kgyrtkirk Nov 14, 2024
1e5c37b
inline const back
kgyrtkirk Nov 14, 2024
acc9eb6
Merge branch 'rename-d1-dbl1' into unnest-relfieldtrimmer-unnestfield…
kgyrtkirk Nov 14, 2024
44523a8
update
kgyrtkirk Nov 14, 2024
351615a
Merge branch 'rename-d1-dbl1' into unnest-relfieldtrimmer-unnestfield…
kgyrtkirk Nov 14, 2024
f89cc82
update 2 more tests
kgyrtkirk Nov 15, 2024
f9823b0
Merge branch 'rename-d1-dbl1' into unnest-relfieldtrimmer-unnestfield…
kgyrtkirk Nov 15, 2024
3aff161
fix fail
kgyrtkirk Nov 15, 2024
797f35d
celanup
kgyrtkirk Nov 15, 2024
8800763
correct indent
kgyrtkirk Nov 15, 2024
7e46880
cleanup
kgyrtkirk Nov 15, 2024
d2e97da
add back dummyproject
kgyrtkirk Nov 15, 2024
afad58c
Merge branch 'rename-d1-dbl1' into unnest-relfieldtrimmer-unnestfield…
kgyrtkirk Nov 15, 2024
0378e65
trimmed
kgyrtkirk Nov 15, 2024
400c05e
last trim possibly nbot needed
kgyrtkirk Nov 15, 2024
79c489c
;stuf
kgyrtkirk Nov 15, 2024
4cc0077
Merge remote-tracking branch 'apache/master' into rename-d1-dbl1
kgyrtkirk Nov 20, 2024
93bae23
Merge branch 'rename-d1-dbl1' into unnest-relfieldtrimmer-unnestfield…
kgyrtkirk Nov 20, 2024
d4ebca9
enable trimmer to create blinding project
kgyrtkirk Nov 20, 2024
0c6b40c
update
kgyrtkirk Nov 20, 2024
bdfcef8
add note; conditional
kgyrtkirk Nov 21, 2024
5ca3f14
more sophisiticated filter
kgyrtkirk Nov 21, 2024
1ad8289
Merge remote-tracking branch 'apache/master' into rename-d1-dbl1
kgyrtkirk Dec 3, 2024
e67b609
Merge branch 'rename-d1-dbl1' into unnest-relfieldtrimmer-unnestfield…
kgyrtkirk Dec 3, 2024
34426e1
remove ds2
kgyrtkirk Dec 3, 2024
d536217
renames
kgyrtkirk Dec 4, 2024
8cb1178
its ok
kgyrtkirk Dec 4, 2024
e7aface
reduce
kgyrtkirk Dec 4, 2024
2c71133
x
kgyrtkirk Dec 4, 2024
285d178
dont care about filter; it only references unnest col
kgyrtkirk Dec 4, 2024
6d577f8
some stuf
kgyrtkirk Dec 4, 2024
3f3335f
updates
kgyrtkirk Dec 4, 2024
12c82dd
more w
kgyrtkirk Dec 4, 2024
7bb3d7a
convert early
kgyrtkirk Dec 4, 2024
f584ab0
convert early
kgyrtkirk Dec 4, 2024
627f4a8
up
kgyrtkirk Dec 4, 2024
b7dcbf6
cleanup
kgyrtkirk Dec 5, 2024
e72d54b
cleanup
kgyrtkirk Dec 5, 2024
1fd2add
cleanup
kgyrtkirk Dec 5, 2024
844b1f2
remove tmp tests
kgyrtkirk Dec 5, 2024
c024d1e
indent
kgyrtkirk Dec 5, 2024
928637d
add
kgyrtkirk Dec 5, 2024
e195135
try to fix unnest outputColumn
kgyrtkirk Dec 7, 2024
adfdbde
Revert "try to fix unnest outputColumn"
kgyrtkirk Dec 7, 2024
034aeed
some progress
kgyrtkirk Dec 7, 2024
48032ce
fixup
kgyrtkirk Dec 7, 2024
fa96b15
fix?
kgyrtkirk Dec 7, 2024
a830e97
uipdate
kgyrtkirk Dec 7, 2024
8f286b3
a
kgyrtkirk Dec 7, 2024
4e84219
removals
kgyrtkirk Dec 7, 2024
5c5ca27
cleanup
kgyrtkirk Dec 7, 2024
86bec3b
update
kgyrtkirk Dec 11, 2024
b8726c3
fix for sqlcompat
kgyrtkirk Dec 12, 2024
ef12701
up
kgyrtkirk Dec 12, 2024
1960994
trial of accepting empty project
kgyrtkirk Dec 13, 2024
c51607e
fix
kgyrtkirk Dec 13, 2024
a161b6c
retain for old
kgyrtkirk Dec 13, 2024
dde6e06
remove boolean
kgyrtkirk Dec 13, 2024
c8d2392
add missing override
kgyrtkirk Dec 13, 2024
e989112
Merge remote-tracking branch 'apache/master' into unnest-relfieldtrim…
kgyrtkirk Dec 13, 2024
3477592
up
kgyrtkirk Dec 13, 2024
cc7e0b4
Merge remote-tracking branch 'apache/master' into unnest-relfieldtrim…
kgyrtkirk Dec 19, 2024
7e5658e
add apidoc
kgyrtkirk Dec 19, 2024
d1e8ae1
up
kgyrtkirk Dec 19, 2024
c518b48
fix compile; add doc
kgyrtkirk Dec 19, 2024
db8d422
rename test
kgyrtkirk Dec 19, 2024
8d46ff5
update apidoc
kgyrtkirk Dec 19, 2024
9fe9b76
Merge remote-tracking branch 'apache/master' into unnest-relfieldtrim…
kgyrtkirk Jan 6, 2025
a700f52
Add test for join with input ref condition
kgyrtkirk Jan 7, 2025
8f189e4
Update test configuration and annotation for unnest predicate not sup…
kgyrtkirk Jan 7, 2025
805f775
Merge remote-tracking branch 'apache/master' into unnest-relfieldtrim…
kgyrtkirk Jan 10, 2025
96be3a2
fx
kgyrtkirk Jan 10, 2025
163dcb4
u
kgyrtkirk Jan 10, 2025
d1106cc
fix
kgyrtkirk Jan 10, 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 @@ -2494,12 +2494,11 @@ public void testJoinUsesDifferentAlgorithm(String contextName, Map<String, Objec
new QueryDataSource(
newScanQueryBuilder()
.dataSource("foo")
.virtualColumns(expressionVirtualColumn("v0", "0", ColumnType.LONG))
.columns("v0")
.columns("__time")
.columnTypes(ColumnType.LONG)
.context(defaultScanQueryContext(
queryContext,
RowSignature.builder().add("v0", ColumnType.LONG).build()
RowSignature.builder().add("__time", ColumnType.LONG).build()
Copy link
Contributor

Choose a reason for hiding this comment

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

I did not understand why the column name changes here. I don't see any other change to the test

Copy link
Member Author

Choose a reason for hiding this comment

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

no columns are needed from the left hand side; but Calcite has some tweaks here and there to avoid relnodes with 0 columns.

This PR suppresses the introduction of a column with the 0 value by the Fieldtrimmer
but in one of the rules there is also an unconditional projection of the 1st columns

which causes this change.

We should be able to handle the case of empty columns - I wanted to dig into that more deeply ; as it seems like there are also some rule combinations which may lead to an empty column set...(but forgot the testcase)

I think that in general Calcite should be able to handle these things - and we should only make
corrections in the execution engine if it causes issues.

))
.intervals(querySegmentSpec(Intervals.ETERNITY))
.build()
Expand All @@ -2518,13 +2517,18 @@ public void testJoinUsesDifferentAlgorithm(String contextName, Map<String, Objec
"a0",
"1",
ColumnType.LONG
),
expressionPostAgg(
"p0",
"(CAST(floor(100), 'DOUBLE') == \"d0\")",
ColumnType.LONG
)
)
.build()

),
"j0.",
"(CAST(floor(100), 'DOUBLE') == \"j0.d0\")",
"(1 == \"j0.p0\")",
JoinType.LEFT,
null,
JoinAlgorithm.SORT_MERGE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,19 @@
import org.apache.calcite.rel.RelNode;
import org.apache.calcite.rel.core.RelFactories;
import org.apache.calcite.rel.metadata.DefaultRelMetadataProvider;
import org.apache.calcite.rel.rules.AggregateProjectMergeRule;
import org.apache.calcite.rel.rules.CoreRules;
import org.apache.calcite.rel.rules.DateRangeRules;
import org.apache.calcite.rel.rules.FilterCorrelateRule;
import org.apache.calcite.rel.rules.FilterJoinRule.FilterIntoJoinRule.FilterIntoJoinRuleConfig;
import org.apache.calcite.rel.rules.FilterProjectTransposeRule;
import org.apache.calcite.rel.rules.JoinExtractFilterRule;
import org.apache.calcite.rel.rules.JoinPushThroughJoinRule;
import org.apache.calcite.rel.rules.ProjectMergeRule;
import org.apache.calcite.rel.rules.PruneEmptyRules;
import org.apache.calcite.sql.SqlExplainFormat;
import org.apache.calcite.sql.SqlExplainLevel;
import org.apache.calcite.sql2rel.RelDecorrelator;
import org.apache.calcite.sql2rel.RelFieldTrimmer;
import org.apache.calcite.tools.Program;
import org.apache.calcite.tools.Programs;
import org.apache.calcite.tools.RelBuilder;
Expand Down Expand Up @@ -281,11 +283,23 @@ private Program buildDecoupledLogicalOptimizationProgram(PlannerContext plannerC
builder.addMatchLimit(CalciteRulesManager.HEP_DEFAULT_MATCH_LIMIT);
builder.addRuleCollection(baseRuleSet(plannerContext));
builder.addRuleInstance(CoreRules.UNION_MERGE);
builder.addRuleInstance(FilterCorrelateRule.Config.DEFAULT.toRule());
builder.addRuleInstance(FilterProjectTransposeRule.Config.DEFAULT.toRule());
builder.addRuleInstance(JoinExtractFilterRule.Config.DEFAULT.toRule());
builder.addRuleInstance(FilterIntoJoinRuleConfig.DEFAULT.withPredicate(DruidJoinRule::isSupportedPredicate).toRule());
builder.addRuleInstance(FilterProjectTransposeRule.Config.DEFAULT.toRule());
builder.addRuleInstance(new LogicalUnnestRule());
builder.addRuleInstance(new UnnestInputCleanupRule());
return Programs.of(builder.build(), true, DefaultRelMetadataProvider.INSTANCE);

final HepProgramBuilder cleanupRules = HepProgram.builder();
cleanupRules.addRuleInstance(FilterProjectTransposeRule.Config.DEFAULT.toRule());
cleanupRules.addRuleInstance(CoreRules.PROJECT_MERGE);
cleanupRules.addRuleInstance(AggregateProjectMergeRule.Config.DEFAULT.toRule());
return Programs.sequence(
Programs.of(builder.build(), true, DefaultRelMetadataProvider.INSTANCE),
new DruidTrimFieldsProgram(),
Programs.of(cleanupRules.build(), true, DefaultRelMetadataProvider.INSTANCE)
);
}

/**
Expand Down Expand Up @@ -541,7 +555,24 @@ public RelNode run(
{
final RelBuilder relBuilder = RelFactories.LOGICAL_BUILDER.create(rel.getCluster(), null);
final RelNode decorrelatedRel = RelDecorrelator.decorrelateQuery(rel, relBuilder);
return new RelFieldTrimmer(null, relBuilder).trim(decorrelatedRel);
RelNode ret = new DruidRelFieldTrimmer(null, relBuilder).trim(decorrelatedRel);
return ret;
}

}

/** Program that trims fields. */
private static class DruidTrimFieldsProgram implements Program
{
@Override
public RelNode run(RelOptPlanner planner, RelNode rel,
RelTraitSet requiredOutputTraits,
List<RelOptMaterialization> materializations,
List<RelOptLattice> lattices)
{
final RelBuilder relBuilder = RelFactories.LOGICAL_BUILDER.create(rel.getCluster(), null);
RelNode ret = new DruidRelFieldTrimmer(null, relBuilder).trim(rel);
return ret;
}
}
}
Loading
Loading