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

The following examples show how to use org.apache.flink.table.types.logical.VarCharType. 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: PythonScalarFunctionOperatorTestBase.java    From flink with Apache License 2.0 6 votes vote down vote up
private OneInputStreamOperatorTestHarness<IN, OUT> getTestHarness(Configuration config) throws Exception {
	RowType dataType = new RowType(Arrays.asList(
		new RowType.RowField("f1", new VarCharType()),
		new RowType.RowField("f2", new VarCharType()),
		new RowType.RowField("f3", new BigIntType())));
	AbstractPythonScalarFunctionOperator<IN, OUT, UDFIN> operator = getTestOperator(
		config,
		new PythonFunctionInfo[] {
			new PythonFunctionInfo(
				AbstractPythonScalarFunctionRunnerTest.DummyPythonFunction.INSTANCE,
				new Integer[]{0})
		},
		dataType,
		dataType,
		new int[]{2},
		new int[]{0, 1}
	);

	OneInputStreamOperatorTestHarness<IN, OUT> testHarness =
		new OneInputStreamOperatorTestHarness<>(operator);
	testHarness.getStreamConfig().setManagedMemoryFraction(0.5);
	testHarness.setup(getOutputTypeSerializer(dataType));
	return testHarness;
}
 
Example #2
Source File: HiveTypeUtil.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public TypeInfo visit(VarCharType varCharType) {
	// Flink's StringType is defined as VARCHAR(Integer.MAX_VALUE)
	// We don't have more information in LogicalTypeRoot to distinguish StringType and a VARCHAR(Integer.MAX_VALUE) instance
	// Thus always treat VARCHAR(Integer.MAX_VALUE) as StringType
	if (varCharType.getLength() == Integer.MAX_VALUE) {
		return TypeInfoFactory.stringTypeInfo;
	}
	// Flink and Hive have different length limit for VARCHAR. Promote it to STRING if it exceeds the limits of
	// Hive and we're told not to check precision. This can be useful when calling Hive UDF to process data.
	if (varCharType.getLength() > HiveVarchar.MAX_VARCHAR_LENGTH || varCharType.getLength() < 1) {
		if (checkPrecision) {
			throw new CatalogException(
					String.format("HiveCatalog doesn't support varchar type with length of '%d'. " +
									"The supported length is [%d, %d]",
							varCharType.getLength(), 1, HiveVarchar.MAX_VARCHAR_LENGTH));
		} else {
			return TypeInfoFactory.stringTypeInfo;
		}
	}
	return TypeInfoFactory.getVarcharTypeInfo(varCharType.getLength());
}
 
Example #3
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 #4
Source File: HiveTypeUtil.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public TypeInfo visit(VarCharType varCharType) {
	// Flink's StringType is defined as VARCHAR(Integer.MAX_VALUE)
	// We don't have more information in LogicalTypeRoot to distinguish StringType and a VARCHAR(Integer.MAX_VALUE) instance
	// Thus always treat VARCHAR(Integer.MAX_VALUE) as StringType
	if (varCharType.getLength() == Integer.MAX_VALUE) {
		return TypeInfoFactory.stringTypeInfo;
	}
	if (varCharType.getLength() > HiveVarchar.MAX_VARCHAR_LENGTH) {
		throw new CatalogException(
				String.format("HiveCatalog doesn't support varchar type with length of '%d'. " +
							"The maximum length is %d",
							varCharType.getLength(), HiveVarchar.MAX_VARCHAR_LENGTH));
	}
	return TypeInfoFactory.getVarcharTypeInfo(varCharType.getLength());
}
 
Example #5
Source File: BytesHashMapTest.java    From flink with Apache License 2.0 6 votes vote down vote up
public BytesHashMapTest() {

		this.keyTypes = new LogicalType[] {
				new IntType(),
				new VarCharType(VarCharType.MAX_LENGTH),
				new DoubleType(),
				new BigIntType(),
				new BooleanType(),
				new FloatType(),
				new SmallIntType()
		};
		this.valueTypes = new LogicalType[] {
				new DoubleType(),
				new BigIntType(),
				new BooleanType(),
				new FloatType(),
				new SmallIntType()
		};

		this.keySerializer = new BinaryRowDataSerializer(keyTypes.length);
		this.valueSerializer = new BinaryRowDataSerializer(valueTypes.length);
		this.defaultValue = valueSerializer.createInstance();
		int valueSize = defaultValue.getFixedLengthPartSize();
		this.defaultValue.pointTo(MemorySegmentFactory.wrap(new byte[valueSize]), 0, valueSize);
	}
 
Example #6
Source File: DataTypeExtractorTest.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Testing data type shared with the Scala tests.
 */
static DataType getSimplePojoDataType(Class<?> simplePojoClass) {
	final StructuredType.Builder builder = StructuredType.newBuilder(simplePojoClass);
	builder.attributes(
		Arrays.asList(
			new StructuredAttribute("intField", new IntType(true)),
			new StructuredAttribute("primitiveBooleanField", new BooleanType(false)),
			new StructuredAttribute("primitiveIntField", new IntType(false)),
			new StructuredAttribute("stringField", new VarCharType(VarCharType.MAX_LENGTH))));
	builder.setFinal(true);
	builder.setInstantiable(true);
	final StructuredType structuredType = builder.build();

	final List<DataType> fieldDataTypes = Arrays.asList(
		DataTypes.INT(),
		DataTypes.BOOLEAN().notNull().bridgedTo(boolean.class),
		DataTypes.INT().notNull().bridgedTo(int.class),
		DataTypes.STRING()
	);

	return new FieldsDataType(structuredType, simplePojoClass, fieldDataTypes);
}
 
Example #7
Source File: DataTypeExtractorTest.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Testing data type shared with the Scala tests.
 */
static DataType getComplexPojoDataType(Class<?> complexPojoClass, Class<?> simplePojoClass) {
	final StructuredType.Builder builder = StructuredType.newBuilder(complexPojoClass);
	builder.attributes(
		Arrays.asList(
			new StructuredAttribute(
				"mapField",
				new MapType(new VarCharType(VarCharType.MAX_LENGTH), new IntType())),
			new StructuredAttribute(
				"simplePojoField",
				getSimplePojoDataType(simplePojoClass).getLogicalType()),
			new StructuredAttribute(
				"someObject",
				new TypeInformationRawType<>(new GenericTypeInfo<>(Object.class)))));
	builder.setFinal(true);
	builder.setInstantiable(true);
	final StructuredType structuredType = builder.build();

	final List<DataType> fieldDataTypes = Arrays.asList(
		DataTypes.MAP(DataTypes.STRING(), DataTypes.INT()),
		getSimplePojoDataType(simplePojoClass),
		DataTypes.RAW(new GenericTypeInfo<>(Object.class))
	);

	return new FieldsDataType(structuredType, complexPojoClass, fieldDataTypes);
}
 
Example #8
Source File: DataTypeExtractorTest.java    From flink with Apache License 2.0 6 votes vote down vote up
private static DataType getInnerTupleDataType() {
	final StructuredType.Builder builder = StructuredType.newBuilder(Tuple2.class);
	builder.attributes(
		Arrays.asList(
			new StructuredAttribute(
				"f0",
				new VarCharType(VarCharType.MAX_LENGTH)),
			new StructuredAttribute(
				"f1",
				new BooleanType())));
	builder.setFinal(true);
	builder.setInstantiable(true);
	final StructuredType structuredType = builder.build();

	final List<DataType> fieldDataTypes = Arrays.asList(
		DataTypes.STRING(),
		DataTypes.BOOLEAN()
	);

	return new FieldsDataType(structuredType, Tuple2.class, fieldDataTypes);
}
 
Example #9
Source File: BytesHashMapTest.java    From flink with Apache License 2.0 6 votes vote down vote up
public BytesHashMapTest() {

		this.keyTypes = new LogicalType[] {
				new IntType(),
				new VarCharType(VarCharType.MAX_LENGTH),
				new DoubleType(),
				new BigIntType(),
				new BooleanType(),
				new FloatType(),
				new SmallIntType()
		};
		this.valueTypes = new LogicalType[] {
				new DoubleType(),
				new BigIntType(),
				new BooleanType(),
				new FloatType(),
				new SmallIntType()
		};

		this.keySerializer = new BinaryRowSerializer(keyTypes.length);
		this.valueSerializer = new BinaryRowSerializer(valueTypes.length);
		this.defaultValue = valueSerializer.createInstance();
		int valueSize = defaultValue.getFixedLengthPartSize();
		this.defaultValue.pointTo(MemorySegmentFactory.wrap(new byte[valueSize]), 0, valueSize);
	}
 
Example #10
Source File: RowDataArrowReaderWriterTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public RowData[] getTestData() {
	RowData row1 = StreamRecordUtils.row((byte) 1, (short) 2, 3, 4L, true, 1.0f, 1.0, "hello", "hello".getBytes(), DecimalData.fromUnscaledLong(1, 10, 3), 100, 3600000, 3600000, 3600000, 3600000,
		TimestampData.fromEpochMillis(3600000), TimestampData.fromEpochMillis(3600000), TimestampData.fromEpochMillis(3600000, 100000), TimestampData.fromEpochMillis(3600000, 100000),
		TimestampData.fromEpochMillis(3600000), TimestampData.fromEpochMillis(3600000), TimestampData.fromEpochMillis(3600000, 100000), TimestampData.fromEpochMillis(3600000, 100000),
		new GenericArrayData(new StringData[] {StringData.fromString("hello"), StringData.fromString("中文"), null}),
		GenericRowData.of(1, StringData.fromString("hello"), new GenericArrayData(new StringData[] {StringData.fromString("hello")}), TimestampData.fromEpochMillis(3600000), GenericRowData.of(1, StringData.fromString("hello"))));
	BinaryRowData row2 = StreamRecordUtils.binaryrow((byte) 1, (short) 2, 3, 4L, false, 1.0f, 1.0, "中文", "中文".getBytes(), DecimalData.fromUnscaledLong(1, 10, 3), 100, 3600000, 3600000, 3600000, 3600000,
		Tuple2.of(TimestampData.fromEpochMillis(3600000), 0), Tuple2.of(TimestampData.fromEpochMillis(3600000), 2), Tuple2.of(TimestampData.fromEpochMillis(3600000, 100000), 4), Tuple2.of(TimestampData.fromEpochMillis(3600000, 100000), 8),
		Tuple2.of(TimestampData.fromEpochMillis(3600000), 0), Tuple2.of(TimestampData.fromEpochMillis(3600000), 2), Tuple2.of(TimestampData.fromEpochMillis(3600000, 100000), 4), Tuple2.of(TimestampData.fromEpochMillis(3600000, 100000), 8),
		Tuple2.of(new GenericArrayData(new String[] {null, null, null}), new ArrayDataSerializer(new VarCharType(), null)),
		Tuple2.of(GenericRowData.of(1, null, new GenericArrayData(new StringData[] {StringData.fromString("hello")}), null, GenericRowData.of(1, StringData.fromString("hello"))), new RowDataSerializer(new ExecutionConfig(), rowFieldType)));
	RowData row3 = StreamRecordUtils.row(null, (short) 2, 3, 4L, false, 1.0f, 1.0, "中文", "中文".getBytes(), DecimalData.fromUnscaledLong(1, 10, 3), 100, 3600000, 3600000, 3600000, 3600000,
		TimestampData.fromEpochMillis(3600000), TimestampData.fromEpochMillis(3600000), TimestampData.fromEpochMillis(3600000, 100000), TimestampData.fromEpochMillis(3600000, 100000),
		TimestampData.fromEpochMillis(3600000), TimestampData.fromEpochMillis(3600000), TimestampData.fromEpochMillis(3600000, 100000), TimestampData.fromEpochMillis(3600000, 100000),
		new GenericArrayData(new String[] {null, null, null}),
		GenericRowData.of(1, null, new GenericArrayData(new StringData[] {StringData.fromString("hello")}), null, null));
	BinaryRowData row4 = StreamRecordUtils.binaryrow((byte) 1, null, 3, 4L, true, 1.0f, 1.0, "hello", "hello".getBytes(), DecimalData.fromUnscaledLong(1, 10, 3), 100, 3600000, 3600000, 3600000, 3600000,
		Tuple2.of(TimestampData.fromEpochMillis(3600000), 0), Tuple2.of(TimestampData.fromEpochMillis(3600000), 2), Tuple2.of(TimestampData.fromEpochMillis(3600000, 100000), 4), Tuple2.of(TimestampData.fromEpochMillis(3600000, 100000), 8),
		Tuple2.of(TimestampData.fromEpochMillis(3600000), 0), Tuple2.of(TimestampData.fromEpochMillis(3600000), 2), Tuple2.of(TimestampData.fromEpochMillis(3600000, 100000), 4), Tuple2.of(TimestampData.fromEpochMillis(3600000, 100000), 8),
		Tuple2.of(new GenericArrayData(new StringData[] {StringData.fromString("hello"), StringData.fromString("中文"), null}), new ArrayDataSerializer(new VarCharType(), null)),
		Tuple2.of(GenericRowData.of(1, null, new GenericArrayData(new StringData[] {StringData.fromString("hello")}), null, null), new RowDataSerializer(new ExecutionConfig(), rowFieldType)));
	RowData row5 = StreamRecordUtils.row(new Object[fieldTypes.size()]);
	BinaryRowData row6 = StreamRecordUtils.binaryrow(new Object[fieldTypes.size()]);
	return new RowData[]{row1, row2, row3, row4, row5, row6};
}
 
Example #11
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 #12
Source File: ArrowSourceFunctionTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void init() {
	fieldTypes.add(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);
	dataType = TypeConversions.fromLogicalToDataType(rowType);
	serializer = new RowDataSerializer(
		new ExecutionConfig(), fieldTypes.toArray(new LogicalType[0]));
	allocator = ArrowUtils.getRootAllocator().newChildAllocator("stdout", 0, Long.MAX_VALUE);
}
 
Example #13
Source File: BinaryRowTypeInfoTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testBinaryRowTypeInfoEquality() {
	BaseRowTypeInfo typeInfo1 = new BaseRowTypeInfo(
			new IntType(),
			new VarCharType(VarCharType.MAX_LENGTH));

	BaseRowTypeInfo typeInfo2 = new BaseRowTypeInfo(
			new IntType(),
			new VarCharType(VarCharType.MAX_LENGTH));

	assertEquals(typeInfo1, typeInfo2);
	assertEquals(typeInfo1.hashCode(), typeInfo2.hashCode());
}
 
Example #14
Source File: RowDataSerializerTest.java    From flink with Apache License 2.0 5 votes vote down vote up
private static Object[] testRowDataSerializerWithComplexTypes() {
	RowDataTypeInfo typeInfo = new RowDataTypeInfo(
		new IntType(),
		new DoubleType(),
		new VarCharType(VarCharType.MAX_LENGTH),
		new ArrayType(new IntType()),
		new MapType(new IntType(), new IntType()));

	GenericRowData[] data = new GenericRowData[]{
		createRow(null, null, null, null, null),
		createRow(0, null, null, null, null),
		createRow(0, 0.0, null, null, null),
		createRow(0, 0.0, fromString("a"), null, null),
		createRow(1, 0.0, fromString("a"), null, null),
		createRow(1, 1.0, fromString("a"), null, null),
		createRow(1, 1.0, fromString("b"), null, null),
		createRow(1, 1.0, fromString("b"), createArray(1), createMap(new int[]{1}, new int[]{1})),
		createRow(1, 1.0, fromString("b"), createArray(1, 2), createMap(new int[]{1, 4}, new int[]{1, 2})),
		createRow(1, 1.0, fromString("b"), createArray(1, 2, 3), createMap(new int[]{1, 5}, new int[]{1, 3})),
		createRow(1, 1.0, fromString("b"), createArray(1, 2, 3, 4), createMap(new int[]{1, 6}, new int[]{1, 4})),
		createRow(1, 1.0, fromString("b"), createArray(1, 2, 3, 4, 5), createMap(new int[]{1, 7}, new int[]{1, 5})),
		createRow(1, 1.0, fromString("b"), createArray(1, 2, 3, 4, 5, 6), createMap(new int[]{1, 8}, new int[]{1, 6}))
	};

	RowDataSerializer serializer = typeInfo.createSerializer(new ExecutionConfig());
	return new Object[] {serializer, data};
}
 
Example #15
Source File: BinaryArrayDataTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testNested() {
	BinaryArrayData array = new BinaryArrayData();
	BinaryArrayWriter writer = new BinaryArrayWriter(array, 2, 8);
	writer.writeRow(0, GenericRowData.of(fromString("1"), 1),
			new RowDataSerializer(null, RowType.of(new VarCharType(VarCharType.MAX_LENGTH), new IntType())));
	writer.setNullAt(1);
	writer.complete();

	RowData nestedRow = array.getRow(0, 2);
	assertEquals("1", nestedRow.getString(0).toString());
	assertEquals(1, nestedRow.getInt(1));
	assertTrue(array.isNullAt(1));
}
 
Example #16
Source File: BinaryRowDataTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testNested() {
	BinaryRowData row = new BinaryRowData(2);
	BinaryRowWriter writer = new BinaryRowWriter(row);
	writer.writeRow(0, GenericRowData.of(fromString("1"), 1),
			new RowDataSerializer(null, RowType.of(new VarCharType(VarCharType.MAX_LENGTH), new IntType())));
	writer.setNullAt(1);
	writer.complete();

	RowData nestedRow = row.getRow(0, 2);
	assertEquals("1", nestedRow.getString(0).toString());
	assertEquals(1, nestedRow.getInt(1));
	assertTrue(row.isNullAt(1));
}
 
Example #17
Source File: RowDataTypeInfoTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testBinaryRowTypeInfoEquality() {
	RowDataTypeInfo typeInfo1 = new RowDataTypeInfo(
			new IntType(),
			new VarCharType(VarCharType.MAX_LENGTH));

	RowDataTypeInfo typeInfo2 = new RowDataTypeInfo(
			new IntType(),
			new VarCharType(VarCharType.MAX_LENGTH));

	assertEquals(typeInfo1, typeInfo2);
	assertEquals(typeInfo1.hashCode(), typeInfo2.hashCode());
}
 
Example #18
Source File: PythonTableFunctionOperatorTestBase.java    From flink with Apache License 2.0 5 votes vote down vote up
private OneInputStreamOperatorTestHarness<IN, OUT> getTestHarness(
	Configuration config,
	JoinRelType joinRelType) throws Exception {
	RowType inputType = new RowType(Arrays.asList(
		new RowType.RowField("f1", new VarCharType()),
		new RowType.RowField("f2", new VarCharType()),
		new RowType.RowField("f3", new BigIntType())));
	RowType outputType = new RowType(Arrays.asList(
		new RowType.RowField("f1", new VarCharType()),
		new RowType.RowField("f2", new VarCharType()),
		new RowType.RowField("f3", new BigIntType()),
		new RowType.RowField("f4", new BigIntType())));
	AbstractPythonTableFunctionOperator<IN, OUT, UDTFIN> operator = getTestOperator(
		config,
		new PythonFunctionInfo(
			AbstractPythonScalarFunctionRunnerTest.DummyPythonFunction.INSTANCE,
			new Integer[]{0}),
		inputType,
		outputType,
		new int[]{2},
		joinRelType
	);

	OneInputStreamOperatorTestHarness<IN, OUT> testHarness =
		new OneInputStreamOperatorTestHarness<>(operator);
	testHarness.getStreamConfig().setManagedMemoryFraction(0.5);
	return testHarness;
}
 
Example #19
Source File: RowDataTypeInfoTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testBinaryRowTypeInfoInequality() {
	RowDataTypeInfo typeInfo1 = new RowDataTypeInfo(
			new IntType(),
			new VarCharType(VarCharType.MAX_LENGTH));

	RowDataTypeInfo typeInfo2 = new RowDataTypeInfo(
			new IntType(),
			new BooleanType());

	assertNotEquals(typeInfo1, typeInfo2);
	assertNotEquals(typeInfo1.hashCode(), typeInfo2.hashCode());
}
 
Example #20
Source File: RowDataSerializerTest.java    From flink with Apache License 2.0 5 votes vote down vote up
private static Object[] testRowDataSerializer() {
	RowDataTypeInfo typeInfo = new RowDataTypeInfo(new IntType(), new VarCharType(VarCharType.MAX_LENGTH));
	GenericRowData row1 = new GenericRowData(2);
	row1.setField(0, 1);
	row1.setField(1, fromString("a"));

	GenericRowData row2 = new GenericRowData(2);
	row2.setField(0, 2);
	row2.setField(1, null);

	RowDataSerializer serializer = typeInfo.createSerializer(new ExecutionConfig());
	return new Object[] {serializer, new RowData[]{row1, row2}};
}
 
Example #21
Source File: RowDataSerializerTest.java    From flink with Apache License 2.0 5 votes vote down vote up
private static Object[] testLargeRowDataSerializer() {
	RowDataTypeInfo typeInfo = new RowDataTypeInfo(
		new IntType(),
		new IntType(),
		new IntType(),
		new IntType(),
		new IntType(),
		new IntType(),
		new IntType(),
		new IntType(),
		new IntType(),
		new IntType(),
		new IntType(),
		new IntType(),
		new VarCharType(VarCharType.MAX_LENGTH));

	GenericRowData row = new GenericRowData(13);
	row.setField(0, 2);
	row.setField(1, null);
	row.setField(3, null);
	row.setField(4, null);
	row.setField(5, null);
	row.setField(6, null);
	row.setField(7, null);
	row.setField(8, null);
	row.setField(9, null);
	row.setField(10, null);
	row.setField(11, null);
	row.setField(12, fromString("Test"));

	RowDataSerializer serializer = typeInfo.createSerializer(new ExecutionConfig());
	return new Object[] {serializer, new RowData[]{row}};
}
 
Example #22
Source File: RowArrowSourceFunctionTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void init() {
	fieldTypes.add(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);
	dataType = TypeConversions.fromLogicalToDataType(rowType);
	allocator = ArrowUtils.getRootAllocator().newChildAllocator("stdout", 0, Long.MAX_VALUE);
}
 
Example #23
Source File: LogicalTypeCasts.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public Boolean visit(VarCharType targetType) {
	if (sourceType.isNullable() && !targetType.isNullable()) {
		return false;
	}
	// CHAR and VARCHAR are very compatible within bounds
	if ((hasRoot(sourceType, LogicalTypeRoot.CHAR) || hasRoot(sourceType, LogicalTypeRoot.VARCHAR)) &&
			getLength(sourceType) <= targetType.getLength()) {
		return true;
	}
	return defaultMethod(targetType);
}
 
Example #24
Source File: LogicalTypeParser.java    From flink with Apache License 2.0 5 votes vote down vote up
private LogicalType parseVarCharType() {
	final int length = parseStringType();
	if (length < 0) {
		return new VarCharType();
	} else {
		return new VarCharType(length);
	}
}
 
Example #25
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 #26
Source File: PythonTypeUtils.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public FlinkFnApi.Schema.FieldType visit(VarCharType varCharType) {
	return FlinkFnApi.Schema.FieldType.newBuilder()
		.setTypeName(FlinkFnApi.Schema.TypeName.VARCHAR)
		.setVarCharInfo(FlinkFnApi.Schema.VarCharInfo.newBuilder().setLength(varCharType.getLength()))
		.setNullable(varCharType.isNullable())
		.build();
}
 
Example #27
Source File: LogicalTypeDuplicatorTest.java    From flink with Apache License 2.0 5 votes vote down vote up
private static StructuredType createHumanType() {
	return StructuredType.newBuilder(ObjectIdentifier.of("cat", "db", "Human"), Human.class)
		.attributes(
			Collections.singletonList(
				new StructuredType.StructuredAttribute("name", new VarCharType(), "Description.")))
		.description("Human type desc.")
		.setFinal(false)
		.setInstantiable(false)
		.build();
}
 
Example #28
Source File: LogicalTypesTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testVarCharType() {
	testAll(
		new VarCharType(33),
		"VARCHAR(33)",
		"VARCHAR(33)",
		new Class[]{String.class, byte[].class},
		new Class[]{String.class, byte[].class},
		new LogicalType[]{},
		new VarCharType(12)
	);
}
 
Example #29
Source File: LogicalTypesTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testVarCharTypeWithMaximumLength() {
	testAll(
		new VarCharType(Integer.MAX_VALUE),
		"VARCHAR(2147483647)",
		"STRING",
		new Class[]{String.class, byte[].class},
		new Class[]{String.class, byte[].class},
		new LogicalType[]{},
		new VarCharType(12)
	);
}
 
Example #30
Source File: LogicalTypesTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testMapType() {
	testAll(
		new MapType(new VarCharType(20), new TimestampType()),
		"MAP<VARCHAR(20), TIMESTAMP(6)>",
		"MAP<VARCHAR(20), TIMESTAMP(6)>",
		new Class[]{Map.class, HashMap.class, TreeMap.class},
		new Class[]{Map.class},
		new LogicalType[]{new VarCharType(20), new TimestampType()},
		new MapType(new VarCharType(99), new TimestampType())
	);
}