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

[CALCITE-6744] Support getColumnOrigins for correlate in RelMdColumnOrigins #4109

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

suibianwanwank
Copy link
Contributor

This PR introduces support for the getOriginColumn method for Correlate.
To represent the origin of the corVar field, the ColumnOrigin class has been modified accordingly. This caused breaking changes, so I'm documenting it in history.md. If there's a better way to do it, welcome any suggestions.

@suibianwanwank
Copy link
Contributor Author

There are some CI errors, I'll fix it tomorrow.

@suibianwanwank suibianwanwank force-pushed the calcite-6744 branch 2 times, most recently from 5aaf7c5 to 21c5065 Compare December 24, 2024 13:17
/**
* RelColumnOrigin is a data structure describing one of the origins of an
* output column produced by a relational expression.
*/
public class RelColumnOrigin {
//~ Instance fields --------------------------------------------------------

private final RelOptTable originTable;
private final @Nullable RelOptTable originTable;
Copy link
Contributor

Choose a reason for hiding this comment

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

Ideally this would be implemented using an interface and two subclasses, one for each kind of origin.
Not sure how easy this can be accomplished while keeping compatibility.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this would also be difficult to keep compatible. Another compromise would be to keep the RelColumnOrigin unchanged and return null if the input field's CorField comes from outside the input RelNode.
This way we just need to add a Map to maintain the mapping of CorrelationId, Index to ColumnOrigin, and go top-down to getColumnOrigin.
public @Nullable Set<RelColumnOrigin> getColumnOrigins(Aggregate rel, RelMetadataQuery mq, int iOutputColumn, Map<Pair<CorrelationId, Integer>, ColumnOrigin>) corVarOriginMap) { ... }

@@ -303,6 +328,17 @@ private static Set<RelColumnOrigin> getMultipleColumns(RexNode rexNode, RelNode
}
return null;
}

@Override public Void visitFieldAccess(RexFieldAccess fieldAccess) {
Copy link
Contributor

Choose a reason for hiding this comment

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

shouldn't this actually use as origin the table that correlated variable comes from (recursively)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure I fully understand what you mean. There is a case where the RelNode that calls getColumnOrigin is not the top-level RelNode, so it may not get the original table.

assertThat(correlationId, notNullValue());
assertThat(correlationId.getName(), equalTo("$cor1"));
assertThat(origin.getOriginColumnOrdinal(), equalTo(1));
continue;
Copy link
Contributor

Choose a reason for hiding this comment

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

in this case I think that an else is more appropriate.

final RelMetadataQuery mq =
new RelMetadataQuery(metadataConfig.getDefaultHandlerProvider());
Set<RelColumnOrigin> origins =
mq.getColumnOrigins(relNode.getInput(0).getInput(1), 0);
Copy link
Contributor

Choose a reason for hiding this comment

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

is this LogicalAggregate? Maybe you can say this in a comment.

}
assertThat(origin.getOriginTable(), notNullValue());
assertThat(origin.getOriginTable().getQualifiedName().get(2), equalTo("DEPT"));
assertThat(origin.getOriginColumnOrdinal(), equalTo(1));
Copy link
Contributor

Choose a reason for hiding this comment

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

is this dept.name?

CorrelationId correlationId = origin.getCorrelationId();
assertThat(correlationId, notNullValue());
assertThat(correlationId.getName(), equalTo("$cor1"));
assertThat(origin.getOriginColumnOrdinal(), equalTo(1));
Copy link
Contributor

Choose a reason for hiding this comment

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

want to check that originTable is null too?
Is this ENAME?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants