vineetgarg02 commented on a change in pull request #567: HIVE-21382: Group by
keys reduction optimization - keys are not reduced in query23
URL: https://github.com/apache/hive/pull/567#discussion_r265396039
##########
File path:
ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/rules/HiveRelFieldTrimmer.java
##########
@@ -315,48 +322,128 @@ private boolean isRexLiteral(final RexNode rexNode) {
}
+ private static class TableRefFinder extends RexVisitorImpl<Void> {
+ private Set<RexTableInputRef> tableRefs = null;
+ TableRefFinder() {
+ super(true);
+ this.tableRefs = new HashSet<>();
+ }
+
+ public Set<RexTableInputRef> getTableRefs() {
+ return this.tableRefs;
+ }
+
+ @Override
+ public Void visitTableInputRef(RexTableInputRef ref) {
+ this.tableRefs.add(ref);
+ return null;
+ }
+ }
+
// Given a groupset this tries to find out if the cardinality of the
grouping columns could have changed
// because if not and it consist of keys (unique + not null OR pk), we can
safely remove rest of the columns
// if those are columns are not being used further up
private ImmutableBitSet generateGroupSetIfCardinalitySame(final Aggregate
aggregate,
final ImmutableBitSet
originalGroupSet, final ImmutableBitSet fieldsUsed) {
- Pair<RelOptTable, List<Integer>> tabToOrgCol =
HiveRelOptUtil.getColumnOriginSet(aggregate.getInput(),
-
originalGroupSet);
- if(tabToOrgCol == null) {
- return originalGroupSet;
- }
- RelOptHiveTable tbl = (RelOptHiveTable)tabToOrgCol.left;
- List<Integer> backtrackedGBList = tabToOrgCol.right;
- ImmutableBitSet backtrackedGBSet =
ImmutableBitSet.builder().addAll(backtrackedGBList).build();
- List<ImmutableBitSet> allKeys = tbl.getNonNullableKeys();
- ImmutableBitSet currentKey = null;
- for(ImmutableBitSet key:allKeys) {
- if(backtrackedGBSet.contains(key)) {
- // only if grouping sets consist of keys
- currentKey = key;
- break;
+ RexBuilder rexBuilder = aggregate.getCluster().getRexBuilder();
+ RelMetadataQuery mq = aggregate.getCluster().getMetadataQuery();
+
+ Iterator<Integer> iterator = originalGroupSet.iterator();
+ Map<Pair<RelOptTable, Integer>, Pair<List<Integer>, List<Integer>>>
mapGBKeysLineage= new HashMap<>();
Review comment:
@jcamachor
> And in L408 you could just use loop (or a lambda would be nicer) to add
the left side from the pairs in the list
But that would add an extra loop no?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services