本文整理汇总了Java中org.apache.calcite.rex.RexProgramBuilder类的典型用法代码示例。如果您正苦于以下问题:Java RexProgramBuilder类的具体用法?Java RexProgramBuilder怎么用?Java RexProgramBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RexProgramBuilder类属于org.apache.calcite.rex包,在下文中一共展示了RexProgramBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onMatch
import org.apache.calcite.rex.RexProgramBuilder; //导入依赖的package包/类
public void onMatch(RelOptRuleCall call) {
final EnumerableFilter filter = call.rel(0);
final RelNode input = filter.getInput();
// Create a program containing a filter.
final RexBuilder rexBuilder = filter.getCluster().getRexBuilder();
final RelDataType inputRowType = input.getRowType();
final RexProgramBuilder programBuilder =
new RexProgramBuilder(inputRowType, rexBuilder);
programBuilder.addIdentity();
programBuilder.addCondition(filter.getCondition());
final RexProgram program = programBuilder.getProgram();
final EnumerableCalc calc = EnumerableCalc.create(input, program);
call.transformTo(calc);
}
示例2: testBuildProgram
import org.apache.calcite.rex.RexProgramBuilder; //导入依赖的package包/类
/**
* Tests construction of a RexProgram.
*/
@Test public void testBuildProgram() {
final RexProgramBuilder builder = createProg(0);
final RexProgram program = builder.getProgram(false);
final String programString = program.toString();
TestUtil.assertEqualsVerbose(
"(expr#0..1=[{inputs}], expr#2=[+($0, 1)], expr#3=[77], "
+ "expr#4=[+($0, $1)], expr#5=[+($0, $0)], expr#6=[+($t4, $t2)], "
+ "a=[$t6], b=[$t5])",
programString);
// Normalize the program using the RexProgramBuilder.normalize API.
// Note that unused expression '77' is eliminated, input refs (e.g. $0)
// become local refs (e.g. $t0), and constants are assigned to locals.
final RexProgram normalizedProgram = program.normalize(rexBuilder, null);
final String normalizedProgramString = normalizedProgram.toString();
TestUtil.assertEqualsVerbose(
"(expr#0..1=[{inputs}], expr#2=[+($t0, $t1)], expr#3=[1], "
+ "expr#4=[+($t0, $t3)], expr#5=[+($t2, $t4)], "
+ "expr#6=[+($t0, $t0)], a=[$t5], b=[$t6])",
normalizedProgramString);
}
示例3: testElimDups
import org.apache.calcite.rex.RexProgramBuilder; //导入依赖的package包/类
/**
* Tests construction and normalization of a RexProgram.
*/
@Test public void testElimDups() {
final RexProgramBuilder builder = createProg(1);
final String unnormalizedProgram = builder.getProgram(false).toString();
TestUtil.assertEqualsVerbose(
"(expr#0..1=[{inputs}], expr#2=[+($0, 1)], expr#3=[77], "
+ "expr#4=[+($0, $1)], expr#5=[+($0, 1)], expr#6=[+($0, $t5)], "
+ "expr#7=[+($t4, $t2)], a=[$t7], b=[$t6])",
unnormalizedProgram);
// normalize eliminates duplicates (specifically "+($0, $1)")
final RexProgramBuilder builder2 = createProg(1);
final String program2 = builder2.getProgram(true).toString();
TestUtil.assertEqualsVerbose(
"(expr#0..1=[{inputs}], expr#2=[+($t0, $t1)], expr#3=[1], "
+ "expr#4=[+($t0, $t3)], expr#5=[+($t2, $t4)], "
+ "expr#6=[+($t0, $t4)], a=[$t5], b=[$t6])",
program2);
}
示例4: onMatch
import org.apache.calcite.rex.RexProgramBuilder; //导入依赖的package包/类
public void onMatch(RelOptRuleCall call) {
Filter topFilter = call.rel(0);
Filter bottomFilter = call.rel(1);
// use RexPrograms to merge the two FilterRels into a single program
// so we can convert the two FilterRel conditions to directly
// reference the bottom FilterRel's child
RexBuilder rexBuilder = topFilter.getCluster().getRexBuilder();
RexProgram bottomProgram = createProgram(bottomFilter);
RexProgram topProgram = createProgram(topFilter);
RexProgram mergedProgram =
RexProgramBuilder.mergePrograms(
topProgram,
bottomProgram,
rexBuilder);
RexNode newCondition =
mergedProgram.expandLocalRef(
mergedProgram.getCondition());
// if(!RexUtil.isFlat(newCondition)){
// RexCall newCall = (RexCall) newCondition;
// newCondition = rexBuilder.makeFlatCall( newCall.getOperator(), newCall.getOperands());
// }
Filter newFilterRel =
(Filter) filterFactory.createFilter(
bottomFilter.getInput(),
RexUtil.flatten(rexBuilder, newCondition));
call.transformTo(newFilterRel);
}
示例5: createProgram
import org.apache.calcite.rex.RexProgramBuilder; //导入依赖的package包/类
/**
* Creates a RexProgram corresponding to a LogicalFilter
*
* @param filterRel the LogicalFilter
* @return created RexProgram
*/
private RexProgram createProgram(Filter filterRel) {
RexProgramBuilder programBuilder =
new RexProgramBuilder(
filterRel.getRowType(),
filterRel.getCluster().getRexBuilder());
programBuilder.addIdentity();
programBuilder.addCondition(filterRel.getCondition());
return programBuilder.getProgram();
}
示例6: getExpression
import org.apache.calcite.rex.RexProgramBuilder; //导入依赖的package包/类
/**
* Create quasi-Java expression from given {@link RexNode}
*
* @param node Expression in the form of {@link RexNode}
* @param inputRowType Input Data type to expression in the form of {@link RelDataType}
* @param outputRowType Output data type of expression in the form of {@link RelDataType}
*
* @return Returns quasi-Java expression
*/
public String getExpression(RexNode node, RelDataType inputRowType, RelDataType outputRowType)
{
final RexProgramBuilder programBuilder = new RexProgramBuilder(inputRowType, rexBuilder);
programBuilder.addProject(node, null);
final RexProgram program = programBuilder.getProgram();
final BlockBuilder builder = new BlockBuilder();
final JavaTypeFactory javaTypeFactory = (JavaTypeFactory)rexBuilder.getTypeFactory();
final RexToLixTranslator.InputGetter inputGetter = new RexToLixTranslator.InputGetterImpl(ImmutableList
.of(Pair.<Expression, PhysType>of(Expressions.variable(Object[].class, "inputValues"),
PhysTypeImpl.of(javaTypeFactory, inputRowType, JavaRowFormat.ARRAY, false))));
final Function1<String, RexToLixTranslator.InputGetter> correlates =
new Function1<String, RexToLixTranslator.InputGetter>()
{
public RexToLixTranslator.InputGetter apply(String a0)
{
throw new UnsupportedOperationException();
}
};
final List<Expression> list = RexToLixTranslator.translateProjects(program, javaTypeFactory, builder,
PhysTypeImpl.of(javaTypeFactory, outputRowType, JavaRowFormat.ARRAY, false), null, inputGetter, correlates);
for (int i = 0; i < list.size(); i++) {
Statement statement = Expressions.statement(list.get(i));
builder.add(statement);
}
return finalizeExpression(builder.toBlock(), inputRowType);
}
示例7: compileToBlock
import org.apache.calcite.rex.RexProgramBuilder; //导入依赖的package包/类
public BlockStatement compileToBlock(List<RexNode> nodes, RelDataType inputRowType) {
final RexProgramBuilder programBuilder =
new RexProgramBuilder(inputRowType, rexBuilder);
for (RexNode node : nodes) {
programBuilder.addProject(node, null);
}
return compileToBlock(programBuilder.getProgram());
}
示例8: compile
import org.apache.calcite.rex.RexProgramBuilder; //导入依赖的package包/类
public String compile(List<RexNode> nodes, RelDataType inputRowType, String className) {
final RexProgramBuilder programBuilder =
new RexProgramBuilder(inputRowType, rexBuilder);
for (RexNode node : nodes) {
programBuilder.addProject(node, null);
}
return compile(programBuilder.getProgram(), className);
}
示例9: implementEnumerable
import org.apache.calcite.rex.RexProgramBuilder; //导入依赖的package包/类
@Override
public EnumerableRel implementEnumerable(List<EnumerableRel> inputs) {
// keep it for having clause
RexBuilder rexBuilder = getCluster().getRexBuilder();
RelDataType inputRowType = getInput().getRowType();
RexProgramBuilder programBuilder = new RexProgramBuilder(inputRowType, rexBuilder);
programBuilder.addIdentity();
programBuilder.addCondition(this.condition);
RexProgram program = programBuilder.getProgram();
return new EnumerableCalc(getCluster(), getCluster().traitSetOf(EnumerableConvention.INSTANCE), //
sole(inputs), program);
}
示例10: onMatch
import org.apache.calcite.rex.RexProgramBuilder; //导入依赖的package包/类
public void onMatch(RelOptRuleCall call) {
final Filter topFilter = call.rel(0);
final Filter bottomFilter = call.rel(1);
// use RexPrograms to merge the two FilterRels into a single program
// so we can convert the two LogicalFilter conditions to directly
// reference the bottom LogicalFilter's child
RexBuilder rexBuilder = topFilter.getCluster().getRexBuilder();
RexProgram bottomProgram = createProgram(bottomFilter);
RexProgram topProgram = createProgram(topFilter);
RexProgram mergedProgram =
RexProgramBuilder.mergePrograms(
topProgram,
bottomProgram,
rexBuilder);
RexNode newCondition =
mergedProgram.expandLocalRef(
mergedProgram.getCondition());
final RelBuilder relBuilder = call.builder();
relBuilder.push(bottomFilter.getInput())
.filter(newCondition);
call.transformTo(relBuilder.build());
}
示例11: onMatch
import org.apache.calcite.rex.RexProgramBuilder; //导入依赖的package包/类
public void onMatch(RelOptRuleCall call) {
final LogicalFilter filter = call.rel(0);
final LogicalCalc calc = call.rel(1);
// Don't merge a filter onto a calc which contains windowed aggregates.
// That would effectively be pushing a multiset down through a filter.
// We'll have chance to merge later, when the over is expanded.
if (calc.getProgram().containsAggs()) {
return;
}
// Create a program containing the filter.
final RexBuilder rexBuilder = filter.getCluster().getRexBuilder();
final RexProgramBuilder progBuilder =
new RexProgramBuilder(
calc.getRowType(),
rexBuilder);
progBuilder.addIdentity();
progBuilder.addCondition(filter.getCondition());
RexProgram topProgram = progBuilder.getProgram();
RexProgram bottomProgram = calc.getProgram();
// Merge the programs together.
RexProgram mergedProgram =
RexProgramBuilder.mergePrograms(
topProgram,
bottomProgram,
rexBuilder);
final LogicalCalc newCalc =
LogicalCalc.create(calc.getInput(), mergedProgram);
call.transformTo(newCalc);
}
示例12: onMatch
import org.apache.calcite.rex.RexProgramBuilder; //导入依赖的package包/类
public void onMatch(RelOptRuleCall call) {
LogicalCalc calc = call.rel(0);
// Expand decimals in every expression in this program. If no
// expression changes, don't apply the rule.
final RexProgram program = calc.getProgram();
if (!RexUtil.requiresDecimalExpansion(program, true)) {
return;
}
final RexBuilder rexBuilder = calc.getCluster().getRexBuilder();
final RexShuttle shuttle = new DecimalShuttle(rexBuilder);
RexProgramBuilder programBuilder =
RexProgramBuilder.create(
rexBuilder,
calc.getInput().getRowType(),
program.getExprList(),
program.getProjectList(),
program.getCondition(),
program.getOutputRowType(),
shuttle,
true);
final RexProgram newProgram = programBuilder.getProgram();
LogicalCalc newCalc = LogicalCalc.create(calc.getInput(), newProgram);
call.transformTo(newCalc);
}
示例13: predicate
import org.apache.calcite.rex.RexProgramBuilder; //导入依赖的package包/类
Expression predicate(EnumerableRelImplementor implementor,
BlockBuilder builder, PhysType leftPhysType, PhysType rightPhysType,
RexNode condition) {
final ParameterExpression left_ =
Expressions.parameter(leftPhysType.getJavaRowType(), "left");
final ParameterExpression right_ =
Expressions.parameter(rightPhysType.getJavaRowType(), "right");
final RexProgramBuilder program =
new RexProgramBuilder(
implementor.getTypeFactory().builder()
.addAll(left.getRowType().getFieldList())
.addAll(right.getRowType().getFieldList())
.build(),
getCluster().getRexBuilder());
program.addCondition(condition);
builder.add(
Expressions.return_(null,
RexToLixTranslator.translateCondition(program.getProgram(),
implementor.getTypeFactory(),
builder,
new RexToLixTranslator.InputGetterImpl(
ImmutableList.of(Pair.of((Expression) left_, leftPhysType),
Pair.of((Expression) right_, rightPhysType))),
implementor.allCorrelateVariables)));
return Expressions.lambda(Predicate2.class, builder.toBlock(), left_,
right_);
}
示例14: testNormalize
import org.apache.calcite.rex.RexProgramBuilder; //导入依赖的package包/类
/**
* Tests construction and normalization of a RexProgram.
*/
@Test public void testNormalize() {
final RexProgramBuilder builder = createProg(0);
final String program = builder.getProgram(true).toString();
TestUtil.assertEqualsVerbose(
"(expr#0..1=[{inputs}], expr#2=[+($t0, $t1)], expr#3=[1], "
+ "expr#4=[+($t0, $t3)], expr#5=[+($t2, $t4)], "
+ "expr#6=[+($t0, $t0)], a=[$t5], b=[$t6])",
program);
}
示例15: testDuplicateAnd
import org.apache.calcite.rex.RexProgramBuilder; //导入依赖的package包/类
/**
* Checks translation of AND(x, x).
*/
@Test public void testDuplicateAnd() {
// RexProgramBuilder used to translate AND(x, x) to x.
// Now it translates it to AND(x, x).
// The optimization of AND(x, x) => x occurs at a higher level.
final RexProgramBuilder builder = createProg(2);
final String program = builder.getProgram(true).toString();
TestUtil.assertEqualsVerbose(
"(expr#0..1=[{inputs}], expr#2=[+($t0, $t1)], expr#3=[1], "
+ "expr#4=[+($t0, $t3)], expr#5=[+($t2, $t4)], "
+ "expr#6=[+($t0, $t0)], expr#7=[>($t2, $t0)], "
+ "a=[$t5], b=[$t6], $condition=[$t7])",
program);
}