oleg-zinovev commented on code in PR #12096:
URL: https://github.com/apache/ignite/pull/12096#discussion_r3303816401
##########
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/rel/IgniteWindow.java:
##########
@@ -179,14 +183,29 @@ public boolean isStreaming() {
* - If they are not, replace them with suitable traits.
* - Request a new trait set from the input accordingly.
*/
- private @Nullable RelTraitSet passThroughOrDerivedTraits(RelTraitSet
target) {
+ private @Nullable RelTraitSet passThroughOrDerivedTraits(RelTraitSet
target, boolean passThrough) {
if (target.getConvention() != IgniteConvention.INSTANCE)
return null;
RelTraitSet traits = target;
RelCollation requiredCollation = TraitUtils.collation(target);
if (!satisfiesCollationSansGroupFields(requiredCollation))
traits = traits.replace(collation());
+ else if (passThrough) {
+ // In case of pass through, required collation can use fields
outside of input row type.
+ // So, we should truncate required collation to input row type.
+ // We do not need any additional range checks, since current
collation keys is a prefix to required collation keys.
+ // Therefore, only additional keys in suffix can be removed here.
+ ImmutableBitSet inputColls =
ImmutableBitSet.range(input.getRowType().getFieldCount());
+
+ List<Integer> newCollationColls =
maxPrefix(requiredCollation.getKeys(), inputColls.asSet());
+ List<RelFieldCollation> newCollationFields =
requiredCollation.getFieldCollations()
+ .stream().filter(k ->
newCollationColls.contains(k.getFieldIndex())).collect(Collectors.toList());
+
+ RelCollation newCollation = RelCollations.of(newCollationFields);
+
+ traits = traits.replace(newCollation);
Review Comment:
@alex-plekhanov
https://github.com/apache/ignite/pull/12096#discussion_r3272424750
The discussion has been marked as outdated, so I’ll write here instead.
I brought back `ProjectWindowConstantsRule` (renaming it to
`WindowConstantsRule`).
At the same time, I reworked its logic:
1. If an aggregation function call inside `LogicalWindow` contains a
reference to a constant, projections will still be added as before.
2. Otherwise, only references in window bounds will be replaced with
constant values.
This way, projections will be added only for cases with constant parameters
in aggregation function calls. This avoids adding extra projections when the
function depends only on input fields.
I also added a test that uses constants in PARTITION BY and ORDER BY to
verify that these constants do not require reference replacement.
Calcite removes such grouping and sorting keys on its own
(org.apache.calcite.rel.logical.LogicalWindow#addWindows)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]