Java Code Examples for org.apache.flink.api.common.typeinfo.Types#POJO

The following examples show how to use org.apache.flink.api.common.typeinfo.Types#POJO . 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: ParquetPojoInputFormatTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testReadPojoFromSimpleRecord() throws IOException {
	Tuple3<Class<? extends SpecificRecord>, SpecificRecord, Row> simple = TestUtil.getSimpleRecordTestData();
	MessageType messageType = SCHEMA_CONVERTER.convert(TestUtil.SIMPLE_SCHEMA);
	Path path = TestUtil.createTempParquetFile(tempRoot.getRoot(), TestUtil.SIMPLE_SCHEMA, Collections.singletonList(simple.f1));

	ParquetPojoInputFormat<PojoSimpleRecord> inputFormat = new ParquetPojoInputFormat<>(
		path, messageType, (PojoTypeInfo<PojoSimpleRecord>) Types.POJO(PojoSimpleRecord.class));
	inputFormat.setRuntimeContext(TestUtil.getMockRuntimeContext());

	FileInputSplit[] splits = inputFormat.createInputSplits(1);
	assertEquals(1, splits.length);
	inputFormat.open(splits[0]);

	PojoSimpleRecord simpleRecord = inputFormat.nextRecord(null);
	assertEquals(simple.f2.getField(0), simpleRecord.getFoo());
	assertEquals(simple.f2.getField(1), simpleRecord.getBar());
	assertArrayEquals((Long[]) simple.f2.getField(2), simpleRecord.getArr());
}
 
Example 2
Source File: ParquetPojoInputFormatTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testProjectedReadPojoFromSimpleRecord() throws IOException, NoSuchFieldError {
	Tuple3<Class<? extends SpecificRecord>, SpecificRecord, Row> simple = TestUtil.getSimpleRecordTestData();
	MessageType messageType = SCHEMA_CONVERTER.convert(TestUtil.SIMPLE_SCHEMA);
	Path path = TestUtil.createTempParquetFile(tempRoot.getRoot(), TestUtil.SIMPLE_SCHEMA, Collections.singletonList(simple.f1));

	ParquetPojoInputFormat<PojoSimpleRecord> inputFormat = new ParquetPojoInputFormat<>(
		path, messageType, (PojoTypeInfo<PojoSimpleRecord>) Types.POJO(PojoSimpleRecord.class));
	inputFormat.setRuntimeContext(TestUtil.getMockRuntimeContext());

	FileInputSplit[] splits = inputFormat.createInputSplits(1);
	assertEquals(1, splits.length);

	inputFormat.selectFields(new String[]{"foo"});
	inputFormat.open(splits[0]);

	PojoSimpleRecord simpleRecord = inputFormat.nextRecord(null);
	assertEquals(simple.f2.getField(0), simpleRecord.getFoo());
	assertEquals("", simpleRecord.getBar());
	assertArrayEquals(new Long[0], simpleRecord.getArr());
}
 
Example 3
Source File: ParquetPojoInputFormatTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testReadPojoFromSimpleRecord() throws IOException {
	Tuple3<Class<? extends SpecificRecord>, SpecificRecord, Row> simple = TestUtil.getSimpleRecordTestData();
	MessageType messageType = SCHEMA_CONVERTER.convert(TestUtil.SIMPLE_SCHEMA);
	Path path = TestUtil.createTempParquetFile(tempRoot.getRoot(), TestUtil.SIMPLE_SCHEMA, Collections.singletonList(simple.f1));

	ParquetPojoInputFormat<PojoSimpleRecord> inputFormat = new ParquetPojoInputFormat<>(
		path, messageType, (PojoTypeInfo<PojoSimpleRecord>) Types.POJO(PojoSimpleRecord.class));
	inputFormat.setRuntimeContext(TestUtil.getMockRuntimeContext());

	FileInputSplit[] splits = inputFormat.createInputSplits(1);
	assertEquals(1, splits.length);
	inputFormat.open(splits[0]);

	PojoSimpleRecord simpleRecord = inputFormat.nextRecord(null);
	assertEquals(simple.f2.getField(0), simpleRecord.getFoo());
	assertEquals(simple.f2.getField(1), simpleRecord.getBar());
	assertArrayEquals((Long[]) simple.f2.getField(2), simpleRecord.getArr());
}
 
Example 4
Source File: ParquetPojoInputFormatTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testProjectedReadPojoFromSimpleRecord() throws IOException, NoSuchFieldError {
	Tuple3<Class<? extends SpecificRecord>, SpecificRecord, Row> simple = TestUtil.getSimpleRecordTestData();
	MessageType messageType = SCHEMA_CONVERTER.convert(TestUtil.SIMPLE_SCHEMA);
	Path path = TestUtil.createTempParquetFile(tempRoot.getRoot(), TestUtil.SIMPLE_SCHEMA, Collections.singletonList(simple.f1));

	ParquetPojoInputFormat<PojoSimpleRecord> inputFormat = new ParquetPojoInputFormat<>(
		path, messageType, (PojoTypeInfo<PojoSimpleRecord>) Types.POJO(PojoSimpleRecord.class));
	inputFormat.setRuntimeContext(TestUtil.getMockRuntimeContext());

	FileInputSplit[] splits = inputFormat.createInputSplits(1);
	assertEquals(1, splits.length);

	inputFormat.selectFields(new String[]{"foo"});
	inputFormat.open(splits[0]);

	PojoSimpleRecord simpleRecord = inputFormat.nextRecord(null);
	assertEquals(simple.f2.getField(0), simpleRecord.getFoo());
	assertEquals("", simpleRecord.getBar());
	assertArrayEquals(new Long[0], simpleRecord.getArr());
}
 
Example 5
Source File: TypeStringUtils.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
private TypeInformation<?> convertPojo() {
	nextToken(TokenType.BEGIN);

	nextToken(TokenType.LITERAL);
	final String className = token().literal;

	nextToken(TokenType.END);

	final Class<?> clazz = EncodingUtils.loadClass(className);
	return Types.POJO(clazz);
}
 
Example 6
Source File: TypeStringUtils.java    From flink with Apache License 2.0 5 votes vote down vote up
private TypeInformation<?> convertPojo() {
	nextToken(TokenType.BEGIN);

	nextToken(TokenType.LITERAL);
	final String className = token().literal;

	nextToken(TokenType.END);

	final Class<?> clazz = EncodingUtils.loadClass(className);
	return Types.POJO(clazz);
}
 
Example 7
Source File: PairComparableTypeInfoFactory.java    From Alink with Apache License 2.0 5 votes vote down vote up
@Override
public TypeInformation<PairComparable> createTypeInfo(Type t, Map<String, TypeInformation<?>> genericParameters) {
	Map<String, TypeInformation<?>> fields = new HashMap<>();
	fields.put("first", Types.INT);
	fields.put("second", NumericType.NUMERIC_TYPE);
	return Types.POJO(PairComparable.class, fields);
}
 
Example 8
Source File: TypeStringUtils.java    From flink with Apache License 2.0 5 votes vote down vote up
private TypeInformation<?> convertPojo() {
	nextToken(TokenType.BEGIN);

	nextToken(TokenType.LITERAL);
	final String className = token().literal;

	nextToken(TokenType.END);

	final Class<?> clazz = EncodingUtils.loadClass(className);
	return Types.POJO(clazz);
}