本文整理汇总了Java中org.apache.calcite.rex.RexNode类的典型用法代码示例。如果您正苦于以下问题:Java RexNode类的具体用法?Java RexNode怎么用?Java RexNode使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RexNode类属于org.apache.calcite.rex包,在下文中一共展示了RexNode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: trans
import org.apache.calcite.rex.RexNode; //导入依赖的package包/类
private String trans(String sql) throws Exception {
Properties info = new Properties();
info.setProperty("lex", "JAVA");
String jsonFile = SolrSqlTest.class.getClassLoader().getResource("solr.json").toString().replaceAll("file:/", "");
try {
Class.forName("org.apache.calcite.jdbc.Driver");
} catch (ClassNotFoundException e1) {
e1.printStackTrace();
}
CalciteConnection connection = (CalciteConnection) DriverManager.getConnection("jdbc:calcite:model="+jsonFile, info);
final SchemaPlus schema = connection.getRootSchema().getSubSchema("solr");
connection.close();
ConfigBuilder builder = Frameworks.newConfigBuilder().defaultSchema(schema).parserConfig(SqlParser.configBuilder().setCaseSensitive(false).build());
FrameworkConfig config = builder.build();
Planner planner = Frameworks.getPlanner(config);
SqlNode sqlNode = planner.parse(sql);
SqlNode node = planner.validate(sqlNode);
RelRoot relRoot = planner.rel(node);
RelNode project = relRoot.project();
RexNode condition = ((Filter) ((Project) project).getInput()).getCondition();
return _trans.translate(condition).toSolrQueryString();
}
示例2: matches
import org.apache.calcite.rex.RexNode; //导入依赖的package包/类
@Override
public boolean matches(RelOptRuleCall call) {
try {
final LogicalFilter filter = (LogicalFilter) call.rel(0);
for (RexNode node : filter.getChildExps()) {
if (!checkedExpressions.get(node)) {
return false;
}
}
return true;
} catch (ExecutionException e) {
throw new IllegalStateException("Failure while trying to evaluate pushdown.", e);
}
}
示例3: convertCall
import org.apache.calcite.rex.RexNode; //导入依赖的package包/类
@Override
public RexNode convertCall(SqlRexContext cx, SqlCall call) {
SqlFlattenOperator operator = (SqlFlattenOperator) call.getOperator();
final List<RexNode> exprs = new LinkedList<>();
for (SqlNode node : call.getOperandList()) {
exprs.add(cx.convertExpression(node));
}
SqlFlattenOperator indexedOperator = operator.withIndex(((SqlValidatorImpl)cx.getValidator()).nextFlattenIndex());
final RexBuilder rexBuilder = cx.getRexBuilder();
// Since we don't have any way of knowing if the output of the flatten is nullable, we should always assume it is.
// This is especially important when accelerating a count(column) query, because the normalizer will convert it to
// a count(1) if it thinks this column is non-nullable, and then remove the flatten altogether. This is actually a
// problem with the fact that flatten is not really a project operator (because it can output more than one row per input).
RelDataType type = rexBuilder
.getTypeFactory()
.createTypeWithNullability(
rexBuilder
.getTypeFactory()
.createSqlType(SqlTypeName.ANY),
true
);
return rexBuilder.makeCall(type, indexedOperator, exprs);
}
示例4: visit
import org.apache.calcite.rex.RexNode; //导入依赖的package包/类
@Override
public RelNode visit(LogicalProject project) {
RelNode input = project.getInput().accept(this);
RelDataType incomingRowType = input.getRowType();
List<RexNode> newProjects;
RelDataTypeField modField = incomingRowType.getField(UPDATE_COLUMN, false, false);
if (modField == null) {
return project;
}
newProjects = FluentIterable.from(project.getProjects())
.append(new RexInputRef(modField.getIndex(), modField.getType()))
.toList();
FieldInfoBuilder fieldInfoBuilder = new FieldInfoBuilder(project.getCluster().getTypeFactory());
for (RelDataTypeField field : project.getRowType().getFieldList()) {
fieldInfoBuilder.add(field);
}
fieldInfoBuilder.add(UPDATE_COLUMN, modField.getType());
return new LogicalProject(
project.getCluster(),
project.getTraitSet(),
input,
newProjects,
fieldInfoBuilder.build()
);
}
示例5: apply
import org.apache.calcite.rex.RexNode; //导入依赖的package包/类
public boolean apply(Join join, JoinRelType joinType, RexNode exp) {
if (joinType != JoinRelType.INNER) {
return true; // In OUTER join, we could not pull-up the filter.
// All we can do is keep the filter with JOIN, and
// then decide whether the filter could be pushed down
// into LEFT/RIGHT.
}
List<RexNode> tmpLeftKeys = Lists.newArrayList();
List<RexNode> tmpRightKeys = Lists.newArrayList();
List<RelDataTypeField> sysFields = Lists.newArrayList();
RexNode remaining = RelOptUtil.splitJoinCondition(sysFields, join.getLeft(), join.getRight(), exp, tmpLeftKeys, tmpRightKeys, null, null);
if (remaining.isAlwaysTrue()) {
return true;
}
return false;
}
示例6: findItemInputRefIndex
import org.apache.calcite.rex.RexNode; //导入依赖的package包/类
private static int findItemInputRefIndex(RexNode rexNode) {
if (rexNode == null) {
return -1;
}
if (rexNode instanceof RexInputRef) {
return ((RexInputRef) rexNode).getIndex();
}
if (rexNode instanceof RexCall) {
String functionName = ((RexCall) rexNode).getOperator().getName();
if (functionName.equalsIgnoreCase("item")) {
return findItemInputRefIndex(((RexCall) rexNode).getOperands().get(0));
}
}
return -1;
}
示例7: noOnOr
import org.apache.calcite.rex.RexNode; //导入依赖的package包/类
@Test
public void noOnOr(){
final RexNode node =
builder.makeCall(SqlStdOperatorTable.OR,
builder.makeCall(SqlStdOperatorTable.EQUALS,
builder.makeInputRef(factory.createSqlType(SqlTypeName.BIGINT), 0),
builder.makeBigintLiteral(BigDecimal.ONE)
),
builder.makeApproxLiteral(BigDecimal.ONE)
);
FindSimpleFilters finder = new FindSimpleFilters(builder);
StateHolder holder = node.accept(finder);
ImmutableList<RexCall> conditions = holder.getConditions();
assertEquals(0, conditions.size());
assertTrue(holder.hasRemainingExpression());
}
示例8: addRenamedProject
import org.apache.calcite.rex.RexNode; //导入依赖的package包/类
protected DrillRel addRenamedProject(DrillRel rel, RelDataType validatedRowType) {
RelDataType t = rel.getRowType();
RexBuilder b = rel.getCluster().getRexBuilder();
List<RexNode> projections = Lists.newArrayList();
int projectCount = t.getFieldList().size();
for (int i =0; i < projectCount; i++) {
projections.add(b.makeInputRef(rel, i));
}
final List<String> fieldNames2 = SqlValidatorUtil.uniquify(validatedRowType.getFieldNames(), SqlValidatorUtil.F_SUGGESTER2);
RelDataType newRowType = RexUtil.createStructType(rel.getCluster().getTypeFactory(), projections, fieldNames2);
DrillProjectRel topProj = DrillProjectRel.create(rel.getCluster(), rel.getTraitSet(), rel, projections, newRowType);
// Add a final non-trivial Project to get the validatedRowType, if child is not project.
if (rel instanceof Project && DrillRelOptUtil.isTrivialProject(topProj, true)) {
return rel;
} else{
return topProj;
}
}
示例9: buildJoinCondition
import org.apache.calcite.rex.RexNode; //导入依赖的package包/类
private RexNode buildJoinCondition(RelNode convertedLeft, RelNode convertedRight, List<Integer> leftKeys,
List<Integer> rightKeys, List<Boolean> filterNulls, RexBuilder builder) {
List<RexNode> equijoinList = Lists.newArrayList();
final int numLeftFields = convertedLeft.getRowType().getFieldCount();
List<RelDataTypeField> leftTypes = convertedLeft.getRowType().getFieldList();
List<RelDataTypeField> rightTypes = convertedRight.getRowType().getFieldList();
for (int i=0; i < leftKeys.size(); i++) {
int leftKeyOrdinal = leftKeys.get(i).intValue();
int rightKeyOrdinal = rightKeys.get(i).intValue();
equijoinList.add(builder.makeCall(
filterNulls.get(i) ? SqlStdOperatorTable.EQUALS : SqlStdOperatorTable.IS_NOT_DISTINCT_FROM,
builder.makeInputRef(leftTypes.get(leftKeyOrdinal).getType(), leftKeyOrdinal),
builder.makeInputRef(rightTypes.get(rightKeyOrdinal).getType(), rightKeyOrdinal + numLeftFields)
));
}
return RexUtil.composeConjunction(builder, equijoinList, false);
}
示例10: doFunction
import org.apache.calcite.rex.RexNode; //导入依赖的package包/类
private LogicalExpression doFunction(RexCall call, String funcName) {
List<LogicalExpression> args = Lists.newArrayList();
for(RexNode r : call.getOperands()){
args.add(r.accept(this));
}
if (FunctionCallFactory.isBooleanOperator(funcName)) {
LogicalExpression func = FunctionCallFactory.createBooleanOperator(funcName, args);
return func;
} else {
args = Lists.reverse(args);
LogicalExpression lastArg = args.get(0);
for(int i = 1; i < args.size(); i++){
lastArg = FunctionCallFactory.createExpression(funcName, Lists.newArrayList(args.get(i), lastArg));
}
return lastArg;
}
}
示例11: visitList
import org.apache.calcite.rex.RexNode; //导入依赖的package包/类
protected List<RexNode> visitList(
List<? extends RexNode> exprs, boolean[] update, LevelHolder output) {
ImmutableList.Builder<RexNode> clonedOperands = ImmutableList.builder();
int level = 0;
for (RexNode operand : exprs) {
LevelHolder cnt = new LevelHolder();
RexNode clonedOperand = operand.accept(this, cnt);
if ((clonedOperand != operand) && (update != null)) {
update[0] = true;
}
level = Math.max(cnt.index, level);
clonedOperands.add(clonedOperand);
}
output.index = level;
return clonedOperands.build();
}
示例12: FilterRelBase
import org.apache.calcite.rex.RexNode; //导入依赖的package包/类
protected FilterRelBase(Convention convention, RelOptCluster cluster, RelTraitSet traits, RelNode child, RexNode condition) {
super(cluster, traits, child, condition);
assert getConvention() == convention;
// save the number of conjuncts that make up the filter condition such
// that repeated calls to the costing function can use the saved copy
conjunctions = RelOptUtil.conjunctions(condition);
numConjuncts = conjunctions.size();
// assert numConjuncts >= 1;
this.hasContains = ContainsRexVisitor.hasContainsCheckOrigin(this, this.getCondition(),-1);
boolean foundFlatten = false;
for (RexNode rex : this.getChildExps()) {
MoreRelOptUtil.FlattenRexVisitor visitor = new MoreRelOptUtil.FlattenRexVisitor();
if (rex.accept(visitor)) {
foundFlatten = true;
}
}
this.hasFlatten = foundFlatten;
}
示例13: render
import org.apache.calcite.rex.RexNode; //导入依赖的package包/类
@Override
public FunctionRender render(FunctionRenderer renderer, RexCall call) {
checkArity(call, 3);
RexNode op0 = call.getOperands().get(0);
if (op0 instanceof RexLiteral) {
final FunctionRender trimChar = call.getOperands().get(1).accept(renderer.getVisitor());
final FunctionRender inputStr = call.getOperands().get(2).accept(renderer.getVisitor());
if (TRIM_CHAR.equals(trimChar.getScript())) {
if (((RexLiteral) op0).getValue() == SqlTrimFunction.Flag.BOTH) {
return new FunctionRender(inputStr.getScript() + ".trim()", inputStr.getNulls());
}
}
}
throw new UnsupportedOperationException("incorrect arguments for trim function");
}
示例14: getDistributionMap
import org.apache.calcite.rex.RexNode; //导入依赖的package包/类
private Map<Integer, Integer> getDistributionMap(DrillProjectRel project) {
Map<Integer, Integer> m = new HashMap<Integer, Integer>();
for (Ord<RexNode> node : Ord.zip(project.getProjects())) {
// For distribution, either $0 or cast($0 as ...) would keep the distribution after projection.
if (node.e instanceof RexInputRef) {
m.put( ((RexInputRef) node.e).getIndex(), node.i);
} else if (node.e.isA(SqlKind.CAST)) {
RexNode operand = ((RexCall) node.e).getOperands().get(0);
if (operand instanceof RexInputRef) {
m.put(((RexInputRef) operand).getIndex(), node.i);
}
}
}
return m;
}
示例15: visitCall
import org.apache.calcite.rex.RexNode; //导入依赖的package包/类
@Override
public PathSegment visitCall(RexCall call) {
if ("ITEM".equals(call.getOperator().getName())) {
PathSegment mapOrArray = call.operands.get(0).accept(this);
if (mapOrArray != null) {
if (call.operands.get(1) instanceof RexLiteral) {
return mapOrArray.cloneWithNewChild(convertLiteral((RexLiteral) call.operands.get(1)));
}
return mapOrArray;
}
} else {
for (RexNode operand : call.operands) {
addColumn(operand.accept(this));
}
}
return null;
}