@Nullable @Override public String toDruidExpression(RexNode rexNode, RelDataType rowType, DruidQuery query ) { final RexCall call = (RexCall) rexNode; if (call.getOperands().size() < 1 || call.getOperands().size() > 2) { throw new IllegalStateException("form_unixtime() requires 1 or 2 argument, got " + call.getOperands().size()); } final String arg = DruidExpressions.toDruidExpression(call.getOperands().get(0), rowType, query); if (arg == null) { return null; } final String numMillis = DruidQuery.format("(%s * '1000')", arg); final String format = call.getOperands().size() == 1 ? DruidExpressions.stringLiteral(DEFAULT_TS_FORMAT) : DruidExpressions .toDruidExpression(call.getOperands().get(1), rowType, query); return DruidExpressions.functionCall("timestamp_format", ImmutableList.of(numMillis, format, DruidExpressions.stringLiteral(TimeZone.getTimeZone("UTC").getID())) ); } }
@Nullable @Override public String toDruidExpression(RexNode rexNode, RelDataType rowType, DruidQuery query ) { final RexCall call = (RexCall) rexNode; if (call.getOperands().size() != 2) { throw new IllegalStateException("date_add/date_sub() requires 2 arguments, got " + call.getOperands().size()); } final String arg0 = DruidExpressions.toDruidExpression(call.getOperands().get(0), rowType, query); final String arg1 = DruidExpressions.toDruidExpression(call.getOperands().get(1), rowType, query); if (arg0 == null || arg1 == null) { return null; } final String steps = direction == -1 ? DruidQuery.format("-( %s )", arg1) : arg1; return DruidExpressions.functionCall( "timestamp_shift", ImmutableList.of( arg0, DruidExpressions.stringLiteral("P1D"), steps, DruidExpressions.stringLiteral(timezoneId(query, call.getOperands().get(0)).getID()))); } }
@Nullable @Override public String toDruidExpression(RexNode rexNode, RelDataType rowType, DruidQuery query ) { final RexCall call = (RexCall) rexNode; if (call.getOperands().size() != 1) { throw new IllegalStateException("to_date() requires 1 argument, got " + call.getOperands().size()); } final String arg = DruidExpressions.toDruidExpression(call.getOperands().get(0), rowType, query); if (arg == null) { return null; } return DruidExpressions.applyTimestampFloor( arg, Period.days(1).toString(), "", timezoneId(query, call.getOperands().get(0))); } }
@Nullable @Override public String toDruidExpression(RexNode rexNode, RelDataType rowType, DruidQuery query ) { final RexCall call = (RexCall) rexNode; final String arg0 = DruidExpressions.toDruidExpression(call.getOperands().get(0), rowType, query); if (arg0 == null) { return null; } if (SqlTypeUtil.isDatetime((call.getOperands().get(0).getType()))) { // Timestamp is represented as long internally no need to any thing here return DruidExpressions.functionCall("div", ImmutableList.of(arg0, DruidExpressions.numberLiteral(1000))); } // dealing with String type final String format = call.getOperands().size() == 2 ? DruidExpressions .toDruidExpression(call.getOperands().get(1), rowType, query) : DEFAULT_TS_FORMAT; return DruidExpressions .functionCall("unix_timestamp", ImmutableList.of(arg0, DruidExpressions.stringLiteral(format))); } }
@Nullable @Override public String toDruidExpression(RexNode rexNode, RelDataType rowType, DruidQuery query ) { final RexCall call = (RexCall) rexNode; final String arg = DruidExpressions.toDruidExpression(call.getOperands().get(0), rowType, query); if (arg == null) { return null; final String indexExp = DruidExpressions.toDruidExpression(call.getOperands().get(1), rowType, query); if (indexExp == null) { return null; length = DruidExpressions.toDruidExpression(call.getOperands().get(2), rowType, query); if (length == null) { return null;
final String arg = DruidExpressions.toDruidExpression(call.getOperands().get(0), rowType, query); if (arg == null) { return null; final String arg = DruidExpressions.toDruidExpression(call.getOperands().get(0), rowType, query); if (arg == null) { return null; String granularity = DruidExpressions.toDruidExpression(call.getOperands().get(1), rowType, query); if (granularity == null) { return null;
@Nullable private static DruidJsonFilter toDruidExpressionFilter(RexNode rexNode, RelDataType rowType, DruidQuery query) { final String expression = DruidExpressions.toDruidExpression(rexNode, rowType, query); return expression == null ? null : new JsonExpressionFilter(expression); }
/** * Translate a list of Calcite {@code RexNode} to Druid expressions. * * @param rexNodes list of Calcite expressions meant to be applied on top of the rows * * @return list of Druid expressions in the same order as rexNodes, or null if not possible. * If a non-null list is returned, all elements will be non-null. */ @Nullable public static List<String> toDruidExpressions( final DruidQuery druidRel, final RelDataType rowType, final List<RexNode> rexNodes) { final List<String> retVal = new ArrayList<>(rexNodes.size()); for (RexNode rexNode : rexNodes) { final String druidExpression = toDruidExpression(rexNode, rowType, druidRel); if (druidExpression == null) { return null; } retVal.add(druidExpression); } return retVal; }
@Override public String toDruidExpression( RexNode rexNode, RelDataType rowType, DruidQuery query) { final RexCall call = (RexCall) rexNode; final RexLiteral flag = (RexLiteral) call.getOperands().get(0); final TimeUnitRange calciteUnit = (TimeUnitRange) flag.getValue(); final RexNode arg = call.getOperands().get(1); final String input = DruidExpressions.toDruidExpression(arg, rowType, query); if (input == null) { return null; } final String druidUnit = EXTRACT_UNIT_MAP.get(calciteUnit); if (druidUnit == null) { return null; } final TimeZone tz = arg.getType().getSqlTypeName() == SqlTypeName.TIMESTAMP_WITH_LOCAL_TIME_ZONE ? TimeZone.getTimeZone(query.getConnectionConfig().timeZone()) : DateTimeUtils.UTC_ZONE; return DruidExpressions.applyTimeExtract(input, druidUnit, tz); } }
DruidQuery query) { final RexCall call = (RexCall) rexNode; final String arg = DruidExpressions.toDruidExpression( call.getOperands().get(0), rowType, query); if (arg == null) { final String arg1 = DruidExpressions.toDruidExpression( call.getOperands().get(1), rowType, query); if (arg1 == null) { length = DruidExpressions.toDruidExpression( call.getOperands().get(2), rowType, query); if (length == null) {
.toDruidExpression(project, inputRowType, druidQuery); if (expression == null) { return null;
final RexCall call = (RexCall) rexNode; final RexNode arg = call.getOperands().get(0); final String druidExpression = DruidExpressions.toDruidExpression( arg, rowType,
final RexCall call = (RexCall) rexNode; final RexNode arg = call.getOperands().get(0); final String druidExpression = DruidExpressions.toDruidExpression( arg, rowType,
.toDruidExpression(project, inputRowType, druidQuery); if (Strings.isNullOrEmpty(expression)) { return null;
} else { expression = DruidExpressions .toDruidExpression(rexNode, inputRowType, druidQuery); if (Strings.isNullOrEmpty(expression)) { return null;
final String operandExpression = DruidExpressions.toDruidExpression(operand, topRel, druidQuery);
final RexNode postProjectRexNode = pair.left; String expression = DruidExpressions .toDruidExpression(postProjectRexNode, postAggInputRowType, this); final String existingFieldName = existingProjects.get(expression); if (existingFieldName != null) {
if (DruidExpressions.toDruidExpression(rexNode, topAgg.getRowType(), query) == null) { return;