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!");
}
}
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!");
}
}
Aggregations