Java Code Examples for org.apache.calcite.util.ImmutableBitSet#union()

The following examples show how to use org.apache.calcite.util.ImmutableBitSet#union() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RelMdColumnUniqueness.java    From calcite with Apache License 2.0 6 votes vote down vote up
/**
 * Deduce constant columns from predicates of rel and return the union
 * bitsets of checkingColumns and the constant columns.
 */
private static ImmutableBitSet decorateWithConstantColumnsFromPredicates(
    ImmutableBitSet checkingColumns, RelNode rel, RelMetadataQuery mq) {
  final RelOptPredicateList predicates = mq.getPulledUpPredicates(rel);
  if (predicates != null) {
    final Set<Integer> constantIndexes = new HashSet();
    predicates.constantMap.keySet().forEach(rex -> {
      if (rex instanceof RexInputRef) {
        constantIndexes.add(((RexInputRef) rex).getIndex());
      }
    });
    if (!constantIndexes.isEmpty()) {
      return checkingColumns.union(ImmutableBitSet.of(constantIndexes));
    }
  }
  // If no constant columns deduced, return the original "checkingColumns".
  return checkingColumns;
}
 
Example 2
Source File: AggregateNode.java    From calcite with Apache License 2.0 6 votes vote down vote up
public AggregateNode(Compiler compiler, Aggregate rel) {
  super(compiler, rel);
  this.dataContext = compiler.getDataContext();

  ImmutableBitSet union = ImmutableBitSet.of();

  if (rel.getGroupSets() != null) {
    for (ImmutableBitSet group : rel.getGroupSets()) {
      union = union.union(group);
      groups.add(new Grouping(group));
    }
  }

  this.unionGroups = union;
  this.outputRowLength = unionGroups.cardinality()
      + rel.getAggCallList().size();

  ImmutableList.Builder<AccumulatorFactory> builder = ImmutableList.builder();
  for (AggregateCall aggregateCall : rel.getAggCallList()) {
    builder.add(getAccumulator(aggregateCall, false));
  }
  accumulatorFactories = builder.build();
}
 
Example 3
Source File: SqlValidatorUtil.java    From Bats with Apache License 2.0 5 votes vote down vote up
/** Computes the rollup of bit sets.
 *
 * <p>For example, <code>rollup({0}, {1})</code>
 * returns <code>({0, 1}, {0}, {})</code>.
 *
 * <p>Bit sets are not necessarily singletons:
 * <code>rollup({0, 2}, {3, 5})</code>
 * returns <code>({0, 2, 3, 5}, {0, 2}, {})</code>. */
@VisibleForTesting
public static ImmutableList<ImmutableBitSet> rollup(
    List<ImmutableBitSet> bitSets) {
  Set<ImmutableBitSet> builder = new LinkedHashSet<>();
  for (;;) {
    final ImmutableBitSet union = ImmutableBitSet.union(bitSets);
    builder.add(union);
    if (union.isEmpty()) {
      break;
    }
    bitSets = bitSets.subList(0, bitSets.size() - 1);
  }
  return ImmutableList.copyOf(builder);
}
 
Example 4
Source File: AggregatingSelectScope.java    From calcite with Apache License 2.0 5 votes vote down vote up
private Resolved resolve() {
  final ImmutableList.Builder<ImmutableList<ImmutableBitSet>> builder =
      ImmutableList.builder();
  List<SqlNode> extraExprs = ImmutableList.of();
  Map<Integer, Integer> groupExprProjection = ImmutableMap.of();
  if (select.getGroup() != null) {
    final SqlNodeList groupList = select.getGroup();
    final SqlValidatorUtil.GroupAnalyzer groupAnalyzer =
        new SqlValidatorUtil.GroupAnalyzer(temporaryGroupExprList);
    for (SqlNode groupExpr : groupList) {
      SqlValidatorUtil.analyzeGroupItem(this, groupAnalyzer, builder,
          groupExpr);
    }
    extraExprs = groupAnalyzer.extraExprs;
    groupExprProjection = groupAnalyzer.groupExprProjection;
  }

  final SortedMap<ImmutableBitSet, Integer> flatGroupSetCount =
      Maps.newTreeMap(ImmutableBitSet.COMPARATOR);
  for (List<ImmutableBitSet> groupSet : Linq4j.product(builder.build())) {
    final ImmutableBitSet set = ImmutableBitSet.union(groupSet);
    flatGroupSetCount.put(set, flatGroupSetCount.getOrDefault(set, 0) + 1);
  }

  // For GROUP BY (), we need a singleton grouping set.
  if (flatGroupSetCount.isEmpty()) {
    flatGroupSetCount.put(ImmutableBitSet.of(), 1);
  }

  return new Resolved(extraExprs, temporaryGroupExprList, flatGroupSetCount.keySet(),
      flatGroupSetCount, groupExprProjection);
}
 
Example 5
Source File: SqlValidatorUtil.java    From calcite with Apache License 2.0 5 votes vote down vote up
/** Computes the rollup of bit sets.
 *
 * <p>For example, <code>rollup({0}, {1})</code>
 * returns <code>({0, 1}, {0}, {})</code>.
 *
 * <p>Bit sets are not necessarily singletons:
 * <code>rollup({0, 2}, {3, 5})</code>
 * returns <code>({0, 2, 3, 5}, {0, 2}, {})</code>. */
@VisibleForTesting
public static ImmutableList<ImmutableBitSet> rollup(
    List<ImmutableBitSet> bitSets) {
  Set<ImmutableBitSet> builder = new LinkedHashSet<>();
  for (;;) {
    final ImmutableBitSet union = ImmutableBitSet.union(bitSets);
    builder.add(union);
    if (union.isEmpty()) {
      break;
    }
    bitSets = bitSets.subList(0, bitSets.size() - 1);
  }
  return ImmutableList.copyOf(builder);
}