本文整理汇总了Java中org.apache.calcite.util.ImmutableBitSet.range方法的典型用法代码示例。如果您正苦于以下问题:Java ImmutableBitSet.range方法的具体用法?Java ImmutableBitSet.range怎么用?Java ImmutableBitSet.range使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.calcite.util.ImmutableBitSet
的用法示例。
在下文中一共展示了ImmutableBitSet.range方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: canPush
import org.apache.calcite.util.ImmutableBitSet; //导入方法依赖的package包/类
private boolean canPush(Aggregate aggregate, ImmutableBitSet rCols) {
// If the filter references columns not in the group key, we cannot push
final ImmutableBitSet groupKeys =
ImmutableBitSet.range(0, aggregate.getGroupSet().cardinality());
if (!groupKeys.contains(rCols)) {
return false;
}
if (aggregate.indicator) {
// If grouping sets are used, the filter can be pushed if
// the columns referenced in the predicate are present in
// all the grouping sets.
for (ImmutableBitSet groupingSet : aggregate.getGroupSets()) {
if (!groupingSet.contains(rCols)) {
return false;
}
}
}
return true;
}
示例2: canPush
import org.apache.calcite.util.ImmutableBitSet; //导入方法依赖的package包/类
private boolean canPush(Aggregate aggregate, ImmutableBitSet rCols) {
// If the filter references columns not in the group key, we cannot push
final ImmutableBitSet groupKeys =
ImmutableBitSet.range(0, aggregate.getGroupSet().cardinality());
if (!groupKeys.contains(rCols)) {
return false;
}
if (aggregate.getGroupType() != Group.SIMPLE) {
// If grouping sets are used, the filter can be pushed if
// the columns referenced in the predicate are present in
// all the grouping sets.
for (ImmutableBitSet groupingSet : aggregate.getGroupSets()) {
if (!groupingSet.contains(rCols)) {
return false;
}
}
}
return true;
}
示例3: trim
import org.apache.calcite.util.ImmutableBitSet; //导入方法依赖的package包/类
/**
* Trims unused fields from a relational expression.
*
* <p>We presume that all fields of the relational expression are wanted by
* its consumer, so only trim fields that are not used within the tree.
*
* @param root Root node of relational expression
* @return Trimmed relational expression
*/
public RelNode trim(RelNode root) {
final int fieldCount = root.getRowType().getFieldCount();
final ImmutableBitSet fieldsUsed = ImmutableBitSet.range(fieldCount);
final Set<RelDataTypeField> extraFields = Collections.emptySet();
final TrimResult trimResult =
dispatchTrimFields(root, fieldsUsed, extraFields);
if (!trimResult.right.isIdentity()) {
throw new IllegalArgumentException();
}
if (SqlToRelConverter.SQL2REL_LOGGER.isDebugEnabled()) {
SqlToRelConverter.SQL2REL_LOGGER.debug(
RelOptUtil.dumpPlan("Plan after trimming unused fields",
trimResult.left, SqlExplainFormat.TEXT,
SqlExplainLevel.EXPPLAN_ATTRIBUTES));
}
return trimResult.left;
}
示例4: getRowCount
import org.apache.calcite.util.ImmutableBitSet; //导入方法依赖的package包/类
@Override
public Double getRowCount(Aggregate rel) {
ImmutableBitSet groupKey = ImmutableBitSet.range(rel.getGroupCount());
if (groupKey.isEmpty()) {
return 1.0;
} else {
return super.getRowCount(rel);
}
}
示例5: getRowCount
import org.apache.calcite.util.ImmutableBitSet; //导入方法依赖的package包/类
@Override
public Double getRowCount(Aggregate rel, RelMetadataQuery mq) {
ImmutableBitSet groupKey = ImmutableBitSet.range(rel.getGroupCount());
if (groupKey.isEmpty()) {
return 1.0;
} else {
return rel.estimateRowCount(mq);
}
}
示例6: getRowCount
import org.apache.calcite.util.ImmutableBitSet; //导入方法依赖的package包/类
@Override
public Double getRowCount(Aggregate rel, RelMetadataQuery mq) {
ImmutableBitSet groupKey = ImmutableBitSet.range(rel.getGroupCount());
if (groupKey.isEmpty()) {
return 1.0;
} else {
return super.getRowCount(rel, mq);
}
}
示例7: Resolved
import org.apache.calcite.util.ImmutableBitSet; //导入方法依赖的package包/类
Resolved(List<SqlNode> extraExprList, List<SqlNode> groupExprList,
Iterable<ImmutableBitSet> groupSets,
Map<Integer, Integer> groupExprProjection) {
this.extraExprList = ImmutableList.copyOf(extraExprList);
this.groupExprList = ImmutableList.copyOf(groupExprList);
this.groupSet = ImmutableBitSet.range(groupExprList.size());
this.groupSets = ImmutableList.copyOf(groupSets);
this.groupExprProjection = ImmutableMap.copyOf(groupExprProjection);
}
示例8: assertUniqueConsistent
import org.apache.calcite.util.ImmutableBitSet; //导入方法依赖的package包/类
/** Asserts that {@link RelMetadataQuery#getUniqueKeys(RelNode)}
* and {@link RelMetadataQuery#areColumnsUnique(RelNode, ImmutableBitSet)}
* return consistent results. */
private void assertUniqueConsistent(RelNode rel) {
final RelMetadataQuery mq = RelMetadataQuery.instance();
final Set<ImmutableBitSet> uniqueKeys = mq.getUniqueKeys(rel);
final ImmutableBitSet allCols =
ImmutableBitSet.range(0, rel.getRowType().getFieldCount());
for (ImmutableBitSet key : allCols.powerSet()) {
Boolean result2 = mq.areColumnsUnique(rel, key);
assertTrue(result2 == null || result2 == isUnique(uniqueKeys, key));
}
}
示例9: getPhase2GroupSet
import org.apache.calcite.util.ImmutableBitSet; //导入方法依赖的package包/类
public ImmutableBitSet getPhase2GroupSet() {
return ImmutableBitSet.range(0, groupSet.cardinality());
}
示例10: areColumnsUnique
import org.apache.calcite.util.ImmutableBitSet; //导入方法依赖的package包/类
public Boolean areColumnsUnique(Aggregate rel, RelMetadataQuery mq,
ImmutableBitSet columns, boolean ignoreNulls) {
// group by keys form a unique key
ImmutableBitSet groupKey = ImmutableBitSet.range(rel.getGroupCount());
return columns.contains(groupKey);
}
示例11: createUnion
import org.apache.calcite.util.ImmutableBitSet; //导入方法依赖的package包/类
@Override protected RelNode createUnion(RelBuilder relBuilder, RexBuilder rexBuilder,
RelNode topProject, RelNode unionInputQuery, RelNode unionInputView) {
// Union
relBuilder.push(unionInputQuery);
relBuilder.push(unionInputView);
relBuilder.union(true);
List<RexNode> exprList = new ArrayList<>(relBuilder.peek().getRowType().getFieldCount());
List<String> nameList = new ArrayList<>(relBuilder.peek().getRowType().getFieldCount());
for (int i = 0; i < relBuilder.peek().getRowType().getFieldCount(); i++) {
// We can take unionInputQuery as it is query based.
RelDataTypeField field = unionInputQuery.getRowType().getFieldList().get(i);
exprList.add(
rexBuilder.ensureType(
field.getType(),
rexBuilder.makeInputRef(relBuilder.peek(), i),
true));
nameList.add(field.getName());
}
relBuilder.project(exprList, nameList);
// Rollup aggregate
Aggregate aggregate = (Aggregate) unionInputQuery;
final ImmutableBitSet groupSet = ImmutableBitSet.range(aggregate.getGroupCount());
final List<AggCall> aggregateCalls = new ArrayList<>();
for (int i = 0; i < aggregate.getAggCallList().size(); i++) {
AggregateCall aggCall = aggregate.getAggCallList().get(i);
if (aggCall.isDistinct()) {
// Cannot ROLLUP distinct
return null;
}
aggregateCalls.add(
relBuilder.aggregateCall(
SubstitutionVisitor.getRollup(aggCall.getAggregation()),
aggCall.isDistinct(), aggCall.isApproximate(), null,
aggCall.name,
rexBuilder.makeInputRef(relBuilder.peek(),
aggregate.getGroupCount() + i)));
}
RelNode prevNode = relBuilder.peek();
RelNode result = relBuilder
.aggregate(relBuilder.groupKey(groupSet, null), aggregateCalls)
.build();
if (prevNode == result && groupSet.cardinality() != result.getRowType().getFieldCount()) {
// Aggregate was not inserted but we need to prune columns
result = relBuilder
.push(result)
.project(relBuilder.fields(groupSet.asList()))
.build();
}
if (topProject != null) {
// Top project
return topProject.copy(topProject.getTraitSet(), ImmutableList.of(result));
}
// Result
return result;
}
示例12: removeJoin
import org.apache.calcite.util.ImmutableBitSet; //导入方法依赖的package包/类
/**
* Determines whether a join of the dimension table in a semijoin can be
* removed. It can be if the dimension keys are unique and the only fields
* referenced from the dimension table are its semijoin keys. The semijoin
* keys can be mapped to the corresponding keys from the fact table (because
* of the equality condition associated with the semijoin keys). Therefore,
* that's why the dimension table can be removed even though those fields
* are referenced elsewhere in the query tree.
*
* @param multiJoin join factors being optimized
* @param semiJoin semijoin under consideration
* @param factIdx id of the fact table in the semijoin
* @param dimIdx id of the dimension table in the semijoin
*/
private void removeJoin(
LoptMultiJoin multiJoin,
SemiJoin semiJoin,
int factIdx,
int dimIdx) {
// if the dimension can be removed because of another semijoin, then
// no need to proceed any further
if (multiJoin.getJoinRemovalFactor(dimIdx) != null) {
return;
}
// Check if the semijoin keys corresponding to the dimension table
// are unique. The semijoin will filter out the nulls.
final ImmutableBitSet dimKeys = ImmutableBitSet.of(semiJoin.getRightKeys());
final RelNode dimRel = multiJoin.getJoinFactor(dimIdx);
if (!RelMdUtil.areColumnsDefinitelyUniqueWhenNullsFiltered(mq, dimRel,
dimKeys)) {
return;
}
// check that the only fields referenced from the dimension table
// in either its projection or join conditions are the dimension
// keys
ImmutableBitSet dimProjRefs = multiJoin.getProjFields(dimIdx);
if (dimProjRefs == null) {
int nDimFields = multiJoin.getNumFieldsInJoinFactor(dimIdx);
dimProjRefs = ImmutableBitSet.range(0, nDimFields);
}
if (!dimKeys.contains(dimProjRefs)) {
return;
}
int [] dimJoinRefCounts = multiJoin.getJoinFieldRefCounts(dimIdx);
for (int i = 0; i < dimJoinRefCounts.length; i++) {
if (dimJoinRefCounts[i] > 0) {
if (!dimKeys.get(i)) {
return;
}
}
}
// criteria met; keep track of the fact table and the semijoin that
// allow the join of this dimension table to be removed
multiJoin.setJoinRemovalFactor(dimIdx, factIdx);
multiJoin.setJoinRemovalSemiJoin(dimIdx, semiJoin);
// if the dimension table doesn't reference anything in its projection
// and the only fields referenced in its joins are the dimension keys
// of this semijoin, then we can decrement the join reference counts
// corresponding to the fact table's semijoin keys, since the
// dimension table doesn't need to use those keys
if (dimProjRefs.cardinality() != 0) {
return;
}
for (int i = 0; i < dimJoinRefCounts.length; i++) {
if (dimJoinRefCounts[i] > 1) {
return;
} else if (dimJoinRefCounts[i] == 1) {
if (!dimKeys.get(i)) {
return;
}
}
}
int [] factJoinRefCounts = multiJoin.getJoinFieldRefCounts(factIdx);
for (Integer key : semiJoin.getLeftKeys()) {
factJoinRefCounts[key]--;
}
}
示例13: perform
import org.apache.calcite.util.ImmutableBitSet; //导入方法依赖的package包/类
protected void perform(RelOptRuleCall call, Project project,
Join join, RelNode left, Aggregate aggregate) {
final RelOptCluster cluster = join.getCluster();
final RexBuilder rexBuilder = cluster.getRexBuilder();
if (project != null) {
final ImmutableBitSet bits =
RelOptUtil.InputFinder.bits(project.getProjects(), null);
final ImmutableBitSet rightBits =
ImmutableBitSet.range(left.getRowType().getFieldCount(),
join.getRowType().getFieldCount());
if (bits.intersects(rightBits)) {
return;
}
}
final JoinInfo joinInfo = join.analyzeCondition();
if (!joinInfo.rightSet().equals(
ImmutableBitSet.range(aggregate.getGroupCount()))) {
// Rule requires that aggregate key to be the same as the join key.
// By the way, neither a super-set nor a sub-set would work.
return;
}
if (!joinInfo.isEqui()) {
return;
}
final RelBuilder relBuilder = call.builder();
relBuilder.push(left);
switch (join.getJoinType()) {
case INNER:
final List<Integer> newRightKeyBuilder = Lists.newArrayList();
final List<Integer> aggregateKeys = aggregate.getGroupSet().asList();
for (int key : joinInfo.rightKeys) {
newRightKeyBuilder.add(aggregateKeys.get(key));
}
final ImmutableIntList newRightKeys = ImmutableIntList.copyOf(newRightKeyBuilder);
relBuilder.push(aggregate.getInput());
final RexNode newCondition =
RelOptUtil.createEquiJoinCondition(relBuilder.peek(2, 0),
joinInfo.leftKeys, relBuilder.peek(2, 1), newRightKeys,
rexBuilder);
relBuilder.semiJoin(newCondition);
break;
case LEFT:
// The right-hand side produces no more than 1 row (because of the
// Aggregate) and no fewer than 1 row (because of LEFT), and therefore
// we can eliminate the semi-join.
break;
default:
throw new AssertionError(join.getJoinType());
}
if (project != null) {
relBuilder.project(project.getProjects(), project.getRowType().getFieldNames());
}
call.transformTo(relBuilder.build());
}
示例14: areRowsUnique
import org.apache.calcite.util.ImmutableBitSet; //导入方法依赖的package包/类
/**
* Returns whether the rows of a given relational expression are distinct.
* This is derived by applying the
* {@link BuiltInMetadata.ColumnUniqueness#areColumnsUnique(org.apache.calcite.util.ImmutableBitSet, boolean)}
* statistic over all columns.
*
* @param rel the relational expression
*
* @return true or false depending on whether the rows are unique, or
* null if not enough information is available to make that determination
*/
public Boolean areRowsUnique(RelNode rel) {
final ImmutableBitSet columns =
ImmutableBitSet.range(rel.getRowType().getFieldCount());
return areColumnsUnique(rel, columns, false);
}