本文整理汇总了Java中org.apache.calcite.tools.RelBuilder.build方法的典型用法代码示例。如果您正苦于以下问题:Java RelBuilder.build方法的具体用法?Java RelBuilder.build怎么用?Java RelBuilder.build使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.calcite.tools.RelBuilder
的用法示例。
在下文中一共展示了RelBuilder.build方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: visit
import org.apache.calcite.tools.RelBuilder; //导入方法依赖的package包/类
@Override
public RelNode visit(final LogicalFilter filter) {
final RelBuilder relBuilder = newCalciteRelBuilderWithoutContext(filter.getCluster());
RelNode input = filter.getInput().accept(this);
relBuilder.push(input);
RexNode newCondition = filter.getCondition().accept(new RexShuttle() {
@Override
public RexNode visitInputRef(RexInputRef inputRef) {
return relBuilder.field(filter.getRowType().getFieldNames().get(inputRef.getIndex()));
}
});
relBuilder.filter(newCondition);
return relBuilder.build();
}
示例2: createUnion
import org.apache.calcite.tools.RelBuilder; //导入方法依赖的package包/类
@Override protected RelNode createUnion(RelBuilder relBuilder, RexBuilder rexBuilder,
RelNode topProject, RelNode unionInputQuery, RelNode unionInputView) {
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);
return relBuilder.build();
}
示例3: createProject
import org.apache.calcite.tools.RelBuilder; //导入方法依赖的package包/类
/**
* Creates a relational expression which projects an array of expressions,
* and optionally optimizes.
*
* <p>The result may not be a
* {@link org.apache.calcite.rel.logical.LogicalProject}. If the
* projection is trivial, <code>child</code> is returned directly; and future
* versions may return other formulations of expressions, such as
* {@link org.apache.calcite.rel.logical.LogicalCalc}.
*
* @param child input relational expression
* @param exprs list of expressions for the input columns
* @param fieldNames aliases of the expressions, or null to generate
* @param optimize Whether to return <code>child</code> unchanged if the
* projections are trivial.
* @param relBuilder Factory to create project operators
*/
public static RelNode createProject(
RelNode child,
List<? extends RexNode> exprs,
List<String> fieldNames,
boolean optimize,
RelBuilder relBuilder) {
final RelOptCluster cluster = child.getCluster();
final RelDataType rowType =
RexUtil.createStructType(cluster.getTypeFactory(), exprs,
fieldNames, SqlValidatorUtil.F_SUGGESTER);
if (optimize
&& RexUtil.isIdentity(exprs, child.getRowType())) {
if (child instanceof Project && fieldNames != null) {
// Rename columns of child projection if desired field names are given.
Project childProject = (Project) child;
child = childProject.copy(childProject.getTraitSet(),
childProject.getInput(), childProject.getProjects(), rowType);
}
return child;
}
relBuilder.push(child);
relBuilder.project(exprs, rowType.getFieldNames(), !optimize);
return relBuilder.build();
}
示例4: updateScan
import org.apache.calcite.tools.RelBuilder; //导入方法依赖的package包/类
public RelNode updateScan(IncrementallyUpdateable scan) {
if (UPDATE_COLUMN.equals(refreshColumn)) {
return scan;
}
RelDataTypeField refreshField = scan.getRowType().getField(refreshColumn, false, false);
if(refreshField == null){
throw UserException.dataReadError()
.message("Table does not include column identified for incremental update of name '%s'.", refreshField.getName())
.build(logger);
} else if(refreshField.getType().getSqlTypeName() != SqlTypeName.BIGINT){
throw UserException.dataReadError()
.message("Dremio only supports incremental column update on BIGINT types. The identified column was of type %s.", refreshField.getType().getSqlTypeName())
.build(logger);
}
final RelBuilder relBuilder = newCalciteRelBuilderWithoutContext(scan.getCluster());
relBuilder.push(scan);
List<String> newFieldNames = ImmutableList.<String>builder().addAll(scan.getRowType().getFieldNames()).add(UPDATE_COLUMN).build();
Iterable<RexInputRef> projects = FluentIterable.from(scan.getRowType().getFieldNames())
.transform(new Function<String, RexInputRef>() {
@Override
public RexInputRef apply(String fieldName) {
return relBuilder.field(fieldName);
}
})
.append(relBuilder.field(refreshColumn));
relBuilder.project(projects, newFieldNames);
return relBuilder.build();
}
示例5: onMatch
import org.apache.calcite.tools.RelBuilder; //导入方法依赖的package包/类
@Override
public void onMatch(RelOptRuleCall call) {
final Project proj = call.rel(0);
final ScanCrel scan = call.rel(1);
ProjectPushInfo columnInfo = PrelUtil.getColumns(scan.getRowType(), proj.getProjects());
// get TableBase, either wrapped in RelOptTable, or TranslatableTable. TableBase table = scan.getTable().unwrap(TableBase.class);
if (columnInfo == null || columnInfo.isStarQuery()) {
return;
}
final RelNode newScan = scan.cloneWithProject(columnInfo.columns);
List<RexNode> newProjects = Lists.newArrayList();
for (RexNode n : proj.getChildExps()) {
newProjects.add(n.accept(columnInfo.getInputRewriter()));
}
final RelBuilder relBuilder = relBuilderFactory.create(proj.getCluster(), null);
relBuilder.push(newScan);
relBuilder.project(newProjects, proj.getRowType().getFieldNames());
final RelNode newProj = relBuilder.build();
if (newProj instanceof Project
&& ProjectRemoveRule.isTrivial((Project) newProj)
&& newScan.getRowType().getFullTypeString().equals(newProj.getRowType().getFullTypeString())) {
call.transformTo(newScan);
} else {
call.transformTo(newProj);
}
}
示例6: onMatch
import org.apache.calcite.tools.RelBuilder; //导入方法依赖的package包/类
@Override
public void onMatch(RelOptRuleCall call) {
final Project proj = call.rel(0);
final OldScanCrel scan = call.rel(1);
ProjectPushInfo columnInfo = PrelUtil.getColumns(scan.getRowType(), proj.getProjects());
// get TableBase, either wrapped in RelOptTable, or TranslatableTable. TableBase table = scan.getTable().unwrap(TableBase.class);
if (columnInfo == null || columnInfo.isStarQuery() || !scan.getGroupScan().canPushdownProjects(columnInfo.columns)) {
return;
}
final OldScanCrel newScan = new OldScanCrel(scan.getCluster(),
scan.getTable(),
scan.getTraitSet(),
columnInfo.createNewRowType(proj.getInput().getCluster().getTypeFactory()),
scan.getGroupScan().clone(columnInfo.columns),
scan.getLayoutInfo(),
scan.getRowCountDiscount());
List<RexNode> newProjects = Lists.newArrayList();
for (RexNode n : proj.getChildExps()) {
newProjects.add(n.accept(columnInfo.getInputRewriter()));
}
final RelBuilder relBuilder = relBuilderFactory.create(proj.getCluster(), null);
relBuilder.push(newScan);
relBuilder.project(newProjects, proj.getRowType().getFieldNames());
final RelNode newProj = relBuilder.build();
if (newProj instanceof Project
&& ProjectRemoveRule.isTrivial((Project) newProj)
&& newScan.getRowType().getFullTypeString().equals(newProj.getRowType().getFullTypeString())) {
call.transformTo(newScan);
} else {
call.transformTo(newProj);
}
}
示例7: runAllExamples
import org.apache.calcite.tools.RelBuilder; //导入方法依赖的package包/类
public void runAllExamples() {
// Create a builder. The config contains a schema mapped
// to the SCOTT database, with tables EMP and DEPT.
final FrameworkConfig config = RelBuilderTest.config().build();
final RelBuilder builder = RelBuilder.create(config);
for (int i = 0; i < 4; i++) {
doExample(builder, i);
final RelNode node = builder.build();
if (verbose) {
System.out.println(RelOptUtil.toString(node));
}
}
}
示例8: rewriteQuery
import org.apache.calcite.tools.RelBuilder; //导入方法依赖的package包/类
@Override protected RelNode rewriteQuery(
RelBuilder relBuilder,
RexBuilder rexBuilder,
RexSimplify simplify,
RelMetadataQuery mq,
RexNode compensationColumnsEquiPred,
RexNode otherCompensationPred,
Project topProject,
RelNode node,
BiMap<RelTableRef, RelTableRef> viewToQueryTableMapping,
EquivalenceClasses viewEC, EquivalenceClasses queryEC) {
// All columns required by compensating predicates must be contained
// in the query.
List<RexNode> queryExprs = extractReferences(rexBuilder, node);
if (!compensationColumnsEquiPred.isAlwaysTrue()) {
compensationColumnsEquiPred = rewriteExpression(rexBuilder, mq,
node, queryExprs, viewToQueryTableMapping.inverse(), queryEC, false,
compensationColumnsEquiPred);
if (compensationColumnsEquiPred == null) {
// Skip it
return null;
}
}
// For the rest, we use the query equivalence classes
if (!otherCompensationPred.isAlwaysTrue()) {
otherCompensationPred = rewriteExpression(rexBuilder, mq,
node, queryExprs, viewToQueryTableMapping.inverse(), viewEC, true,
otherCompensationPred);
if (otherCompensationPred == null) {
// Skip it
return null;
}
}
final RexNode queryCompensationPred = RexUtil.not(
RexUtil.composeConjunction(
rexBuilder,
ImmutableList.of(
compensationColumnsEquiPred,
otherCompensationPred),
false));
// Generate query rewriting.
relBuilder.push(node);
relBuilder.filter(simplify.simplify(queryCompensationPred));
if (topProject != null) {
return topProject.copy(topProject.getTraitSet(), ImmutableList.of(relBuilder.build()));
}
return relBuilder.build();
}
示例9: createTopProject
import org.apache.calcite.tools.RelBuilder; //导入方法依赖的package包/类
/**
* Creates the topmost projection that will sit on top of the selected join
* ordering. The projection needs to match the original join ordering. Also,
* places any post-join filters on top of the project.
*
* @param multiJoin join factors being optimized
* @param joinTree selected join ordering
* @param fieldNames field names corresponding to the projection expressions
*
* @return created projection
*/
private RelNode createTopProject(
RelBuilder relBuilder,
LoptMultiJoin multiJoin,
LoptJoinTree joinTree,
List<String> fieldNames) {
List<RexNode> newProjExprs = Lists.newArrayList();
RexBuilder rexBuilder =
multiJoin.getMultiJoinRel().getCluster().getRexBuilder();
// create a projection on top of the joins, matching the original
// join order
final List<Integer> newJoinOrder = joinTree.getTreeOrder();
int nJoinFactors = multiJoin.getNumJoinFactors();
List<RelDataTypeField> fields = multiJoin.getMultiJoinFields();
// create a mapping from each factor to its field offset in the join
// ordering
final Map<Integer, Integer> factorToOffsetMap = new HashMap<>();
for (int pos = 0, fieldStart = 0; pos < nJoinFactors; pos++) {
factorToOffsetMap.put(newJoinOrder.get(pos), fieldStart);
fieldStart +=
multiJoin.getNumFieldsInJoinFactor(newJoinOrder.get(pos));
}
for (int currFactor = 0; currFactor < nJoinFactors; currFactor++) {
// if the factor is the right factor in a removable self-join,
// then where possible, remap references to the right factor to
// the corresponding reference in the left factor
Integer leftFactor = null;
if (multiJoin.isRightFactorInRemovableSelfJoin(currFactor)) {
leftFactor = multiJoin.getOtherSelfJoinFactor(currFactor);
}
for (int fieldPos = 0;
fieldPos < multiJoin.getNumFieldsInJoinFactor(currFactor);
fieldPos++) {
int newOffset = factorToOffsetMap.get(currFactor) + fieldPos;
if (leftFactor != null) {
Integer leftOffset =
multiJoin.getRightColumnMapping(currFactor, fieldPos);
if (leftOffset != null) {
newOffset =
factorToOffsetMap.get(leftFactor) + leftOffset;
}
}
newProjExprs.add(
rexBuilder.makeInputRef(
fields.get(newProjExprs.size()).getType(),
newOffset));
}
}
relBuilder.push(joinTree.getJoinTree());
relBuilder.project(newProjExprs, fieldNames);
// Place the post-join filter (if it exists) on top of the final
// projection.
RexNode postJoinFilter =
multiJoin.getMultiJoinRel().getPostJoinFilter();
if (postJoinFilter != null) {
relBuilder.filter(postJoinFilter);
}
return relBuilder.build();
}