use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.util.TimestampString in project flink by apache.
the class RexNodeJsonDeserializer method deserializeLiteralValue.
@Nullable
private static Object deserializeLiteralValue(JsonNode literalNode, SqlTypeName sqlTypeName, SerdeContext serdeContext) {
final JsonNode valueNode = literalNode.required(FIELD_NAME_VALUE);
if (valueNode.isNull()) {
return null;
}
switch(sqlTypeName) {
case BOOLEAN:
return valueNode.booleanValue();
case TINYINT:
case SMALLINT:
case INTEGER:
case BIGINT:
case FLOAT:
case DOUBLE:
case DECIMAL:
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:
return new BigDecimal(valueNode.asText());
case DATE:
return new DateString(valueNode.asText());
case TIME:
return new TimeString(valueNode.asText());
case TIMESTAMP:
case TIMESTAMP_WITH_LOCAL_TIME_ZONE:
return new TimestampString(valueNode.asText());
case BINARY:
case VARBINARY:
return ByteString.ofBase64(valueNode.asText());
case CHAR:
case VARCHAR:
return serdeContext.getRexBuilder().makeLiteral(valueNode.asText()).getValue();
case SYMBOL:
final JsonNode symbolNode = literalNode.required(FIELD_NAME_SYMBOL);
final SerializableSymbol symbol = SerializableSymbol.of(symbolNode.asText(), valueNode.asText());
return serializableToCalcite(symbol);
default:
throw new TableException("Unknown literal: " + valueNode);
}
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.util.TimestampString 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);
}
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.util.TimestampString in project druid by alibaba.
the class CalciteMySqlNodeVisitor method visit.
public boolean visit(SQLTimestampExpr x) {
String literal = x.getLiteral();
int precision = 0;
if (literal.endsWith("00")) {
char c3 = literal.charAt(literal.length() - 3);
if (c3 >= '0' && c3 <= '9') {
literal = literal.substring(0, literal.length() - 2);
precision = 3;
}
}
TimestampString ts = new TimestampString(literal);
sqlNode = SqlLiteral.createTimestamp(ts, precision, SqlParserPos.ZERO);
return false;
}
Aggregations