APISonar


org.apache.calcite.sql.type.SqlTypeName.DATE

> org > apache > calcite > sql > type > SqlTypeName > DATE
org APIs apache APIs calcite APIs sql APIs type APIs SqlTypeName APIs DATE APIs

Example 1
public RexLiteral makeDateLiteral(DateString date) {
    return makeLiteral(Objects.requireNonNull(date),
        typeFactory.createSqlType(SqlTypeName.DATE), SqlTypeName.DATE);
  }
Example 2
@Test public void testDate() {
    SqlTypeName tn =
        SqlTypeName.getNameForJdbcType(Types.DATE);
    assertEquals(
        "DATE did not map to DATE",
        SqlTypeName.DATE,
        tn);
  }
Example 3
@Test public void testConvertThrowsForUnsupportedFromType() {
    thrown.expect(UnsupportedOperationException.class);

    BeamSqlPrimitive intervalPrimitive = BeamSqlPrimitive
        .of(SqlTypeName.INTERVAL_DAY, new BigDecimal(2));

    Reinterpreter reinterpreter = newReinterpreter();
    reinterpreter.convert(SqlTypeName.DATE, intervalPrimitive);
  }
Example 4
private static boolean isDateNode(SqlTypeName type, Object value) {
    return (type == SqlTypeName.DATE || type == SqlTypeName.TIMESTAMP)
        && value instanceof Calendar;
  }
Example 5
@Test public void testConvertThrowsForUnsupportedInput() {
    thrown.expect(IllegalArgumentException.class);

    ReinterpretConversion conversion = ReinterpretConversion.builder()
        .from(SqlTypeName.DATE)
        .to(SqlTypeName.BOOLEAN)
        .convert(mock(Function.class))
        .build();

    conversion.convert(BeamSqlPrimitive.of(SqlTypeName.INTEGER, 3));
  }
Example 6
@Test public void testCannotConvertFromUnsupportedTypes() {
    Reinterpreter reinterpreter = Reinterpreter.builder()
        .withConversion(mockConversion(SqlTypeName.SYMBOL, SqlTypeName.SMALLINT, SqlTypeName.DATE))
        .withConversion(mockConversion(SqlTypeName.INTEGER, SqlTypeName.FLOAT))
        .build();

    Set<SqlTypeName> unsupportedTypes = new HashSet<>(SqlTypeName.ALL_TYPES);
    unsupportedTypes.removeAll(
          Sets.newSet(SqlTypeName.DATE, SqlTypeName.SMALLINT, SqlTypeName.FLOAT));

    for (SqlTypeName unsupportedType : unsupportedTypes) {
      assertFalse(reinterpreter.canConvert(unsupportedType, SqlTypeName.DATE));
      assertFalse(reinterpreter.canConvert(unsupportedType, SqlTypeName.INTEGER));
    }
  }
Example 7
public static String dateTimeFormatString(final SqlTypeName sqlTypeName) {
    if (sqlTypeName == SqlTypeName.DATE) {
      return "yyyy-MM-dd";
    } else if (sqlTypeName == SqlTypeName.TIMESTAMP) {
      return "yyyy-MM-dd HH:mm:ss";
    } else if (sqlTypeName == SqlTypeName.TIMESTAMP_WITH_LOCAL_TIME_ZONE) {
      return "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";
    } else {
      return null;
    }
  }
Example 8
public static long toMillisLiteral(final RexNode literal, final DateTimeZone timeZone)
  {
    final SqlTypeName typeName = literal.getType().getSqlTypeName();
    if (literal.getKind() != SqlKind.LITERAL || (typeName != SqlTypeName.TIMESTAMP && typeName != SqlTypeName.DATE)) {
      throw new IAE("Expected TIMESTAMP or DATE literal but got[%s:%s]", literal.getKind(), typeName);
    }

    final Calendar calendar = (Calendar) RexLiteral.value(literal);
    return Calcites.calciteTimestampToJoda(calendar.getTimeInMillis(), timeZone).getMillis();
  }
Example 9
@Test public void evaluate() throws Exception {
    List<BeamSqlExpression> operands = new ArrayList<>();
    operands.add(BeamSqlPrimitive.of(SqlTypeName.DATE,
        str2DateTime("2017-05-22 09:10:11")));
    // YEAR
    operands.add(BeamSqlPrimitive.of(SqlTypeName.SYMBOL, TimeUnitRange.YEAR));
    Assert.assertEquals(str2DateTime("2018-01-01 00:00:00"),
        new BeamSqlDateCeilExpression(operands)
            .evaluate(BeamSqlFnExecutorTestBase.row, null).getDate());

    operands.set(1, BeamSqlPrimitive.of(SqlTypeName.SYMBOL, TimeUnitRange.MONTH));
    Assert.assertEquals(str2DateTime("2017-06-01 00:00:00"),
        new BeamSqlDateCeilExpression(operands)
            .evaluate(BeamSqlFnExecutorTestBase.row, null).getDate());
  }
Example 10
private static boolean needUtcTimeExtract(RexNode rexNode) {
    return rexNode.getType().getSqlTypeName() == SqlTypeName.DATE
        || rexNode.getType().getSqlTypeName() == SqlTypeName.TIMESTAMP
        || rexNode.getType().getSqlTypeName()
        == SqlTypeName.TIMESTAMP_WITH_LOCAL_TIME_ZONE;
  }