[CALCITE-1551] fix for: RelBuilder's project() doesn't preserve alias #340
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is accomplished by changing the structure of the Frame in
RelBuilder to include alias and field information for all fields in the
relnode irrespective of their origin. Rel aliases also preserved on
group keys through aggregate operations.
General approach:
Frame
now maintains a list of fields, each field having a set of rel aliases by which it can be referred to. I renamedFrame.right
toFrame.fields
and the type is nowPair<Set<String>, RelDataTypeField>
.RelBuilder.field(alias, fieldName)
modified slightly to check aliases and field name equality. Code is simpler now as there is an entry for each field.RelBuilder.project()
modified to build a field list preserving any aliases linked byRexInputRef
nodes.RelBuilder.filter()
, sort, sortLimit modified to retain the existing set of aliases & fields.RelBuilder.aggregate()
modified to retain aliases of group keys which areRexInputRef
nodes.A few notes about the patch:
PigRelBuilder
to use anull
alias for theaggregateCall()
. It was previously taken from the (first) rel alias which doesn't seem to have any utility. If this needs to do something else, I'll gladly change it.RelBuilder.field(ordinals)
uses a special version offield()
which may assign an alias. I didn't understand the original intention of this in 2193c6e. I'm no longer using thatalias
argument and everything seems to work well without it. Is it ok to remove?