ImmutableBitSet gbKeysDeleted = originalGroupSet.except(updatedGroupSet); ImmutableBitSet updatedGroupFields = ImmutableBitSet.range(originalGroupSet.cardinality()); final int updatedGroupCount = updatedGroupSet.cardinality();
/** Returns a bit set the same as this but with a given bit cleared if * condition is true. */ public ImmutableBitSet clearIf(int i, boolean condition) { return condition ? except(ImmutableBitSet.of(i)) : this; }
/** Returns a bit set the same as this but with a given bit cleared if * condition is true. */ public ImmutableBitSet clearIf(int i, boolean condition) { return condition ? except(ImmutableBitSet.of(i)) : this; }
/** Returns a bit set the same as this but with a given bit cleared. */ public ImmutableBitSet clear(int i) { return except(ImmutableBitSet.of(i)); }
/** Returns a bit set the same as this but with a given bit cleared. */ public ImmutableBitSet clear(int i) { return except(ImmutableBitSet.of(i)); }
public double cardinality(ImmutableBitSet columnOrdinals) { final ImmutableBitSet originalOrdinals = columnOrdinals; for (;;) { final Distribution distribution = distributionMap.get(columnOrdinals); if (distribution != null) { if (columnOrdinals == originalOrdinals) { return distribution.cardinality; } else { final List<Double> cardinalityList = new ArrayList<>(); cardinalityList.add(distribution.cardinality); for (int ordinal : originalOrdinals.except(columnOrdinals)) { final Distribution d = singletonDistributionList.get(ordinal); cardinalityList.add(d.cardinality); } return Lattice.getRowCount(rowCount.rowCount, cardinalityList); } } // Clear the last bit and iterate. // Better would be to combine all of our nearest ancestors. final List<Integer> list = columnOrdinals.asList(); columnOrdinals = columnOrdinals.clear(Util.last(list)); } } }
public double cardinality(ImmutableBitSet columnOrdinals) { final ImmutableBitSet originalOrdinals = columnOrdinals; for (;;) { final Distribution distribution = distributionMap.get(columnOrdinals); if (distribution != null) { if (columnOrdinals == originalOrdinals) { return distribution.cardinality; } else { final List<Double> cardinalityList = new ArrayList<>(); cardinalityList.add(distribution.cardinality); for (int ordinal : originalOrdinals.except(columnOrdinals)) { final Distribution d = singletonDistributionList.get(ordinal); cardinalityList.add(d.cardinality); } return Lattice.getRowCount(rowCount.rowCount, cardinalityList); } } // Clear the last bit and iterate. // Better would be to combine all of our nearest ancestors. final List<Integer> list = columnOrdinals.asList(); columnOrdinals = columnOrdinals.clear(Util.last(list)); } } }
/** Estimates the cardinality of a collection of columns represented by * {@code columnOrdinals}, drawing on existing distributions. Does not * look in the distribution map for this column set. */ private double expectedCardinality(double rowCount, ImmutableBitSet columns) { switch (columns.cardinality()) { case 0: return 1d; case 1: return rowCount; default: double c = rowCount; for (ImmutableBitSet bitSet : keyPoset.getParents(columns, true)) { if (bitSet.isEmpty()) { // If the parent is the empty group (i.e. "GROUP BY ()", the grand // total) we cannot improve on the estimate. continue; } final Distribution d1 = distributions.get(bitSet); final double c2 = cardinality(rowCount, columns.except(bitSet)); final double d = Lattice.getRowCount(rowCount, d1.cardinality, c2); c = Math.min(c, d); } for (ImmutableBitSet bitSet : keyPoset.getChildren(columns, true)) { final Distribution d1 = distributions.get(bitSet); c = Math.min(c, d1.cardinality); } return c; } }
/** Estimates the cardinality of a collection of columns represented by * {@code columnOrdinals}, drawing on existing distributions. Does not * look in the distribution map for this column set. */ private double expectedCardinality(double rowCount, ImmutableBitSet columns) { switch (columns.cardinality()) { case 0: return 1d; case 1: return rowCount; default: double c = rowCount; for (ImmutableBitSet bitSet : keyPoset.getParents(columns, true)) { if (bitSet.isEmpty()) { // If the parent is the empty group (i.e. "GROUP BY ()", the grand // total) we cannot improve on the estimate. continue; } final Distribution d1 = distributions.get(bitSet); final double c2 = cardinality(rowCount, columns.except(bitSet)); final double d = Lattice.getRowCount(rowCount, d1.cardinality, c2); c = Math.min(c, d); } for (ImmutableBitSet bitSet : keyPoset.getChildren(columns, true)) { final Distribution d1 = distributions.get(bitSet); c = Math.min(c, d1.cardinality); } return c; } }
space.columnOrdinals.except(s.columnOrdinals); for (int i : s.columnOrdinals) { final Space s1 = singletonSpaces.get(i);
space.columnOrdinals.except(s.columnOrdinals); for (int i : s.columnOrdinals) { final Space s1 = singletonSpaces.get(i);
space.columnOrdinals.except(s.columnOrdinals); for (int i : s.columnOrdinals) { final Space s1 = singletonSpaces.get(i);
space.columnOrdinals.except(s.columnOrdinals); for (int i : s.columnOrdinals) { final Space s1 = singletonSpaces.get(i);
private static void addWindows( Multimap<WindowKey, RexOver> windowMap, RexOver over, final int inputFieldCount) { final RexWindow aggWindow = over.getWindow(); // Look up or create a window. RelCollation orderKeys = getCollation( Lists.newArrayList( Util.filter(aggWindow.orderKeys, rexFieldCollation -> // If ORDER BY references constant (i.e. RexInputRef), // then we can ignore such ORDER BY key. rexFieldCollation.left instanceof RexLocalRef))); ImmutableBitSet groupSet = ImmutableBitSet.of(getProjectOrdinals(aggWindow.partitionKeys)); final int groupLength = groupSet.length(); if (inputFieldCount < groupLength) { // If PARTITION BY references constant, we can ignore such partition key. // All the inputs after inputFieldCount are literals, thus we can clear. groupSet = groupSet.except(ImmutableBitSet.range(inputFieldCount, groupLength)); } WindowKey windowKey = new WindowKey( groupSet, orderKeys, aggWindow.isRows(), aggWindow.getLowerBound(), aggWindow.getUpperBound()); windowMap.put(windowKey, over); } }
private static void addWindows( Multimap<WindowKey, RexOver> windowMap, RexOver over, final int inputFieldCount) { final RexWindow aggWindow = over.getWindow(); // Look up or create a window. RelCollation orderKeys = getCollation( Lists.newArrayList( Util.filter(aggWindow.orderKeys, rexFieldCollation -> // If ORDER BY references constant (i.e. RexInputRef), // then we can ignore such ORDER BY key. rexFieldCollation.left instanceof RexLocalRef))); ImmutableBitSet groupSet = ImmutableBitSet.of(getProjectOrdinals(aggWindow.partitionKeys)); final int groupLength = groupSet.length(); if (inputFieldCount < groupLength) { // If PARTITION BY references constant, we can ignore such partition key. // All the inputs after inputFieldCount are literals, thus we can clear. groupSet = groupSet.except(ImmutableBitSet.range(inputFieldCount, groupLength)); } WindowKey windowKey = new WindowKey( groupSet, orderKeys, aggWindow.isRows(), aggWindow.getLowerBound(), aggWindow.getUpperBound()); windowMap.put(windowKey, over); } }