Java Code Examples for org.apache.flink.api.common.typeinfo.Types#LOCAL_TIME
The following examples show how to use
org.apache.flink.api.common.typeinfo.Types#LOCAL_TIME .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JsonRowSerializationSchema.java From flink with Apache License 2.0 | 5 votes |
private Optional<SerializationRuntimeConverter> createConverterForSimpleType(TypeInformation<?> simpleTypeInfo) { if (simpleTypeInfo == Types.VOID) { return Optional.of((mapper, reuse, object) -> mapper.getNodeFactory().nullNode()); } else if (simpleTypeInfo == Types.BOOLEAN) { return Optional.of((mapper, reuse, object) -> mapper.getNodeFactory().booleanNode((Boolean) object)); } else if (simpleTypeInfo == Types.STRING) { return Optional.of((mapper, reuse, object) -> mapper.getNodeFactory().textNode((String) object)); } else if (simpleTypeInfo == Types.INT) { return Optional.of((mapper, reuse, object) -> mapper.getNodeFactory().numberNode((Integer) object)); } else if (simpleTypeInfo == Types.LONG) { return Optional.of((mapper, reuse, object) -> mapper.getNodeFactory().numberNode((Long) object)); } else if (simpleTypeInfo == Types.DOUBLE) { return Optional.of((mapper, reuse, object) -> mapper.getNodeFactory().numberNode((Double) object)); } else if (simpleTypeInfo == Types.FLOAT) { return Optional.of((mapper, reuse, object) -> mapper.getNodeFactory().numberNode((Float) object)); } else if (simpleTypeInfo == Types.SHORT) { return Optional.of((mapper, reuse, object) -> mapper.getNodeFactory().numberNode((Short) object)); } else if (simpleTypeInfo == Types.BYTE) { return Optional.of((mapper, reuse, object) -> mapper.getNodeFactory().numberNode((Byte) object)); } else if (simpleTypeInfo == Types.BIG_DEC) { return Optional.of(createBigDecimalConverter()); } else if (simpleTypeInfo == Types.BIG_INT) { return Optional.of(createBigIntegerConverter()); } else if (simpleTypeInfo == Types.SQL_DATE) { return Optional.of(this::convertDate); } else if (simpleTypeInfo == Types.SQL_TIME) { return Optional.of(this::convertTime); } else if (simpleTypeInfo == Types.SQL_TIMESTAMP) { return Optional.of(this::convertTimestamp); } else if (simpleTypeInfo == Types.LOCAL_DATE) { return Optional.of(this::convertLocalDate); } else if (simpleTypeInfo == Types.LOCAL_TIME) { return Optional.of(this::convertLocalTime); } else if (simpleTypeInfo == Types.LOCAL_DATE_TIME) { return Optional.of(this::convertLocalDateTime); } else { return Optional.empty(); } }
Example 2
Source File: JsonRowDeserializationSchema.java From flink with Apache License 2.0 | 5 votes |
private Optional<DeserializationRuntimeConverter> createConverterForSimpleType(TypeInformation<?> simpleTypeInfo) { if (simpleTypeInfo == Types.VOID) { return Optional.of((mapper, jsonNode) -> null); } else if (simpleTypeInfo == Types.BOOLEAN) { return Optional.of(this::convertToBoolean); } else if (simpleTypeInfo == Types.STRING) { return Optional.of((mapper, jsonNode) -> jsonNode.asText()); } else if (simpleTypeInfo == Types.INT) { return Optional.of(this::convertToInt); } else if (simpleTypeInfo == Types.LONG) { return Optional.of(this::convertToLong); } else if (simpleTypeInfo == Types.DOUBLE) { return Optional.of(this::convertToDouble); } else if (simpleTypeInfo == Types.FLOAT) { return Optional.of((mapper, jsonNode) -> Float.parseFloat(jsonNode.asText().trim())); } else if (simpleTypeInfo == Types.SHORT) { return Optional.of((mapper, jsonNode) -> Short.parseShort(jsonNode.asText().trim())); } else if (simpleTypeInfo == Types.BYTE) { return Optional.of((mapper, jsonNode) -> Byte.parseByte(jsonNode.asText().trim())); } else if (simpleTypeInfo == Types.BIG_DEC) { return Optional.of(this::convertToBigDecimal); } else if (simpleTypeInfo == Types.BIG_INT) { return Optional.of(this::convertToBigInteger); } else if (simpleTypeInfo == Types.SQL_DATE) { return Optional.of(this::convertToDate); } else if (simpleTypeInfo == Types.SQL_TIME) { return Optional.of(this::convertToTime); } else if (simpleTypeInfo == Types.SQL_TIMESTAMP) { return Optional.of(this::convertToTimestamp); } else if (simpleTypeInfo == Types.LOCAL_DATE) { return Optional.of(this::convertToLocalDate); } else if (simpleTypeInfo == Types.LOCAL_TIME) { return Optional.of(this::convertToLocalTime); } else if (simpleTypeInfo == Types.LOCAL_DATE_TIME) { return Optional.of(this::convertToLocalDateTime); } else { return Optional.empty(); } }
Example 3
Source File: LegacyTypeInfoDataTypeConverter.java From flink with Apache License 2.0 | 4 votes |
public static TypeInformation<?> toLegacyTypeInfo(DataType dataType) { // time indicators first as their hashCode/equals is shared with those of regular timestamps if (canConvertToTimeAttributeTypeInfo(dataType)) { return convertToTimeAttributeTypeInfo((TimestampType) dataType.getLogicalType()); } // check in the map but relax the nullability constraint as every not null data type can be // stored in the corresponding nullable type information final TypeInformation<?> foundTypeInfo = dataTypeTypeInfoMap.get(dataType.nullable()); if (foundTypeInfo != null) { return foundTypeInfo; } // we are relaxing the constraint for DECIMAL, CHAR, VARCHAR, TIMESTAMP_WITHOUT_TIME_ZONE to // support value literals in legacy planner LogicalType logicalType = dataType.getLogicalType(); if (hasRoot(logicalType, LogicalTypeRoot.DECIMAL)) { return Types.BIG_DEC; } else if (hasRoot(logicalType, LogicalTypeRoot.CHAR)) { return Types.STRING; } else if (hasRoot(logicalType, LogicalTypeRoot.VARCHAR)) { return Types.STRING; } // relax the precision constraint as Timestamp can store the highest precision else if (hasRoot(logicalType, LogicalTypeRoot.TIMESTAMP_WITHOUT_TIME_ZONE) && dataType.getConversionClass() == Timestamp.class) { return Types.SQL_TIMESTAMP; } // relax the precision constraint as LocalDateTime can store the highest precision else if (hasRoot(logicalType, LogicalTypeRoot.TIMESTAMP_WITHOUT_TIME_ZONE) && dataType.getConversionClass() == LocalDateTime.class) { return Types.LOCAL_DATE_TIME; } // relax the precision constraint as LocalTime can store the highest precision else if (hasRoot(logicalType, LogicalTypeRoot.TIME_WITHOUT_TIME_ZONE) && dataType.getConversionClass() == LocalTime.class) { return Types.LOCAL_TIME; } else if (canConvertToLegacyTypeInfo(dataType)) { return convertToLegacyTypeInfo(dataType); } else if (canConvertToRowTypeInfo(dataType)) { return convertToRowTypeInfo((FieldsDataType) dataType); } // this could also match for basic array type info but this is covered by legacy type info else if (canConvertToObjectArrayTypeInfo(dataType)) { return convertToObjectArrayTypeInfo((CollectionDataType) dataType); } else if (canConvertToMultisetTypeInfo(dataType)) { return convertToMultisetTypeInfo((CollectionDataType) dataType); } else if (canConvertToMapTypeInfo(dataType)) { return convertToMapTypeInfo((KeyValueDataType) dataType); } // makes the raw type accessible in the legacy planner else if (canConvertToRawTypeInfo(dataType)) { return convertToRawTypeInfo(dataType); } throw new TableException( String.format( "Unsupported conversion from data type '%s' (conversion class: %s) to type information. Only data types " + "that originated from type information fully support a reverse conversion.", dataType, dataType.getConversionClass().getName())); }