@Nullable public static DruidExpression makeTrimExpression( final SqlTrimFunction.Flag trimStyle, final DruidExpression stringExpression, final DruidExpression charsExpression ) { final String functionName; switch (trimStyle) { case LEADING: functionName = "ltrim"; break; case TRAILING: functionName = "rtrim"; break; case BOTH: functionName = "trim"; break; default: // Not reached throw new UnsupportedOperationException(); } // Druid version of trim is multi-function (ltrim/rtrim/trim) and the other two args are swapped. return DruidExpression.fromFunctionCall(functionName, ImmutableList.of(stringExpression, charsExpression)); }
@Nullable public static DruidExpression convertCall( final PlannerContext plannerContext, final RowSignature rowSignature, final RexNode rexNode, final String functionName ) { return convertCall( plannerContext, rowSignature, rexNode, druidExpressions -> DruidExpression.fromFunctionCall(functionName, druidExpressions) ); }
public static DruidExpression applyTimeExtract( final DruidExpression timeExpression, final TimestampExtractExprMacro.Unit unit, final DateTimeZone timeZone ) { return DruidExpression.fromFunctionCall( "timestamp_extract", ImmutableList.of( timeExpression, DruidExpression.fromExpression(DruidExpression.stringLiteral(unit.name())), DruidExpression.fromExpression(DruidExpression.stringLiteral(timeZone.getID())) ) ); }
} else { return DruidExpression.fromFunctionCall("timestamp_floor", druidExpressions);
: plannerContext.getTimeZone(); return DruidExpression.fromFunctionCall( "timestamp_format", ImmutableList.of(
private static DruidExpression castDateTimeToChar( final PlannerContext plannerContext, final DruidExpression operand, final SqlTypeName fromType ) { return DruidExpression.fromFunctionCall( "timestamp_format", ImmutableList.of( operand, DruidExpression.fromExpression(DruidExpression.stringLiteral(dateTimeFormatString(fromType))), DruidExpression.fromExpression(DruidExpression.stringLiteral(plannerContext.getTimeZone().getID())) ) ); }
return DruidExpression.fromFunctionCall( "timestamp_floor", ImmutableList.of(
return DruidExpression.fromFunctionCall( "timestamp_ceil", Stream
private static DruidExpression castCharToDateTime( final PlannerContext plannerContext, final DruidExpression operand, final SqlTypeName toType ) { // Cast strings to datetimes by parsing them from SQL format. final DruidExpression timestampExpression = DruidExpression.fromFunctionCall( "timestamp_parse", ImmutableList.of( operand, DruidExpression.fromExpression(DruidExpression.nullLiteral()), DruidExpression.fromExpression(DruidExpression.stringLiteral(plannerContext.getTimeZone().getID())) ) ); if (toType == SqlTypeName.DATE) { return TimeFloorOperatorConversion.applyTimestampFloor( timestampExpression, new PeriodGranularity(Period.days(1), null, plannerContext.getTimeZone()), plannerContext.getExprMacroTable() ); } else if (toType == SqlTypeName.TIMESTAMP) { return timestampExpression; } else { throw new ISE("Unsupported DateTime type[%s]", toType); } }
return DruidExpression.fromFunctionCall( "timestamp_floor", ImmutableList.of(
@Nullable public static DruidExpression makeTrimExpression( final SqlTrimFunction.Flag trimStyle, final DruidExpression stringExpression, final DruidExpression charsExpression ) { final String functionName; switch (trimStyle) { case LEADING: functionName = "ltrim"; break; case TRAILING: functionName = "rtrim"; break; case BOTH: functionName = "trim"; break; default: // Not reached throw new UnsupportedOperationException(); } // Druid version of trim is multi-function (ltrim/rtrim/trim) and the other two args are swapped. return DruidExpression.fromFunctionCall(functionName, ImmutableList.of(stringExpression, charsExpression)); }
@Nullable public static DruidExpression convertCall( final PlannerContext plannerContext, final RowSignature rowSignature, final RexNode rexNode, final String functionName ) { return convertCall( plannerContext, rowSignature, rexNode, druidExpressions -> DruidExpression.fromFunctionCall(functionName, druidExpressions) ); }
public static DruidExpression applyTimeExtract( final DruidExpression timeExpression, final TimestampExtractExprMacro.Unit unit, final DateTimeZone timeZone ) { return DruidExpression.fromFunctionCall( "timestamp_extract", ImmutableList.of( timeExpression, DruidExpression.fromExpression(DruidExpression.stringLiteral(unit.name())), DruidExpression.fromExpression(DruidExpression.stringLiteral(timeZone.getID())) ) ); }
} else { return DruidExpression.fromFunctionCall("timestamp_floor", druidExpressions);
: plannerContext.getTimeZone(); return DruidExpression.fromFunctionCall( "timestamp_format", ImmutableList.of(
private static DruidExpression castDateTimeToChar( final PlannerContext plannerContext, final DruidExpression operand, final SqlTypeName fromType ) { return DruidExpression.fromFunctionCall( "timestamp_format", ImmutableList.of( operand, DruidExpression.fromExpression(DruidExpression.stringLiteral(dateTimeFormatString(fromType))), DruidExpression.fromExpression(DruidExpression.stringLiteral(plannerContext.getTimeZone().getID())) ) ); }
return DruidExpression.fromFunctionCall( "timestamp_floor", ImmutableList.of(
return DruidExpression.fromFunctionCall( "timestamp_ceil", Arrays.asList(
private static DruidExpression castCharToDateTime( final PlannerContext plannerContext, final DruidExpression operand, final SqlTypeName toType ) { // Cast strings to datetimes by parsing them from SQL format. final DruidExpression timestampExpression = DruidExpression.fromFunctionCall( "timestamp_parse", ImmutableList.of( operand, DruidExpression.fromExpression(DruidExpression.nullLiteral()), DruidExpression.fromExpression(DruidExpression.stringLiteral(plannerContext.getTimeZone().getID())) ) ); if (toType == SqlTypeName.DATE) { return TimeFloorOperatorConversion.applyTimestampFloor( timestampExpression, new PeriodGranularity(Period.days(1), null, plannerContext.getTimeZone()), plannerContext.getExprMacroTable() ); } else if (toType == SqlTypeName.TIMESTAMP) { return timestampExpression; } else { throw new ISE("Unsupported DateTime type[%s]", toType); } }
return DruidExpression.fromFunctionCall( "timestamp_floor", ImmutableList.of(