@Override public String toDruidExpression(RexNode rexNode, RelDataType rowType, DruidQuery druidQuery) { final RexCall call = (RexCall) rexNode; final List<String> druidExpressions = DruidExpressions.toDruidExpressions( druidQuery, rowType, call.getOperands()); if (druidExpressions == null) { return null; } return DruidQuery.format("%s(%s)", druidOperator, Iterables.getOnlyElement(druidExpressions)); } }
@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()))); } }
public static String fromColumn(String columnName) { return DruidQuery.format("\"%s\"", columnName); }
@Override public String toDruidExpression(RexNode rexNode, RelDataType rowType, DruidQuery druidQuery) { final RexCall call = (RexCall) rexNode; final List<String> druidExpressions = DruidExpressions.toDruidExpressions( druidQuery, rowType, call.getOperands()); if (druidExpressions == null) { return null; } if (druidExpressions.size() != 2) { throw new IllegalStateException( DruidQuery.format("Got binary operator[%s] with %s args?", operator.getName(), druidExpressions.size())); } return DruidQuery .format("(%s %s %s)", druidExpressions.get(0), druidOperator, druidExpressions.get(1)); } }
@Override public String toDruidExpression(RexNode rexNode, RelDataType rowType, DruidQuery druidQuery) { final RexCall call = (RexCall) rexNode; final List<String> druidExpressions = DruidExpressions.toDruidExpressions( druidQuery, rowType, call.getOperands()); if (druidExpressions == null) { return null; } return DruidQuery .format("(%s %s)", druidOperator, Iterables.getOnlyElement(druidExpressions)); } }
@Override public String toDruidExpression(RexNode rexNode, RelDataType rowType, DruidQuery druidQuery) { final RexCall call = (RexCall) rexNode; final List<String> druidExpressions = DruidExpressions.toDruidExpressions( druidQuery, rowType, call.getOperands()); if (druidExpressions == null) { return null; } return DruidQuery.format( "(%s %s)", Iterables.getOnlyElement(druidExpressions), druidOperator); } }
private static String castCharToDateTime( TimeZone timeZone, String operand, final SqlTypeName toType, String format) { // Cast strings to date times by parsing them from SQL format. final String timestampExpression = DruidExpressions.functionCall( "timestamp_parse", ImmutableList.of( operand, DruidExpressions.stringLiteral(format), DruidExpressions.stringLiteral(timeZone.getID()))); if (toType == SqlTypeName.DATE) { // case to date we need to floor to day first return DruidExpressions.applyTimestampFloor( timestampExpression, Period.days(1).toString(), "", timeZone); } else if (toType == SqlTypeName.TIMESTAMP || toType == SqlTypeName.TIMESTAMP_WITH_LOCAL_TIME_ZONE) { return timestampExpression; } else { throw new IllegalStateException( DruidQuery.format("Unsupported DateTime type[%s]", toType)); } }
if (e.getKind() != SqlKind.IN && e.getKind() != SqlKind.NOT_IN) { throw new AssertionError( DruidQuery.format("Expecting IN or NOT IN but got [%s]", e.getKind()));
@Nullable private static DruidJsonFilter toIsNullKindDruidFilter(RexNode rexNode, RelDataType rowType, DruidQuery druidQuery) { if (rexNode.getKind() != SqlKind.IS_NULL && rexNode.getKind() != SqlKind.IS_NOT_NULL) { throw new AssertionError( DruidQuery.format("Expecting IS_NULL or IS_NOT_NULL but got [%s]", rexNode.getKind())); } final RexCall rexCall = (RexCall) rexNode; final RexNode refNode = rexCall.getOperands().get(0); Pair<String, ExtractionFunction> druidColumn = DruidQuery .toDruidColumn(refNode, rowType, druidQuery); final String columnName = druidColumn.left; final ExtractionFunction extractionFunction = druidColumn.right; if (columnName == null) { return null; } if (rexNode.getKind() == SqlKind.IS_NOT_NULL) { return toNotDruidFilter(new JsonSelector(columnName, null, extractionFunction)); } return new JsonSelector(columnName, null, extractionFunction); }
} else if (call.getOperands().size() == 1) { return DruidQuery.format("floor(%s)", druidExpression); } else if (call.getOperands().size() == 2) {
} else if (call.getOperands().size() == 1) { return DruidQuery.format("ceil(%s)", druidExpression); } else if (call.getOperands().size() == 2) {
typeCastExpression = DruidQuery.format("CAST(%s, '%s')", operandExpression, toExprType .toString());
if (rexNode.getKind() != SqlKind.EQUALS && rexNode.getKind() != SqlKind.NOT_EQUALS) { throw new AssertionError( DruidQuery.format("Expecting EQUALS or NOT_EQUALS but got [%s]", rexNode.getKind()));