@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))); } }
final TimeZone tz = timezoneId(query, call.getOperands().get(0)); return applyTimestampFormat( DruidExpressions.applyTimestampFloor(arg, Period.days(1).toString(), "", tz), YYYY_MM_DD, tz); DruidExpressions.applyTimestampFloor(arg, unit, "", tz), YYYY_MM_DD, tz);
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)); } }
return null; return DruidExpressions.applyTimestampFloor( druidExpression, isoPeriodFormat,
return DruidExpressions.applyTimestampFloor( typeCastExpression, Period.days(1).toString(),