Search in sources :

Example 26 with DecimalType

use of org.apache.flink.table.types.logical.DecimalType in project flink by apache.

the class SortCodeGeneratorTest method value2.

private Object value2(LogicalType type, Random rnd) {
    switch(type.getTypeRoot()) {
        case BOOLEAN:
            return false;
        case TINYINT:
            return (byte) 0;
        case SMALLINT:
            return (short) 0;
        case INTEGER:
            return 0;
        case BIGINT:
            return 0L;
        case FLOAT:
            return 0f;
        case DOUBLE:
            return 0d;
        case VARCHAR:
            return StringData.fromString("0");
        case DECIMAL:
            DecimalType decimalType = (DecimalType) type;
            return DecimalData.fromBigDecimal(new BigDecimal(0), decimalType.getPrecision(), decimalType.getScale());
        case TIMESTAMP_WITHOUT_TIME_ZONE:
            return TimestampData.fromEpochMillis(0);
        case ARRAY:
        case VARBINARY:
            byte[] bytes = new byte[rnd.nextInt(7) + 10];
            rnd.nextBytes(bytes);
            return type instanceof VarBinaryType ? bytes : BinaryArrayData.fromPrimitiveArray(bytes);
        case ROW:
            RowType rowType = (RowType) type;
            if (rowType.getFields().get(0).getType().getTypeRoot() == INTEGER) {
                return GenericRowData.of(rnd.nextInt());
            } else {
                return GenericRowData.of(GenericRowData.of(new Object[] { null }));
            }
        case RAW:
            return RawValueData.fromObject(rnd.nextInt());
        default:
            throw new RuntimeException("Not support!");
    }
}
Also used : VarBinaryType(org.apache.flink.table.types.logical.VarBinaryType) DecimalType(org.apache.flink.table.types.logical.DecimalType) RowType(org.apache.flink.table.types.logical.RowType) BigDecimal(java.math.BigDecimal)

Example 27 with DecimalType

use of org.apache.flink.table.types.logical.DecimalType in project flink by apache.

the class SortCodeGeneratorTest method value3.

private Object value3(LogicalType type, Random rnd) {
    switch(type.getTypeRoot()) {
        case BOOLEAN:
            return true;
        case TINYINT:
            return Byte.MAX_VALUE;
        case SMALLINT:
            return Short.MAX_VALUE;
        case INTEGER:
            return Integer.MAX_VALUE;
        case BIGINT:
            return Long.MAX_VALUE;
        case FLOAT:
            return Float.MAX_VALUE;
        case DOUBLE:
            return Double.MAX_VALUE;
        case VARCHAR:
            return StringData.fromString(RandomStringUtils.random(100));
        case DECIMAL:
            DecimalType decimalType = (DecimalType) type;
            return DecimalData.fromBigDecimal(new BigDecimal(Integer.MAX_VALUE), decimalType.getPrecision(), decimalType.getScale());
        case TIMESTAMP_WITHOUT_TIME_ZONE:
            return TimestampData.fromEpochMillis(Long.MAX_VALUE, 999999);
        case ARRAY:
        case VARBINARY:
            byte[] bytes = new byte[rnd.nextInt(100) + 100];
            rnd.nextBytes(bytes);
            return type instanceof VarBinaryType ? bytes : BinaryArrayData.fromPrimitiveArray(bytes);
        case ROW:
            RowType rowType = (RowType) type;
            if (rowType.getFields().get(0).getType().getTypeRoot() == INTEGER) {
                return GenericRowData.of(rnd.nextInt());
            } else {
                return GenericRowData.of(GenericRowData.of(rnd.nextInt()));
            }
        case RAW:
            return RawValueData.fromObject(rnd.nextInt());
        default:
            throw new RuntimeException("Not support!");
    }
}
Also used : VarBinaryType(org.apache.flink.table.types.logical.VarBinaryType) DecimalType(org.apache.flink.table.types.logical.DecimalType) RowType(org.apache.flink.table.types.logical.RowType) BigDecimal(java.math.BigDecimal)

Aggregations

DecimalType (org.apache.flink.table.types.logical.DecimalType)27 LogicalType (org.apache.flink.table.types.logical.LogicalType)14 RowType (org.apache.flink.table.types.logical.RowType)12 TimestampType (org.apache.flink.table.types.logical.TimestampType)12 ArrayType (org.apache.flink.table.types.logical.ArrayType)8 BigIntType (org.apache.flink.table.types.logical.BigIntType)8 IntType (org.apache.flink.table.types.logical.IntType)8 BigDecimal (java.math.BigDecimal)7 LocalZonedTimestampType (org.apache.flink.table.types.logical.LocalZonedTimestampType)7 SmallIntType (org.apache.flink.table.types.logical.SmallIntType)7 TinyIntType (org.apache.flink.table.types.logical.TinyIntType)7 VarBinaryType (org.apache.flink.table.types.logical.VarBinaryType)7 VarCharType (org.apache.flink.table.types.logical.VarCharType)7 DataType (org.apache.flink.table.types.DataType)6 BooleanType (org.apache.flink.table.types.logical.BooleanType)6 DoubleType (org.apache.flink.table.types.logical.DoubleType)6 FloatType (org.apache.flink.table.types.logical.FloatType)6 LegacyTypeInformationType (org.apache.flink.table.types.logical.LegacyTypeInformationType)6 ArrayList (java.util.ArrayList)5 DateType (org.apache.flink.table.types.logical.DateType)5