Search in sources :

Example 21 with SqlIntervalQualifier

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlIntervalQualifier in project hive by apache.

the class RexNodeExprFactory method createIntervalMinuteConstantExpr.

/**
 * {@inheritDoc}
 */
@Override
protected RexLiteral createIntervalMinuteConstantExpr(String value) {
    HiveIntervalDayTime v = new HiveIntervalDayTime(0, 0, Integer.parseInt(value), 0, 0);
    BigDecimal secsValueBd = BigDecimal.valueOf(v.getTotalSeconds() * 1000);
    BigDecimal nanosValueBd = BigDecimal.valueOf((v).getNanos(), 6);
    return rexBuilder.makeIntervalLiteral(secsValueBd.add(nanosValueBd), new SqlIntervalQualifier(TimeUnit.MILLISECOND, null, new SqlParserPos(1, 1)));
}
Also used : SqlParserPos(org.apache.calcite.sql.parser.SqlParserPos) SqlIntervalQualifier(org.apache.calcite.sql.SqlIntervalQualifier) HiveIntervalDayTime(org.apache.hadoop.hive.common.type.HiveIntervalDayTime) BigDecimal(java.math.BigDecimal)

Example 22 with SqlIntervalQualifier

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlIntervalQualifier in project druid by druid-io.

the class ExpressionsTest method testTimeMinusYearMonthInterval.

@Test
public void testTimeMinusYearMonthInterval() {
    final Period period = new Period("P1Y1M");
    testHelper.testExpression(SqlTypeName.TIMESTAMP, SqlStdOperatorTable.MINUS_DATE, ImmutableList.of(testHelper.makeInputRef("t"), testHelper.makeLiteral(// YEAR-MONTH literals value is months
    new BigDecimal(13), new SqlIntervalQualifier(TimeUnit.YEAR, TimeUnit.MONTH, SqlParserPos.ZERO))), DruidExpression.ofExpression(ColumnType.LONG, DruidExpression.functionCall("timestamp_shift"), ImmutableList.of(DruidExpression.ofColumn(ColumnType.LONG, "t"), // RexNode type "interval year to month" is not reported as ColumnType.STRING
    DruidExpression.ofLiteral(null, DruidExpression.stringLiteral("P13M")), DruidExpression.ofLiteral(ColumnType.LONG, DruidExpression.numberLiteral(-1)), DruidExpression.ofStringLiteral("UTC"))), DateTimes.of("2000-02-03T04:05:06").minus(period).getMillis());
}
Also used : SqlIntervalQualifier(org.apache.calcite.sql.SqlIntervalQualifier) Period(org.joda.time.Period) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 23 with SqlIntervalQualifier

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlIntervalQualifier in project druid by druid-io.

the class GreatestExpressionTest method testInvalidType.

@Test
public void testInvalidType() {
    expectException(IllegalArgumentException.class, "Argument 0 has invalid type: INTERVAL_YEAR_MONTH");
    testExpression(Collections.singletonList(testHelper.makeLiteral(// YEAR-MONTH literals value is months
    new BigDecimal(13), new SqlIntervalQualifier(TimeUnit.YEAR, TimeUnit.MONTH, SqlParserPos.ZERO))), null, null);
}
Also used : SqlIntervalQualifier(org.apache.calcite.sql.SqlIntervalQualifier) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 24 with SqlIntervalQualifier

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlIntervalQualifier in project druid by druid-io.

the class ExpressionsTest method testTimePlusDayTimeInterval.

@Test
public void testTimePlusDayTimeInterval() {
    final Period period = new Period("P1DT1H1M");
    testHelper.testExpressionString(SqlStdOperatorTable.DATETIME_PLUS, ImmutableList.of(testHelper.makeInputRef("t"), testHelper.makeLiteral(// DAY-TIME literals value is millis
    new BigDecimal(period.toStandardDuration().getMillis()), new SqlIntervalQualifier(TimeUnit.DAY, TimeUnit.MINUTE, SqlParserPos.ZERO))), makeExpression(ColumnType.LONG, "(\"t\" + 90060000)"), DateTimes.of("2000-02-03T04:05:06").plus(period).getMillis());
}
Also used : SqlIntervalQualifier(org.apache.calcite.sql.SqlIntervalQualifier) Period(org.joda.time.Period) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 25 with SqlIntervalQualifier

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlIntervalQualifier in project flink by apache.

the class RelDataTypeJsonSerdeTest method testRelDataTypeSerde.

// --------------------------------------------------------------------------------------------
// Test data
// --------------------------------------------------------------------------------------------
public static List<RelDataType> testRelDataTypeSerde() {
    // the values in the list do not care about nullable.
    final List<RelDataType> types = Arrays.asList(FACTORY.createSqlType(SqlTypeName.BOOLEAN), FACTORY.createSqlType(SqlTypeName.TINYINT), FACTORY.createSqlType(SqlTypeName.SMALLINT), FACTORY.createSqlType(SqlTypeName.INTEGER), FACTORY.createSqlType(SqlTypeName.BIGINT), FACTORY.createSqlType(SqlTypeName.DECIMAL, 10, 3), FACTORY.createSqlType(SqlTypeName.DECIMAL, 19, 0), FACTORY.createSqlType(SqlTypeName.DECIMAL, 38, 19), FACTORY.createSqlType(SqlTypeName.FLOAT), FACTORY.createSqlType(SqlTypeName.DOUBLE), FACTORY.createSqlType(SqlTypeName.DATE), FACTORY.createSqlType(SqlTypeName.TIME), FACTORY.createSqlType(SqlTypeName.TIMESTAMP), FACTORY.createSqlType(SqlTypeName.TIMESTAMP_WITH_LOCAL_TIME_ZONE), FACTORY.createSqlIntervalType(new SqlIntervalQualifier(TimeUnit.DAY, 2, TimeUnit.MINUTE, RelDataType.PRECISION_NOT_SPECIFIED, SqlParserPos.ZERO)), FACTORY.createSqlIntervalType(new SqlIntervalQualifier(TimeUnit.DAY, 6, TimeUnit.SECOND, 9, SqlParserPos.ZERO)), FACTORY.createSqlIntervalType(new SqlIntervalQualifier(TimeUnit.HOUR, RelDataType.PRECISION_NOT_SPECIFIED, TimeUnit.SECOND, 9, SqlParserPos.ZERO)), FACTORY.createSqlIntervalType(new SqlIntervalQualifier(TimeUnit.MINUTE, RelDataType.PRECISION_NOT_SPECIFIED, TimeUnit.SECOND, 0, SqlParserPos.ZERO)), FACTORY.createSqlIntervalType(new SqlIntervalQualifier(TimeUnit.SECOND, RelDataType.PRECISION_NOT_SPECIFIED, TimeUnit.SECOND, 6, SqlParserPos.ZERO)), FACTORY.createSqlType(SqlTypeName.CHAR), FACTORY.createSqlType(SqlTypeName.CHAR, 0), FACTORY.createSqlType(SqlTypeName.CHAR, 32), FACTORY.createSqlType(SqlTypeName.VARCHAR), FACTORY.createSqlType(SqlTypeName.VARCHAR, 0), FACTORY.createSqlType(SqlTypeName.VARCHAR, 10), FACTORY.createSqlType(SqlTypeName.BINARY), FACTORY.createSqlType(SqlTypeName.BINARY, 0), FACTORY.createSqlType(SqlTypeName.BINARY, 100), FACTORY.createSqlType(SqlTypeName.VARBINARY), FACTORY.createSqlType(SqlTypeName.VARBINARY, 0), FACTORY.createSqlType(SqlTypeName.VARBINARY, 1000), FACTORY.createSqlType(SqlTypeName.NULL), FACTORY.createSqlType(SqlTypeName.SYMBOL), FACTORY.createMultisetType(FACTORY.createSqlType(SqlTypeName.VARCHAR), -1), FACTORY.createArrayType(FACTORY.createSqlType(SqlTypeName.VARCHAR, 16), -1), FACTORY.createArrayType(FACTORY.createArrayType(FACTORY.createSqlType(SqlTypeName.VARCHAR, 16), -1), -1), FACTORY.createMapType(FACTORY.createSqlType(SqlTypeName.INTEGER), FACTORY.createSqlType(SqlTypeName.VARCHAR, 10)), FACTORY.createMapType(FACTORY.createMapType(FACTORY.createSqlType(SqlTypeName.INTEGER), FACTORY.createSqlType(SqlTypeName.VARCHAR, 10)), FACTORY.createArrayType(FACTORY.createMapType(FACTORY.createSqlType(SqlTypeName.INTEGER), FACTORY.createSqlType(SqlTypeName.VARCHAR, 10)), -1)), // simple struct type
    FACTORY.createStructType(StructKind.PEEK_FIELDS_NO_EXPAND, Arrays.asList(FACTORY.createSqlType(SqlTypeName.INTEGER), FACTORY.createSqlType(SqlTypeName.DECIMAL, 10, 3)), Arrays.asList("f1", "f2")), // struct type with array type
    FACTORY.createStructType(StructKind.PEEK_FIELDS_NO_EXPAND, Arrays.asList(FACTORY.createSqlType(SqlTypeName.VARCHAR), FACTORY.createArrayType(FACTORY.createSqlType(SqlTypeName.VARCHAR, 16), -1)), Arrays.asList("f1", "f2")), // nested struct type
    FACTORY.createStructType(StructKind.PEEK_FIELDS_NO_EXPAND, Arrays.asList(FACTORY.createStructType(StructKind.PEEK_FIELDS_NO_EXPAND, Arrays.asList(FACTORY.createSqlType(SqlTypeName.VARCHAR, 5), FACTORY.createSqlType(SqlTypeName.VARCHAR, 10)), Arrays.asList("f1", "f2")), FACTORY.createArrayType(FACTORY.createSqlType(SqlTypeName.VARCHAR, 16), -1)), Arrays.asList("f3", "f4")), FACTORY.createRowtimeIndicatorType(true, false), FACTORY.createRowtimeIndicatorType(true, true), FACTORY.createProctimeIndicatorType(true), FACTORY.createFieldTypeFromLogicalType(StructuredType.newBuilder(ObjectIdentifier.of("cat", "db", "structuredType"), DataTypeJsonSerdeTest.PojoClass.class).attributes(Arrays.asList(new StructuredType.StructuredAttribute("f0", new IntType(true)), new StructuredType.StructuredAttribute("f1", new BigIntType(true)), new StructuredType.StructuredAttribute("f2", new VarCharType(200), "desc"))).comparison(StructuredType.StructuredComparison.FULL).setFinal(false).setInstantiable(false).description("description for StructuredType").build()));
    final List<RelDataType> mutableTypes = new ArrayList<>(types.size() * 2);
    for (RelDataType type : types) {
        mutableTypes.add(FACTORY.createTypeWithNullability(type, true));
        mutableTypes.add(FACTORY.createTypeWithNullability(type, false));
    }
    mutableTypes.add(FACTORY.createTypeWithNullability(FACTORY.createFieldTypeFromLogicalType(new RawType<>(true, Void.class, VoidSerializer.INSTANCE)), true));
    mutableTypes.add(FACTORY.createTypeWithNullability(FACTORY.createFieldTypeFromLogicalType(new RawType<>(false, Void.class, VoidSerializer.INSTANCE)), false));
    mutableTypes.add(FACTORY.createTypeWithNullability(FACTORY.createFieldTypeFromLogicalType(new RawType<>(true, Void.class, VoidSerializer.INSTANCE)), false));
    return mutableTypes;
}
Also used : SqlIntervalQualifier(org.apache.calcite.sql.SqlIntervalQualifier) ArrayList(java.util.ArrayList) BigIntType(org.apache.flink.table.types.logical.BigIntType) RelDataType(org.apache.calcite.rel.type.RelDataType) VarCharType(org.apache.flink.table.types.logical.VarCharType) StructuredType(org.apache.flink.table.types.logical.StructuredType) IntType(org.apache.flink.table.types.logical.IntType) BigIntType(org.apache.flink.table.types.logical.BigIntType)

Aggregations

SqlIntervalQualifier (org.apache.calcite.sql.SqlIntervalQualifier)31 BigDecimal (java.math.BigDecimal)24 RelDataType (org.apache.calcite.rel.type.RelDataType)13 SqlParserPos (org.apache.calcite.sql.parser.SqlParserPos)12 Test (org.junit.Test)8 HiveIntervalDayTime (org.apache.hadoop.hive.common.type.HiveIntervalDayTime)6 RelDataTypeFactory (org.apache.calcite.rel.type.RelDataTypeFactory)5 Period (org.joda.time.Period)5 Calendar (java.util.Calendar)4 RexBuilder (org.apache.calcite.rex.RexBuilder)4 RexNode (org.apache.calcite.rex.RexNode)4 SqlIntervalLiteral (org.apache.calcite.sql.SqlIntervalLiteral)4 SqlNode (org.apache.calcite.sql.SqlNode)4 TimestampString (org.apache.calcite.util.TimestampString)4 BigInteger (java.math.BigInteger)3 BitString (org.apache.calcite.util.BitString)3 DateString (org.apache.calcite.util.DateString)3 GregorianCalendar (java.util.GregorianCalendar)2 TimeUnit (org.apache.calcite.avatica.util.TimeUnit)2 RexLiteral (org.apache.calcite.rex.RexLiteral)2