Search in sources :

Example 26 with SqlIntervalQualifier

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

the class RexToExpressionTest method test_intervalYearMonth.

@Test
public void test_intervalYearMonth() {
    RelDataType type = FACTORY.createSqlIntervalType(new SqlIntervalQualifier(YEAR, MONTH, SqlParserPos.ZERO));
    RexLiteral literal = BUILDER.makeSearchArgumentLiteral(sarg(new BigDecimal(1), new BigDecimal(2)), type);
    Range<?> converted = convert(literal);
    assertThat(converted).isEqualToComparingFieldByField(range(new SqlYearMonthInterval(1), new SqlYearMonthInterval(2)));
}
Also used : RexLiteral(org.apache.calcite.rex.RexLiteral) SqlIntervalQualifier(org.apache.calcite.sql.SqlIntervalQualifier) SqlYearMonthInterval(com.hazelcast.sql.impl.type.SqlYearMonthInterval) RelDataType(org.apache.calcite.rel.type.RelDataType) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 27 with SqlIntervalQualifier

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

the class RexToExpressionTest method test_intervalDaySecond.

@Test
public void test_intervalDaySecond() {
    RelDataType type = FACTORY.createSqlIntervalType(new SqlIntervalQualifier(DAY, SECOND, SqlParserPos.ZERO));
    RexLiteral literal = BUILDER.makeSearchArgumentLiteral(sarg(new BigDecimal(1), new BigDecimal(2)), type);
    Range<?> converted = convert(literal);
    assertThat(converted).isEqualToComparingFieldByField(range(new SqlDaySecondInterval(1), new SqlDaySecondInterval(2)));
}
Also used : RexLiteral(org.apache.calcite.rex.RexLiteral) SqlIntervalQualifier(org.apache.calcite.sql.SqlIntervalQualifier) RelDataType(org.apache.calcite.rel.type.RelDataType) SqlDaySecondInterval(com.hazelcast.sql.impl.type.SqlDaySecondInterval) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 28 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 29 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 30 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)

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