本文整理汇总了Java中org.apache.calcite.rex.RexBuilder.makeLiteral方法的典型用法代码示例。如果您正苦于以下问题:Java RexBuilder.makeLiteral方法的具体用法?Java RexBuilder.makeLiteral怎么用?Java RexBuilder.makeLiteral使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.calcite.rex.RexBuilder
的用法示例。
在下文中一共展示了RexBuilder.makeLiteral方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: item
import org.apache.calcite.rex.RexBuilder; //导入方法依赖的package包/类
private RexLiteral item(Ast.Node node, RelDataType type) {
final RexBuilder rexBuilder = builder.getRexBuilder();
switch (node.op) {
case LITERAL:
final Ast.Literal literal = (Ast.Literal) node;
return (RexLiteral) rexBuilder.makeLiteral(literal.value, type, false);
case TUPLE:
final Ast.Call tuple = (Ast.Call) node;
final ImmutableList<RexLiteral> list = tuple(tuple.operands, type);
return (RexLiteral) rexBuilder.makeLiteral(list, type, false);
case BAG:
final Ast.Call bag = (Ast.Call) node;
final ImmutableList<RexLiteral> list2 = bag(bag.operands, type);
return (RexLiteral) rexBuilder.makeLiteral(list2, type, false);
default:
throw new IllegalArgumentException("not a literal: " + node);
}
}
示例2: literal
import org.apache.calcite.rex.RexBuilder; //导入方法依赖的package包/类
/** Creates a literal (constant expression). */
public RexNode literal(Object value) {
final RexBuilder rexBuilder = cluster.getRexBuilder();
if (value == null) {
return rexBuilder.constantNull();
} else if (value instanceof Boolean) {
return rexBuilder.makeLiteral((Boolean) value);
} else if (value instanceof BigDecimal) {
return rexBuilder.makeExactLiteral((BigDecimal) value);
} else if (value instanceof Float || value instanceof Double) {
return rexBuilder.makeApproxLiteral(
BigDecimal.valueOf(((Number) value).doubleValue()));
} else if (value instanceof Number) {
return rexBuilder.makeExactLiteral(
BigDecimal.valueOf(((Number) value).longValue()));
} else if (value instanceof String) {
return rexBuilder.makeLiteral((String) value);
} else {
throw new IllegalArgumentException("cannot convert " + value
+ " (" + value.getClass() + ") to a constant");
}
}
示例3: andJoinFilters
import org.apache.calcite.rex.RexBuilder; //导入方法依赖的package包/类
/**
* Ands two sets of join filters together, either of which can be null.
*
* @param rexBuilder rexBuilder to create AND expression
* @param left filter on the left that the right will be AND'd to
* @param right filter on the right
* @return AND'd filter
*
* @see org.apache.calcite.rex.RexUtil#composeConjunction
*/
public static RexNode andJoinFilters(
RexBuilder rexBuilder,
RexNode left,
RexNode right) {
// don't bother AND'ing in expressions that always evaluate to
// true
if ((left != null) && !left.isAlwaysTrue()) {
if ((right != null) && !right.isAlwaysTrue()) {
left =
rexBuilder.makeCall(
SqlStdOperatorTable.AND,
left,
right);
}
} else {
left = right;
}
// Joins must have some filter
if (left == null) {
left = rexBuilder.makeLiteral(true);
}
return left;
}
示例4: splitOr
import org.apache.calcite.rex.RexBuilder; //导入方法依赖的package包/类
private static RexNode splitOr(
final RexBuilder rexBuilder, RexNode condition, RexNode target) {
List<RexNode> conditions = RelOptUtil.disjunctions(condition);
int conditionsLength = conditions.size();
int targetsLength = 0;
for (RexNode e : RelOptUtil.disjunctions(target)) {
removeAll(conditions, e);
targetsLength++;
}
if (conditions.isEmpty() && conditionsLength == targetsLength) {
return rexBuilder.makeLiteral(true);
} else if (conditions.isEmpty()) {
return condition;
}
return null;
}
示例5: setUp
import org.apache.calcite.rex.RexBuilder; //导入方法依赖的package包/类
@Before public void setUp() {
typeFactory = new JavaTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
rexBuilder = new RexBuilder(typeFactory);
boolRelDataType = typeFactory.createSqlType(SqlTypeName.BOOLEAN);
x = new RexInputRef(
0,
typeFactory.createTypeWithNullability(boolRelDataType, true));
y = new RexInputRef(
1,
typeFactory.createTypeWithNullability(boolRelDataType, true));
z = new RexInputRef(
2,
typeFactory.createTypeWithNullability(boolRelDataType, true));
trueRex = rexBuilder.makeLiteral(true);
falseRex = rexBuilder.makeLiteral(false);
}
示例6: addRow
import org.apache.calcite.rex.RexBuilder; //导入方法依赖的package包/类
private void addRow(ImmutableList.Builder<ImmutableList<RexLiteral>> builder,
RexBuilder rexBuilder, Object... values) {
ImmutableList.Builder<RexLiteral> b = ImmutableList.builder();
final RelDataType varcharType =
rexBuilder.getTypeFactory().createSqlType(SqlTypeName.VARCHAR);
for (Object value : values) {
final RexLiteral literal;
if (value == null) {
literal = rexBuilder.makeNullLiteral(varcharType);
} else if (value instanceof Integer) {
literal = rexBuilder.makeExactLiteral(
BigDecimal.valueOf((Integer) value));
} else {
literal = rexBuilder.makeLiteral((String) value);
}
b.add(literal);
}
builder.add(b.build());
}
示例7: newColumnDefaultValue
import org.apache.calcite.rex.RexBuilder; //导入方法依赖的package包/类
@Override public RexNode newColumnDefaultValue(RelOptTable table,
int iColumn, InitializerContext context) {
final RexBuilder rexBuilder = context.getRexBuilder();
final RelDataTypeFactory typeFactory = rexBuilder.getTypeFactory();
switch (iColumn) {
case 0:
return rexBuilder.makeExactLiteral(new BigDecimal(123),
typeFactory.createSqlType(SqlTypeName.INTEGER));
case 1:
return rexBuilder.makeLiteral("Bob");
case 5:
return rexBuilder.makeExactLiteral(new BigDecimal(555),
typeFactory.createSqlType(SqlTypeName.INTEGER));
default:
return rexBuilder.constantNull();
}
}
示例8: setUp
import org.apache.calcite.rex.RexBuilder; //导入方法依赖的package包/类
@Before
public void setUp() {
typeFactory = new JavaTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
rexBuilder = new RexBuilder(typeFactory);
RexExecutor executor =
new RexExecutorImpl(new DummyTestDataContext());
simplify =
new RexSimplify(rexBuilder, RelOptPredicateList.EMPTY, false, executor);
trueLiteral = rexBuilder.makeLiteral(true);
falseLiteral = rexBuilder.makeLiteral(false);
final RelDataType intType = typeFactory.createSqlType(SqlTypeName.INTEGER);
nullLiteral = rexBuilder.makeNullLiteral(intType);
unknownLiteral = rexBuilder.makeNullLiteral(trueLiteral.getType());
}
示例9: generateLiteral
import org.apache.calcite.rex.RexBuilder; //导入方法依赖的package包/类
public RexNode generateLiteral(RexBuilder rexBuilder, RelDataTypeFactory typeFactory){
return rexBuilder.makeLiteral(value, typeFactory.createSqlType(SqlTypeName.BIGINT), false);
}
示例10: projectPredicate
import org.apache.calcite.rex.RexBuilder; //导入方法依赖的package包/类
/** Converts a predicate on a particular set of columns into a predicate on
* a subset of those columns, weakening if necessary.
*
* <p>If not possible to simplify, returns {@code true}, which is the weakest
* possible predicate.
*
* <p>Examples:<ol>
* <li>The predicate {@code $7 = $9} on columns [7]
* becomes {@code $7 is not null}
* <li>The predicate {@code $7 = $9 + $11} on columns [7, 9]
* becomes {@code $7 is not null or $9 is not null}
* <li>The predicate {@code $7 = $9 and $9 = 5} on columns [7] becomes
* {@code $7 = 5}
* <li>The predicate
* {@code $7 = $9 and ($9 = $1 or $9 = $2) and $1 > 3 and $2 > 10}
* on columns [7] becomes {@code $7 > 3}
* </ol>
*
* <p>We currently only handle examples 1 and 2.
*
* @param rexBuilder Rex builder
* @param input Input relational expression
* @param r Predicate expression
* @param columnsMapped Columns which the final predicate can reference
* @return Predicate expression narrowed to reference only certain columns
*/
private RexNode projectPredicate(final RexBuilder rexBuilder, RelNode input,
RexNode r, ImmutableBitSet columnsMapped) {
ImmutableBitSet rCols = RelOptUtil.InputFinder.bits(r);
if (columnsMapped.contains(rCols)) {
// All required columns are present. No need to weaken.
return r;
}
if (columnsMapped.intersects(rCols)) {
final List<RexNode> list = new ArrayList<>();
for (int c : columnsMapped.intersect(rCols)) {
if (input.getRowType().getFieldList().get(c).getType().isNullable()
&& Strong.isNull(r, ImmutableBitSet.of(c))) {
list.add(
rexBuilder.makeCall(SqlStdOperatorTable.IS_NOT_NULL,
rexBuilder.makeInputRef(input, c)));
}
}
if (!list.isEmpty()) {
return RexUtil.composeDisjunction(rexBuilder, list);
}
}
// Cannot weaken to anything non-trivial
return rexBuilder.makeLiteral(true);
}
示例11: getRemaining
import org.apache.calcite.rex.RexBuilder; //导入方法依赖的package包/类
@Override public RexNode getRemaining(RexBuilder rexBuilder) {
return rexBuilder.makeLiteral(true);
}