本文整理汇总了Java中org.apache.calcite.rex.RexLiteral.getValue方法的典型用法代码示例。如果您正苦于以下问题:Java RexLiteral.getValue方法的具体用法?Java RexLiteral.getValue怎么用?Java RexLiteral.getValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.calcite.rex.RexLiteral
的用法示例。
在下文中一共展示了RexLiteral.getValue方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: visitLiteral
import org.apache.calcite.rex.RexLiteral; //导入方法依赖的package包/类
@Override
public TupleFilter visitLiteral(RexLiteral literal) {
String strValue = null;
Object literalValue = literal.getValue();
if (literalValue instanceof NlsString) {
strValue = ((NlsString) literalValue).getValue();
} else if (literalValue instanceof GregorianCalendar) {
GregorianCalendar g = (GregorianCalendar) literalValue;
//strValue = "" + g.get(Calendar.YEAR) + "-" + normToTwoDigits(g.get(Calendar.MONTH) + 1) + "-" + normToTwoDigits(g.get(Calendar.DAY_OF_MONTH));
strValue = Long.toString(g.getTimeInMillis());
} else if (literalValue instanceof TimeUnitRange) {
// Extract(x from y) in where clause
strValue = ((TimeUnitRange) literalValue).name();
} else if (literalValue == null) {
strValue = null;
} else {
strValue = literalValue.toString();
}
TupleFilter filter = new ConstantTupleFilter(strValue);
return filter;
}
示例2: extractGranularity
import org.apache.calcite.rex.RexLiteral; //导入方法依赖的package包/类
/**
* Infers granularity from a time unit.
* It supports {@code FLOOR(<time> TO <timeunit>)}
* and {@code EXTRACT(<timeunit> FROM <time>)}.
* Returns null if it cannot be inferred.
*
* @param node the Rex node
* @return the granularity, or null if it cannot be inferred
*/
public static Granularity extractGranularity(RexNode node, String timeZone) {
final int flagIndex;
if (TimeExtractionFunction.isValidTimeExtract(node)) {
flagIndex = 0;
} else if (TimeExtractionFunction.isValidTimeFloor(node)) {
flagIndex = 1;
} else {
// We can only infer granularity from floor and extract.
return null;
}
final RexCall call = (RexCall) node;
final RexLiteral flag = (RexLiteral) call.operands.get(flagIndex);
final TimeUnitRange timeUnit = (TimeUnitRange) flag.getValue();
return Granularities.createGranularity(timeUnit, timeZone);
}
示例3: isValidTimeExtract
import org.apache.calcite.rex.RexLiteral; //导入方法依赖的package包/类
/**
* Returns whether the RexCall contains a valid extract unit that we can
* serialize to Druid.
*
* @param rexNode Extract expression
*
* @return true if the extract unit is valid
*/
public static boolean isValidTimeExtract(RexNode rexNode) {
if (rexNode.getKind() != SqlKind.EXTRACT) {
return false;
}
final RexCall call = (RexCall) rexNode;
final RexLiteral flag = (RexLiteral) call.operands.get(0);
final TimeUnitRange timeUnit = (TimeUnitRange) flag.getValue();
return timeUnit != null && VALID_TIME_EXTRACT.contains(timeUnit);
}
示例4: isValidTimeFloor
import org.apache.calcite.rex.RexLiteral; //导入方法依赖的package包/类
/**
* Returns whether the RexCall contains a valid FLOOR unit that we can
* serialize to Druid.
*
* @param rexNode Extract expression
*
* @return true if the extract unit is valid
*/
public static boolean isValidTimeFloor(RexNode rexNode) {
if (rexNode.getKind() != SqlKind.FLOOR) {
return false;
}
final RexCall call = (RexCall) rexNode;
if (call.operands.size() != 2) {
return false;
}
final RexLiteral flag = (RexLiteral) call.operands.get(1);
final TimeUnitRange timeUnit = (TimeUnitRange) flag.getValue();
return timeUnit != null && VALID_TIME_EXTRACT.contains(timeUnit);
}
示例5: visitLiteral
import org.apache.calcite.rex.RexLiteral; //导入方法依赖的package包/类
@Override public String visitLiteral(RexLiteral literal) {
if (literal.getValue() == null) {
return "null";
}
return "{$literal: "
+ RexToLixTranslator.translateLiteral(literal, literal.getType(),
typeFactory, RexImpTable.NullAs.NOT_POSSIBLE)
+ "}";
}
示例6: isExtractCall
import org.apache.calcite.rex.RexLiteral; //导入方法依赖的package包/类
boolean isExtractCall(RexNode e) {
switch (e.getKind()) {
case EXTRACT:
final RexCall call = (RexCall) e;
final RexLiteral flag = (RexLiteral) call.operands.get(0);
final TimeUnitRange timeUnit = (TimeUnitRange) flag.getValue();
return timeUnit == this.timeUnit;
default:
return false;
}
}
示例7: visitLiteral
import org.apache.calcite.rex.RexLiteral; //导入方法依赖的package包/类
@Override public String visitLiteral(RexLiteral literal) {
if (literal.getValue() == null) {
return "null";
}
return "\"literal\":\""
+ RexToLixTranslator.translateLiteral(literal, literal.getType(),
typeFactory, RexImpTable.NullAs.NOT_POSSIBLE)
+ "\"";
}
示例8: toSplitsSearchQuery
import org.apache.calcite.rex.RexLiteral; //导入方法依赖的package包/类
public static SearchQuery toSplitsSearchQuery(List<FilterProperties> filters, Field field) {
Preconditions.checkNotNull(field);
final CompleteType ct = CompleteType.fromField(field);
final FieldType fieldType = getFieldType(ct);
final String columnKey = DatasetSplitConverter.buildColumnKey(fieldType, field.getName());
final SearchQuery partitionColumnNotDefinedQuery = SearchQueryUtils.newDoesNotExistQuery(columnKey);
final List<SearchQuery> filterQueries = Lists.newArrayList();
for (FilterProperties filter: filters) {
final RexLiteral literal = filter.getLiteral();
SearchQuery matchingSplitsQuery = null;
final RangeQueryInput rangeQueryInput;
switch (ct.toMinorType()) {
case BIGINT:
rangeQueryInput = new RangeQueryInput(
((BigDecimal) literal.getValue()).setScale(0, BigDecimal.ROUND_HALF_UP).longValue(), filter.getKind());
matchingSplitsQuery = SearchQueryUtils.newRangeLong(columnKey, (Long) rangeQueryInput.min, (Long) rangeQueryInput.max, rangeQueryInput.includeMin, rangeQueryInput.includeMax);
break;
case DATE:
case TIME:
rangeQueryInput = new RangeQueryInput((int) ((GregorianCalendar) literal.getValue()).getTimeInMillis(), filter.getKind());
matchingSplitsQuery = SearchQueryUtils.newRangeInt(columnKey, (Integer) rangeQueryInput.min, (Integer) rangeQueryInput.max, rangeQueryInput.includeMin, rangeQueryInput.includeMax);
break;
case VARCHAR:
if (literal.getValue() instanceof NlsString) {
rangeQueryInput = new RangeQueryInput(((NlsString) literal.getValue()).getValue(), filter.getKind());
} else {
rangeQueryInput = new RangeQueryInput((literal.getValue3().toString()), filter.getKind());
}
matchingSplitsQuery = SearchQueryUtils.newRangeTerm(columnKey, (String) rangeQueryInput.min, (String) rangeQueryInput.max, rangeQueryInput.includeMin, rangeQueryInput.includeMax);
break;
case FLOAT4:
rangeQueryInput = new RangeQueryInput(((BigDecimal) literal.getValue()).floatValue(), filter.getKind());
matchingSplitsQuery = SearchQueryUtils.newRangeFloat(columnKey, (Float) rangeQueryInput.min, (Float) rangeQueryInput.max, rangeQueryInput.includeMin, rangeQueryInput.includeMax);
break;
case FLOAT8:
rangeQueryInput = new RangeQueryInput(((BigDecimal) literal.getValue()).doubleValue(), filter.getKind());
matchingSplitsQuery = SearchQueryUtils.newRangeDouble(columnKey, (Double) rangeQueryInput.min, (Double) rangeQueryInput.max, rangeQueryInput.includeMin, rangeQueryInput.includeMax);
break;
case INT:
rangeQueryInput = new RangeQueryInput(((BigDecimal) literal.getValue()).setScale(0, BigDecimal.ROUND_HALF_UP).intValue(), filter.getKind());
matchingSplitsQuery = SearchQueryUtils.newRangeInt(columnKey, (Integer) rangeQueryInput.min, (Integer) rangeQueryInput.max, rangeQueryInput.includeMin, rangeQueryInput.includeMax);
break;
case TIMESTAMP:
rangeQueryInput = new RangeQueryInput(((GregorianCalendar) literal.getValue()).getTimeInMillis(), filter.getKind());
matchingSplitsQuery = SearchQueryUtils.newRangeLong(columnKey, (Long) rangeQueryInput.min, (Long) rangeQueryInput.max, rangeQueryInput.includeMin, rangeQueryInput.includeMax);
break;
default:
throw new UnsupportedOperationException("type not supported " + ct.toMinorType());
}
if (matchingSplitsQuery != null) {
filterQueries.add(matchingSplitsQuery);
}
}
return SearchQueryUtils.or(SearchQueryUtils.and(filterQueries), partitionColumnNotDefinedQuery);
}
示例9: dealWithTrivialExpr
import org.apache.calcite.rex.RexLiteral; //导入方法依赖的package包/类
TupleFilter dealWithTrivialExpr(RexCall call) {
ImmutableList<RexNode> operators = call.operands;
if (operators.size() != 2) {
return null;
}
BigDecimal left = null;
BigDecimal right = null;
for (RexNode rexNode : operators) {
if (!(rexNode instanceof RexLiteral)) {
return null;// only trivial expr with constants
}
RexLiteral temp = (RexLiteral) rexNode;
if (temp.getType().getFamily() != SqlTypeFamily.NUMERIC || !(temp.getValue() instanceof BigDecimal)) {
return null;// only numeric constants now
}
if (left == null) {
left = (BigDecimal) temp.getValue();
} else {
right = (BigDecimal) temp.getValue();
}
}
Preconditions.checkNotNull(left);
Preconditions.checkNotNull(right);
switch (call.op.getKind()) {
case PLUS:
return new ConstantTupleFilter(left.add(right).toString());
case MINUS:
return new ConstantTupleFilter(left.subtract(right).toString());
case TIMES:
return new ConstantTupleFilter(left.multiply(right).toString());
case DIVIDE:
return new ConstantTupleFilter(left.divide(right).toString());
default:
return null;
}
}
示例10: getValue
import org.apache.calcite.rex.RexLiteral; //导入方法依赖的package包/类
public static Pair<Integer, ?> getValue(RexNode inputRef, RexNode literal) {
inputRef = removeCast(inputRef);
literal = removeCast(literal);
if (inputRef instanceof RexInputRef
&& literal instanceof RexLiteral) {
final int index = ((RexInputRef) inputRef).getIndex();
final RexLiteral rexLiteral = (RexLiteral) literal;
final RelDataType type = inputRef.getType();
if (type.getSqlTypeName() == null) {
LOGGER.warn("{} returned null SqlTypeName", inputRef.toString());
return null;
}
switch (type.getSqlTypeName()) {
case INTEGER:
return Pair.of(index, rexLiteral.getValueAs(Integer.class));
case DOUBLE:
return Pair.of(index, rexLiteral.getValueAs(Double.class));
case REAL:
return Pair.of(index, rexLiteral.getValueAs(Float.class));
case BIGINT:
return Pair.of(index, rexLiteral.getValueAs(Long.class));
case SMALLINT:
return Pair.of(index, rexLiteral.getValueAs(Short.class));
case TINYINT:
return Pair.of(index, rexLiteral.getValueAs(Byte.class));
case DECIMAL:
return Pair.of(index, rexLiteral.getValueAs(BigDecimal.class));
case DATE:
case TIME:
return Pair.of(index, rexLiteral.getValueAs(Integer.class));
case TIMESTAMP:
return Pair.of(index, rexLiteral.getValueAs(Long.class));
case CHAR:
return Pair.of(index, rexLiteral.getValueAs(Character.class));
case VARCHAR:
return Pair.of(index, rexLiteral.getValueAs(String.class));
default:
// TODO: Support few more supported cases
LOGGER.warn("{} for value of class {} is being handled in default way",
type.getSqlTypeName(), rexLiteral.getValue().getClass());
if (rexLiteral.getValue() instanceof NlsString) {
return Pair.of(index, ((NlsString) rexLiteral.getValue()).getValue());
} else {
return Pair.of(index, rexLiteral.getValue());
}
}
}
// Unsupported Arguments
return null;
}