Java Code Examples for org.apache.flink.formats.avro.generated.User#getTypeMap()

The following examples show how to use org.apache.flink.formats.avro.generated.User#getTypeMap() . 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: AvroRecordInputFormatTest.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
/**
 * Test if the AvroInputFormat is able to properly read data from an Avro file.
 */
@Test
public void testDeserialization() throws IOException {
	Configuration parameters = new Configuration();

	AvroInputFormat<User> format = new AvroInputFormat<>(new Path(testFile.getAbsolutePath()), User.class);

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

	User u = format.nextRecord(null);
	assertNotNull(u);

	String name = u.getName().toString();
	assertNotNull("empty record", name);
	assertEquals("name not equal", TEST_NAME, name);

	// check arrays
	List<CharSequence> sl = u.getTypeArrayString();
	assertEquals("element 0 not equal", TEST_ARRAY_STRING_1, sl.get(0).toString());
	assertEquals("element 1 not equal", TEST_ARRAY_STRING_2, sl.get(1).toString());

	List<Boolean> bl = u.getTypeArrayBoolean();
	assertEquals("element 0 not equal", TEST_ARRAY_BOOLEAN_1, bl.get(0));
	assertEquals("element 1 not equal", TEST_ARRAY_BOOLEAN_2, bl.get(1));

	// check enums
	Colors enumValue = u.getTypeEnum();
	assertEquals("enum not equal", TEST_ENUM_COLOR, enumValue);

	// check maps
	Map<CharSequence, Long> lm = u.getTypeMap();
	assertEquals("map value of key 1 not equal", TEST_MAP_VALUE1, lm.get(new Utf8(TEST_MAP_KEY1)).longValue());
	assertEquals("map value of key 2 not equal", TEST_MAP_VALUE2, lm.get(new Utf8(TEST_MAP_KEY2)).longValue());

	assertFalse("expecting second element", format.reachedEnd());
	assertNotNull("expecting second element", format.nextRecord(u));

	assertNull(format.nextRecord(u));
	assertTrue(format.reachedEnd());

	format.close();
}
 
Example 2
Source File: AvroRecordInputFormatTest.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
/**
 * Test if the AvroInputFormat is able to properly read data from an Avro file.
 */
@Test
public void testDeserializationReuseAvroRecordFalse() throws IOException {
	Configuration parameters = new Configuration();

	AvroInputFormat<User> format = new AvroInputFormat<>(new Path(testFile.getAbsolutePath()), User.class);
	format.setReuseAvroValue(false);

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

	User u = format.nextRecord(null);
	assertNotNull(u);

	String name = u.getName().toString();
	assertNotNull("empty record", name);
	assertEquals("name not equal", TEST_NAME, name);

	// check arrays
	List<CharSequence> sl = u.getTypeArrayString();
	assertEquals("element 0 not equal", TEST_ARRAY_STRING_1, sl.get(0).toString());
	assertEquals("element 1 not equal", TEST_ARRAY_STRING_2, sl.get(1).toString());

	List<Boolean> bl = u.getTypeArrayBoolean();
	assertEquals("element 0 not equal", TEST_ARRAY_BOOLEAN_1, bl.get(0));
	assertEquals("element 1 not equal", TEST_ARRAY_BOOLEAN_2, bl.get(1));

	// check enums
	Colors enumValue = u.getTypeEnum();
	assertEquals("enum not equal", TEST_ENUM_COLOR, enumValue);

	// check maps
	Map<CharSequence, Long> lm = u.getTypeMap();
	assertEquals("map value of key 1 not equal", TEST_MAP_VALUE1, lm.get(new Utf8(TEST_MAP_KEY1)).longValue());
	assertEquals("map value of key 2 not equal", TEST_MAP_VALUE2, lm.get(new Utf8(TEST_MAP_KEY2)).longValue());

	assertFalse("expecting second element", format.reachedEnd());
	assertNotNull("expecting second element", format.nextRecord(u));

	assertNull(format.nextRecord(u));
	assertTrue(format.reachedEnd());

	format.close();
}
 
Example 3
Source File: AvroRecordInputFormatTest.java    From flink with Apache License 2.0 4 votes vote down vote up
/**
 * Test if the AvroInputFormat is able to properly read data from an Avro file.
 */
@Test
public void testDeserialization() throws IOException {
	Configuration parameters = new Configuration();

	AvroInputFormat<User> format = new AvroInputFormat<>(new Path(testFile.getAbsolutePath()), User.class);

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

	User u = format.nextRecord(null);
	assertNotNull(u);

	String name = u.getName().toString();
	assertNotNull("empty record", name);
	assertEquals("name not equal", TEST_NAME, name);

	// check arrays
	List<CharSequence> sl = u.getTypeArrayString();
	assertEquals("element 0 not equal", TEST_ARRAY_STRING_1, sl.get(0).toString());
	assertEquals("element 1 not equal", TEST_ARRAY_STRING_2, sl.get(1).toString());

	List<Boolean> bl = u.getTypeArrayBoolean();
	assertEquals("element 0 not equal", TEST_ARRAY_BOOLEAN_1, bl.get(0));
	assertEquals("element 1 not equal", TEST_ARRAY_BOOLEAN_2, bl.get(1));

	// check enums
	Colors enumValue = u.getTypeEnum();
	assertEquals("enum not equal", TEST_ENUM_COLOR, enumValue);

	// check maps
	Map<CharSequence, Long> lm = u.getTypeMap();
	assertEquals("map value of key 1 not equal", TEST_MAP_VALUE1, lm.get(new Utf8(TEST_MAP_KEY1)).longValue());
	assertEquals("map value of key 2 not equal", TEST_MAP_VALUE2, lm.get(new Utf8(TEST_MAP_KEY2)).longValue());

	assertFalse("expecting second element", format.reachedEnd());
	assertNotNull("expecting second element", format.nextRecord(u));

	assertNull(format.nextRecord(u));
	assertTrue(format.reachedEnd());

	format.close();
}
 
Example 4
Source File: AvroRecordInputFormatTest.java    From flink with Apache License 2.0 4 votes vote down vote up
/**
 * Test if the AvroInputFormat is able to properly read data from an Avro file.
 */
@Test
public void testDeserializationReuseAvroRecordFalse() throws IOException {
	Configuration parameters = new Configuration();

	AvroInputFormat<User> format = new AvroInputFormat<>(new Path(testFile.getAbsolutePath()), User.class);
	format.setReuseAvroValue(false);

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

	User u = format.nextRecord(null);
	assertNotNull(u);

	String name = u.getName().toString();
	assertNotNull("empty record", name);
	assertEquals("name not equal", TEST_NAME, name);

	// check arrays
	List<CharSequence> sl = u.getTypeArrayString();
	assertEquals("element 0 not equal", TEST_ARRAY_STRING_1, sl.get(0).toString());
	assertEquals("element 1 not equal", TEST_ARRAY_STRING_2, sl.get(1).toString());

	List<Boolean> bl = u.getTypeArrayBoolean();
	assertEquals("element 0 not equal", TEST_ARRAY_BOOLEAN_1, bl.get(0));
	assertEquals("element 1 not equal", TEST_ARRAY_BOOLEAN_2, bl.get(1));

	// check enums
	Colors enumValue = u.getTypeEnum();
	assertEquals("enum not equal", TEST_ENUM_COLOR, enumValue);

	// check maps
	Map<CharSequence, Long> lm = u.getTypeMap();
	assertEquals("map value of key 1 not equal", TEST_MAP_VALUE1, lm.get(new Utf8(TEST_MAP_KEY1)).longValue());
	assertEquals("map value of key 2 not equal", TEST_MAP_VALUE2, lm.get(new Utf8(TEST_MAP_KEY2)).longValue());

	assertFalse("expecting second element", format.reachedEnd());
	assertNotNull("expecting second element", format.nextRecord(u));

	assertNull(format.nextRecord(u));
	assertTrue(format.reachedEnd());

	format.close();
}
 
Example 5
Source File: AvroRecordInputFormatTest.java    From flink with Apache License 2.0 4 votes vote down vote up
/**
 * Test if the AvroInputFormat is able to properly read data from an Avro file.
 */
@Test
public void testDeserialization() throws IOException {
	Configuration parameters = new Configuration();

	AvroInputFormat<User> format = new AvroInputFormat<>(new Path(testFile.getAbsolutePath()), User.class);

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

	User u = format.nextRecord(null);
	assertNotNull(u);

	String name = u.getName().toString();
	assertNotNull("empty record", name);
	assertEquals("name not equal", TEST_NAME, name);

	// check arrays
	List<CharSequence> sl = u.getTypeArrayString();
	assertEquals("element 0 not equal", TEST_ARRAY_STRING_1, sl.get(0).toString());
	assertEquals("element 1 not equal", TEST_ARRAY_STRING_2, sl.get(1).toString());

	List<Boolean> bl = u.getTypeArrayBoolean();
	assertEquals("element 0 not equal", TEST_ARRAY_BOOLEAN_1, bl.get(0));
	assertEquals("element 1 not equal", TEST_ARRAY_BOOLEAN_2, bl.get(1));

	// check enums
	Colors enumValue = u.getTypeEnum();
	assertEquals("enum not equal", TEST_ENUM_COLOR, enumValue);

	// check maps
	Map<CharSequence, Long> lm = u.getTypeMap();
	assertEquals("map value of key 1 not equal", TEST_MAP_VALUE1, lm.get(new Utf8(TEST_MAP_KEY1)).longValue());
	assertEquals("map value of key 2 not equal", TEST_MAP_VALUE2, lm.get(new Utf8(TEST_MAP_KEY2)).longValue());

	assertFalse("expecting second element", format.reachedEnd());
	assertNotNull("expecting second element", format.nextRecord(u));

	assertNull(format.nextRecord(u));
	assertTrue(format.reachedEnd());

	format.close();
}
 
Example 6
Source File: AvroRecordInputFormatTest.java    From flink with Apache License 2.0 4 votes vote down vote up
/**
 * Test if the AvroInputFormat is able to properly read data from an Avro file.
 */
@Test
public void testDeserializationReuseAvroRecordFalse() throws IOException {
	Configuration parameters = new Configuration();

	AvroInputFormat<User> format = new AvroInputFormat<>(new Path(testFile.getAbsolutePath()), User.class);
	format.setReuseAvroValue(false);

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

	User u = format.nextRecord(null);
	assertNotNull(u);

	String name = u.getName().toString();
	assertNotNull("empty record", name);
	assertEquals("name not equal", TEST_NAME, name);

	// check arrays
	List<CharSequence> sl = u.getTypeArrayString();
	assertEquals("element 0 not equal", TEST_ARRAY_STRING_1, sl.get(0).toString());
	assertEquals("element 1 not equal", TEST_ARRAY_STRING_2, sl.get(1).toString());

	List<Boolean> bl = u.getTypeArrayBoolean();
	assertEquals("element 0 not equal", TEST_ARRAY_BOOLEAN_1, bl.get(0));
	assertEquals("element 1 not equal", TEST_ARRAY_BOOLEAN_2, bl.get(1));

	// check enums
	Colors enumValue = u.getTypeEnum();
	assertEquals("enum not equal", TEST_ENUM_COLOR, enumValue);

	// check maps
	Map<CharSequence, Long> lm = u.getTypeMap();
	assertEquals("map value of key 1 not equal", TEST_MAP_VALUE1, lm.get(new Utf8(TEST_MAP_KEY1)).longValue());
	assertEquals("map value of key 2 not equal", TEST_MAP_VALUE2, lm.get(new Utf8(TEST_MAP_KEY2)).longValue());

	assertFalse("expecting second element", format.reachedEnd());
	assertNotNull("expecting second element", format.nextRecord(u));

	assertNull(format.nextRecord(u));
	assertTrue(format.reachedEnd());

	format.close();
}