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

The following examples show how to use org.apache.flink.api.common.typeinfo.Types#SHORT . 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: TaxiRideTableSource.java    From flink-training-exercises with Apache License 2.0 5 votes vote down vote up
/**
 * Specifies schema of the produced table.
 *
 * @return The schema of the produced table.
 */
@Override
public TypeInformation<Row> getReturnType() {

	TypeInformation<?>[] types = new TypeInformation[] {
			Types.LONG,
			Types.LONG,
			Types.LONG,
			Types.BOOLEAN,
			Types.FLOAT,
			Types.FLOAT,
			Types.FLOAT,
			Types.FLOAT,
			Types.SHORT
	};

	String[] names = new String[]{
			"rideId",
			"taxiId",
			"driverId",
			"isStart",
			"startLon",
			"startLat",
			"endLon",
			"endLat",
			"passengerCnt"
	};

	return new RowTypeInfo(types, names);
}
 
Example 2
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 3
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 4
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 5
Source File: TableUtil.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Determine whether it is number type, number type includes double, long, byte, int, float and short.
 *
 * @param dataType the dataType to determine.
 * @return whether it is number type
 */
public static boolean isSupportedNumericType(TypeInformation<?> dataType) {
	return Types.DOUBLE == dataType
		|| Types.LONG == dataType
		|| Types.BYTE == dataType
		|| Types.INT == dataType
		|| Types.FLOAT == dataType
		|| Types.SHORT == dataType;
}
 
Example 6
Source File: TaxiRideTableSource.java    From flink-training-exercises with Apache License 2.0 5 votes vote down vote up
@Override
public TableSchema getTableSchema() {
	TypeInformation<?>[] types = new TypeInformation[] {
			Types.LONG,
			Types.LONG,
			Types.LONG,
			Types.BOOLEAN,
			Types.FLOAT,
			Types.FLOAT,
			Types.FLOAT,
			Types.FLOAT,
			Types.SHORT,
			Types.SQL_TIMESTAMP
	};

	String[] names = new String[]{
			"rideId",
			"taxiId",
			"driverId",
			"isStart",
			"startLon",
			"startLat",
			"endLon",
			"endLat",
			"passengerCnt",
			"eventTime"
	};

	return new TableSchema(names, types);
}
 
Example 7
Source File: OrcTableSourceTest.java    From Flink-CEPplus 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 8
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 9
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 10
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 11
Source File: FirstValueAggFunction.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public TypeInformation<Short> getResultType() {
	return Types.SHORT;
}
 
Example 12
Source File: LastValueWithRetractAggFunction.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public TypeInformation<Short> getResultType() {
	return Types.SHORT;
}
 
Example 13
Source File: LastValueAggFunction.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public TypeInformation<Short> getResultType() {
	return Types.SHORT;
}
 
Example 14
Source File: FirstValueWithRetractAggFunction.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public TypeInformation<Short> getResultType() {
	return Types.SHORT;
}
 
Example 15
Source File: FirstValueWithRetractAggFunction.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public TypeInformation<Short> getResultType() {
	return Types.SHORT;
}
 
Example 16
Source File: LastValueAggFunction.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public TypeInformation<Short> getResultType() {
	return Types.SHORT;
}
 
Example 17
Source File: LastValueWithRetractAggFunction.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public TypeInformation<Short> getResultType() {
	return Types.SHORT;
}
 
Example 18
Source File: FirstValueAggFunction.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public TypeInformation<Short> getResultType() {
	return Types.SHORT;
}
 
Example 19
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 20
Source File: TypeStringUtils.java    From Flink-CEPplus 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);
	}
}