本文整理汇总了Java中org.apache.calcite.util.ImmutableBitSet.of方法的典型用法代码示例。如果您正苦于以下问题:Java ImmutableBitSet.of方法的具体用法?Java ImmutableBitSet.of怎么用?Java ImmutableBitSet.of使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.calcite.util.ImmutableBitSet
的用法示例。
在下文中一共展示了ImmutableBitSet.of方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: AggregateNode
import org.apache.calcite.util.ImmutableBitSet; //导入方法依赖的package包/类
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.indicator ? unionGroups.cardinality() : 0)
+ rel.getAggCallList().size();
ImmutableList.Builder<AccumulatorFactory> builder = ImmutableList.builder();
for (AggregateCall aggregateCall : rel.getAggCallList()) {
builder.add(getAccumulator(aggregateCall, false));
}
accumulatorFactories = builder.build();
}
示例2: testInduceGroupingType1
import org.apache.calcite.util.ImmutableBitSet; //导入方法依赖的package包/类
/** Tests a singleton grouping set {2}, whose power set has only two elements,
* { {2}, {} }. */
@Test public void testInduceGroupingType1() {
final ImmutableBitSet groupSet = ImmutableBitSet.of(2);
// Could be ROLLUP but we prefer CUBE
List<ImmutableBitSet> groupSets = Lists.newArrayList();
groupSets.add(groupSet);
groupSets.add(ImmutableBitSet.of());
assertEquals(Aggregate.Group.CUBE,
Aggregate.Group.induce(groupSet, groupSets));
groupSets = Lists.newArrayList();
groupSets.add(ImmutableBitSet.of());
assertEquals(Aggregate.Group.OTHER,
Aggregate.Group.induce(groupSet, groupSets));
groupSets = Lists.newArrayList();
groupSets.add(groupSet);
assertEquals(Aggregate.Group.SIMPLE,
Aggregate.Group.induce(groupSet, groupSets));
groupSets = Lists.newArrayList();
assertEquals(Aggregate.Group.OTHER,
Aggregate.Group.induce(groupSet, groupSets));
}
示例3: validateCubeLatticeFilter
import org.apache.calcite.util.ImmutableBitSet; //导入方法依赖的package包/类
private void validateCubeLatticeFilter(Lattice.Builder latticeBuilder) {
if (latticeBuilder.filter != null) {
ImmutableBitSet rCols = RelOptUtil.InputFinder.bits(latticeBuilder.filter);
Set<Integer> dimSet = new HashSet<>();
for (Dimension dimension : dimensions) {
dimSet.add(latticeBuilder.resolveColumn(dimension.qualifiedCol).ordinal);
}
ImmutableBitSet dims = ImmutableBitSet.of(dimSet);
if (!dims.contains(rCols)) {
throw new RuntimeException("Cube filter is only allowed on dimensions");
}
}
}
示例4: addWindows
import org.apache.calcite.util.ImmutableBitSet; //导入方法依赖的package包/类
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(
Iterables.filter(aggWindow.orderKeys,
new PredicateImpl<RexFieldCollation>() {
public boolean test(RexFieldCollation rexFieldCollation) {
// If ORDER BY references constant (i.e. RexInputRef),
// then we can ignore such ORDER BY key.
return 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);
}
示例5: visitInputRef
import org.apache.calcite.util.ImmutableBitSet; //导入方法依赖的package包/类
public Double visitInputRef(RexInputRef var) {
int index = var.getIndex();
ImmutableBitSet col = ImmutableBitSet.of(index);
Double distinctRowCount =
mq.getDistinctRowCount(rel.getInput(), col, null);
if (distinctRowCount == null) {
return null;
} else {
return numDistinctVals(distinctRowCount, mq.getRowCount(rel));
}
}
示例6: getOrdinalBitSet
import org.apache.calcite.util.ImmutableBitSet; //导入方法依赖的package包/类
/**
* Gets the bit-set to the column ordinals in the source for columns that
* intersect in the target.
*
* @param sourceRowType The source upon which to ordinate the bit set.
* @param indexToField The map of ordinals to target fields.
*/
public static ImmutableBitSet getOrdinalBitSet(
RelDataType sourceRowType,
Map<Integer, RelDataTypeField> indexToField) {
ImmutableBitSet source = ImmutableBitSet.of(
Lists.transform(
sourceRowType.getFieldList(),
new RelDataTypeField.ToFieldIndex()));
ImmutableBitSet target =
ImmutableBitSet.of(indexToField.keySet());
return source.intersect(target);
}
示例7: testDistinctRowCountTable
import org.apache.calcite.util.ImmutableBitSet; //导入方法依赖的package包/类
@Test public void testDistinctRowCountTable() {
// no unique key information is available so return null
RelNode rel = convertSql("select * from emp where deptno = 10");
final RelMetadataQuery mq = RelMetadataQuery.instance();
ImmutableBitSet groupKey =
ImmutableBitSet.of(rel.getRowType().getFieldNames().indexOf("DEPTNO"));
Double result = mq.getDistinctRowCount(rel, groupKey, null);
assertThat(result, nullValue());
}
示例8: testDistinctRowCountTableEmptyKey
import org.apache.calcite.util.ImmutableBitSet; //导入方法依赖的package包/类
@Test public void testDistinctRowCountTableEmptyKey() {
RelNode rel = convertSql("select * from emp where deptno = 10");
ImmutableBitSet groupKey = ImmutableBitSet.of(); // empty key
final RelMetadataQuery mq = RelMetadataQuery.instance();
Double result = mq.getDistinctRowCount(rel, groupKey, null);
assertThat(result, is(1D));
}
示例9: testInduceGroupingType0
import org.apache.calcite.util.ImmutableBitSet; //导入方法依赖的package包/类
@Test public void testInduceGroupingType0() {
final ImmutableBitSet groupSet = ImmutableBitSet.of();
// Could be CUBE or ROLLUP but we choose SIMPLE
List<ImmutableBitSet> groupSets = Lists.newArrayList();
groupSets.add(groupSet);
assertEquals(Aggregate.Group.SIMPLE,
Aggregate.Group.induce(groupSet, groupSets));
groupSets = Lists.newArrayList();
assertEquals(Aggregate.Group.OTHER,
Aggregate.Group.induce(groupSet, groupSets));
}
示例10: LeafVertex
import org.apache.calcite.util.ImmutableBitSet; //导入方法依赖的package包/类
LeafVertex(int id, RelNode rel, double cost, int fieldOffset) {
super(id, ImmutableBitSet.of(id), cost);
this.rel = rel;
this.fieldOffset = fieldOffset;
}
示例11: setFactorWeights
import org.apache.calcite.util.ImmutableBitSet; //导入方法依赖的package包/类
/**
* Sets weighting for each combination of factors, depending on which join
* filters reference which factors. Greater weight is given to equality
* conditions. Also, sets bitmaps indicating which factors are referenced by
* each factor within join filters that are comparisons.
*/
public void setFactorWeights() {
factorWeights = new int[nJoinFactors][nJoinFactors];
factorsRefByFactor = new ImmutableBitSet[nJoinFactors];
for (int i = 0; i < nJoinFactors; i++) {
factorsRefByFactor[i] = ImmutableBitSet.of();
}
for (RexNode joinFilter : allJoinFilters) {
ImmutableBitSet factorRefs = factorsRefByJoinFilter.get(joinFilter);
// don't give weights to non-comparison expressions
if (!(joinFilter instanceof RexCall)) {
continue;
}
if (!joinFilter.isA(SqlKind.COMPARISON)) {
continue;
}
// OR the factors referenced in this join filter into the
// bitmaps corresponding to each of the factors; however,
// exclude the bit corresponding to the factor itself
for (int factor : factorRefs) {
factorsRefByFactor[factor] =
factorsRefByFactor[factor]
.rebuild()
.addAll(factorRefs)
.clear(factor)
.build();
}
if (factorRefs.cardinality() == 2) {
int leftFactor = factorRefs.nextSetBit(0);
int rightFactor = factorRefs.nextSetBit(leftFactor + 1);
final RexCall call = (RexCall) joinFilter;
ImmutableBitSet leftFields = fieldBitmap(call.getOperands().get(0));
ImmutableBitSet leftBitmap = factorBitmap(leftFields);
// filter contains only two factor references, one on each
// side of the operator
int weight;
if (leftBitmap.cardinality() == 1) {
// give higher weight to equi-joins
switch (joinFilter.getKind()) {
case EQUALS:
weight = 3;
break;
default:
weight = 2;
}
} else {
// cross product of two tables
weight = 1;
}
setFactorWeight(weight, leftFactor, rightFactor);
} else {
// multiple factor references -- set a weight for each
// combination of factors referenced within the filter
final List<Integer> list = ImmutableIntList.copyOf(factorRefs);
for (int outer : list) {
for (int inner : list) {
if (outer != inner) {
setFactorWeight(1, outer, inner);
}
}
}
}
}
}
示例12: computeScore
import org.apache.calcite.util.ImmutableBitSet; //导入方法依赖的package包/类
/**
* Computes a score relevant to applying a set of semijoins on a fact table.
* The higher the score, the better.
*
* @param factRel fact table being filtered
* @param dimRel dimension table that participates in semijoin
* @param semiJoin semijoin between fact and dimension tables
*
* @return computed score of applying the dimension table filters on the
* fact table
*/
private double computeScore(
RelNode factRel,
RelNode dimRel,
SemiJoin semiJoin) {
// Estimate savings as a result of applying semijoin filter on fact
// table. As a heuristic, the selectivity of the semijoin needs to
// be less than half. There may be instances where an even smaller
// selectivity value is required because of the overhead of
// index lookups on a very large fact table. Half was chosen as
// a middle ground based on testing that was done with a large
// data set.
final ImmutableBitSet dimCols = ImmutableBitSet.of(semiJoin.getRightKeys());
final double selectivity =
RelMdUtil.computeSemiJoinSelectivity(mq, factRel, dimRel, semiJoin);
if (selectivity > .5) {
return 0;
}
final RelOptCost factCost = mq.getCumulativeCost(factRel);
// if not enough information, return a low score
if (factCost == null) {
return 0;
}
double savings =
(1.0 - Math.sqrt(selectivity))
* Math.max(1.0, factCost.getRows());
// Additional savings if the dimension columns are unique. We can
// ignore nulls since they will be filtered out by the semijoin.
boolean uniq =
RelMdUtil.areColumnsDefinitelyUniqueWhenNullsFiltered(mq,
dimRel, dimCols);
if (uniq) {
savings *= 2.0;
}
// compute the cost of doing an extra scan on the dimension table,
// including the distinct sort on top of the scan; if the dimension
// columns are already unique, no need to add on the dup removal cost
final Double dimSortCost = mq.getRowCount(dimRel);
final Double dupRemCost = uniq ? 0 : dimSortCost;
final RelOptCost dimCost = mq.getCumulativeCost(dimRel);
if ((dimSortCost == null)
|| (dupRemCost == null)
|| (dimCost == null)) {
return 0;
}
Double dimRows = dimCost.getRows();
if (dimRows < 1.0) {
dimRows = 1.0;
}
return savings / dimRows;
}
示例13: 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]--;
}
}
示例14: leftSet
import org.apache.calcite.util.ImmutableBitSet; //导入方法依赖的package包/类
public ImmutableBitSet leftSet() {
return ImmutableBitSet.of(leftKeys);
}
示例15: rightSet
import org.apache.calcite.util.ImmutableBitSet; //导入方法依赖的package包/类
public ImmutableBitSet rightSet() {
return ImmutableBitSet.of(rightKeys);
}