本文整理汇总了Java中org.apache.calcite.rel.RelCollation类的典型用法代码示例。如果您正苦于以下问题:Java RelCollation类的具体用法?Java RelCollation怎么用?Java RelCollation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RelCollation类属于org.apache.calcite.rel包,在下文中一共展示了RelCollation类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onMatch
import org.apache.calcite.rel.RelCollation; //导入依赖的package包/类
@Override
public void onMatch(RelOptRuleCall call) {
final DrillWriterRel writer = call.rel(0);
final RelNode input = call.rel(1);
final List<Integer> keys = writer.getPartitionKeys();
final RelCollation collation = getCollation(keys);
final boolean hashDistribute = PrelUtil.getPlannerSettings(call.getPlanner()).getOptions().getOption(ExecConstants.CTAS_PARTITIONING_HASH_DISTRIBUTE_VALIDATOR);
final RelTraitSet traits = hashDistribute ?
input.getTraitSet().plus(Prel.DRILL_PHYSICAL).plus(collation).plus(getDistribution(keys)) :
input.getTraitSet().plus(Prel.DRILL_PHYSICAL).plus(collation);
final RelNode convertedInput = convert(input, traits);
if (!new WriteTraitPull(call).go(writer, convertedInput)) {
DrillWriterRelBase newWriter = new WriterPrel(writer.getCluster(), convertedInput.getTraitSet(),
convertedInput, writer.getCreateTableEntry());
call.transformTo(newWriter);
}
}
示例2: planSort
import org.apache.calcite.rel.RelCollation; //导入依赖的package包/类
private PlannerOp planSort(EnumerableSort op, RelDataType rowType) {
PlannerOp input = convertRelNode(op.getInput(), rowType, false);
RelCollation collation = op.getCollation();
List<RelFieldCollation> fieldCollations = collation.getFieldCollations();
boolean[] directions = new boolean[fieldCollations.size()];
int[] fields = new int[fieldCollations.size()];
int i = 0;
for (RelFieldCollation col : fieldCollations) {
RelFieldCollation.Direction direction = col.getDirection();
int index = col.getFieldIndex();
directions[i] = direction == RelFieldCollation.Direction.ASCENDING
|| direction == RelFieldCollation.Direction.STRICTLY_ASCENDING;
fields[i++] = index;
}
return new SortOp(input, directions, fields);
}
示例3: trimUnusedFields
import org.apache.calcite.rel.RelCollation; //导入依赖的package包/类
/**
* Walks over a tree of relational expressions, replacing each
* {@link RelNode} with a 'slimmed down' relational expression that projects
* only the fields required by its consumer.
*
* <p>This may make things easier for the optimizer, by removing crud that
* would expand the search space, but is difficult for the optimizer itself
* to do it, because optimizer rules must preserve the number and type of
* fields. Hence, this transform that operates on the entire tree, similar
* to the {@link RelStructuredTypeFlattener type-flattening transform}.
*
* <p>Currently this functionality is disabled in farrago/luciddb; the
* default implementation of this method does nothing.
*
* @param ordered Whether the relational expression must produce results in
* a particular order (typically because it has an ORDER BY at top level)
* @param rootRel Relational expression that is at the root of the tree
* @return Trimmed relational expression
*/
public RelNode trimUnusedFields(boolean ordered, RelNode rootRel) {
// Trim fields that are not used by their consumer.
if (isTrimUnusedFields()) {
final RelFieldTrimmer trimmer = newFieldTrimmer();
final List<RelCollation> collations =
rootRel.getTraitSet().getTraits(RelCollationTraitDef.INSTANCE);
rootRel = trimmer.trim(rootRel);
if (!ordered
&& collations != null
&& !collations.isEmpty()
&& !collations.equals(ImmutableList.of(RelCollations.EMPTY))) {
final RelTraitSet traitSet = rootRel.getTraitSet()
.replace(RelCollationTraitDef.INSTANCE, collations);
rootRel = rootRel.copy(traitSet, rootRel.getInputs());
}
if (SQL2REL_LOGGER.isDebugEnabled()) {
SQL2REL_LOGGER.debug(
RelOptUtil.dumpPlan("Plan after trimming unused fields", rootRel,
SqlExplainFormat.TEXT, SqlExplainLevel.EXPPLAN_ATTRIBUTES));
}
}
return rootRel;
}
示例4: create
import org.apache.calcite.rel.RelCollation; //导入依赖的package包/类
/** Creates an DirPrunedEnumerableTableScan. */
public static EnumerableTableScan create(RelOptCluster cluster,
RelOptTable relOptTable, String digestFromSelection) {
final Table table = relOptTable.unwrap(Table.class);
Class elementType = EnumerableTableScan.deduceElementType(table);
final RelTraitSet traitSet =
cluster.traitSetOf(EnumerableConvention.INSTANCE)
.replaceIfs(RelCollationTraitDef.INSTANCE,
new Supplier<List<RelCollation>>() {
public List<RelCollation> get() {
if (table != null) {
return table.getStatistic().getCollations();
}
return ImmutableList.of();
}
});
return new DirPrunedEnumerableTableScan(cluster, traitSet, relOptTable, elementType, digestFromSelection);
}
示例5: createResultSet
import org.apache.calcite.rel.RelCollation; //导入依赖的package包/类
protected MetaResultSet createResultSet(
Map<String, Object> internalParameters, List<ColumnMetaData> columns,
CursorFactory cursorFactory, final Frame firstFrame) {
try {
final CalciteConnectionImpl connection = getConnection();
final AvaticaStatement statement = connection.createStatement();
final CalcitePrepare.CalciteSignature<Object> signature =
new CalcitePrepare.CalciteSignature<Object>("",
ImmutableList.<AvaticaParameter>of(), internalParameters, null,
columns, cursorFactory, ImmutableList.<RelCollation>of(), -1,
null, Meta.StatementType.SELECT) {
@Override
public Enumerable<Object> enumerable(
DataContext dataContext) {
return Linq4j.asEnumerable(firstFrame.rows);
}
};
return MetaResultSet.create(connection.id, statement.getId(), true,
signature, firstFrame);
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
示例6: CalciteSignature
import org.apache.calcite.rel.RelCollation; //导入依赖的package包/类
CalciteSignature(String sql,
List<AvaticaParameter> parameterList,
Map<String, Object> internalParameters,
RelDataType rowType,
List<ColumnMetaData> columns,
Meta.CursorFactory cursorFactory,
List<RelCollation> collationList,
long maxRowCount,
Bindable<T> bindable,
Meta.StatementType statementType) {
super(columns, sql, parameterList, internalParameters, cursorFactory,
statementType);
this.rowType = rowType;
this.collationList = collationList;
this.maxRowCount = maxRowCount;
this.bindable = bindable;
}
示例7: create
import org.apache.calcite.rel.RelCollation; //导入依赖的package包/类
@Override
public ResultSet create(ColumnMetaData.AvaticaType elementType,
Iterable<Object> iterable) {
final List<ColumnMetaData> columnMetaDataList;
if (elementType instanceof ColumnMetaData.StructType) {
columnMetaDataList = ((ColumnMetaData.StructType) elementType).columns;
} else {
columnMetaDataList =
ImmutableList.of(ColumnMetaData.dummy(elementType, false));
}
final CalcitePrepare.CalciteSignature signature =
(CalcitePrepare.CalciteSignature) this.signature;
final CalcitePrepare.CalciteSignature<Object> newSignature =
new CalcitePrepare.CalciteSignature<>(signature.sql,
signature.parameters, signature.internalParameters,
signature.rowType, columnMetaDataList, Meta.CursorFactory.ARRAY,
ImmutableList.<RelCollation>of(), -1, null);
ResultSetMetaData subResultSetMetaData =
new AvaticaResultSetMetaData(statement, null, newSignature);
final CalciteResultSet resultSet =
new CalciteResultSet(statement, signature, subResultSetMetaData,
localCalendar.getTimeZone(), new Meta.Frame(0, true, iterable));
final Cursor cursor = resultSet.createCursor(elementType, iterable);
return resultSet.execute2(cursor, columnMetaDataList);
}
示例8: create
import org.apache.calcite.rel.RelCollation; //导入依赖的package包/类
@Override
public ResultSet create(ColumnMetaData.AvaticaType elementType,
Iterable<Object> iterable) {
final List<ColumnMetaData> columnMetaDataList;
if (elementType instanceof ColumnMetaData.StructType) {
columnMetaDataList = ((ColumnMetaData.StructType) elementType).columns;
} else {
columnMetaDataList =
ImmutableList.of(ColumnMetaData.dummy(elementType, false));
}
final CalcitePrepare.CalciteSignature signature =
(CalcitePrepare.CalciteSignature) this.signature;
final CalcitePrepare.CalciteSignature<Object> newSignature =
new CalcitePrepare.CalciteSignature<>(signature.sql,
signature.parameters, signature.internalParameters,
signature.rowType, columnMetaDataList, Meta.CursorFactory.ARRAY,
signature.rootSchema, ImmutableList.<RelCollation>of(), -1, null);
ResultSetMetaData subResultSetMetaData =
new AvaticaResultSetMetaData(statement, null, newSignature);
final QuarkResultSet resultSet =
new QuarkResultSet(statement, signature, subResultSetMetaData,
localCalendar.getTimeZone(), new Meta.Frame(0, true, iterable));
final Cursor cursor = resultSet.createCursor(elementType, iterable);
return resultSet.execute2(cursor, columnMetaDataList);
}
示例9: createResultSet
import org.apache.calcite.rel.RelCollation; //导入依赖的package包/类
protected MetaResultSet createResultSet(
Map<String, Object> internalParameters, List<ColumnMetaData> columns,
CursorFactory cursorFactory, final Frame firstFrame) {
try {
final QuarkConnectionImpl connection = getConnection();
final AvaticaStatement statement = connection.createStatement();
final CalcitePrepare.CalciteSignature<Object> signature =
new CalcitePrepare.CalciteSignature<Object>("",
ImmutableList.<AvaticaParameter>of(), internalParameters, null,
columns, cursorFactory, null, ImmutableList.<RelCollation>of(), -1,
null, Meta.StatementType.SELECT) {
@Override public Enumerable<Object> enumerable(
DataContext dataContext) {
return Linq4j.asEnumerable(firstFrame.rows);
}
};
return MetaResultSet.create(connection.id, statement.getId(), true,
signature, firstFrame);
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
示例10: trimUnusedFields
import org.apache.calcite.rel.RelCollation; //导入依赖的package包/类
/**
* Walks over a tree of relational expressions, replacing each
* {@link RelNode} with a 'slimmed down' relational expression that projects
* only the fields required by its consumer.
*
* <p>This may make things easier for the optimizer, by removing crud that
* would expand the search space, but is difficult for the optimizer itself
* to do it, because optimizer rules must preserve the number and type of
* fields. Hence, this transform that operates on the entire tree, similar
* to the {@link RelStructuredTypeFlattener type-flattening transform}.
*
* <p>Currently this functionality is disabled in farrago/luciddb; the
* default implementation of this method does nothing.
*
* @param ordered Whether the relational expression must produce results in
* a particular order (typically because it has an ORDER BY at top level)
* @param rootRel Relational expression that is at the root of the tree
* @return Trimmed relational expression
*/
public RelNode trimUnusedFields(boolean ordered, RelNode rootRel) {
// Trim fields that are not used by their consumer.
if (isTrimUnusedFields()) {
final RelFieldTrimmer trimmer = newFieldTrimmer();
final List<RelCollation> collations =
rootRel.getTraitSet().getTraits(RelCollationTraitDef.INSTANCE);
rootRel = trimmer.trim(rootRel);
if (!ordered
&& collations != null
&& !collations.isEmpty()
&& !collations.equals(ImmutableList.of(RelCollations.EMPTY))) {
final RelTraitSet traitSet = rootRel.getTraitSet()
.replace(RelCollationTraitDef.INSTANCE, collations);
rootRel = rootRel.copy(traitSet, rootRel.getInputs());
}
if (SQL2REL_LOGGER.isDebugEnabled()) {
SQL2REL_LOGGER.debug(
RelOptUtil.dumpPlan("Plan after trimming unused fields", rootRel,
SqlExplainFormat.TEXT, SqlExplainLevel.EXPPLAN_ATTRIBUTES));
}
}
return rootRel;
}
示例11: getImplicitCollation
import org.apache.calcite.rel.RelCollation; //导入依赖的package包/类
/** Infer the implicit correlation from the unrestricted clustering keys.
*
* @return The collation of the filtered results
*/
public RelCollation getImplicitCollation() {
// No collation applies if we aren't restricted to a single partition
if (!isSinglePartition()) {
return RelCollations.EMPTY;
}
// Pull out the correct fields along with their original collations
List<RelFieldCollation> fieldCollations = new ArrayList<RelFieldCollation>();
for (int i = restrictedClusteringKeys; i < clusteringKeys.size(); i++) {
int fieldIndex = fieldNames.indexOf(clusteringKeys.get(i));
RelFieldCollation.Direction direction = implicitFieldCollations.get(i).getDirection();
fieldCollations.add(new RelFieldCollation(fieldIndex, direction));
}
return RelCollations.of(fieldCollations);
}
示例12: create
import org.apache.calcite.rel.RelCollation; //导入依赖的package包/类
/** Creates a LogicalProject, specifying row type rather than field names. */
public static LogicalProject create(final RelNode input,
final List<? extends RexNode> projects, RelDataType rowType) {
final RelOptCluster cluster = input.getCluster();
final RelMetadataQuery mq = cluster.getMetadataQuery();
final RelTraitSet traitSet =
cluster.traitSet().replace(Convention.NONE)
.replaceIfs(
RelCollationTraitDef.INSTANCE,
new Supplier<List<RelCollation>>() {
public List<RelCollation> get() {
return RelMdCollation.project(mq, input, projects);
}
});
return new LogicalProject(cluster, traitSet, input, projects, rowType);
}
示例13: create
import org.apache.calcite.rel.RelCollation; //导入依赖的package包/类
/** Creates a LogicalFilter. */
public static LogicalFilter create(final RelNode input, RexNode condition,
ImmutableSet<CorrelationId> variablesSet) {
final RelOptCluster cluster = input.getCluster();
final RelMetadataQuery mq = cluster.getMetadataQuery();
final RelTraitSet traitSet = cluster.traitSetOf(Convention.NONE)
.replaceIfs(RelCollationTraitDef.INSTANCE,
new Supplier<List<RelCollation>>() {
public List<RelCollation> get() {
return RelMdCollation.filter(mq, input);
}
})
.replaceIf(RelDistributionTraitDef.INSTANCE,
new Supplier<RelDistribution>() {
public RelDistribution get() {
return RelMdDistribution.filter(mq, input);
}
});
return new LogicalFilter(cluster, traitSet, input, condition, variablesSet);
}
示例14: create
import org.apache.calcite.rel.RelCollation; //导入依赖的package包/类
/** Creates a LogicalTableScan.
*
* @param cluster Cluster
* @param relOptTable Table
*/
public static LogicalTableScan create(RelOptCluster cluster,
final RelOptTable relOptTable) {
final Table table = relOptTable.unwrap(Table.class);
final RelTraitSet traitSet =
cluster.traitSetOf(Convention.NONE)
.replaceIfs(RelCollationTraitDef.INSTANCE,
new Supplier<List<RelCollation>>() {
public List<RelCollation> get() {
if (table != null) {
return table.getStatistic().getCollations();
}
return ImmutableList.of();
}
});
return new LogicalTableScan(cluster, traitSet, relOptTable);
}
示例15: checkInputForCollationAndLimit
import org.apache.calcite.rel.RelCollation; //导入依赖的package包/类
/** Returns whether a relational expression is already sorted and has fewer
* rows than the sum of offset and limit.
*
* <p>If this is the case, it is safe to push down a
* {@link org.apache.calcite.rel.core.Sort} with limit and optional offset. */
public static boolean checkInputForCollationAndLimit(RelMetadataQuery mq,
RelNode input, RelCollation collation, RexNode offset, RexNode fetch) {
// Check if the input is already sorted
boolean alreadySorted = collation.getFieldCollations().isEmpty();
for (RelCollation inputCollation : mq.collations(input)) {
if (inputCollation.satisfies(collation)) {
alreadySorted = true;
break;
}
}
// Check if we are not reducing the number of tuples
boolean alreadySmaller = true;
final Double rowCount = mq.getMaxRowCount(input);
if (rowCount != null && fetch != null) {
final int offsetVal = offset == null ? 0 : RexLiteral.intValue(offset);
final int limit = RexLiteral.intValue(fetch);
if ((double) offsetVal + (double) limit < rowCount) {
alreadySmaller = false;
}
}
return alreadySorted && alreadySmaller;
}