本文整理汇总了Java中org.apache.calcite.rex.RexProgram类的典型用法代码示例。如果您正苦于以下问题:Java RexProgram类的具体用法?Java RexProgram怎么用?Java RexProgram使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RexProgram类属于org.apache.calcite.rex包,在下文中一共展示了RexProgram类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: visitCalc
import org.apache.calcite.rex.RexProgram; //导入依赖的package包/类
public Result visitCalc(Calc e) {
Result x = visitChild(0, e.getInput());
final RexProgram program = e.getProgram();
Builder builder =
program.getCondition() != null
? x.builder(e, Clause.WHERE)
: x.builder(e);
if (!isStar(program)) {
final List<SqlNode> selectList = new ArrayList<>();
for (RexLocalRef ref : program.getProjectList()) {
SqlNode sqlExpr = builder.context.toSql(program, ref);
addSelect(selectList, sqlExpr, e.getRowType());
}
builder.setSelect(new SqlNodeList(selectList, POS));
}
if (program.getCondition() != null) {
builder.setWhere(
builder.context.toSql(program, program.getCondition()));
}
return builder.result();
}
示例2: convert
import org.apache.calcite.rex.RexProgram; //导入依赖的package包/类
public RelNode convert(RelNode rel) {
final LogicalCalc calc = (LogicalCalc) rel;
// If there's a multiset, let FarragoMultisetSplitter work on it
// first.
final RexProgram program = calc.getProgram();
if (RexMultisetUtil.containsMultiset(program)
|| program.containsAggs()) {
return null;
}
return new SparkCalc(
rel.getCluster(),
rel.getTraitSet().replace(SparkRel.CONVENTION),
convert(calc.getInput(),
calc.getInput().getTraitSet().replace(SparkRel.CONVENTION)),
program);
}
示例3: create
import org.apache.calcite.rex.RexProgram; //导入依赖的package包/类
public static LogicalCalc create(final RelNode input,
final RexProgram program) {
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.calc(mq, input, program);
}
})
.replaceIf(RelDistributionTraitDef.INSTANCE,
new Supplier<RelDistribution>() {
public RelDistribution get() {
return RelMdDistribution.calc(mq, input, program);
}
});
return new LogicalCalc(cluster, traitSet, input, program);
}
示例4: toSql
import org.apache.calcite.rex.RexProgram; //导入依赖的package包/类
private SqlNode toSql(RexProgram program, RexFieldCollation rfc) {
SqlNode node = toSql(program, rfc.left);
switch (rfc.getDirection()) {
case DESCENDING:
case STRICTLY_DESCENDING:
node = SqlStdOperatorTable.DESC.createCall(POS, node);
}
if (rfc.getNullDirection()
!= dialect.defaultNullDirection(rfc.getDirection())) {
switch (rfc.getNullDirection()) {
case FIRST:
node = SqlStdOperatorTable.NULLS_FIRST.createCall(POS, node);
break;
case LAST:
node = SqlStdOperatorTable.NULLS_LAST.createCall(POS, node);
break;
}
}
return node;
}
示例5: visit
import org.apache.calcite.rex.RexProgram; //导入依赖的package包/类
/** @see #dispatch */
public Result visit(Calc e) {
Result x = visitChild(0, e.getInput());
parseCorrelTable(e, x);
final RexProgram program = e.getProgram();
Builder builder =
program.getCondition() != null
? x.builder(e, Clause.WHERE)
: x.builder(e);
if (!isStar(program)) {
final List<SqlNode> selectList = new ArrayList<>();
for (RexLocalRef ref : program.getProjectList()) {
SqlNode sqlExpr = builder.context.toSql(program, ref);
addSelect(selectList, sqlExpr, e.getRowType());
}
builder.setSelect(new SqlNodeList(selectList, POS));
}
if (program.getCondition() != null) {
builder.setWhere(
builder.context.toSql(program, program.getCondition()));
}
return builder.result();
}
示例6: onMatch
import org.apache.calcite.rex.RexProgram; //导入依赖的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);
}
示例7: RexToLixTranslator
import org.apache.calcite.rex.RexProgram; //导入依赖的package包/类
private RexToLixTranslator(
RexProgram program,
JavaTypeFactory typeFactory,
Expression root,
InputGetter inputGetter,
BlockBuilder list,
Map<? extends RexNode, Boolean> exprNullableMap,
RexBuilder builder,
RexToLixTranslator parent,
Function1<String, InputGetter> correlates) {
this.program = program;
this.typeFactory = typeFactory;
this.root = root;
this.inputGetter = inputGetter;
this.list = list;
this.exprNullableMap = exprNullableMap;
this.builder = builder;
this.parent = parent;
this.correlates = correlates;
}
示例8: translateProjects
import org.apache.calcite.rex.RexProgram; //导入依赖的package包/类
/**
* Translates a {@link RexProgram} to a sequence of expressions and
* declarations.
*
* @param program Program to be translated
* @param typeFactory Type factory
* @param list List of statements, populated with declarations
* @param outputPhysType Output type, or null
* @param root Root expression
* @param inputGetter Generates expressions for inputs
* @param correlates Provider of references to the values of correlated
* variables
* @return Sequence of expressions, optional condition
*/
public static List<Expression> translateProjects(RexProgram program,
JavaTypeFactory typeFactory,
BlockBuilder list,
PhysType outputPhysType,
Expression root,
InputGetter inputGetter,
Function1<String, InputGetter> correlates) {
List<Type> storageTypes = null;
if (outputPhysType != null) {
final RelDataType rowType = outputPhysType.getRowType();
storageTypes = new ArrayList<>(rowType.getFieldCount());
for (int i = 0; i < rowType.getFieldCount(); i++) {
storageTypes.add(outputPhysType.getJavaFieldType(i));
}
}
return new RexToLixTranslator(program, typeFactory, root, inputGetter, list)
.setCorrelates(correlates)
.translateList(program.getProjectList(), storageTypes);
}
示例9: translateCondition
import org.apache.calcite.rex.RexProgram; //导入依赖的package包/类
public static Expression translateCondition(
RexProgram program,
JavaTypeFactory typeFactory,
BlockBuilder list,
InputGetter inputGetter,
Function1<String, InputGetter> correlates) {
if (program.getCondition() == null) {
return RexImpTable.TRUE_EXPR;
}
final ParameterExpression root = DataContext.ROOT;
RexToLixTranslator translator =
new RexToLixTranslator(program, typeFactory, root, inputGetter, list);
translator = translator.setCorrelates(correlates);
return translator.translate(
program.getCondition(),
RexImpTable.NullAs.FALSE);
}
示例10: create
import org.apache.calcite.rex.RexProgram; //导入依赖的package包/类
/** Creates an EnumerableCalc. */
public static EnumerableCalc create(final RelNode input,
final RexProgram program) {
final RelOptCluster cluster = input.getCluster();
final RelMetadataQuery mq = cluster.getMetadataQuery();
final RelTraitSet traitSet = cluster.traitSet()
.replace(EnumerableConvention.INSTANCE)
.replaceIfs(RelCollationTraitDef.INSTANCE,
new Supplier<List<RelCollation>>() {
public List<RelCollation> get() {
return RelMdCollation.calc(mq, input, program);
}
})
.replaceIf(RelDistributionTraitDef.INSTANCE,
new Supplier<RelDistribution>() {
public RelDistribution get() {
return RelMdDistribution.calc(mq, input, program);
}
});
return new EnumerableCalc(cluster, traitSet, input, program);
}
示例11: testBuildProgram
import org.apache.calcite.rex.RexProgram; //导入依赖的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);
}
示例12: testSimplifyCondition
import org.apache.calcite.rex.RexProgram; //导入依赖的package包/类
/**
* Tests how the condition is simplified.
*/
@Test public void testSimplifyCondition() {
final RexProgram program = createProg(3).getProgram(false);
assertThat(program.toString(),
is("(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)], expr#8=[5], expr#9=[>($t2, $t8)], "
+ "expr#10=[true], expr#11=[IS NOT NULL($t5)], expr#12=[false], "
+ "expr#13=[null], expr#14=[CASE($t9, $t10, $t11, $t12, $t13)], "
+ "expr#15=[NOT($t14)], a=[$t7], b=[$t6], $condition=[$t15])"));
assertThat(program.normalize(rexBuilder, simplify).toString(),
is("(expr#0..1=[{inputs}], expr#2=[+($t0, $t1)], expr#3=[1], "
+ "expr#4=[+($t0, $t3)], expr#5=[+($t2, $t4)], "
+ "expr#6=[+($t0, $t4)], expr#7=[5], expr#8=[>($t4, $t7)], "
+ "expr#9=[CAST($t8):BOOLEAN], expr#10=[IS FALSE($t9)], "
+ "a=[$t5], b=[$t6], $condition=[$t10])"));
}
示例13: testSimplifyCondition2
import org.apache.calcite.rex.RexProgram; //导入依赖的package包/类
/**
* Tests how the condition is simplified.
*/
@Test public void testSimplifyCondition2() {
final RexProgram program = createProg(4).getProgram(false);
assertThat(program.toString(),
is("(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)], expr#8=[5], expr#9=[>($t2, $t8)], "
+ "expr#10=[true], expr#11=[IS NOT NULL($t5)], expr#12=[false], "
+ "expr#13=[null], expr#14=[CASE($t9, $t10, $t11, $t12, $t13)], "
+ "expr#15=[NOT($t14)], expr#16=[IS TRUE($t15)], a=[$t7], b=[$t6], "
+ "$condition=[$t16])"));
assertThat(program.normalize(rexBuilder, simplify).toString(),
is("(expr#0..1=[{inputs}], expr#2=[+($t0, $t1)], expr#3=[1], "
+ "expr#4=[+($t0, $t3)], expr#5=[+($t2, $t4)], "
+ "expr#6=[+($t0, $t4)], expr#7=[5], expr#8=[>($t4, $t7)], "
+ "expr#9=[CAST($t8):BOOLEAN], expr#10=[IS FALSE($t9)], "
+ "a=[$t5], b=[$t6], $condition=[$t10])"));
}
示例14: onMatch
import org.apache.calcite.rex.RexProgram; //导入依赖的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);
}
示例15: createProgram
import org.apache.calcite.rex.RexProgram; //导入依赖的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();
}