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

The following examples show how to use org.apache.flink.table.types.logical.IntType. 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: BaseRowTest.java    From flink with Apache License 2.0 6 votes vote down vote up
private BinaryRow getBinaryRow() {
	BinaryRow row = new BinaryRow(16);
	BinaryRowWriter writer = new BinaryRowWriter(row);
	writer.writeBoolean(0, true);
	writer.writeByte(1, (byte) 1);
	writer.writeShort(2, (short) 2);
	writer.writeInt(3, 3);
	writer.writeLong(4, 4);
	writer.writeFloat(5, 5);
	writer.writeDouble(6, 6);
	writer.writeString(8, str);
	writer.writeGeneric(9, generic);
	writer.writeDecimal(10, decimal1, 5);
	writer.writeDecimal(11, decimal2, 20);
	writer.writeArray(12, array, new BaseArraySerializer(DataTypes.INT().getLogicalType(), null));
	writer.writeMap(13, map, new BaseMapSerializer(
		DataTypes.INT().getLogicalType(), DataTypes.INT().getLogicalType(), null));
	writer.writeRow(14, underRow, new BaseRowSerializer(null, RowType.of(new IntType(), new IntType())));
	writer.writeBinary(15, bytes);
	return row;
}
 
Example #2
Source File: DataTypeExtractorTest.java    From flink with Apache License 2.0 6 votes vote down vote up
private static DataType getPojoWithRawSelfReferenceDataType() {
	final StructuredType.Builder builder = StructuredType.newBuilder(PojoWithRawSelfReference.class);
	builder.attributes(
		Arrays.asList(
			new StructuredAttribute(
				"integer",
				new IntType()),
			new StructuredAttribute(
				"reference",
				new TypeInformationRawType<>(new GenericTypeInfo<>(PojoWithRawSelfReference.class)))));
	builder.setFinal(true);
	builder.setInstantiable(true);
	final StructuredType structuredType = builder.build();

	final List<DataType> fieldDataTypes = Arrays.asList(
		DataTypes.INT(),
		DataTypes.RAW(new GenericTypeInfo<>(PojoWithRawSelfReference.class))
	);

	return new FieldsDataType(structuredType, PojoWithRawSelfReference.class, fieldDataTypes);
}
 
Example #3
Source File: RowDataTest.java    From flink with Apache License 2.0 6 votes vote down vote up
private BinaryRowData getBinaryRow() {
	BinaryRowData row = new BinaryRowData(18);
	BinaryRowWriter writer = new BinaryRowWriter(row);
	writer.writeBoolean(0, true);
	writer.writeByte(1, (byte) 1);
	writer.writeShort(2, (short) 2);
	writer.writeInt(3, 3);
	writer.writeLong(4, 4);
	writer.writeFloat(5, 5);
	writer.writeDouble(6, 6);
	writer.writeString(8, str);
	writer.writeRawValue(9, generic, genericSerializer);
	writer.writeDecimal(10, decimal1, 5);
	writer.writeDecimal(11, decimal2, 20);
	writer.writeArray(12, array, new ArrayDataSerializer(DataTypes.INT().getLogicalType(), null));
	writer.writeMap(13, map, new MapDataSerializer(
		DataTypes.INT().getLogicalType(), DataTypes.INT().getLogicalType(), null));
	writer.writeRow(14, underRow, new RowDataSerializer(null, RowType.of(new IntType(), new IntType())));
	writer.writeBinary(15, bytes);
	writer.writeTimestamp(16, timestamp1, 3);
	writer.writeTimestamp(17, timestamp2, 9);
	return row;
}
 
Example #4
Source File: LongHashJoinGeneratorTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public Object newOperator(long memorySize, HashJoinType type, boolean reverseJoinFunction) {
	RowType keyType = RowType.of(new IntType());
	Assert.assertTrue(LongHashJoinGenerator.support(type, keyType, new boolean[] {true}));
	return LongHashJoinGenerator.gen(
			new TableConfig(), type,
			keyType,
			RowType.of(new IntType(), new IntType()),
			RowType.of(new IntType(), new IntType()),
			new int[]{0},
			new int[]{0},
			20, 10000,
			reverseJoinFunction,
			new GeneratedJoinCondition(MyJoinCondition.class.getCanonicalName(), "", new Object[0])
	);
}
 
Example #5
Source File: LongHashJoinGeneratorTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public Object newOperator(long memorySize, HashJoinType type, boolean reverseJoinFunction) {
	RowType keyType = RowType.of(new IntType());
	Assert.assertTrue(LongHashJoinGenerator.support(type, keyType, new boolean[] {true}));
	return LongHashJoinGenerator.gen(
			new TableConfig(), type,
			keyType,
			RowType.of(new IntType(), new IntType()),
			RowType.of(new IntType(), new IntType()),
			new int[]{0},
			new int[]{0},
			memorySize, memorySize, 0, 20, 10000,
			reverseJoinFunction,
			new GeneratedJoinCondition(MyJoinCondition.class.getCanonicalName(), "", new Object[0])
	);
}
 
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
/**
 * Testing data type shared with the Scala tests.
 */
public static DataType getPojoWithCustomOrderDataType(Class<?> pojoClass) {
	final StructuredType.Builder builder = StructuredType.newBuilder(pojoClass);
	builder.attributes(
		Arrays.asList(
			new StructuredAttribute(
				"z",
				new BigIntType()),
			new StructuredAttribute(
				"y",
				new BooleanType()),
			new StructuredAttribute(
				"x",
				new IntType())));
	builder.setFinal(true);
	builder.setInstantiable(true);
	final StructuredType structuredType = builder.build();

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

	return new FieldsDataType(structuredType, pojoClass, 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: JdbcRowDataInputFormatTest.java    From flink with Apache License 2.0 6 votes vote down vote up
private void verifySplit(InputSplit split, int expectedIDSum) throws IOException {
	int sum = 0;

	RowData row = new GenericRowData(5);
	inputFormat.open(split);
	while (!inputFormat.reachedEnd()) {
		row = inputFormat.nextRecord(row);

		int id = ((int) RowData.get(row, 0, new IntType()));
		int testDataIndex = id - 1001;

		assertEquals(TEST_DATA[testDataIndex], row);
		sum += id;
	}

	Assert.assertEquals(expectedIDSum, sum);
}
 
Example #11
Source File: DataTypeExtractorTest.java    From flink with Apache License 2.0 6 votes vote down vote up
private static DataType getOuterTupleDataType() {
	final StructuredType.Builder builder = StructuredType.newBuilder(Tuple2.class);
	builder.attributes(
		Arrays.asList(
			new StructuredAttribute(
				"f0",
				new IntType()),
			new StructuredAttribute(
				"f1",
				getInnerTupleDataType().getLogicalType())));
	builder.setFinal(true);
	builder.setInstantiable(true);
	final StructuredType structuredType = builder.build();

	final List<DataType> fieldDataTypes = Arrays.asList(
		DataTypes.INT(),
		getInnerTupleDataType()
	);

	return new FieldsDataType(structuredType, Tuple2.class, fieldDataTypes);
}
 
Example #12
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 #13
Source File: BinaryArrayTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testNested() {
	BinaryArray array = new BinaryArray();
	BinaryArrayWriter writer = new BinaryArrayWriter(array, 2, 8);
	writer.writeRow(0, GenericRow.of(fromString("1"), 1),
			new BaseRowSerializer(null, RowType.of(new VarCharType(VarCharType.MAX_LENGTH), new IntType())));
	writer.setNullAt(1);
	writer.complete();

	BaseRow nestedRow = array.getRow(0, 2);
	assertEquals("1", nestedRow.getString(0).toString());
	assertEquals(1, nestedRow.getInt(1));
	assertTrue(array.isNullAt(1));
}
 
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: BinaryRowTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testNested() {
	BinaryRow row = new BinaryRow(2);
	BinaryRowWriter writer = new BinaryRowWriter(row);
	writer.writeRow(0, GenericRow.of(fromString("1"), 1),
			new BaseRowSerializer(null, RowType.of(new VarCharType(VarCharType.MAX_LENGTH), new IntType())));
	writer.setNullAt(1);
	writer.complete();

	BaseRow nestedRow = row.getRow(0, 2);
	assertEquals("1", nestedRow.getString(0).toString());
	assertEquals(1, nestedRow.getInt(1));
	assertTrue(row.isNullAt(1));
}
 
Example #16
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 #17
Source File: BinaryRowTypeInfoTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testBinaryRowTypeInfoInequality() {
	BaseRowTypeInfo typeInfo1 = new BaseRowTypeInfo(
			new IntType(),
			new VarCharType(VarCharType.MAX_LENGTH));

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

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

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

	BaseRowSerializer serializer = typeInfo.createSerializer(new ExecutionConfig());
	return new Object[] {serializer, new BaseRow[]{row1, row2}};
}
 
Example #19
Source File: BaseRowSerializerTest.java    From flink with Apache License 2.0 5 votes vote down vote up
private static Object[] testLargeBaseRowSerializer() {
	BaseRowTypeInfo typeInfo = new BaseRowTypeInfo(
		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));

	GenericRow row = new GenericRow(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"));

	BaseRowSerializer serializer = typeInfo.createSerializer(new ExecutionConfig());
	return new Object[] {serializer, new BaseRow[]{row}};
}
 
Example #20
Source File: BaseRowSerializerTest.java    From flink with Apache License 2.0 5 votes vote down vote up
private static Object[] testBaseRowSerializerWithComplexTypes() {
	BaseRowTypeInfo typeInfo = new BaseRowTypeInfo(
		new IntType(),
		new DoubleType(),
		new VarCharType(VarCharType.MAX_LENGTH),
		new ArrayType(new IntType()),
		new MapType(new IntType(), new IntType()));

	GenericRow[] data = new GenericRow[]{
		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}))
	};

	BaseRowSerializer serializer = typeInfo.createSerializer(new ExecutionConfig());
	return new Object[] {serializer, data};
}
 
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: LogicalTypeDuplicatorTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Parameters(name = "{index}: {0}")
public static List<Object[]> testData() {
	return Arrays.asList(
		new Object[][]{
			{new CharType(2), new CharType(2)},
			{createMultisetType(new IntType()), createMultisetType(new BigIntType())},
			{createArrayType(new IntType()), createArrayType(new BigIntType())},
			{createMapType(new IntType()), createMapType(new BigIntType())},
			{createRowType(new IntType()), createRowType(new BigIntType())},
			{createDistinctType(new IntType()), createDistinctType(new BigIntType())},
			{createUserType(new IntType()), createUserType(new BigIntType())},
			{createHumanType(), createHumanType()}
		}
	);
}
 
Example #23
Source File: LogicalTypesTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testIntType() {
	testAll(
		new IntType(),
		"INT",
		"INT",
		new Class[]{Integer.class, int.class},
		new Class[]{Integer.class},
		new LogicalType[]{},
		new IntType(false)
	);
}
 
Example #24
Source File: LogicalTypeDuplicatorTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Parameters(name = "{index}: {0}")
public static List<Object[]> testData() {
	return Arrays.asList(
		new Object[][]{
			{new CharType(2), new CharType(2)},
			{createMultisetType(new IntType()), createMultisetType(new BigIntType())},
			{createArrayType(new IntType()), createArrayType(new BigIntType())},
			{createMapType(new IntType()), createMapType(new BigIntType())},
			{createRowType(new IntType()), createRowType(new BigIntType())},
			{createDistinctType(new IntType()), createDistinctType(new BigIntType())},
			{createUserType(new IntType()), createUserType(new BigIntType())},
			{createHumanType(), createHumanType()}
		}
	);
}
 
Example #25
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 #26
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 #27
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 #28
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 #29
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 #30
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}};
}