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

The following examples show how to use org.apache.flink.api.common.typeinfo.Types#FLOAT . 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: TaxiFareTableSource.java    From flink-training-exercises with Apache License 2.0 6 votes vote down vote up
@Override
public TableSchema getTableSchema() {
	TypeInformation<?>[] types = new TypeInformation[] {
			Types.LONG,
			Types.LONG,
			Types.LONG,
			Types.STRING,
			Types.FLOAT,
			Types.FLOAT,
			Types.FLOAT,
			Types.SQL_TIMESTAMP
	};

	String[] names = new String[]{
			"rideId",
			"taxiId",
			"driverId",
			"paymentType",
			"tip",
			"tolls",
			"totalFare",
			"eventTime"
	};

	return new TableSchema(names, types);
}
 
Example 2
Source File: TripRecord.java    From pravega-samples with Apache License 2.0 6 votes vote down vote up
public static TypeInformation[] getTypeInformation() {
    TypeInformation<?>[] typeInfo = new TypeInformation[] {
            Types.INT,
            Types.INT,
            Types.SQL_TIMESTAMP,
            Types.SQL_TIMESTAMP,
            Types.INT,
            Types.FLOAT,
            Types.INT,
            Types.INT,

            Types.STRING,
            Types.STRING,
            Types.STRING,
            Types.STRING,
            Types.STRING,
            Types.STRING
    };
    return typeInfo;
}
 
Example 3
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 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: 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 6
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 7
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 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(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 9
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 10
Source File: AvroSchemaConverter.java    From flink with Apache License 2.0 4 votes vote down vote up
private static TypeInformation<?> convertToTypeInfo(Schema schema) {
	switch (schema.getType()) {
		case RECORD:
			final List<Schema.Field> fields = schema.getFields();

			final TypeInformation<?>[] types = new TypeInformation<?>[fields.size()];
			final String[] names = new String[fields.size()];
			for (int i = 0; i < fields.size(); i++) {
				final Schema.Field field = fields.get(i);
				types[i] = convertToTypeInfo(field.schema());
				names[i] = field.name();
			}
			return Types.ROW_NAMED(names, types);
		case ENUM:
			return Types.STRING;
		case ARRAY:
			// result type might either be ObjectArrayTypeInfo or BasicArrayTypeInfo for Strings
			return Types.OBJECT_ARRAY(convertToTypeInfo(schema.getElementType()));
		case MAP:
			return Types.MAP(Types.STRING, convertToTypeInfo(schema.getValueType()));
		case UNION:
			final Schema actualSchema;
			if (schema.getTypes().size() == 2 && schema.getTypes().get(0).getType() == Schema.Type.NULL) {
				actualSchema = schema.getTypes().get(1);
			} else if (schema.getTypes().size() == 2 && schema.getTypes().get(1).getType() == Schema.Type.NULL) {
				actualSchema = schema.getTypes().get(0);
			} else if (schema.getTypes().size() == 1) {
				actualSchema = schema.getTypes().get(0);
			} else {
				// use Kryo for serialization
				return Types.GENERIC(Object.class);
			}
			return convertToTypeInfo(actualSchema);
		case FIXED:
			// logical decimal type
			if (schema.getLogicalType() instanceof LogicalTypes.Decimal) {
				return Types.BIG_DEC;
			}
			// convert fixed size binary data to primitive byte arrays
			return Types.PRIMITIVE_ARRAY(Types.BYTE);
		case STRING:
			// convert Avro's Utf8/CharSequence to String
			return Types.STRING;
		case BYTES:
			// logical decimal type
			if (schema.getLogicalType() instanceof LogicalTypes.Decimal) {
				return Types.BIG_DEC;
			}
			return Types.PRIMITIVE_ARRAY(Types.BYTE);
		case INT:
			// logical date and time type
			final org.apache.avro.LogicalType logicalType = schema.getLogicalType();
			if (logicalType == LogicalTypes.date()) {
				return Types.SQL_DATE;
			} else if (logicalType == LogicalTypes.timeMillis()) {
				return Types.SQL_TIME;
			}
			return Types.INT;
		case LONG:
			// logical timestamp type
			if (schema.getLogicalType() == LogicalTypes.timestampMillis()) {
				return Types.SQL_TIMESTAMP;
			}
			return Types.LONG;
		case FLOAT:
			return Types.FLOAT;
		case DOUBLE:
			return Types.DOUBLE;
		case BOOLEAN:
			return Types.BOOLEAN;
		case NULL:
			return Types.VOID;
	}
	throw new IllegalArgumentException("Unsupported Avro type '" + schema.getType() + "'.");
}
 
Example 11
Source File: LastValueWithRetractAggFunction.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public TypeInformation<Float> getResultType() {
	return Types.FLOAT;
}
 
Example 12
Source File: GeoUtils.java    From infoworld-post with Apache License 2.0 4 votes vote down vote up
@Override
public TypeInformation getResultType(Class[] signature) {
    return new TupleTypeInfo<>(Types.FLOAT, Types.FLOAT);
}
 
Example 13
Source File: AvroSchemaConverter.java    From flink with Apache License 2.0 4 votes vote down vote up
private static TypeInformation<?> convertToTypeInfo(Schema schema) {
	switch (schema.getType()) {
		case RECORD:
			final List<Schema.Field> fields = schema.getFields();

			final TypeInformation<?>[] types = new TypeInformation<?>[fields.size()];
			final String[] names = new String[fields.size()];
			for (int i = 0; i < fields.size(); i++) {
				final Schema.Field field = fields.get(i);
				types[i] = convertToTypeInfo(field.schema());
				names[i] = field.name();
			}
			return Types.ROW_NAMED(names, types);
		case ENUM:
			return Types.STRING;
		case ARRAY:
			// result type might either be ObjectArrayTypeInfo or BasicArrayTypeInfo for Strings
			return Types.OBJECT_ARRAY(convertToTypeInfo(schema.getElementType()));
		case MAP:
			return Types.MAP(Types.STRING, convertToTypeInfo(schema.getValueType()));
		case UNION:
			final Schema actualSchema;
			if (schema.getTypes().size() == 2 && schema.getTypes().get(0).getType() == Schema.Type.NULL) {
				actualSchema = schema.getTypes().get(1);
			} else if (schema.getTypes().size() == 2 && schema.getTypes().get(1).getType() == Schema.Type.NULL) {
				actualSchema = schema.getTypes().get(0);
			} else if (schema.getTypes().size() == 1) {
				actualSchema = schema.getTypes().get(0);
			} else {
				// use Kryo for serialization
				return Types.GENERIC(Object.class);
			}
			return convertToTypeInfo(actualSchema);
		case FIXED:
			// logical decimal type
			if (schema.getLogicalType() instanceof LogicalTypes.Decimal) {
				return Types.BIG_DEC;
			}
			// convert fixed size binary data to primitive byte arrays
			return Types.PRIMITIVE_ARRAY(Types.BYTE);
		case STRING:
			// convert Avro's Utf8/CharSequence to String
			return Types.STRING;
		case BYTES:
			// logical decimal type
			if (schema.getLogicalType() instanceof LogicalTypes.Decimal) {
				return Types.BIG_DEC;
			}
			return Types.PRIMITIVE_ARRAY(Types.BYTE);
		case INT:
			// logical date and time type
			final LogicalType logicalType = schema.getLogicalType();
			if (logicalType == LogicalTypes.date()) {
				return Types.SQL_DATE;
			} else if (logicalType == LogicalTypes.timeMillis()) {
				return Types.SQL_TIME;
			}
			return Types.INT;
		case LONG:
			// logical timestamp type
			if (schema.getLogicalType() == LogicalTypes.timestampMillis()) {
				return Types.SQL_TIMESTAMP;
			}
			return Types.LONG;
		case FLOAT:
			return Types.FLOAT;
		case DOUBLE:
			return Types.DOUBLE;
		case BOOLEAN:
			return Types.BOOLEAN;
		case NULL:
			return Types.VOID;
	}
	throw new IllegalArgumentException("Unsupported Avro type '" + schema.getType() + "'.");
}
 
Example 14
Source File: FirstValueAggFunction.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public TypeInformation<Float> getResultType() {
	return Types.FLOAT;
}
 
Example 15
Source File: LastValueAggFunction.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public TypeInformation<Float> getResultType() {
	return Types.FLOAT;
}
 
Example 16
Source File: FirstValueWithRetractAggFunction.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public TypeInformation<Float> getResultType() {
	return Types.FLOAT;
}
 
Example 17
Source File: FirstValueWithRetractAggFunction.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public TypeInformation<Float> getResultType() {
	return Types.FLOAT;
}
 
Example 18
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 19
Source File: FirstValueAggFunction.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public TypeInformation<Float> getResultType() {
	return Types.FLOAT;
}
 
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);
	}
}