use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rex.RexLiteral in project druid by druid-io.
the class TimeFormatOperatorConversion method toDruidExpression.
@Override
public DruidExpression toDruidExpression(final PlannerContext plannerContext, final RowSignature rowSignature, final RexNode rexNode) {
final RexCall call = (RexCall) rexNode;
final RexNode timeArg = call.getOperands().get(0);
final DruidExpression timeExpression = Expressions.toDruidExpression(plannerContext, rowSignature, timeArg);
if (timeExpression == null) {
return null;
}
final String pattern = OperatorConversions.getOperandWithDefault(call.getOperands(), 1, RexLiteral::stringValue, DEFAULT_PATTERN);
final DateTimeZone timeZone = OperatorConversions.getOperandWithDefault(call.getOperands(), 2, operand -> {
try {
return DateTimes.inferTzFromString(RexLiteral.stringValue(operand), false);
} catch (IllegalArgumentException e) {
throw new IAE(e.getMessage());
}
}, plannerContext.getTimeZone());
return DruidExpression.ofFunctionCall(Calcites.getColumnTypeForRelDataType(rexNode.getType()), "timestamp_format", ImmutableList.of(timeExpression, DruidExpression.ofStringLiteral(pattern), DruidExpression.ofStringLiteral(timeZone.getID())));
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rex.RexLiteral in project hazelcast by hazelcast.
the class IndexResolver method prepareSingleColumnSearchCandidateComparison.
@SuppressWarnings({ "ConstantConditions", "UnstableApiUsage" })
private static IndexComponentCandidate prepareSingleColumnSearchCandidateComparison(RexNode exp, RexNode operand1, RexNode operand2) {
// SARG is supported only for literals, not for dynamic parameters
if (operand1.getKind() != SqlKind.INPUT_REF || operand2.getKind() != SqlKind.LITERAL) {
return null;
}
int columnIndex = ((RexInputRef) operand1).getIndex();
RexLiteral literal = (RexLiteral) operand2;
QueryDataType hazelcastType = HazelcastTypeUtils.toHazelcastType(literal.getType());
RangeSet<?> rangeSet = RexToExpression.extractRangeFromSearch(literal);
if (rangeSet == null) {
return null;
}
Set<? extends Range<?>> ranges = rangeSet.asRanges();
IndexFilter indexFilter;
if (ranges.size() == 1) {
indexFilter = createIndexFilterForSingleRange(Iterables.getFirst(ranges, null), hazelcastType);
} else if (ranges.stream().allMatch(IndexResolver::isSingletonRange)) {
indexFilter = new IndexInFilter(toList(ranges, range -> createIndexFilterForSingleRange(range, hazelcastType)));
} else {
// No support for IndexInFilter with multiple IndexFilterForSingleRanges
return null;
}
return new IndexComponentCandidate(exp, columnIndex, indexFilter);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rex.RexLiteral in project hazelcast by hazelcast.
the class RexToExpressionTest method test_date.
@Test
public void test_date() {
RexLiteral literal = literal(new DateString("2021-09-17"), new DateString("2021-09-18"), SqlTypeName.DATE);
Range<?> converted = convert(literal);
assertThat(converted).isEqualToComparingFieldByField(range(LocalDate.of(2021, 9, 17), LocalDate.of(2021, 9, 18)));
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rex.RexLiteral in project hazelcast by hazelcast.
the class RexToExpressionTest method test_real.
@Test
public void test_real() {
RexLiteral literal = literal(new BigDecimal(1), new BigDecimal(2), SqlTypeName.REAL);
Range<?> converted = convert(literal);
assertThat(converted).isEqualToComparingFieldByField(range(1F, 2F));
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rex.RexLiteral in project hazelcast by hazelcast.
the class RexToExpressionTest method test_int.
@Test
public void test_int() {
RexLiteral literal = literal(new BigDecimal(1), new BigDecimal(2), SqlTypeName.INTEGER);
Range<?> converted = convert(literal);
assertThat(converted).isEqualToComparingFieldByField(range(1, 2));
}
Aggregations