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-6893] Remove agg from Union children in IntersectToDistinctRule #4246

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

Conversation

xiedeyantu
Copy link
Contributor

Jira link: CALCITE-6893

@@ -44,25 +48,16 @@
*
* <h2>Example</h2>
*
* <p>Query: <code>R1 Intersect All R2</code>
* <p>Query: <code>R1 Intersect R2</code>
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you revise this whole section? The previous author used terms such as 'GB' (which is used in Hive but not in Calcite). I suspect that SQL queries are clearer than pseudo-relational algebra.

// Generate count(*) filter (where i = n) as count_i{n}
aggCalls[i] = relBuilder.countStar(null)
.filter(
relBuilder.equals(relBuilder.field(indexAlias),
Copy link
Contributor

Choose a reason for hiding this comment

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

don't use indexAlias (a string); use an int

aggCalls[i] = relBuilder.countStar(null)
.filter(
relBuilder.equals(relBuilder.field(indexAlias),
relBuilder.literal(i))).as(countPrefix + i);
Copy link
Contributor

Choose a reason for hiding this comment

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

fix indent

}

// create a union above all the branches
final int branchCount = intersect.getInputs().size();
Copy link
Contributor

Choose a reason for hiding this comment

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

i prefer the old name, branchCount, to inputCount.

relBuilder.equals(relBuilder.field(fieldCount - 1),
rexBuilder.makeBigintLiteral(new BigDecimal(branchCount))));
// Add filter count_i{n} > 0 for each branch
relBuilder.filter(relBuilder.and(filters));
Copy link
Contributor

Choose a reason for hiding this comment

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

relBuilder.filter(relBuilder.and(filters))relBuilder.filter(filters)


// Project all but the last field
relBuilder.project(Util.skipLast(relBuilder.fields()));
// Project all but the last added field(e.g. i and count_i{n})
Copy link
Contributor

Choose a reason for hiding this comment

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

add space before '('

final int oriFieldCount = intersect.getRowType().getFieldCount();
final int inputCount = intersect.getInputs().size();

AggCall[] aggCalls = new AggCall[inputCount];
Copy link
Contributor

Choose a reason for hiding this comment

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

use list rather than array

relBuilder.push(input);
relBuilder.aggregate(relBuilder.groupKey(relBuilder.fields()),
relBuilder.countStar(null));
final String countPrefix = "count_i";
Copy link
Contributor

Choose a reason for hiding this comment

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

inline countPrefix. no need for a variable (when you start using field ordinals rather than field names)

relBuilder.push(input);
relBuilder.aggregate(relBuilder.groupKey(relBuilder.fields()),
relBuilder.countStar(null));
final String countPrefix = "count_i";
Copy link
Contributor

Choose a reason for hiding this comment

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

You've removed more comments than you've added. This method doesn't need line-by-line comments but a 'here's the overall plan' comment is necessary. Give a good example of the SQL you intend to generate.

// Add a constant column "i" for each input
fields.add(
relBuilder.alias(
rexBuilder.makeBigintLiteral(new BigDecimal(i)), indexAlias));
Copy link
Contributor

Choose a reason for hiding this comment

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

why bigint not int?

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