Java Code Examples for org.apache.flink.table.api.DataTypes#TINYINT

The following examples show how to use org.apache.flink.table.api.DataTypes#TINYINT . 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: HiveCatalogDataTypeTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testDataTypes() throws Exception {
	DataType[] types = new DataType[] {
		DataTypes.TINYINT(),
		DataTypes.SMALLINT(),
		DataTypes.INT(),
		DataTypes.BIGINT(),
		DataTypes.FLOAT(),
		DataTypes.DOUBLE(),
		DataTypes.BOOLEAN(),
		DataTypes.STRING(),
		DataTypes.BYTES(),
		DataTypes.DATE(),
		DataTypes.TIMESTAMP(),
		DataTypes.CHAR(HiveChar.MAX_CHAR_LENGTH),
		DataTypes.VARCHAR(HiveVarchar.MAX_VARCHAR_LENGTH),
		DataTypes.DECIMAL(5, 3)
	};

	verifyDataTypes(types);
}
 
Example 2
Source File: HiveCatalogDataTypeTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testDataTypes() throws Exception {
	DataType[] types = new DataType[] {
		DataTypes.TINYINT(),
		DataTypes.SMALLINT(),
		DataTypes.INT(),
		DataTypes.BIGINT(),
		DataTypes.FLOAT(),
		DataTypes.DOUBLE(),
		DataTypes.BOOLEAN(),
		DataTypes.STRING(),
		DataTypes.BYTES(),
		DataTypes.DATE(),
		DataTypes.TIMESTAMP(9),
		DataTypes.CHAR(HiveChar.MAX_CHAR_LENGTH),
		DataTypes.VARCHAR(HiveVarchar.MAX_VARCHAR_LENGTH),
		DataTypes.DECIMAL(5, 3)
	};

	verifyDataTypes(types);
}
 
Example 3
Source File: HiveTypeUtil.java    From flink with Apache License 2.0 5 votes vote down vote up
private static DataType toFlinkPrimitiveType(PrimitiveTypeInfo hiveType) {
	checkNotNull(hiveType, "hiveType cannot be null");

	switch (hiveType.getPrimitiveCategory()) {
		case CHAR:
			return DataTypes.CHAR(((CharTypeInfo) hiveType).getLength());
		case VARCHAR:
			return DataTypes.VARCHAR(((VarcharTypeInfo) hiveType).getLength());
		case STRING:
			return DataTypes.STRING();
		case BOOLEAN:
			return DataTypes.BOOLEAN();
		case BYTE:
			return DataTypes.TINYINT();
		case SHORT:
			return DataTypes.SMALLINT();
		case INT:
			return DataTypes.INT();
		case LONG:
			return DataTypes.BIGINT();
		case FLOAT:
			return DataTypes.FLOAT();
		case DOUBLE:
			return DataTypes.DOUBLE();
		case DATE:
			return DataTypes.DATE();
		case TIMESTAMP:
			return DataTypes.TIMESTAMP();
		case BINARY:
			return DataTypes.BYTES();
		case DECIMAL:
			DecimalTypeInfo decimalTypeInfo = (DecimalTypeInfo) hiveType;
			return DataTypes.DECIMAL(decimalTypeInfo.getPrecision(), decimalTypeInfo.getScale());
		default:
			throw new UnsupportedOperationException(
				String.format("Flink doesn't support Hive primitive type %s yet", hiveType));
	}
}
 
Example 4
Source File: SchemaUtils.java    From pulsar-flink with Apache License 2.0 5 votes vote down vote up
public static DataType si2SqlType(SchemaInfo si) throws IncompatibleSchemaException {
    switch (si.getType()) {
        case NONE:
        case BYTES:
            return DataTypes.BYTES();
        case BOOLEAN:
            return DataTypes.BOOLEAN();
        case DATE:
            return DataTypes.DATE();
        case STRING:
            return DataTypes.STRING();
        case TIMESTAMP:
            return DataTypes.TIMESTAMP(3).bridgedTo(java.sql.Timestamp.class);
        case INT8:
            return DataTypes.TINYINT();
        case DOUBLE:
            return DataTypes.DOUBLE();
        case FLOAT:
            return DataTypes.FLOAT();
        case INT32:
            return DataTypes.INT();
        case INT64:
            return DataTypes.BIGINT();
        case INT16:
            return DataTypes.SMALLINT();
        case AVRO:
        case JSON:
            Schema avroSchema =
                    new Schema.Parser().parse(new String(si.getSchema(), StandardCharsets.UTF_8));
            return avro2SqlType(avroSchema, Collections.emptySet());
        default:
            throw new UnsupportedOperationException(String.format("We do not support %s currently.", si.getType()));
    }
}
 
Example 5
Source File: HiveTypeUtil.java    From flink with Apache License 2.0 5 votes vote down vote up
private static DataType toFlinkPrimitiveType(PrimitiveTypeInfo hiveType) {
	checkNotNull(hiveType, "hiveType cannot be null");

	switch (hiveType.getPrimitiveCategory()) {
		case CHAR:
			return DataTypes.CHAR(((CharTypeInfo) hiveType).getLength());
		case VARCHAR:
			return DataTypes.VARCHAR(((VarcharTypeInfo) hiveType).getLength());
		case STRING:
			return DataTypes.STRING();
		case BOOLEAN:
			return DataTypes.BOOLEAN();
		case BYTE:
			return DataTypes.TINYINT();
		case SHORT:
			return DataTypes.SMALLINT();
		case INT:
			return DataTypes.INT();
		case LONG:
			return DataTypes.BIGINT();
		case FLOAT:
			return DataTypes.FLOAT();
		case DOUBLE:
			return DataTypes.DOUBLE();
		case DATE:
			return DataTypes.DATE();
		case TIMESTAMP:
			return DataTypes.TIMESTAMP(9);
		case BINARY:
			return DataTypes.BYTES();
		case DECIMAL:
			DecimalTypeInfo decimalTypeInfo = (DecimalTypeInfo) hiveType;
			return DataTypes.DECIMAL(decimalTypeInfo.getPrecision(), decimalTypeInfo.getScale());
		default:
			throw new UnsupportedOperationException(
				String.format("Flink doesn't support Hive primitive type %s yet", hiveType));
	}
}
 
Example 6
Source File: KuduTypeUtils.java    From bahir-flink with Apache License 2.0 5 votes vote down vote up
public static DataType toFlinkType(Type type, ColumnTypeAttributes typeAttributes) {
    switch (type) {
        case STRING:
            return DataTypes.STRING();
        case FLOAT:
            return DataTypes.FLOAT();
        case INT8:
            return DataTypes.TINYINT();
        case INT16:
            return DataTypes.SMALLINT();
        case INT32:
            return DataTypes.INT();
        case INT64:
            return DataTypes.BIGINT();
        case DOUBLE:
            return DataTypes.DOUBLE();
        case DECIMAL:
            return DataTypes.DECIMAL(typeAttributes.getPrecision(), typeAttributes.getScale());
        case BOOL:
            return DataTypes.BOOLEAN();
        case BINARY:
            return DataTypes.BYTES();
        case UNIXTIME_MICROS:
            return new AtomicDataType(new TimestampType(3), Timestamp.class);

        default:
            throw new IllegalArgumentException("Illegal var type: " + type);
    }
}
 
Example 7
Source File: IncrSumAggFunction.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public DataType getResultType() {
	return DataTypes.TINYINT();
}
 
Example 8
Source File: AvgAggFunction.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public DataType getResultType() {
	return DataTypes.TINYINT();
}
 
Example 9
Source File: StrategyUtils.java    From flink with Apache License 2.0 4 votes vote down vote up
/**
 * Returns a data type for the given data type and expected root.
 *
 * <p>This method is aligned with {@link LogicalTypeCasts#supportsImplicitCast(LogicalType, LogicalType)}.
 *
 * <p>The "fallback" data type for each root represents the default data type for a NULL literal. NULL
 * literals will receive the smallest precision possible for having little impact when finding a common
 * type. The output of this method needs to be checked again if an implicit cast is supported.
 */
private static @Nullable DataType findDataTypeOfRoot(
		DataType actualDataType,
		LogicalTypeRoot expectedRoot) {
	final LogicalType actualType = actualDataType.getLogicalType();
	if (hasRoot(actualType, expectedRoot)) {
		return actualDataType;
	}
	switch (expectedRoot) {
		case CHAR:
			return DataTypes.CHAR(CharType.DEFAULT_LENGTH);
		case VARCHAR:
			if (hasRoot(actualType, CHAR)) {
				return DataTypes.VARCHAR(getLength(actualType));
			}
			return DataTypes.VARCHAR(VarCharType.DEFAULT_LENGTH);
		case BOOLEAN:
			return DataTypes.BOOLEAN();
		case BINARY:
			return DataTypes.BINARY(BinaryType.DEFAULT_LENGTH);
		case VARBINARY:
			if (hasRoot(actualType, BINARY)) {
				return DataTypes.VARBINARY(getLength(actualType));
			}
			return DataTypes.VARBINARY(VarBinaryType.DEFAULT_LENGTH);
		case DECIMAL:
			if (hasFamily(actualType, EXACT_NUMERIC)) {
				return DataTypes.DECIMAL(getPrecision(actualType), getScale(actualType));
			} else if (hasFamily(actualType, APPROXIMATE_NUMERIC)) {
				final int precision = getPrecision(actualType);
				// we don't know where the precision occurs (before or after the dot)
				return DataTypes.DECIMAL(precision * 2, precision);
			}
			return DataTypes.DECIMAL(DecimalType.MIN_PRECISION, DecimalType.MIN_SCALE);
		case TINYINT:
			return DataTypes.TINYINT();
		case SMALLINT:
			return DataTypes.SMALLINT();
		case INTEGER:
			return DataTypes.INT();
		case BIGINT:
			return DataTypes.BIGINT();
		case FLOAT:
			return DataTypes.FLOAT();
		case DOUBLE:
			return DataTypes.DOUBLE();
		case DATE:
			return DataTypes.DATE();
		case TIME_WITHOUT_TIME_ZONE:
			if (hasRoot(actualType, TIMESTAMP_WITHOUT_TIME_ZONE)) {
				return DataTypes.TIME(getPrecision(actualType));
			}
			return DataTypes.TIME();
		case TIMESTAMP_WITHOUT_TIME_ZONE:
			return DataTypes.TIMESTAMP();
		case TIMESTAMP_WITH_TIME_ZONE:
			return DataTypes.TIMESTAMP_WITH_TIME_ZONE();
		case TIMESTAMP_WITH_LOCAL_TIME_ZONE:
			return DataTypes.TIMESTAMP_WITH_LOCAL_TIME_ZONE();
		case INTERVAL_YEAR_MONTH:
			return DataTypes.INTERVAL(DataTypes.MONTH());
		case INTERVAL_DAY_TIME:
			return DataTypes.INTERVAL(DataTypes.SECOND());
		case NULL:
			return DataTypes.NULL();
		case ARRAY:
		case MULTISET:
		case MAP:
		case ROW:
		case DISTINCT_TYPE:
		case STRUCTURED_TYPE:
		case RAW:
		case SYMBOL:
		case UNRESOLVED:
		default:
			return null;
	}
}
 
Example 10
Source File: SumWithRetractAggFunction.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public DataType getResultType() {
	return DataTypes.TINYINT();
}
 
Example 11
Source File: SumWithRetractAggFunction.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public DataType getResultType() {
	return DataTypes.TINYINT();
}
 
Example 12
Source File: SumAggFunction.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public DataType getResultType() {
	return DataTypes.TINYINT();
}
 
Example 13
Source File: Sum0AggFunction.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public DataType getResultType() {
	return DataTypes.TINYINT();
}
 
Example 14
Source File: IncrSumAggFunction.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public DataType getResultType() {
	return DataTypes.TINYINT();
}
 
Example 15
Source File: IncrSumWithRetractAggFunction.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public DataType getResultType() {
	return DataTypes.TINYINT();
}
 
Example 16
Source File: MaxAggFunction.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public DataType getResultType() {
	return DataTypes.TINYINT();
}
 
Example 17
Source File: LeadLagAggFunction.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public DataType getResultType() {
	return DataTypes.TINYINT();
}
 
Example 18
Source File: LeadLagAggFunction.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public DataType getResultType() {
	return DataTypes.TINYINT();
}
 
Example 19
Source File: AvgAggFunction.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public DataType getResultType() {
	return DataTypes.TINYINT();
}
 
Example 20
Source File: Sum0AggFunction.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public DataType getResultType() {
	return DataTypes.TINYINT();
}