Search in sources :

Example 16 with TimeString

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.util.TimeString in project flink by apache.

the class RexLiteral method appendAsJava.

/**
 * Appends the specified value in the provided destination as a Java string. The value must be
 * consistent with the type, as per {@link #valueMatchesType}.
 *
 * <p>Typical return values:
 *
 * <ul>
 *   <li>true
 *   <li>null
 *   <li>"Hello, world!"
 *   <li>1.25
 *   <li>1234ABCD
 * </ul>
 *
 * @param value Value to be appended to the provided destination as a Java string
 * @param sb Destination to which to append the specified value
 * @param typeName Type name to be used for the transformation of the value to a Java string
 * @param type Type to be used for the transformation of the value to a Java string
 * @param includeType Whether to include the data type in the Java representation
 */
private static void appendAsJava(Comparable value, StringBuilder sb, SqlTypeName typeName, RelDataType type, boolean java, RexDigestIncludeType includeType) {
    switch(typeName) {
        case CHAR:
            NlsString nlsString = (NlsString) value;
            if (java) {
                Util.printJavaString(sb, nlsString.getValue(), true);
            } else {
                boolean includeCharset = (nlsString.getCharsetName() != null) && !nlsString.getCharsetName().equals(CalciteSystemProperty.DEFAULT_CHARSET.value());
                sb.append(nlsString.asSql(includeCharset, false));
            }
            break;
        case BOOLEAN:
            assert value instanceof Boolean;
            sb.append(value.toString());
            break;
        case DECIMAL:
            assert value instanceof BigDecimal;
            sb.append(value.toString());
            break;
        case DOUBLE:
            assert value instanceof BigDecimal;
            sb.append(Util.toScientificNotation((BigDecimal) value));
            break;
        case BIGINT:
            assert value instanceof BigDecimal;
            long narrowLong = ((BigDecimal) value).longValue();
            sb.append(String.valueOf(narrowLong));
            sb.append('L');
            break;
        case BINARY:
            assert value instanceof ByteString;
            sb.append("X'");
            sb.append(((ByteString) value).toString(16));
            sb.append("'");
            break;
        case NULL:
            assert value == null;
            sb.append("null");
            break;
        case SARG:
            assert value instanceof Sarg;
            // noinspection unchecked,rawtypes
            Util.asStringBuilder(sb, sb2 -> printSarg(sb2, (Sarg) value, type));
            break;
        case SYMBOL:
            assert value instanceof Enum;
            sb.append("FLAG(");
            sb.append(value.toString());
            sb.append(")");
            break;
        case DATE:
            assert value instanceof DateString;
            sb.append(value.toString());
            break;
        case TIME:
        case TIME_WITH_LOCAL_TIME_ZONE:
            assert value instanceof TimeString;
            sb.append(value.toString());
            break;
        case TIMESTAMP:
        case TIMESTAMP_WITH_LOCAL_TIME_ZONE:
            assert value instanceof TimestampString;
            sb.append(value.toString());
            break;
        case INTERVAL_YEAR:
        case INTERVAL_YEAR_MONTH:
        case INTERVAL_MONTH:
        case INTERVAL_DAY:
        case INTERVAL_DAY_HOUR:
        case INTERVAL_DAY_MINUTE:
        case INTERVAL_DAY_SECOND:
        case INTERVAL_HOUR:
        case INTERVAL_HOUR_MINUTE:
        case INTERVAL_HOUR_SECOND:
        case INTERVAL_MINUTE:
        case INTERVAL_MINUTE_SECOND:
        case INTERVAL_SECOND:
            assert value instanceof BigDecimal;
            sb.append(value.toString());
            break;
        case MULTISET:
        case ROW:
            final List<RexLiteral> list = (List) value;
            Util.asStringBuilder(sb, sb2 -> Util.printList(sb, list.size(), (sb3, i) -> sb3.append(list.get(i).computeDigest(includeType))));
            break;
        case GEOMETRY:
            final String wkt = GeoFunctions.ST_AsWKT((Geometries.Geom) value);
            sb.append(wkt);
            break;
        default:
            assert valueMatchesType(value, typeName, true);
            throw Util.needToImplement(typeName);
    }
}
Also used : SimpleDateFormat(java.text.SimpleDateFormat) TimeUnit(org.apache.calcite.avatica.util.TimeUnit) ByteBuffer(java.nio.ByteBuffer) TimeString(org.apache.calcite.util.TimeString) BigDecimal(java.math.BigDecimal) Calendar(java.util.Calendar) ImmutableList(com.google.common.collect.ImmutableList) Charset(java.nio.charset.Charset) DateTimeUtils(org.apache.calcite.avatica.util.DateTimeUtils) Geometries(org.apache.calcite.runtime.Geometries) Locale(java.util.Locale) Map(java.util.Map) SqlOperator(org.apache.calcite.sql.SqlOperator) CalciteSystemProperty(org.apache.calcite.config.CalciteSystemProperty) GeoFunctions(org.apache.calcite.runtime.GeoFunctions) Functions(org.apache.calcite.linq4j.function.Functions) PrintWriter(java.io.PrintWriter) RelDataType(org.apache.calcite.rel.type.RelDataType) Litmus(org.apache.calcite.util.Litmus) Sarg(org.apache.calcite.util.Sarg) SqlKind(org.apache.calcite.sql.SqlKind) SqlTypeName(org.apache.calcite.sql.type.SqlTypeName) DateString(org.apache.calcite.util.DateString) NlsString(org.apache.calcite.util.NlsString) ByteString(org.apache.calcite.avatica.util.ByteString) TimeZone(java.util.TimeZone) TimestampString(org.apache.calcite.util.TimestampString) ConversionUtil(org.apache.calcite.util.ConversionUtil) RelNode(org.apache.calcite.rel.RelNode) SqlCollation(org.apache.calcite.sql.SqlCollation) CompositeList(org.apache.calcite.util.CompositeList) Objects(java.util.Objects) List(java.util.List) SqlStdOperatorTable(org.apache.calcite.sql.fun.SqlStdOperatorTable) FlatLists(org.apache.calcite.runtime.FlatLists) RelDataTypeField(org.apache.calcite.rel.type.RelDataTypeField) Preconditions(com.google.common.base.Preconditions) Util(org.apache.calcite.util.Util) SqlParserUtil(org.apache.calcite.sql.parser.SqlParserUtil) Sarg(org.apache.calcite.util.Sarg) TimeString(org.apache.calcite.util.TimeString) ByteString(org.apache.calcite.avatica.util.ByteString) Geometries(org.apache.calcite.runtime.Geometries) TimeString(org.apache.calcite.util.TimeString) DateString(org.apache.calcite.util.DateString) NlsString(org.apache.calcite.util.NlsString) ByteString(org.apache.calcite.avatica.util.ByteString) TimestampString(org.apache.calcite.util.TimestampString) BigDecimal(java.math.BigDecimal) DateString(org.apache.calcite.util.DateString) NlsString(org.apache.calcite.util.NlsString) ImmutableList(com.google.common.collect.ImmutableList) CompositeList(org.apache.calcite.util.CompositeList) List(java.util.List) TimestampString(org.apache.calcite.util.TimestampString)

Example 17 with TimeString

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.util.TimeString in project flink by apache.

the class ExpressionConverterTest method testTimeLiteral.

@Test
public void testTimeLiteral() {
    RexNode rex = converter.visit(valueLiteral(LocalTime.parse("12:12:12.12345"), DataTypes.TIME(2).notNull()));
    assertThat(((RexLiteral) rex).getValueAs(TimeString.class), equalTo(new TimeString("12:12:12.12")));
    assertThat(rex.getType().getSqlTypeName(), equalTo(SqlTypeName.TIME));
    assertThat(rex.getType().getPrecision(), equalTo(2));
}
Also used : TimeString(org.apache.calcite.util.TimeString) RexNode(org.apache.calcite.rex.RexNode) Test(org.junit.Test)

Example 18 with TimeString

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.util.TimeString in project flink by apache.

the class ExpressionConverterTest method testTimeLiteralBiggerPrecision.

@Test
public void testTimeLiteralBiggerPrecision() {
    RexNode rex = converter.visit(valueLiteral(LocalTime.parse("12:12:12.12345"), DataTypes.TIME(5).notNull()));
    // TODO planner supports up to TIME(3)
    assertThat(((RexLiteral) rex).getValueAs(TimeString.class), equalTo(new TimeString("12:12:12.123")));
    assertThat(rex.getType().getSqlTypeName(), equalTo(SqlTypeName.TIME));
    assertThat(rex.getType().getPrecision(), equalTo(3));
}
Also used : TimeString(org.apache.calcite.util.TimeString) RexNode(org.apache.calcite.rex.RexNode) Test(org.junit.Test)

Example 19 with TimeString

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.util.TimeString in project druid by alibaba.

the class CalciteMySqlNodeVisitor method visit.

public boolean visit(SQLTimeExpr x) {
    String literal = ((SQLCharExpr) x.getLiteral()).getText();
    TimeString ds = new TimeString(literal);
    sqlNode = SqlLiteral.createTime(ds, 0, SqlParserPos.ZERO);
    return false;
}
Also used : TimeString(org.apache.calcite.util.TimeString) DateString(org.apache.calcite.util.DateString) TimestampString(org.apache.calcite.util.TimestampString) TimeString(org.apache.calcite.util.TimeString)

Aggregations

TimeString (org.apache.calcite.util.TimeString)19 TimestampString (org.apache.calcite.util.TimestampString)10 Test (org.junit.Test)10 DateString (org.apache.calcite.util.DateString)9 RelDataType (org.apache.calcite.rel.type.RelDataType)6 BigDecimal (java.math.BigDecimal)5 RexNode (org.apache.calcite.rex.RexNode)5 RexLiteral (org.apache.calcite.rex.RexLiteral)4 NlsString (org.apache.calcite.util.NlsString)4 ByteString (org.apache.calcite.avatica.util.ByteString)3 ImmutableList (com.google.common.collect.ImmutableList)2 Calendar (java.util.Calendar)2 List (java.util.List)2 DateTimeUtils (org.apache.calcite.avatica.util.DateTimeUtils)2 CompositeList (org.apache.calcite.util.CompositeList)2 Preconditions (com.google.common.base.Preconditions)1 Literal (com.hazelcast.jet.sql.impl.validate.literal.Literal)1 QueryException (com.hazelcast.sql.impl.QueryException)1 QueryDataType (com.hazelcast.sql.impl.type.QueryDataType)1 Converter (com.hazelcast.sql.impl.type.converter.Converter)1