private void handleOffsetFetch(SqlNode offset, SqlNode fetch) { if (offset instanceof SqlDynamicParam) { setValidatedNodeType(offset, typeFactory.createSqlType(SqlTypeName.INTEGER)); } if (fetch instanceof SqlDynamicParam) { setValidatedNodeType(fetch, typeFactory.createSqlType(SqlTypeName.INTEGER)); } }
public TableBuilderInfo field(String name, SqlTypeName type) { return field(name, typeFactory.createSqlType(type)); }
public List<RelDataType> getParameterTypes(RelDataTypeFactory typeFactory) { return ImmutableList.of( typeFactory.createTypeWithNullability( typeFactory.createSqlType(SqlTypeName.ANY), true)); }
public RelDataType getReturnType(RelDataTypeFactory typeFactory) { return typeFactory.createTypeWithNullability( typeFactory.createSqlType(SqlTypeName.ANY), true); }
public TableBuilderInfo field(String name, SqlTypeName type, ColumnConstraint constraint) { interpretConstraint(constraint, fields.size()); return field(name, typeFactory.createSqlType(type)); }
private RexNode integerLiteral(final int integer) { return rexBuilder.makeLiteral(new BigDecimal(integer), typeFactory.createSqlType(SqlTypeName.INTEGER), true); }
/** Creates an expression that casts an expression to a given type. */ public RexNode cast(RexNode expr, SqlTypeName typeName) { final RelDataType type = cluster.getTypeFactory().createSqlType(typeName); return cluster.getRexBuilder().makeCast(type, expr); }
/** Creates an expression that casts an expression to a type with a given name * and precision or length. */ public RexNode cast(RexNode expr, SqlTypeName typeName, int precision) { final RelDataType type = cluster.getTypeFactory().createSqlType(typeName, precision); return cluster.getRexBuilder().makeCast(type, expr); }
/** Creates an expression that casts an expression to a type with a given * name, precision and scale. */ public RexNode cast(RexNode expr, SqlTypeName typeName, int precision, int scale) { final RelDataType type = cluster.getTypeFactory().createSqlType(typeName, precision, scale); return cluster.getRexBuilder().makeCast(type, expr); }
@Override public AggregateCall other(RelDataTypeFactory typeFactory, AggregateCall e) { return AggregateCall.create( new HiveSqlCountAggFunction(isDistinct, returnTypeInference, operandTypeInference, operandTypeChecker), false, ImmutableIntList.of(), -1, typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.BIGINT), true), "count"); }
@Override public AggregateCall other(RelDataTypeFactory typeFactory, AggregateCall e) { return AggregateCall.create( new HiveSqlCountAggFunction(isDistinct, returnTypeInference, operandTypeInference, operandTypeChecker), false, ImmutableIntList.of(), -1, typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.BIGINT), true), "count"); } }
@Override public AggregateCall other(RelDataTypeFactory typeFactory, AggregateCall e) { RelDataType countRetType = typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.BIGINT), true); return AggregateCall.create( new HiveSqlCountAggFunction(isDistinct, ReturnTypes.explicit(countRetType), operandTypeInference, operandTypeChecker), false, ImmutableIntList.of(), -1, countRetType, "count"); }
private RexNode makeCast(SqlTypeName typeName, final RexNode child) { RelDataType sqlType = cluster.getTypeFactory().createSqlType(typeName); RelDataType nullableType = cluster.getTypeFactory().createTypeWithNullability(sqlType, true); return cluster.getRexBuilder().makeCast(nullableType, child); }
@Override public AggregateCall other(RelDataTypeFactory typeFactory, AggregateCall e) { RelDataType countRetType = typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.BIGINT), true); return AggregateCall.create( new HiveSqlCountAggFunction(isDistinct, ReturnTypes.explicit(countRetType), operandTypeInference, operandTypeChecker), false, ImmutableIntList.of(), -1, countRetType, "count"); }
@Test public void testTimeMinusDayTimeInterval() { final Period period = new Period("P1DT1H1M"); testExpression( rexBuilder.makeCall( typeFactory.createSqlType(SqlTypeName.TIMESTAMP), SqlStdOperatorTable.MINUS_DATE, ImmutableList.of( inputRef("t"), rexBuilder.makeIntervalLiteral( new BigDecimal(period.toStandardDuration().getMillis()), // DAY-TIME literals value is millis new SqlIntervalQualifier(TimeUnit.DAY, TimeUnit.MINUTE, SqlParserPos.ZERO) ) ) ), DruidExpression.of( null, "(\"t\" - 90060000)" ), DateTimes.of("2000-02-03T04:05:06").minus(period).getMillis() ); }
@Test public void testConcat() { testExpression( rexBuilder.makeCall( typeFactory.createSqlType(SqlTypeName.VARCHAR), SqlStdOperatorTable.CONCAT, ImmutableList.of( inputRef("s"), rexBuilder.makeLiteral("bar") ) ), DruidExpression.fromExpression("concat(\"s\",'bar')"), "foobar" ); }
@Test public void testTimeMinusYearMonthInterval() { final Period period = new Period("P1Y1M"); testExpression( rexBuilder.makeCall( typeFactory.createSqlType(SqlTypeName.TIMESTAMP), SqlStdOperatorTable.MINUS_DATE, ImmutableList.of( inputRef("t"), rexBuilder.makeIntervalLiteral( new BigDecimal(13), // YEAR-MONTH literals value is months new SqlIntervalQualifier(TimeUnit.YEAR, TimeUnit.MONTH, SqlParserPos.ZERO) ) ) ), DruidExpression.of( null, "timestamp_shift(\"t\",concat('P', 13, 'M'),-1)" ), DateTimes.of("2000-02-03T04:05:06").minus(period).getMillis() ); }
@Test public void testCastAsDate() { testExpression( rexBuilder.makeAbstractCast( typeFactory.createSqlType(SqlTypeName.DATE), inputRef("t") ), DruidExpression.fromExpression("timestamp_floor(\"t\",'P1D',null,'UTC')"), DateTimes.of("2000-02-03").getMillis() ); testExpression( rexBuilder.makeAbstractCast( typeFactory.createSqlType(SqlTypeName.DATE), inputRef("dstr") ), DruidExpression.fromExpression( "timestamp_floor(timestamp_parse(\"dstr\",null,'UTC'),'P1D',null,'UTC')" ), DateTimes.of("2000-02-03").getMillis() ); }
@Test public void testCastAsTimestamp() { testExpression( rexBuilder.makeAbstractCast( typeFactory.createSqlType(SqlTypeName.TIMESTAMP), inputRef("t") ), DruidExpression.of( SimpleExtraction.of("t", null), "\"t\"" ), DateTimes.of("2000-02-03T04:05:06Z").getMillis() ); testExpression( rexBuilder.makeAbstractCast( typeFactory.createSqlType(SqlTypeName.TIMESTAMP), inputRef("tstr") ), DruidExpression.of( null, "timestamp_parse(\"tstr\",null,'UTC')" ), DateTimes.of("2000-02-03T04:05:06Z").getMillis() ); }
@Test public void testTimeShift() { testExpression( rexBuilder.makeCall( new TimeShiftOperatorConversion().calciteOperator(), inputRef("t"), rexBuilder.makeLiteral("PT2H"), rexBuilder.makeLiteral(-3, typeFactory.createSqlType(SqlTypeName.INTEGER), true) ), DruidExpression.fromExpression("timestamp_shift(\"t\",'PT2H',-3)"), DateTimes.of("2000-02-02T22:05:06").getMillis() ); }