[
https://issues.apache.org/jira/browse/CALCITE-5061?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17536548#comment-17536548
]
Ruben Q L commented on CALCITE-5061:
------------------------------------
[~thomas.rebele], I think [~julianhyde] has a point when he claims that this
particular problem (as it is phrased in the ticket title) could / should be
solved by improving the existing {{RelFieldTrimmer}}. That does not mean, of
course, that we should not study further improvements (e.g. decoupling field
usage & field trimming on different entities) on other separate tickets.
If I an not mistaken, the current ticket (even if a RelNode itself cannot be
trimmed, try to trim inside its subtree as much as possible) could be solved by
adapting the "default" method for "generic" RelNodes in {{RelFieldTrimmer}},
i.e. instead of doing this:
{code}
public TrimResult trimFields(
RelNode rel,
ImmutableBitSet fieldsUsed,
Set<RelDataTypeField> extraFields) {
// We don't know how to trim this kind of relational expression, so give it
back intact.
Util.discard(fieldsUsed);
return result(rel,
Mappings.createIdentity(rel.getRowType().getFieldCount()));
}
{code}
Try something like this (*code not verified*):
{code}
public TrimResult trimFields(
RelNode rel,
ImmutableBitSet fieldsUsed,
Set<RelDataTypeField> extraFields) {
// We don't know how to trim this kind of relational expression
Util.discard(fieldsUsed);
if (rel.getInputs().isEmpty()) {
return result(rel,
Mappings.createIdentity(rel.getRowType().getFieldCount()));
}
// We don't know how to trim this RelNode, but we can try to trim inside
its inputs
List<RelNode> newInputs = new ArrayList<>(rel.getInputs().size());
for (RelNode input : rel.getInputs()) {
ImmutableBitSet inputFieldsUsed =
ImmutableBitSet.range(input.getRowType().getFieldCount());
TrimResult trimResult = dispatchTrimFields(input, inputFieldsUsed,
extraFields);
if (!trimResult.right.isIdentity()) {
throw new IllegalArgumentException();
}
newInputs.add(trimResult.left);
}
RelNode newRel = rel.copy(rel.getTraitSet(), newInputs);
return result(newRel,
Mappings.createIdentity(newRel.getRowType().getFieldCount()));
}
{code}
When I have some time, I'll try to produce a PR with this proposal.
> Improve recursive application of the field trimming
> ---------------------------------------------------
>
> Key: CALCITE-5061
> URL: https://issues.apache.org/jira/browse/CALCITE-5061
> Project: Calcite
> Issue Type: Improvement
> Reporter: Thomas Rebele
> Assignee: Thomas Rebele
> Priority: Major
>
> The RelFieldTrimmer has some shortcomings:
> * If the plan contains certain set ops (e.g., UNION(all=false)), even if the
> operator needs all fields for the correct result (CALCITE-3399), it may still
> make sense to apply the trimming to the children. See CALCITE-5051 for an
> example.
> * Same applies for a Sort with dynamic parameters in the fetch/offset, and
> RepeatUnions
> * The makeZeroLiteral logic in trimChildRestore(...) does not work for ARRAY
> / Java types.
--
This message was sent by Atlassian Jira
(v8.20.7#820007)