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

The following examples show how to use org.apache.flink.api.common.typeinfo.Types#BIG_INT . 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 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 2
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 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(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 4
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(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 5
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 6
Source File: JsonRowDeserializationSchema.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
private Object convert(JsonNode node, TypeInformation<?> info) {
	if (info == Types.VOID || node.isNull()) {
		return null;
	} else if (info == Types.BOOLEAN) {
		return node.asBoolean();
	} else if (info == Types.STRING) {
		return node.asText();
	} else if (info == Types.BIG_DEC) {
		return node.decimalValue();
	} else if (info == Types.BIG_INT) {
		return node.bigIntegerValue();
	} else if (info == Types.SQL_DATE) {
		return Date.valueOf(node.asText());
	} else if (info == Types.SQL_TIME) {
		// according to RFC 3339 every full-time must have a timezone;
		// until we have full timezone support, we only support UTC;
		// users can parse their time as string as a workaround
		final String time = node.asText();
		if (time.indexOf('Z') < 0 || time.indexOf('.') >= 0) {
			throw new IllegalStateException(
				"Invalid time format. Only a time in UTC timezone without milliseconds is supported yet. " +
					"Format: HH:mm:ss'Z'");
		}
		return Time.valueOf(time.substring(0, time.length() - 1));
	} else if (info == Types.SQL_TIMESTAMP) {
		// according to RFC 3339 every date-time must have a timezone;
		// until we have full timezone support, we only support UTC;
		// users can parse their time as string as a workaround
		final String timestamp = node.asText();
		if (timestamp.indexOf('Z') < 0) {
			throw new IllegalStateException(
				"Invalid timestamp format. Only a timestamp in UTC timezone is supported yet. " +
					"Format: yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
		}
		return Timestamp.valueOf(timestamp.substring(0, timestamp.length() - 1).replace('T', ' '));
	} else if (info instanceof RowTypeInfo) {
		return convertRow(node, (RowTypeInfo) info);
	} else if (info instanceof ObjectArrayTypeInfo) {
		return convertObjectArray(node, ((ObjectArrayTypeInfo) info).getComponentInfo());
	} else if (info instanceof BasicArrayTypeInfo) {
		return convertObjectArray(node, ((BasicArrayTypeInfo) info).getComponentInfo());
	} else if (info instanceof PrimitiveArrayTypeInfo &&
			((PrimitiveArrayTypeInfo) info).getComponentType() == Types.BYTE) {
		return convertByteArray(node);
	} else {
		// for types that were specified without JSON schema
		// e.g. POJOs
		try {
			return objectMapper.treeToValue(node, info.getTypeClass());
		} catch (JsonProcessingException e) {
			throw new IllegalStateException("Unsupported type information '" + info + "' for node: " + node);
		}
	}
}