本文整理汇总了Java中org.apache.calcite.rex.RexLiteral类的典型用法代码示例。如果您正苦于以下问题:Java RexLiteral类的具体用法?Java RexLiteral怎么用?Java RexLiteral使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RexLiteral类属于org.apache.calcite.rex包,在下文中一共展示了RexLiteral类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: verifyRowType
import org.apache.calcite.rex.RexLiteral; //导入依赖的package包/类
private static void verifyRowType(final ImmutableList<ImmutableList<RexLiteral>> tuples, RelDataType rowType){
for (List<RexLiteral> tuple : tuples) {
assert (tuple.size() == rowType.getFieldCount());
for (Pair<RexLiteral, RelDataTypeField> pair : Pair.zip(tuple, rowType.getFieldList())) {
RexLiteral literal = (RexLiteral) pair.left;
RelDataType fieldType = ((RelDataTypeField) pair.right).getType();
if ((!(RexLiteral.isNullLiteral(literal)))
&& (!(SqlTypeUtil.canAssignFrom(fieldType, literal.getType())))) {
throw new AssertionError("to " + fieldType + " from " + literal);
}
}
}
}
示例2: convertToJsonNode
import org.apache.calcite.rex.RexLiteral; //导入依赖的package包/类
private static JsonNode convertToJsonNode(RelDataType rowType, ImmutableList<ImmutableList<RexLiteral>> tuples) throws IOException{
TokenBuffer out = new TokenBuffer(MAPPER.getFactory().getCodec(), false);
JsonOutput json = new ExtendedJsonOutput(out);
json.writeStartArray();
String[] fields = rowType.getFieldNames().toArray(new String[rowType.getFieldCount()]);
for(List<RexLiteral> row : tuples){
json.writeStartObject();
int i =0;
for(RexLiteral field : row){
json.writeFieldName(fields[i]);
writeLiteral(field, json);
i++;
}
json.writeEndObject();
}
json.writeEndArray();
json.flush();
return out.asParser().readValueAsTree();
}
示例3: onMatch
import org.apache.calcite.rex.RexLiteral; //导入依赖的package包/类
@Override
public void onMatch(RelOptRuleCall call) {
final LimitPrel limit = (LimitPrel) call.rel(0);
final SingleMergeExchangePrel smex = (SingleMergeExchangePrel) call.rel(1);
final SortPrel sort = (SortPrel) call.rel(2);
// First offset to include into results (inclusive). Null implies it is starting from offset 0
int offset = limit.getOffset() != null ? Math.max(0, RexLiteral.intValue(limit.getOffset())) : 0;
int fetch = limit.getFetch() != null? Math.max(0, RexLiteral.intValue(limit.getFetch())) : 0;
final TopNPrel topN = new TopNPrel(limit.getCluster(), sort.getTraitSet(), sort.getInput(), offset + fetch, sort.getCollation());
final LimitPrel newLimit = new LimitPrel(limit.getCluster(), limit.getTraitSet(),
new SingleMergeExchangePrel(smex.getCluster(), smex.getTraitSet(), topN, sort.getCollation()),
limit.getOffset(), limit.getFetch());
call.transformTo(newLimit);
}
示例4: onMatch
import org.apache.calcite.rex.RexLiteral; //导入依赖的package包/类
@Override
public void onMatch(RelOptRuleCall call) {
final LimitPrel limit = (LimitPrel) call.rel(0);
final UnionExchangePrel unionExchangePrel = (UnionExchangePrel) call.rel(1);
RelNode child = unionExchangePrel.getInput();
final int offset = limit.getOffset() != null ? Math.max(0, RexLiteral.intValue(limit.getOffset())) : 0;
final int fetch = Math.max(0, RexLiteral.intValue(limit.getFetch()));
// child Limit uses conservative approach: use offset 0 and fetch = parent limit offset + parent limit fetch.
final RexNode childFetch = limit.getCluster().getRexBuilder().makeExactLiteral(BigDecimal.valueOf(offset + fetch));
final RelNode limitUnderExchange = new LimitPrel(child.getCluster(), child.getTraitSet(), child, null, childFetch);
final RelNode newUnionExch = new UnionExchangePrel(unionExchangePrel.getCluster(), unionExchangePrel.getTraitSet(), limitUnderExchange);
final RelNode limitAboveExchange = new LimitPrel(limit.getCluster(), limit.getTraitSet(), newUnionExch, limit.getOffset(), limit.getFetch(), true);
call.transformTo(limitAboveExchange);
}
示例5: visitCall
import org.apache.calcite.rex.RexLiteral; //导入依赖的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;
}
示例6: toDrill
import org.apache.calcite.rex.RexLiteral; //导入依赖的package包/类
protected LogicalExpression toDrill(AggregateCall call, List<String> fn) {
DrillParseContext context = new DrillParseContext(PrelUtil.getSettings(getCluster()));
List<LogicalExpression> args = Lists.newArrayList();
for (Integer i : call.getArgList()) {
final int indexInConstants = i - fn.size();
if (i < fn.size()) {
args.add(new FieldReference(fn.get(i)));
} else {
final RexLiteral constant = constants.get(indexInConstants);
LogicalExpression expr = DrillOptiq.toDrill(context, getInput(), constant);
args.add(expr);
}
}
// for count(1).
if (args.isEmpty()) {
args.add(new ValueExpressions.LongExpression(1l));
}
return new FunctionCall(call.getAggregation().getName().toLowerCase(), args, ExpressionPosition.UNKNOWN);
}
示例7: getPhysicalOperator
import org.apache.calcite.rex.RexLiteral; //导入依赖的package包/类
@Override
public PhysicalOperator getPhysicalOperator(PhysicalPlanCreator creator) throws IOException {
Prel child = (Prel) this.getInput();
PhysicalOperator childPOP = child.getPhysicalOperator(creator);
// First offset to include into results (inclusive). Null implies it is starting from offset 0
int first = offset != null ? Math.max(0, RexLiteral.intValue(offset)) : 0;
// Last offset to stop including into results (exclusive), translating fetch row counts into an offset.
// Null value implies including entire remaining result set from first offset
Integer last = fetch != null ? Math.max(0, RexLiteral.intValue(fetch)) + first : null;
Limit limit = new Limit(childPOP, first, last);
return creator.addMetadata(this, limit);
}
示例8: visitCall
import org.apache.calcite.rex.RexLiteral; //导入依赖的package包/类
@Override
public Boolean visitCall(RexCall call) {
if (call.getOperator() == SqlStdOperatorTable.ITEM) {
final RexNode op0 = call.getOperands().get(0);
final RexNode op1 = call.getOperands().get(1);
if (op0 instanceof RexInputRef &&
op1 instanceof RexLiteral && ((RexLiteral) op1).getTypeName() == SqlTypeName.CHAR) {
return true;
} else if (op0 instanceof RexCall &&
op1 instanceof RexLiteral && ((RexLiteral) op1).getTypeName() == SqlTypeName.CHAR) {
return op0.accept(this);
}
}
return false;
}
示例9: verifyRowType
import org.apache.calcite.rex.RexLiteral; //导入依赖的package包/类
private static void verifyRowType(final ImmutableList<ImmutableList<RexLiteral>> tuples, RelDataType rowType){
for (List<RexLiteral> tuple : tuples) {
assert (tuple.size() == rowType.getFieldCount());
for (Pair<RexLiteral, RelDataTypeField> pair : Pair.zip(tuple, rowType.getFieldList())) {
RexLiteral literal = pair.left;
RelDataType fieldType = pair.right.getType();
if ((!(RexLiteral.isNullLiteral(literal)))
&& (!(SqlTypeUtil.canAssignFrom(fieldType, literal.getType())))) {
throw new AssertionError("to " + fieldType + " from " + literal);
}
}
}
}
示例10: toExpr
import org.apache.calcite.rex.RexLiteral; //导入依赖的package包/类
protected LogicalExpression toExpr(AggregateCall call, List<String> fn) {
ParseContext context = new ParseContext(PrelUtil.getSettings(getCluster()));
List<LogicalExpression> args = Lists.newArrayList();
for (Integer i : call.getArgList()) {
final int indexInConstants = i - fn.size();
if (i < fn.size()) {
args.add(new FieldReference(fn.get(i)));
} else {
final RexLiteral constant = constants.get(indexInConstants);
LogicalExpression expr = RexToExpr.toExpr(context, getInput(), constant);
args.add(expr);
}
}
// for count(1).
if (args.isEmpty()) {
args.add(new ValueExpressions.LongExpression(1l));
}
return new FunctionCall(call.getAggregation().getName().toLowerCase(), args);
}
示例11: matches
import org.apache.calcite.rex.RexLiteral; //导入依赖的package包/类
@Override
public boolean matches(RelOptRuleCall call) {
final LimitPrel limit = call.rel(0);
final ElasticsearchIntermediatePrel intermediatePrel = call.rel(1);
if (intermediatePrel.hasTerminalPrel()) {
return false;
}
// TODO: this can probably be supported in many cases.
if (limit.getOffset() != null && RexLiteral.intValue(limit.getOffset()) != 0) {
return false;
}
final PlannerSettings plannerSettings = PrelUtil.getPlannerSettings(limit.getCluster().getPlanner());
if (intermediatePrel.contains(ElasticsearchSample.class)
&& limit.getFetch() != null
&& RexLiteral.intValue(limit.getFetch()) >= SampleCrel.getSampleSizeAndSetMinSampleSize(plannerSettings, ElasticSampleRule.SAMPLE_SIZE_DENOMINATOR)) {
return false;
}
return true;
}
示例12: render
import org.apache.calcite.rex.RexLiteral; //导入依赖的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");
}
示例13: planValues
import org.apache.calcite.rex.RexLiteral; //导入依赖的package包/类
private PlannerOp planValues(EnumerableValues op) {
List<List<CompiledSQLExpression>> tuples = new ArrayList<>(op.getTuples().size());
RelDataType rowType = op.getRowType();
List<RelDataTypeField> fieldList = rowType.getFieldList();
Column[] columns = new Column[fieldList.size()];
for (ImmutableList<RexLiteral> tuple : op.getTuples()) {
List<CompiledSQLExpression> row = new ArrayList<>(tuple.size());
for (RexLiteral node : tuple) {
CompiledSQLExpression exp = SQLExpressionCompiler.compileExpression(node);
row.add(exp);
}
tuples.add(row);
}
int i = 0;
String[] fieldNames = new String[fieldList.size()];
for (RelDataTypeField field : fieldList) {
Column col = Column.column(field.getName(), convertToHerdType(field.getType()));
fieldNames[i] = field.getName();
columns[i++] = col;
}
return new ValuesOp(manager.getNodeId(), fieldNames,
columns, tuples);
}
示例14: buildBeamPipeline
import org.apache.calcite.rex.RexLiteral; //导入依赖的package包/类
@Override public PCollection<BeamRecord> buildBeamPipeline(PCollectionTuple inputPCollections
, BeamSqlEnv sqlEnv) throws Exception {
List<BeamRecord> rows = new ArrayList<>(tuples.size());
String stageName = BeamSqlRelUtils.getStageName(this);
if (tuples.isEmpty()) {
throw new IllegalStateException("Values with empty tuples!");
}
BeamRecordSqlType beamSQLRowType = CalciteUtils.toBeamRowType(this.getRowType());
for (ImmutableList<RexLiteral> tuple : tuples) {
List<Object> fieldsValue = new ArrayList<>(beamSQLRowType.getFieldCount());
for (int i = 0; i < tuple.size(); i++) {
fieldsValue.add(BeamTableUtils.autoCastField(
beamSQLRowType.getFieldTypeByIndex(i), tuple.get(i).getValue()));
}
rows.add(new BeamRecord(beamSQLRowType, fieldsValue));
}
return inputPCollections.getPipeline().apply(stageName, Create.of(rows))
.setCoder(beamSQLRowType.getRecordCoder());
}
示例15: extractJoinColumns
import org.apache.calcite.rex.RexLiteral; //导入依赖的package包/类
private List<Pair<Integer, Integer>> extractJoinColumns(int leftRowColumnCount) {
// it's a CROSS JOIN because: condition == true
if (condition instanceof RexLiteral && (Boolean) ((RexLiteral) condition).getValue()) {
throw new UnsupportedOperationException("CROSS JOIN is not supported!");
}
RexCall call = (RexCall) condition;
List<Pair<Integer, Integer>> pairs = new ArrayList<>();
if ("AND".equals(call.getOperator().getName())) {
List<RexNode> operands = call.getOperands();
for (RexNode rexNode : operands) {
Pair<Integer, Integer> pair = extractOneJoinColumn((RexCall) rexNode, leftRowColumnCount);
pairs.add(pair);
}
} else if ("=".equals(call.getOperator().getName())) {
pairs.add(extractOneJoinColumn(call, leftRowColumnCount));
} else {
throw new UnsupportedOperationException(
"Operator " + call.getOperator().getName() + " is not supported in join condition");
}
return pairs;
}