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-1551] fix for: RelBuilder's project() doesn't preserve alias #340

Closed
wants to merge 4 commits into from

Conversation

jbalint
Copy link
Member

@jbalint jbalint commented Dec 27, 2016

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:

  • Each Frame now maintains a list of fields, each field having a set of rel aliases by which it can be referred to. I renamed Frame.right to Frame.fields and the type is now Pair<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 by RexInputRef nodes.
  • RelBuilder.filter(), sort, sortLimit modified to retain the existing set of aliases & fields.
  • RelBuilder.aggregate() modified to retain aliases of group keys which are RexInputRef nodes.

A few notes about the patch:

  • Changed PigRelBuilder to use a null alias for the aggregateCall(). 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 of field() which may assign an alias. I didn't understand the original intention of this in 2193c6e. I'm no longer using that alias argument and everything seems to work well without it. Is it ok to remove?

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.
julianhyde added a commit to julianhyde/calcite that referenced this pull request Dec 29, 2016
@asfgit asfgit closed this in 31d68f7 Dec 30, 2016
ldming pushed a commit to ldming/mycalcite that referenced this pull request Sep 13, 2018
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.

In PigRelBuilder, we retain aggregate aliases, because Pig Latin
relies upon them.

Close apache/calcite#340
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.

1 participant