Java Code Examples for org.apache.flink.api.common.typeinfo.Types#BYTE

The following examples show how to use org.apache.flink.api.common.typeinfo.Types#BYTE . 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: JsonRowDeserializationSchema.java    From flink with Apache License 2.0 5 votes vote down vote up
private Optional<DeserializationRuntimeConverter> createConverterForSimpleType(TypeInformation<?> simpleTypeInfo) {
	if (simpleTypeInfo == Types.VOID) {
		return Optional.of((mapper, jsonNode) -> null);
	} else if (simpleTypeInfo == Types.BOOLEAN) {
		return Optional.of((mapper, jsonNode) -> jsonNode.asBoolean());
	} else if (simpleTypeInfo == Types.STRING) {
		return Optional.of((mapper, jsonNode) -> jsonNode.asText());
	} else if (simpleTypeInfo == Types.INT) {
		return Optional.of((mapper, jsonNode) -> jsonNode.asInt());
	} else if (simpleTypeInfo == Types.LONG) {
		return Optional.of((mapper, jsonNode) -> jsonNode.asLong());
	} else if (simpleTypeInfo == Types.DOUBLE) {
		return Optional.of((mapper, jsonNode) -> jsonNode.asDouble());
	} 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((mapper, jsonNode) -> jsonNode.decimalValue());
	} else if (simpleTypeInfo == Types.BIG_INT) {
		return Optional.of((mapper, jsonNode) -> jsonNode.bigIntegerValue());
	} else if (simpleTypeInfo == Types.SQL_DATE) {
		return Optional.of(createDateConverter());
	} else if (simpleTypeInfo == Types.SQL_TIME) {
		return Optional.of(createTimeConverter());
	} else if (simpleTypeInfo == Types.SQL_TIMESTAMP) {
		return Optional.of(createTimestampConverter());
	} else {
		return Optional.empty();
	}
}
 
Example 2
Source File: JsonRowSerializationSchema.java    From flink with Apache License 2.0 5 votes vote down vote up
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 3
Source File: JsonRowSerializationSchema.java    From flink with Apache License 2.0 5 votes vote down vote up
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(createDateConverter());
	} else if (simpleTypeInfo == Types.SQL_TIME) {
		return Optional.of(createTimeConverter());
	} else if (simpleTypeInfo == Types.SQL_TIMESTAMP) {
		return Optional.of(createTimestampConverter());
	} else {
		return Optional.empty();
	}
}
 
Example 4
Source File: OrcTableSourceTest.java    From flink with Apache License 2.0 5 votes vote down vote up
private TypeInformation[] getNestedFieldTypes() {
	return new TypeInformation[]{
		Types.BOOLEAN, Types.BYTE, Types.SHORT, Types.INT, Types.LONG, Types.FLOAT, Types.DOUBLE,
		PrimitiveArrayTypeInfo.BYTE_PRIMITIVE_ARRAY_TYPE_INFO, Types.STRING,
		Types.ROW_NAMED(
			new String[]{"list"},
			ObjectArrayTypeInfo.getInfoFor(
				Types.ROW_NAMED(
					new String[]{"int1", "string1"},
					Types.INT, Types.STRING
				)
			)
		),
		ObjectArrayTypeInfo.getInfoFor(
			Types.ROW_NAMED(
				new String[]{"int1", "string1"},
				Types.INT, Types.STRING
			)
		),
		new MapTypeInfo<>(
			Types.STRING,
			Types.ROW_NAMED(
				new String[]{"int1", "string1"},
				Types.INT, Types.STRING
			)
		)
	};
}
 
Example 5
Source File: OrcTableSourceTest.java    From flink with Apache License 2.0 5 votes vote down vote up
private TypeInformation[] getNestedFieldTypes() {
	return new TypeInformation[]{
		Types.BOOLEAN, Types.BYTE, Types.SHORT, Types.INT, Types.LONG, Types.FLOAT, Types.DOUBLE,
		PrimitiveArrayTypeInfo.BYTE_PRIMITIVE_ARRAY_TYPE_INFO, Types.STRING,
		Types.ROW_NAMED(
			new String[]{"list"},
			ObjectArrayTypeInfo.getInfoFor(
				Types.ROW_NAMED(
					new String[]{"int1", "string1"},
					Types.INT, Types.STRING
				)
			)
		),
		ObjectArrayTypeInfo.getInfoFor(
			Types.ROW_NAMED(
				new String[]{"int1", "string1"},
				Types.INT, Types.STRING
			)
		),
		new MapTypeInfo<>(
			Types.STRING,
			Types.ROW_NAMED(
				new String[]{"int1", "string1"},
				Types.INT, Types.STRING
			)
		)
	};
}
 
Example 6
Source File: CsvRowSchemaConverter.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Convert {@link TypeInformation} to {@link CsvSchema.ColumnType} based on Jackson's categories.
 */
private static CsvSchema.ColumnType convertType(String fieldName, TypeInformation<?> info) {
	if (STRING_TYPES.contains(info)) {
		return CsvSchema.ColumnType.STRING;
	} else if (NUMBER_TYPES.contains(info)) {
		return CsvSchema.ColumnType.NUMBER;
	} else if (BOOLEAN_TYPES.contains(info)) {
		return CsvSchema.ColumnType.BOOLEAN;
	} else if (info instanceof ObjectArrayTypeInfo) {
		validateNestedField(fieldName, ((ObjectArrayTypeInfo) info).getComponentInfo());
		return CsvSchema.ColumnType.ARRAY;
	} else if (info instanceof BasicArrayTypeInfo) {
		validateNestedField(fieldName, ((BasicArrayTypeInfo) info).getComponentInfo());
		return CsvSchema.ColumnType.ARRAY;
	} else if (info instanceof RowTypeInfo) {
		final TypeInformation<?>[] types = ((RowTypeInfo) info).getFieldTypes();
		for (TypeInformation<?> type : types) {
			validateNestedField(fieldName, type);
		}
		return CsvSchema.ColumnType.ARRAY;
	} else if (info instanceof PrimitiveArrayTypeInfo &&
			((PrimitiveArrayTypeInfo) info).getComponentType() == Types.BYTE) {
		return CsvSchema.ColumnType.STRING;
	} else {
		throw new IllegalArgumentException(
			"Unsupported type information '" + info.toString() + "' for field '" + fieldName + "'.");
	}
}
 
Example 7
Source File: LastValueAggFunction.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public TypeInformation<Byte> getResultType() {
	return Types.BYTE;
}
 
Example 8
Source File: LastValueWithRetractAggFunction.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public TypeInformation<Byte> getResultType() {
	return Types.BYTE;
}
 
Example 9
Source File: CsvRowSerializationSchema.java    From flink with Apache License 2.0 4 votes vote down vote up
private static RuntimeConverter createRuntimeConverter(TypeInformation<?> info) {
	if (info.equals(Types.VOID)) {
		return (csvMapper, container, obj) -> container.nullNode();
	} else if (info.equals(Types.STRING)) {
		return (csvMapper, container, obj) -> container.textNode((String) obj);
	} else if (info.equals(Types.BOOLEAN)) {
		return (csvMapper, container, obj) -> container.booleanNode((Boolean) obj);
	} else if (info.equals(Types.BYTE)) {
		return (csvMapper, container, obj) -> container.numberNode((Byte) obj);
	} else if (info.equals(Types.SHORT)) {
		return (csvMapper, container, obj) -> container.numberNode((Short) obj);
	} else if (info.equals(Types.INT)) {
		return (csvMapper, container, obj) -> container.numberNode((Integer) obj);
	} else if (info.equals(Types.LONG)) {
		return (csvMapper, container, obj) -> container.numberNode((Long) obj);
	} else if (info.equals(Types.FLOAT)) {
		return (csvMapper, container, obj) -> container.numberNode((Float) obj);
	} else if (info.equals(Types.DOUBLE)) {
		return (csvMapper, container, obj) -> container.numberNode((Double) obj);
	} else if (info.equals(Types.BIG_DEC)) {
		return (csvMapper, container, obj) -> container.numberNode((BigDecimal) obj);
	} else if (info.equals(Types.BIG_INT)) {
		return (csvMapper, container, obj) -> container.numberNode((BigInteger) obj);
	} else if (info.equals(Types.SQL_DATE)) {
		return (csvMapper, container, obj) -> container.textNode(obj.toString());
	} else if (info.equals(Types.SQL_TIME)) {
		return (csvMapper, container, obj) -> container.textNode(obj.toString());
	} else if (info.equals(Types.SQL_TIMESTAMP)) {
		return (csvMapper, container, obj) -> container.textNode(obj.toString());
	} else if (info instanceof RowTypeInfo){
		return createRowRuntimeConverter((RowTypeInfo) info, false);
	} else if (info instanceof BasicArrayTypeInfo) {
		return createObjectArrayRuntimeConverter(((BasicArrayTypeInfo) info).getComponentInfo());
	} else if (info instanceof ObjectArrayTypeInfo) {
		return createObjectArrayRuntimeConverter(((ObjectArrayTypeInfo) info).getComponentInfo());
	} else if (info instanceof PrimitiveArrayTypeInfo &&
			((PrimitiveArrayTypeInfo) info).getComponentType() == Types.BYTE) {
		return createByteArrayRuntimeConverter();
	}
	else {
		throw new RuntimeException("Unsupported type information '" + info + "'.");
	}
}
 
Example 10
Source File: LastValueAggFunction.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public TypeInformation<Byte> getResultType() {
	return Types.BYTE;
}
 
Example 11
Source File: TypeStringUtils.java    From flink with Apache License 2.0 4 votes vote down vote up
private TypeInformation<?> convertType() {
	final TypeInformation<?> typeInfo;
	switch (token().literal) {
		case VARCHAR:
		case STRING:
			return Types.STRING;
		case BOOLEAN:
			return Types.BOOLEAN;
		case TINYINT:
		case BYTE:
			return Types.BYTE;
		case SMALLINT:
		case SHORT:
			return Types.SHORT;
		case INT:
			return Types.INT;
		case BIGINT:
		case LONG:
			return Types.LONG;
		case FLOAT:
			return Types.FLOAT;
		case DOUBLE:
			return Types.DOUBLE;
		case DECIMAL:
			return Types.BIG_DEC;
		case DATE:
		case SQL_DATE:
			return Types.SQL_DATE;
		case TIMESTAMP:
		case SQL_TIMESTAMP:
			return Types.SQL_TIMESTAMP;
		case TIME:
		case SQL_TIME:
			return Types.SQL_TIME;
		case ROW:
			return convertRow();
		case ANY:
			return convertAny();
		case POJO:
			return convertPojo();
		case MAP:
			return convertMap();
		case MULTISET:
			return convertMultiset();
		case PRIMITIVE_ARRAY:
			return convertPrimitiveArray();
		case OBJECT_ARRAY:
			return convertObjectArray();
		default:
			throw parsingError("Unsupported type: " + token().literal);
	}
}
 
Example 12
Source File: LastValueWithRetractAggFunction.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public TypeInformation<Byte> getResultType() {
	return Types.BYTE;
}
 
Example 13
Source File: CsvRowDeserializationSchema.java    From flink with Apache License 2.0 4 votes vote down vote up
private static RuntimeConverter createRuntimeConverter(TypeInformation<?> info, boolean ignoreParseErrors) {
	if (info.equals(Types.VOID)) {
		return (node) -> null;
	} else if (info.equals(Types.STRING)) {
		return JsonNode::asText;
	} else if (info.equals(Types.BOOLEAN)) {
		return (node) -> Boolean.valueOf(node.asText().trim());
	} else if (info.equals(Types.BYTE)) {
		return (node) -> Byte.valueOf(node.asText().trim());
	} else if (info.equals(Types.SHORT)) {
		return (node) -> Short.valueOf(node.asText().trim());
	} else if (info.equals(Types.INT)) {
		return (node) -> Integer.valueOf(node.asText().trim());
	} else if (info.equals(Types.LONG)) {
		return (node) -> Long.valueOf(node.asText().trim());
	} else if (info.equals(Types.FLOAT)) {
		return (node) -> Float.valueOf(node.asText().trim());
	} else if (info.equals(Types.DOUBLE)) {
		return (node) -> Double.valueOf(node.asText().trim());
	} else if (info.equals(Types.BIG_DEC)) {
		return (node) -> new BigDecimal(node.asText().trim());
	} else if (info.equals(Types.BIG_INT)) {
		return (node) -> new BigInteger(node.asText().trim());
	} else if (info.equals(Types.SQL_DATE)) {
		return (node) -> Date.valueOf(node.asText());
	} else if (info.equals(Types.SQL_TIME)) {
		return (node) -> Time.valueOf(node.asText());
	} else if (info.equals(Types.SQL_TIMESTAMP)) {
		return (node) -> Timestamp.valueOf(node.asText());
	} else if (info.equals(Types.LOCAL_DATE)) {
		return (node) -> Date.valueOf(node.asText()).toLocalDate();
	} else if (info.equals(Types.LOCAL_TIME)) {
		return (node) -> Time.valueOf(node.asText()).toLocalTime();
	} else if (info.equals(Types.LOCAL_DATE_TIME)) {
		return (node) -> Timestamp.valueOf(node.asText()).toLocalDateTime();
	} else if (info instanceof RowTypeInfo) {
		final RowTypeInfo rowTypeInfo = (RowTypeInfo) info;
		return createRowRuntimeConverter(rowTypeInfo, ignoreParseErrors, false);
	} else if (info instanceof BasicArrayTypeInfo) {
		return createObjectArrayRuntimeConverter(
			((BasicArrayTypeInfo<?, ?>) info).getComponentInfo(),
			ignoreParseErrors);
	} else if (info instanceof ObjectArrayTypeInfo) {
		return createObjectArrayRuntimeConverter(
			((ObjectArrayTypeInfo<?, ?>) info).getComponentInfo(),
			ignoreParseErrors);
	} else if (info instanceof PrimitiveArrayTypeInfo &&
			((PrimitiveArrayTypeInfo) info).getComponentType() == Types.BYTE) {
		return createByteArrayRuntimeConverter(ignoreParseErrors);
	} else {
		throw new RuntimeException("Unsupported type information '" + info + "'.");
	}
}
 
Example 14
Source File: FirstValueWithRetractAggFunction.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public TypeInformation<Byte> getResultType() {
	return Types.BYTE;
}
 
Example 15
Source File: TypeStringUtils.java    From flink with Apache License 2.0 4 votes vote down vote up
private TypeInformation<?> convertType() {
	final TypeInformation<?> typeInfo;
	switch (token().literal) {
		case VARCHAR:
		case STRING:
			return Types.STRING;
		case BOOLEAN:
			return Types.BOOLEAN;
		case TINYINT:
		case BYTE:
			return Types.BYTE;
		case SMALLINT:
		case SHORT:
			return Types.SHORT;
		case INT:
			return Types.INT;
		case BIGINT:
		case LONG:
			return Types.LONG;
		case FLOAT:
			return Types.FLOAT;
		case DOUBLE:
			return Types.DOUBLE;
		case DECIMAL:
			return Types.BIG_DEC;
		case DATE:
		case SQL_DATE:
			return Types.SQL_DATE;
		case TIMESTAMP:
		case SQL_TIMESTAMP:
			return Types.SQL_TIMESTAMP;
		case TIME:
		case SQL_TIME:
			return Types.SQL_TIME;
		case ROW:
			return convertRow();
		case ANY:
			return convertAny();
		case POJO:
			return convertPojo();
		case MAP:
			return convertMap();
		case MULTISET:
			return convertMultiset();
		case PRIMITIVE_ARRAY:
			return convertPrimitiveArray();
		case OBJECT_ARRAY:
			return convertObjectArray();
		default:
			throw parsingError("Unsupported type: " + token().literal);
	}
}
 
Example 16
Source File: JsonRowSerializationSchema.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
private JsonNode convert(ContainerNode<?> container, JsonNode reuse, TypeInformation<?> info, Object object) {
	if (info == Types.VOID || object == null) {
		return container.nullNode();
	} else if (info == Types.BOOLEAN) {
		return container.booleanNode((Boolean) object);
	} else if (info == Types.STRING) {
		return container.textNode((String) object);
	} else if (info == Types.BIG_DEC) {
		// convert decimal if necessary
		if (object instanceof BigDecimal) {
			return container.numberNode((BigDecimal) object);
		}
		return container.numberNode(BigDecimal.valueOf(((Number) object).doubleValue()));
	} else if (info == Types.BIG_INT) {
		// convert integer if necessary
		if (object instanceof BigInteger) {
			return container.numberNode((BigInteger) object);
		}
		return container.numberNode(BigInteger.valueOf(((Number) object).longValue()));
	} else if (info == Types.SQL_DATE) {
		return container.textNode(object.toString());
	} else if (info == Types.SQL_TIME) {
		final Time time = (Time) object;
		// strip milliseconds if possible
		if (time.getTime() % 1000 > 0) {
			return container.textNode(timeFormatWithMillis.format(time));
		}
		return container.textNode(timeFormat.format(time));
	} else if (info == Types.SQL_TIMESTAMP) {
		return container.textNode(timestampFormat.format((Timestamp) object));
	} else if (info instanceof RowTypeInfo) {
		if (reuse != null && reuse instanceof ObjectNode) {
			return convertRow((ObjectNode) reuse, (RowTypeInfo) info, (Row) object);
		} else {
			return convertRow(null, (RowTypeInfo) info, (Row) object);
		}
	} else if (info instanceof ObjectArrayTypeInfo) {
		if (reuse != null && reuse instanceof ArrayNode) {
			return convertObjectArray((ArrayNode) reuse, ((ObjectArrayTypeInfo) info).getComponentInfo(), (Object[]) object);
		} else {
			return convertObjectArray(null, ((ObjectArrayTypeInfo) info).getComponentInfo(), (Object[]) object);
		}
	} else if (info instanceof BasicArrayTypeInfo) {
		if (reuse != null && reuse instanceof ArrayNode) {
			return convertObjectArray((ArrayNode) reuse, ((BasicArrayTypeInfo) info).getComponentInfo(), (Object[]) object);
		} else {
			return convertObjectArray(null, ((BasicArrayTypeInfo) info).getComponentInfo(), (Object[]) object);
		}
	} else if (info instanceof PrimitiveArrayTypeInfo && ((PrimitiveArrayTypeInfo) info).getComponentType() == Types.BYTE) {
		return container.binaryNode((byte[]) object);
	} else {
		// for types that were specified without JSON schema
		// e.g. POJOs
		try {
			return mapper.valueToTree(object);
		} catch (IllegalArgumentException e) {
			throw new IllegalStateException("Unsupported type information '" + info + "' for object: " + object, e);
		}
	}
}
 
Example 17
Source File: FirstValueWithRetractAggFunction.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public TypeInformation<Byte> getResultType() {
	return Types.BYTE;
}
 
Example 18
Source File: CsvRowDeserializationSchema.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
private static RuntimeConverter createRuntimeConverter(TypeInformation<?> info, boolean ignoreParseErrors) {
	if (info.equals(Types.VOID)) {
		return (node) -> null;
	} else if (info.equals(Types.STRING)) {
		return JsonNode::asText;
	} else if (info.equals(Types.BOOLEAN)) {
		return (node) -> Boolean.valueOf(node.asText().trim());
	} else if (info.equals(Types.BYTE)) {
		return (node) -> Byte.valueOf(node.asText().trim());
	} else if (info.equals(Types.SHORT)) {
		return (node) -> Short.valueOf(node.asText().trim());
	} else if (info.equals(Types.INT)) {
		return (node) -> Integer.valueOf(node.asText().trim());
	} else if (info.equals(Types.LONG)) {
		return (node) -> Long.valueOf(node.asText().trim());
	} else if (info.equals(Types.FLOAT)) {
		return (node) -> Float.valueOf(node.asText().trim());
	} else if (info.equals(Types.DOUBLE)) {
		return (node) -> Double.valueOf(node.asText().trim());
	} else if (info.equals(Types.BIG_DEC)) {
		return (node) -> new BigDecimal(node.asText().trim());
	} else if (info.equals(Types.BIG_INT)) {
		return (node) -> new BigInteger(node.asText().trim());
	} else if (info.equals(Types.SQL_DATE)) {
		return (node) -> Date.valueOf(node.asText());
	} else if (info.equals(Types.SQL_TIME)) {
		return (node) -> Time.valueOf(node.asText());
	} else if (info.equals(Types.SQL_TIMESTAMP)) {
		return (node) -> Timestamp.valueOf(node.asText());
	} else if (info instanceof RowTypeInfo) {
		final RowTypeInfo rowTypeInfo = (RowTypeInfo) info;
		return createRowRuntimeConverter(rowTypeInfo, ignoreParseErrors, false);
	} else if (info instanceof BasicArrayTypeInfo) {
		return createObjectArrayRuntimeConverter(
			((BasicArrayTypeInfo<?, ?>) info).getComponentInfo(),
			ignoreParseErrors);
	} else if (info instanceof ObjectArrayTypeInfo) {
		return createObjectArrayRuntimeConverter(
			((ObjectArrayTypeInfo<?, ?>) info).getComponentInfo(),
			ignoreParseErrors);
	} else if (info instanceof PrimitiveArrayTypeInfo &&
			((PrimitiveArrayTypeInfo) info).getComponentType() == Types.BYTE) {
		return createByteArrayRuntimeConverter(ignoreParseErrors);
	} else {
		throw new RuntimeException("Unsupported type information '" + info + "'.");
	}
}
 
Example 19
Source File: FirstValueAggFunction.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public TypeInformation<Byte> getResultType() {
	return Types.BYTE;
}
 
Example 20
Source File: CsvRowSerializationSchema.java    From flink with Apache License 2.0 4 votes vote down vote up
private static RuntimeConverter createRuntimeConverter(TypeInformation<?> info) {
	if (info.equals(Types.VOID)) {
		return (csvMapper, container, obj) -> container.nullNode();
	} else if (info.equals(Types.STRING)) {
		return (csvMapper, container, obj) -> container.textNode((String) obj);
	} else if (info.equals(Types.BOOLEAN)) {
		return (csvMapper, container, obj) -> container.booleanNode((Boolean) obj);
	} else if (info.equals(Types.BYTE)) {
		return (csvMapper, container, obj) -> container.numberNode((Byte) obj);
	} else if (info.equals(Types.SHORT)) {
		return (csvMapper, container, obj) -> container.numberNode((Short) obj);
	} else if (info.equals(Types.INT)) {
		return (csvMapper, container, obj) -> container.numberNode((Integer) obj);
	} else if (info.equals(Types.LONG)) {
		return (csvMapper, container, obj) -> container.numberNode((Long) obj);
	} else if (info.equals(Types.FLOAT)) {
		return (csvMapper, container, obj) -> container.numberNode((Float) obj);
	} else if (info.equals(Types.DOUBLE)) {
		return (csvMapper, container, obj) -> container.numberNode((Double) obj);
	} else if (info.equals(Types.BIG_DEC)) {
		return (csvMapper, container, obj) -> container.numberNode((BigDecimal) obj);
	} else if (info.equals(Types.BIG_INT)) {
		return (csvMapper, container, obj) -> container.numberNode((BigInteger) obj);
	} else if (info.equals(Types.SQL_DATE)) {
		return (csvMapper, container, obj) -> container.textNode(obj.toString());
	} else if (info.equals(Types.SQL_TIME)) {
		return (csvMapper, container, obj) -> container.textNode(obj.toString());
	} else if (info.equals(Types.SQL_TIMESTAMP)) {
		return (csvMapper, container, obj) -> container.textNode(obj.toString());
	} else if (info.equals(Types.LOCAL_DATE)) {
		return (csvMapper, container, obj) -> container.textNode(obj.toString());
	} else if (info.equals(Types.LOCAL_TIME)) {
		return (csvMapper, container, obj) -> container.textNode(obj.toString());
	} else if (info.equals(Types.LOCAL_DATE_TIME)) {
		return (csvMapper, container, obj) -> container.textNode(DATE_TIME_FORMATTER.format((LocalDateTime) obj));
	} else if (info instanceof RowTypeInfo){
		return createRowRuntimeConverter((RowTypeInfo) info, false);
	} else if (info instanceof BasicArrayTypeInfo) {
		return createObjectArrayRuntimeConverter(((BasicArrayTypeInfo) info).getComponentInfo());
	} else if (info instanceof ObjectArrayTypeInfo) {
		return createObjectArrayRuntimeConverter(((ObjectArrayTypeInfo) info).getComponentInfo());
	} else if (info instanceof PrimitiveArrayTypeInfo &&
			((PrimitiveArrayTypeInfo) info).getComponentType() == Types.BYTE) {
		return createByteArrayRuntimeConverter();
	}
	else {
		throw new RuntimeException("Unsupported type information '" + info + "'.");
	}
}