org.apache.flink.table.types.logical.VarBinaryType Java Examples

The following examples show how to use org.apache.flink.table.types.logical.VarBinaryType. 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: LogicalTypesTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testEmptyStringLiterals() {
	final CharType charType = CharType.ofEmptyLiteral();
	final VarCharType varcharType = VarCharType.ofEmptyLiteral();
	final BinaryType binaryType = BinaryType.ofEmptyLiteral();
	final VarBinaryType varBinaryType = VarBinaryType.ofEmptyLiteral();

	// make the types nullable for testing
	testEquality(charType.copy(true), new CharType(1));
	testEquality(varcharType.copy(true), new VarCharType(1));
	testEquality(binaryType.copy(true), new BinaryType(1));
	testEquality(varBinaryType.copy(true), new VarBinaryType(1));

	testStringSummary(charType, "CHAR(0) NOT NULL");
	testStringSummary(varcharType, "VARCHAR(0) NOT NULL");
	testStringSummary(binaryType, "BINARY(0) NOT NULL");
	testStringSummary(varBinaryType, "VARBINARY(0) NOT NULL");

	testInvalidStringSerializability(charType);
	testInvalidStringSerializability(varcharType);
	testInvalidStringSerializability(binaryType);
	testInvalidStringSerializability(varBinaryType);
}
 
Example #2
Source File: LogicalTypesTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testEmptyStringLiterals() {
	final CharType charType = CharType.ofEmptyLiteral();
	final VarCharType varcharType = VarCharType.ofEmptyLiteral();
	final BinaryType binaryType = BinaryType.ofEmptyLiteral();
	final VarBinaryType varBinaryType = VarBinaryType.ofEmptyLiteral();

	// make the types nullable for testing
	testEquality(charType.copy(true), new CharType(1));
	testEquality(varcharType.copy(true), new VarCharType(1));
	testEquality(binaryType.copy(true), new BinaryType(1));
	testEquality(varBinaryType.copy(true), new VarBinaryType(1));

	testStringSummary(charType, "CHAR(0) NOT NULL");
	testStringSummary(varcharType, "VARCHAR(0) NOT NULL");
	testStringSummary(binaryType, "BINARY(0) NOT NULL");
	testStringSummary(varBinaryType, "VARBINARY(0) NOT NULL");

	testInvalidStringSerializability(charType);
	testInvalidStringSerializability(varcharType);
	testInvalidStringSerializability(binaryType);
	testInvalidStringSerializability(varBinaryType);
}
 
Example #3
Source File: SortCodeGeneratorTest.java    From flink with Apache License 2.0 5 votes vote down vote up
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 BinaryString.fromString("0");
		case DECIMAL:
			DecimalType decimalType = (DecimalType) type;
			return Decimal.fromBigDecimal(new BigDecimal(0),
					decimalType.getPrecision(), decimalType.getScale());
		case ARRAY:
		case VARBINARY:
			byte[] bytes = new byte[rnd.nextInt(7) + 10];
			rnd.nextBytes(bytes);
			return type instanceof VarBinaryType ? bytes : BinaryArray.fromPrimitiveArray(bytes);
		case ROW:
			RowType rowType = (RowType) type;
			if (rowType.getFields().get(0).getType().getTypeRoot() == INTEGER) {
				return GenericRow.of(rnd.nextInt());
			} else {
				return GenericRow.of(GenericRow.of(new Object[]{null}));
			}
		case ANY:
			return new BinaryGeneric<>(rnd.nextInt(), IntSerializer.INSTANCE);
		default:
			throw new RuntimeException("Not support!");
	}
}
 
Example #4
Source File: LogicalTypeMerging.java    From flink with Apache License 2.0 5 votes vote down vote up
private static LogicalType createStringType(LogicalTypeRoot typeRoot, int length) {
	switch (typeRoot) {
		case CHAR:
			return new CharType(length);
		case VARCHAR:
			return new VarCharType(length);
		case BINARY:
			return new BinaryType(length);
		case VARBINARY:
			return new VarBinaryType(length);
		default:
			throw new IllegalArgumentException();
	}
}
 
Example #5
Source File: LogicalTypeParser.java    From flink with Apache License 2.0 5 votes vote down vote up
private LogicalType parseVarBinaryType() {
	final int length = parseStringType();
	if (length < 0) {
		return new VarBinaryType();
	} else {
		return new VarBinaryType(length);
	}
}
 
Example #6
Source File: LogicalTypesTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testVarBinaryType() {
	testAll(
		new VarBinaryType(22),
		"VARBINARY(22)",
		"VARBINARY(22)",
		new Class[]{byte[].class},
		new Class[]{byte[].class},
		new LogicalType[]{},
		new VarBinaryType()
	);
}
 
Example #7
Source File: LogicalTypeCasts.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public Boolean visit(VarBinaryType targetType) {
	if (sourceType.isNullable() && !targetType.isNullable()) {
		return false;
	}
	// BINARY and VARBINARY are very compatible within bounds
	if ((hasRoot(sourceType, LogicalTypeRoot.BINARY) || hasRoot(sourceType, LogicalTypeRoot.VARBINARY)) &&
			getLength(sourceType) <= targetType.getLength()) {
		return true;
	}
	return defaultMethod(targetType);
}
 
Example #8
Source File: LogicalTypesTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testVarBinaryTypeWithMaximumLength() {
	testAll(
		new VarBinaryType(Integer.MAX_VALUE),
		"VARBINARY(2147483647)",
		"BYTES",
		new Class[]{byte[].class},
		new Class[]{byte[].class},
		new LogicalType[]{},
		new VarBinaryType(12)
	);
}
 
Example #9
Source File: HiveTypeUtil.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public TypeInfo visit(VarBinaryType varBinaryType) {
	// Flink's BytesType is defined as VARBINARY(Integer.MAX_VALUE)
	// We don't have more information in LogicalTypeRoot to distinguish BytesType and a VARBINARY(Integer.MAX_VALUE) instance
	// Thus always treat VARBINARY(Integer.MAX_VALUE) as BytesType
	if (varBinaryType.getLength() == VarBinaryType.MAX_LENGTH) {
		return TypeInfoFactory.binaryTypeInfo;
	}
	return defaultMethod(varBinaryType);
}
 
Example #10
Source File: HiveTypeUtil.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public TypeInfo visit(VarBinaryType varBinaryType) {
	// Flink's BytesType is defined as VARBINARY(Integer.MAX_VALUE)
	// We don't have more information in LogicalTypeRoot to distinguish BytesType and a VARBINARY(Integer.MAX_VALUE) instance
	// Thus always treat VARBINARY(Integer.MAX_VALUE) as BytesType
	if (varBinaryType.getLength() == VarBinaryType.MAX_LENGTH) {
		return TypeInfoFactory.binaryTypeInfo;
	}
	return defaultMethod(varBinaryType);
}
 
Example #11
Source File: FlinkTypeToType.java    From iceberg with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("checkstyle:CyclomaticComplexity")
@Override
public Type atomic(AtomicDataType type) {
  LogicalType inner = type.getLogicalType();
  if (inner instanceof VarCharType ||
      inner instanceof CharType) {
    return Types.StringType.get();
  } else if (inner instanceof BooleanType) {
    return Types.BooleanType.get();
  } else if (inner instanceof IntType ||
      inner instanceof SmallIntType ||
      inner instanceof TinyIntType) {
    return Types.IntegerType.get();
  } else if (inner instanceof BigIntType) {
    return Types.LongType.get();
  } else if (inner instanceof VarBinaryType) {
    return Types.BinaryType.get();
  } else if (inner instanceof BinaryType) {
    BinaryType binaryType = (BinaryType) inner;
    return Types.FixedType.ofLength(binaryType.getLength());
  } else if (inner instanceof FloatType) {
    return Types.FloatType.get();
  } else if (inner instanceof DoubleType) {
    return Types.DoubleType.get();
  } else if (inner instanceof DateType) {
    return Types.DateType.get();
  } else if (inner instanceof TimeType) {
    return Types.TimeType.get();
  } else if (inner instanceof TimestampType) {
    return Types.TimestampType.withoutZone();
  } else if (inner instanceof LocalZonedTimestampType) {
    return Types.TimestampType.withZone();
  } else if (inner instanceof DecimalType) {
    DecimalType decimalType = (DecimalType) inner;
    return Types.DecimalType.of(decimalType.getPrecision(), decimalType.getScale());
  } else {
    throw new UnsupportedOperationException("Not a supported type: " + type.toString());
  }
}
 
Example #12
Source File: SortCodeGeneratorTest.java    From flink with Apache License 2.0 5 votes vote down vote up
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 BinaryString.fromString(RandomStringUtils.random(100));
		case DECIMAL:
			DecimalType decimalType = (DecimalType) type;
			return Decimal.fromBigDecimal(new BigDecimal(Integer.MAX_VALUE),
					decimalType.getPrecision(), decimalType.getScale());
		case ARRAY:
		case VARBINARY:
			byte[] bytes = new byte[rnd.nextInt(100) + 100];
			rnd.nextBytes(bytes);
			return type instanceof VarBinaryType ? bytes : BinaryArray.fromPrimitiveArray(bytes);
		case ROW:
			RowType rowType = (RowType) type;
			if (rowType.getFields().get(0).getType().getTypeRoot() == INTEGER) {
				return GenericRow.of(rnd.nextInt());
			} else {
				return GenericRow.of(GenericRow.of(rnd.nextInt()));
			}
		case ANY:
			return new BinaryGeneric<>(rnd.nextInt(), IntSerializer.INSTANCE);
		default:
			throw new RuntimeException("Not support!");
	}
}
 
Example #13
Source File: LogicalTypesTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testVarBinaryTypeWithMaximumLength() {
	testAll(
		new VarBinaryType(Integer.MAX_VALUE),
		"VARBINARY(2147483647)",
		"BYTES",
		new Class[]{byte[].class},
		new Class[]{byte[].class},
		new LogicalType[]{},
		new VarBinaryType(12)
	);
}
 
Example #14
Source File: LogicalTypesTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testVarBinaryType() {
	testAll(
		new VarBinaryType(22),
		"VARBINARY(22)",
		"VARBINARY(22)",
		new Class[]{byte[].class},
		new Class[]{byte[].class},
		new LogicalType[]{},
		new VarBinaryType()
	);
}
 
Example #15
Source File: LogicalTypeGeneralization.java    From flink with Apache License 2.0 5 votes vote down vote up
private static LogicalType createStringType(LogicalTypeRoot typeRoot, int length) {
	switch (typeRoot) {
		case CHAR:
			return new CharType(length);
		case VARCHAR:
			return new VarCharType(length);
		case BINARY:
			return new BinaryType(length);
		case VARBINARY:
			return new VarBinaryType(length);
		default:
			throw new IllegalArgumentException();
	}
}
 
Example #16
Source File: PythonTypeUtils.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public FlinkFnApi.Schema.FieldType visit(VarBinaryType varBinaryType) {
	return FlinkFnApi.Schema.FieldType.newBuilder()
		.setTypeName(FlinkFnApi.Schema.TypeName.VARBINARY)
		.setVarBinaryInfo(FlinkFnApi.Schema.VarBinaryInfo.newBuilder().setLength(varBinaryType.getLength()))
		.setNullable(varBinaryType.isNullable())
		.build();
}
 
Example #17
Source File: LogicalTypeParser.java    From flink with Apache License 2.0 5 votes vote down vote up
private LogicalType parseVarBinaryType() {
	final int length = parseStringType();
	if (length < 0) {
		return new VarBinaryType();
	} else {
		return new VarBinaryType(length);
	}
}
 
Example #18
Source File: SortCodeGeneratorTest.java    From flink with Apache License 2.0 4 votes vote down vote up
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!");
	}
}
 
Example #19
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 #20
Source File: SortCodeGeneratorTest.java    From flink with Apache License 2.0 4 votes vote down vote up
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!");
	}
}
 
Example #21
Source File: PythonTypeUtils.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public TypeSerializer visit(VarBinaryType varBinaryType) {
	return BytePrimitiveArraySerializer.INSTANCE;
}
 
Example #22
Source File: SortCodeGeneratorTest.java    From flink with Apache License 2.0 4 votes vote down vote up
private Object[] generateValues(LogicalType type) {

		Random rnd = new Random();

		int seedNum = RECORD_NUM / 5;
		Object[] seeds = new Object[seedNum];
		seeds[0] = null;
		seeds[1] = value1(type, rnd);
		seeds[2] = value2(type, rnd);
		seeds[3] = value3(type, rnd);
		for (int i = 4; i < seeds.length; i++) {
			switch (type.getTypeRoot()) {
				case BOOLEAN:
					seeds[i] = rnd.nextBoolean();
					break;
				case TINYINT:
					seeds[i] = (byte) rnd.nextLong();
					break;
				case SMALLINT:
					seeds[i] = (short) rnd.nextLong();
					break;
				case INTEGER:
					seeds[i] = rnd.nextInt();
					break;
				case BIGINT:
					seeds[i] = rnd.nextLong();
					break;
				case FLOAT:
					seeds[i] = rnd.nextFloat() * rnd.nextLong();
					break;
				case DOUBLE:
					seeds[i] = rnd.nextDouble() * rnd.nextLong();
					break;
				case VARCHAR:
					seeds[i] = StringData.fromString(RandomStringUtils.random(rnd.nextInt(20)));
					break;
				case DECIMAL:
					DecimalType decimalType = (DecimalType) type;
					BigDecimal decimal = new BigDecimal(
							rnd.nextInt()).divide(
							new BigDecimal(ThreadLocalRandom.current().nextInt(1, 256)),
							ThreadLocalRandom.current().nextInt(1, 30), BigDecimal.ROUND_HALF_EVEN);
					seeds[i] = DecimalData.fromBigDecimal(decimal, decimalType.getPrecision(), decimalType.getScale());
					break;
				case TIMESTAMP_WITHOUT_TIME_ZONE:
					TimestampType timestampType = (TimestampType) type;
					if (timestampType.getPrecision() <= 3) {
						seeds[i] = TimestampData.fromEpochMillis(rnd.nextLong());
					} else {
						seeds[i] = TimestampData.fromEpochMillis(rnd.nextLong(), rnd.nextInt(1000000));
					}
					break;
				case ARRAY:
				case VARBINARY:
					byte[] bytes = new byte[rnd.nextInt(16) + 1];
					rnd.nextBytes(bytes);
					seeds[i] = type instanceof VarBinaryType ? bytes : BinaryArrayData.fromPrimitiveArray(bytes);
					break;
				case ROW:
					RowType rowType = (RowType) type;
					if (rowType.getFields().get(0).getType().getTypeRoot() == INTEGER) {
						seeds[i] = GenericRowData.of(rnd.nextInt());
					} else {
						seeds[i] = GenericRowData.of(GenericRowData.of(rnd.nextInt()));
					}
					break;
				case RAW:
					seeds[i] = RawValueData.fromObject(rnd.nextInt());
					break;
				default:
					throw new RuntimeException("Not support!");
			}
		}

		// result values
		Object[] results = new Object[RECORD_NUM];
		for (int i = 0; i < RECORD_NUM; i++) {
			results[i] = seeds[rnd.nextInt(seedNum)];
		}
		return results;
	}
 
Example #23
Source File: ArrowUtils.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public ArrowType visit(VarBinaryType varCharType) {
	return ArrowType.Binary.INSTANCE;
}
 
Example #24
Source File: ArrowUtilsTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@BeforeClass
public static void init() {
	testFields = new ArrayList<>();
	testFields.add(Tuple7.of(
		"f1", new TinyIntType(), new ArrowType.Int(8, true), RowTinyIntWriter.class,
		TinyIntWriter.TinyIntWriterForRow.class, TinyIntFieldReader.class, ArrowTinyIntColumnVector.class));

	testFields.add(Tuple7.of("f2", new SmallIntType(), new ArrowType.Int(8 * 2, true),
		RowSmallIntWriter.class, SmallIntWriter.SmallIntWriterForRow.class, SmallIntFieldReader.class, ArrowSmallIntColumnVector.class));

	testFields.add(Tuple7.of("f3", new IntType(), new ArrowType.Int(8 * 4, true),
		RowIntWriter.class, IntWriter.IntWriterForRow.class, IntFieldReader.class, ArrowIntColumnVector.class));

	testFields.add(Tuple7.of("f4", new BigIntType(), new ArrowType.Int(8 * 8, true),
		RowBigIntWriter.class, BigIntWriter.BigIntWriterForRow.class, BigIntFieldReader.class, ArrowBigIntColumnVector.class));

	testFields.add(Tuple7.of("f5", new BooleanType(), new ArrowType.Bool(),
		RowBooleanWriter.class, BooleanWriter.BooleanWriterForRow.class, BooleanFieldReader.class, ArrowBooleanColumnVector.class));

	testFields.add(Tuple7.of("f6", new FloatType(), new ArrowType.FloatingPoint(FloatingPointPrecision.SINGLE),
		RowFloatWriter.class, FloatWriter.FloatWriterForRow.class, FloatFieldReader.class, ArrowFloatColumnVector.class));

	testFields.add(Tuple7.of("f7", new DoubleType(), new ArrowType.FloatingPoint(FloatingPointPrecision.DOUBLE),
		RowDoubleWriter.class, DoubleWriter.DoubleWriterForRow.class, DoubleFieldReader.class, ArrowDoubleColumnVector.class));

	testFields.add(Tuple7.of("f8", new VarCharType(), ArrowType.Utf8.INSTANCE,
		RowVarCharWriter.class, VarCharWriter.VarCharWriterForRow.class, VarCharFieldReader.class, ArrowVarCharColumnVector.class));

	testFields.add(Tuple7.of("f9", new VarBinaryType(), ArrowType.Binary.INSTANCE,
		RowVarBinaryWriter.class, VarBinaryWriter.VarBinaryWriterForRow.class, VarBinaryFieldReader.class, ArrowVarBinaryColumnVector.class));

	testFields.add(Tuple7.of("f10", new DecimalType(10, 3), new ArrowType.Decimal(10, 3),
		RowDecimalWriter.class, DecimalWriter.DecimalWriterForRow.class, DecimalFieldReader.class, ArrowDecimalColumnVector.class));

	testFields.add(Tuple7.of("f11", new DateType(), new ArrowType.Date(DateUnit.DAY),
		RowDateWriter.class, DateWriter.DateWriterForRow.class, DateFieldReader.class, ArrowDateColumnVector.class));

	testFields.add(Tuple7.of("f13", new TimeType(0), new ArrowType.Time(TimeUnit.SECOND, 32),
		RowTimeWriter.class, TimeWriter.TimeWriterForRow.class, TimeFieldReader.class, ArrowTimeColumnVector.class));

	testFields.add(Tuple7.of("f14", new TimeType(2), new ArrowType.Time(TimeUnit.MILLISECOND, 32),
		RowTimeWriter.class, TimeWriter.TimeWriterForRow.class, TimeFieldReader.class, ArrowTimeColumnVector.class));

	testFields.add(Tuple7.of("f15", new TimeType(4), new ArrowType.Time(TimeUnit.MICROSECOND, 64),
		RowTimeWriter.class, TimeWriter.TimeWriterForRow.class, TimeFieldReader.class, ArrowTimeColumnVector.class));

	testFields.add(Tuple7.of("f16", new TimeType(8), new ArrowType.Time(TimeUnit.NANOSECOND, 64),
		RowTimeWriter.class, TimeWriter.TimeWriterForRow.class, TimeFieldReader.class, ArrowTimeColumnVector.class));

	testFields.add(Tuple7.of("f17", new LocalZonedTimestampType(0), new ArrowType.Timestamp(TimeUnit.SECOND, null),
		RowTimestampWriter.class, TimestampWriter.TimestampWriterForRow.class, TimestampFieldReader.class, ArrowTimestampColumnVector.class));

	testFields.add(Tuple7.of("f18", new LocalZonedTimestampType(2), new ArrowType.Timestamp(TimeUnit.MILLISECOND, null),
		RowTimestampWriter.class, TimestampWriter.TimestampWriterForRow.class, TimestampFieldReader.class, ArrowTimestampColumnVector.class));

	testFields.add(Tuple7.of("f19", new LocalZonedTimestampType(4), new ArrowType.Timestamp(TimeUnit.MICROSECOND, null),
		RowTimestampWriter.class, TimestampWriter.TimestampWriterForRow.class, TimestampFieldReader.class, ArrowTimestampColumnVector.class));

	testFields.add(Tuple7.of("f20", new LocalZonedTimestampType(8), new ArrowType.Timestamp(TimeUnit.NANOSECOND, null),
		RowTimestampWriter.class, TimestampWriter.TimestampWriterForRow.class, TimestampFieldReader.class, ArrowTimestampColumnVector.class));

	testFields.add(Tuple7.of("f21", new TimestampType(0), new ArrowType.Timestamp(TimeUnit.SECOND, null),
		RowTimestampWriter.class, TimestampWriter.TimestampWriterForRow.class, TimestampFieldReader.class, ArrowTimestampColumnVector.class));

	testFields.add(Tuple7.of("f22", new TimestampType(2), new ArrowType.Timestamp(TimeUnit.MILLISECOND, null),
		RowTimestampWriter.class, TimestampWriter.TimestampWriterForRow.class, TimestampFieldReader.class, ArrowTimestampColumnVector.class));

	testFields.add(Tuple7.of("f23", new TimestampType(4), new ArrowType.Timestamp(TimeUnit.MICROSECOND, null),
		RowTimestampWriter.class, TimestampWriter.TimestampWriterForRow.class, TimestampFieldReader.class, ArrowTimestampColumnVector.class));

	testFields.add(Tuple7.of("f24", new TimestampType(8), new ArrowType.Timestamp(TimeUnit.NANOSECOND, null),
		RowTimestampWriter.class, TimestampWriter.TimestampWriterForRow.class, TimestampFieldReader.class, ArrowTimestampColumnVector.class));

	testFields.add(Tuple7.of("f25", new ArrayType(new VarCharType()), ArrowType.List.INSTANCE,
		RowArrayWriter.class, ArrayWriter.ArrayWriterForRow.class, ArrayFieldReader.class, ArrowArrayColumnVector.class));

	RowType rowFieldType = new RowType(Arrays.asList(
		new RowType.RowField("a", new IntType()),
		new RowType.RowField("b", new VarCharType()),
		new RowType.RowField("c", new ArrayType(new VarCharType())),
		new RowType.RowField("d", new TimestampType(2)),
		new RowType.RowField("e", new RowType((Arrays.asList(
			new RowType.RowField("e1", new IntType()),
			new RowType.RowField("e2", new VarCharType())))))));
	testFields.add(Tuple7.of("f26", rowFieldType, ArrowType.Struct.INSTANCE,
		RowRowWriter.class, RowWriter.RowWriterForRow.class, RowFieldReader.class, ArrowRowColumnVector.class));

	List<RowType.RowField> rowFields = new ArrayList<>();
	for (Tuple7<String, LogicalType, ArrowType, Class<?>, Class<?>, Class<?>, Class<?>> field : testFields) {
		rowFields.add(new RowType.RowField(field.f0, field.f1));
	}
	rowType = new RowType(rowFields);

	allocator = ArrowUtils.getRootAllocator().newChildAllocator("stdout", 0, Long.MAX_VALUE);
}
 
Example #25
Source File: RowArrowReaderWriterTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@BeforeClass
public static void init() {
	List<LogicalType> fieldTypes = new ArrayList<>();
	fieldTypes.add(new TinyIntType());
	fieldTypes.add(new SmallIntType());
	fieldTypes.add(new IntType());
	fieldTypes.add(new BigIntType());
	fieldTypes.add(new BooleanType());
	fieldTypes.add(new FloatType());
	fieldTypes.add(new DoubleType());
	fieldTypes.add(new VarCharType());
	fieldTypes.add(new VarBinaryType());
	fieldTypes.add(new DecimalType(10, 0));
	fieldTypes.add(new DateType());
	fieldTypes.add(new TimeType(0));
	fieldTypes.add(new TimeType(2));
	fieldTypes.add(new TimeType(4));
	fieldTypes.add(new TimeType(8));
	fieldTypes.add(new LocalZonedTimestampType(0));
	fieldTypes.add(new LocalZonedTimestampType(2));
	fieldTypes.add(new LocalZonedTimestampType(4));
	fieldTypes.add(new LocalZonedTimestampType(8));
	fieldTypes.add(new TimestampType(0));
	fieldTypes.add(new TimestampType(2));
	fieldTypes.add(new TimestampType(4));
	fieldTypes.add(new TimestampType(8));
	fieldTypes.add(new ArrayType(new VarCharType()));
	fieldTypes.add(new RowType(Arrays.asList(
		new RowType.RowField("a", new IntType()),
		new RowType.RowField("b", new VarCharType()),
		new RowType.RowField("c", new ArrayType(new VarCharType())),
		new RowType.RowField("d", new TimestampType(2)),
		new RowType.RowField("e", new RowType(Arrays.asList(
			new RowType.RowField("e1", new IntType()),
			new RowType.RowField("e2", new VarCharType())))))));

	List<RowType.RowField> rowFields = new ArrayList<>();
	for (int i = 0; i < fieldTypes.size(); i++) {
		rowFields.add(new RowType.RowField("f" + i, fieldTypes.get(i)));
	}
	rowType = new RowType(rowFields);
	allocator = ArrowUtils.getRootAllocator().newChildAllocator("stdout", 0, Long.MAX_VALUE);
}
 
Example #26
Source File: RowDataArrowReaderWriterTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@BeforeClass
public static void init() {
	fieldTypes.add(new TinyIntType());
	fieldTypes.add(new SmallIntType());
	fieldTypes.add(new IntType());
	fieldTypes.add(new BigIntType());
	fieldTypes.add(new BooleanType());
	fieldTypes.add(new FloatType());
	fieldTypes.add(new DoubleType());
	fieldTypes.add(new VarCharType());
	fieldTypes.add(new VarBinaryType());
	fieldTypes.add(new DecimalType(10, 3));
	fieldTypes.add(new DateType());
	fieldTypes.add(new TimeType(0));
	fieldTypes.add(new TimeType(2));
	fieldTypes.add(new TimeType(4));
	fieldTypes.add(new TimeType(8));
	fieldTypes.add(new LocalZonedTimestampType(0));
	fieldTypes.add(new LocalZonedTimestampType(2));
	fieldTypes.add(new LocalZonedTimestampType(4));
	fieldTypes.add(new LocalZonedTimestampType(8));
	fieldTypes.add(new TimestampType(0));
	fieldTypes.add(new TimestampType(2));
	fieldTypes.add(new TimestampType(4));
	fieldTypes.add(new TimestampType(8));
	fieldTypes.add(new ArrayType(new VarCharType()));
	rowFieldType = new RowType(Arrays.asList(
		new RowType.RowField("a", new IntType()),
		new RowType.RowField("b", new VarCharType()),
		new RowType.RowField("c", new ArrayType(new VarCharType())),
		new RowType.RowField("d", new TimestampType(2)),
		new RowType.RowField("e", new RowType(Arrays.asList(
			new RowType.RowField("e1", new IntType()),
			new RowType.RowField("e2", new VarCharType()))))));
	fieldTypes.add(rowFieldType);

	List<RowType.RowField> rowFields = new ArrayList<>();
	for (int i = 0; i < fieldTypes.size(); i++) {
		rowFields.add(new RowType.RowField("f" + i, fieldTypes.get(i)));
	}
	rowType = new RowType(rowFields);
	allocator = ArrowUtils.getRootAllocator().newChildAllocator("stdout", 0, Long.MAX_VALUE);
}
 
Example #27
Source File: LogicalTypeDefaultVisitor.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public R visit(VarBinaryType varBinaryType) {
	return defaultMethod(varBinaryType);
}
 
Example #28
Source File: LogicalTypeParser.java    From flink with Apache License 2.0 4 votes vote down vote up
private LogicalType parseTypeByKeyword() {
	nextToken(TokenType.KEYWORD);
	switch (tokenAsKeyword()) {
		case CHAR:
			return parseCharType();
		case VARCHAR:
			return parseVarCharType();
		case STRING:
			return new VarCharType(VarCharType.MAX_LENGTH);
		case BOOLEAN:
			return new BooleanType();
		case BINARY:
			return parseBinaryType();
		case VARBINARY:
			return parseVarBinaryType();
		case BYTES:
			return new VarBinaryType(VarBinaryType.MAX_LENGTH);
		case DECIMAL:
		case NUMERIC:
		case DEC:
			return parseDecimalType();
		case TINYINT:
			return new TinyIntType();
		case SMALLINT:
			return new SmallIntType();
		case INT:
		case INTEGER:
			return new IntType();
		case BIGINT:
			return new BigIntType();
		case FLOAT:
			return new FloatType();
		case DOUBLE:
			return parseDoubleType();
		case DATE:
			return new DateType();
		case TIME:
			return parseTimeType();
		case TIMESTAMP:
			return parseTimestampType();
		case INTERVAL:
			return parseIntervalType();
		case ARRAY:
			return parseArrayType();
		case MULTISET:
			return parseMultisetType();
		case MAP:
			return parseMapType();
		case ROW:
			return parseRowType();
		case NULL:
			return new NullType();
		case RAW:
			return parseRawType();
		case LEGACY:
			return parseLegacyType();
		default:
			throw parsingError("Unsupported type: " + token().value);
	}
}
 
Example #29
Source File: LogicalTypeChecks.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public Integer visit(VarBinaryType varBinaryType) {
	return varBinaryType.getLength();
}
 
Example #30
Source File: LogicalTypeDataTypeConverter.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public DataType visit(VarBinaryType varBinaryType) {
	return new AtomicDataType(varBinaryType);
}