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

The following examples show how to use org.apache.calcite.util.ImmutableBitSet#indexOf() . 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: FlinkAggregateJoinTransposeRule.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Convert aggregate with AUXILIARY_GROUP to regular aggregate.
 * Return original aggregate and null project if the given aggregate does not contain AUXILIARY_GROUP,
 * else new aggregate without AUXILIARY_GROUP and a project to permute output columns if needed.
 */
private Pair<Aggregate, List<RexNode>> toRegularAggregate(Aggregate aggregate) {
	Tuple2<int[], Seq<AggregateCall>> auxGroupAndRegularAggCalls = AggregateUtil.checkAndSplitAggCalls(aggregate);
	final int[] auxGroup = auxGroupAndRegularAggCalls._1;
	final Seq<AggregateCall> regularAggCalls = auxGroupAndRegularAggCalls._2;
	if (auxGroup.length != 0) {
		int[] fullGroupSet = AggregateUtil.checkAndGetFullGroupSet(aggregate);
		ImmutableBitSet newGroupSet = ImmutableBitSet.of(fullGroupSet);
		List<AggregateCall> aggCalls = JavaConverters.seqAsJavaListConverter(regularAggCalls).asJava();
		final Aggregate newAgg = aggregate.copy(
				aggregate.getTraitSet(),
				aggregate.getInput(),
				aggregate.indicator,
				newGroupSet,
				com.google.common.collect.ImmutableList.of(newGroupSet),
				aggCalls);
		final List<RelDataTypeField> aggFields = aggregate.getRowType().getFieldList();
		final List<RexNode> projectAfterAgg = new ArrayList<>();
		for (int i = 0; i < fullGroupSet.length; ++i) {
			int group = fullGroupSet[i];
			int index = newGroupSet.indexOf(group);
			projectAfterAgg.add(new RexInputRef(index, aggFields.get(i).getType()));
		}
		int fieldCntOfAgg = aggFields.size();
		for (int i = fullGroupSet.length; i < fieldCntOfAgg; ++i) {
			projectAfterAgg.add(new RexInputRef(i, aggFields.get(i).getType()));
		}
		Preconditions.checkArgument(projectAfterAgg.size() == fieldCntOfAgg);
		return new Pair<>(newAgg, projectAfterAgg);
	} else {
		return new Pair<>(aggregate, null);
	}
}
 
Example 2
Source File: FlinkAggregateJoinTransposeRule.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Convert aggregate with AUXILIARY_GROUP to regular aggregate.
 * Return original aggregate and null project if the given aggregate does not contain AUXILIARY_GROUP,
 * else new aggregate without AUXILIARY_GROUP and a project to permute output columns if needed.
 */
private Pair<Aggregate, List<RexNode>> toRegularAggregate(Aggregate aggregate) {
	Tuple2<int[], Seq<AggregateCall>> auxGroupAndRegularAggCalls = AggregateUtil.checkAndSplitAggCalls(aggregate);
	final int[] auxGroup = auxGroupAndRegularAggCalls._1;
	final Seq<AggregateCall> regularAggCalls = auxGroupAndRegularAggCalls._2;
	if (auxGroup.length != 0) {
		int[] fullGroupSet = AggregateUtil.checkAndGetFullGroupSet(aggregate);
		ImmutableBitSet newGroupSet = ImmutableBitSet.of(fullGroupSet);
		List<AggregateCall> aggCalls = JavaConverters.seqAsJavaListConverter(regularAggCalls).asJava();
		final Aggregate newAgg = aggregate.copy(
				aggregate.getTraitSet(),
				aggregate.getInput(),
				aggregate.indicator,
				newGroupSet,
				com.google.common.collect.ImmutableList.of(newGroupSet),
				aggCalls);
		final List<RelDataTypeField> aggFields = aggregate.getRowType().getFieldList();
		final List<RexNode> projectAfterAgg = new ArrayList<>();
		for (int i = 0; i < fullGroupSet.length; ++i) {
			int group = fullGroupSet[i];
			int index = newGroupSet.indexOf(group);
			projectAfterAgg.add(new RexInputRef(index, aggFields.get(i).getType()));
		}
		int fieldCntOfAgg = aggFields.size();
		for (int i = fullGroupSet.length; i < fieldCntOfAgg; ++i) {
			projectAfterAgg.add(new RexInputRef(i, aggFields.get(i).getType()));
		}
		Preconditions.checkArgument(projectAfterAgg.size() == fieldCntOfAgg);
		return new Pair<>(newAgg, projectAfterAgg);
	} else {
		return new Pair<>(aggregate, null);
	}
}
 
Example 3
Source File: AggregateExpandDistinctAggregatesRule.java    From Bats with Apache License 2.0 4 votes vote down vote up
private static int remap(ImmutableBitSet groupSet, int arg) {
    return arg < 0 ? -1 : groupSet.indexOf(arg);
}
 
Example 4
Source File: FlinkAggregateExpandDistinctAggregatesRule.java    From flink with Apache License 2.0 4 votes vote down vote up
private static int remap(ImmutableBitSet groupSet, int arg) {
	return arg < 0 ? -1 : groupSet.indexOf(arg);
}
 
Example 5
Source File: FlinkAggregateExpandDistinctAggregatesRule.java    From flink with Apache License 2.0 4 votes vote down vote up
private static int remap(ImmutableBitSet groupSet, int arg) {
	return arg < 0 ? -1 : groupSet.indexOf(arg);
}
 
Example 6
Source File: AggregateExpandDistinctAggregatesRule.java    From calcite with Apache License 2.0 4 votes vote down vote up
private static int remap(ImmutableBitSet groupSet, int arg) {
  return arg < 0 ? -1 : groupSet.indexOf(arg);
}