public static String numberLiteral(final Number n) { return n == null ? nullLiteral() : n.toString(); }
public static String stringLiteral(final String s) { return s == null ? nullLiteral() : "'" + escape(s) + "'"; }
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.fromExpression(DruidExpression.nullLiteral()); } else if (SqlTypeName.NUMERIC_TYPES.contains(sqlTypeName)) { return DruidExpression.fromExpression(DruidExpression.numberLiteral((Number) RexLiteral.value(rexNode))); } else if (SqlTypeName.TIMESTAMP == sqlTypeName || SqlTypeName.DATE == sqlTypeName) { if (RexLiteral.isNullLiteral(rexNode)) { return DruidExpression.fromExpression(DruidExpression.nullLiteral()); } else { return DruidExpression.fromExpression(
@Test public void testCountNullableExpression() throws Exception { testQuery( "SELECT COUNT(CASE WHEN dim2 = 'abc' THEN 'yes' WHEN dim2 = 'def' THEN 'yes' END) FROM druid.foo", ImmutableList.of( Druids.newTimeseriesQueryBuilder() .dataSource(CalciteTests.DATASOURCE1) .intervals(QSS(Filtration.eternity())) .granularity(Granularities.ALL) .aggregators(AGGS( new FilteredAggregatorFactory( new CountAggregatorFactory("a0"), EXPRESSION_FILTER( "notnull(case_searched((\"dim2\" == 'abc'),'yes',(\"dim2\" == 'def'),'yes'," + DruidExpression.nullLiteral() + "))" ) ) )) .context(TIMESERIES_CONTEXT_DEFAULT) .build() ), ImmutableList.of( new Object[]{1L} ) ); }
+ "(timestamp_extract(\"__time\",'DAY','UTC') == 0)," + "'zero'," + DruidExpression.nullLiteral() + ")", ValueType.STRING
public static String numberLiteral(final Number n) { return n == null ? nullLiteral() : n.toString(); }
public static String stringLiteral(final String s) { return s == null ? nullLiteral() : "'" + escape(s) + "'"; }
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.fromExpression(DruidExpression.nullLiteral()); } else if (SqlTypeName.NUMERIC_TYPES.contains(sqlTypeName)) { return DruidExpression.fromExpression(DruidExpression.numberLiteral((Number) RexLiteral.value(rexNode))); } else if (SqlTypeName.TIMESTAMP == sqlTypeName || SqlTypeName.DATE == sqlTypeName) { if (RexLiteral.isNullLiteral(rexNode)) { return DruidExpression.fromExpression(DruidExpression.nullLiteral()); } else { return DruidExpression.fromExpression(