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

The following examples show how to use org.apache.flink.formats.avro.generated.User#setName() . 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: AvroOutputFormatITCase.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Override
public User map(Tuple3<String, Integer, String> value) {
	User user = new User();
	user.setName(value.f0);
	user.setFavoriteNumber(value.f1);
	user.setFavoriteColor(value.f2);
	user.setTypeBoolTest(true);
	user.setTypeArrayString(Collections.emptyList());
	user.setTypeArrayBoolean(Collections.emptyList());
	user.setTypeEnum(Colors.BLUE);
	user.setTypeMap(Collections.emptyMap());
	user.setTypeBytes(ByteBuffer.allocate(10));
	user.setTypeDate(LocalDate.parse("2014-03-01"));
	user.setTypeTimeMillis(LocalTime.parse("12:12:12"));
	user.setTypeTimeMicros(123456);
	user.setTypeTimestampMillis(DateTime.parse("2014-03-01T12:12:12.321Z"));
	user.setTypeTimestampMicros(123456L);
	// 20.00
	user.setTypeDecimalBytes(ByteBuffer.wrap(BigDecimal.valueOf(2000, 2).unscaledValue().toByteArray()));
	// 20.00
	user.setTypeDecimalFixed(new Fixed2(BigDecimal.valueOf(2000, 2).unscaledValue().toByteArray()));
	return user;
}
 
Example 2
Source File: AvroOutputFormatITCase.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public User map(Tuple3<String, Integer, String> value) {
	User user = new User();
	user.setName(value.f0);
	user.setFavoriteNumber(value.f1);
	user.setFavoriteColor(value.f2);
	user.setTypeBoolTest(true);
	user.setTypeArrayString(Collections.emptyList());
	user.setTypeArrayBoolean(Collections.emptyList());
	user.setTypeEnum(Colors.BLUE);
	user.setTypeMap(Collections.emptyMap());
	user.setTypeBytes(ByteBuffer.allocate(10));
	user.setTypeDate(LocalDate.parse("2014-03-01"));
	user.setTypeTimeMillis(LocalTime.parse("12:12:12"));
	user.setTypeTimeMicros(123456);
	user.setTypeTimestampMillis(DateTime.parse("2014-03-01T12:12:12.321Z"));
	user.setTypeTimestampMicros(123456L);
	// 20.00
	user.setTypeDecimalBytes(ByteBuffer.wrap(BigDecimal.valueOf(2000, 2).unscaledValue().toByteArray()));
	// 20.00
	user.setTypeDecimalFixed(new Fixed2(BigDecimal.valueOf(2000, 2).unscaledValue().toByteArray()));
	return user;
}
 
Example 3
Source File: AvroOutputFormatITCase.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public User map(Tuple3<String, Integer, String> value) {
	User user = new User();
	user.setName(value.f0);
	user.setFavoriteNumber(value.f1);
	user.setFavoriteColor(value.f2);
	user.setTypeBoolTest(true);
	user.setTypeArrayString(Collections.emptyList());
	user.setTypeArrayBoolean(Collections.emptyList());
	user.setTypeEnum(Colors.BLUE);
	user.setTypeMap(Collections.emptyMap());
	user.setTypeBytes(ByteBuffer.allocate(10));
	user.setTypeDate(LocalDate.parse("2014-03-01"));
	user.setTypeTimeMillis(LocalTime.parse("12:12:12"));
	user.setTypeTimeMicros(123456);
	user.setTypeTimestampMillis(DateTime.parse("2014-03-01T12:12:12.321Z"));
	user.setTypeTimestampMicros(123456L);
	// 20.00
	user.setTypeDecimalBytes(ByteBuffer.wrap(BigDecimal.valueOf(2000, 2).unscaledValue().toByteArray()));
	// 20.00
	user.setTypeDecimalFixed(new Fixed2(BigDecimal.valueOf(2000, 2).unscaledValue().toByteArray()));
	return user;
}
 
Example 4
Source File: AvroOutputFormatTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
private void output(final AvroOutputFormat<User> outputFormat) throws IOException {
	outputFormat.configure(new Configuration());
	outputFormat.open(1, 1);
	for (int i = 0; i < 100; i++) {
		User user = new User();
		user.setName("testUser");
		user.setFavoriteNumber(1);
		user.setFavoriteColor("blue");
		user.setTypeBoolTest(true);
		user.setTypeArrayString(Collections.emptyList());
		user.setTypeArrayBoolean(Collections.emptyList());
		user.setTypeEnum(Colors.BLUE);
		user.setTypeMap(Collections.emptyMap());
		user.setTypeBytes(ByteBuffer.allocate(10));
		user.setTypeDate(LocalDate.parse("2014-03-01"));
		user.setTypeTimeMillis(LocalTime.parse("12:12:12"));
		user.setTypeTimeMicros(123456);
		user.setTypeTimestampMillis(DateTime.parse("2014-03-01T12:12:12.321Z"));
		user.setTypeTimestampMicros(123456L);
		// 20.00
		user.setTypeDecimalBytes(ByteBuffer.wrap(BigDecimal.valueOf(2000, 2).unscaledValue().toByteArray()));
		// 20.00
		user.setTypeDecimalFixed(new Fixed2(BigDecimal.valueOf(2000, 2).unscaledValue().toByteArray()));

		outputFormat.writeRecord(user);
	}
	outputFormat.close();
}
 
Example 5
Source File: AvroOutputFormatTest.java    From flink with Apache License 2.0 5 votes vote down vote up
private void output(final AvroOutputFormat<User> outputFormat) throws IOException {
	outputFormat.configure(new Configuration());
	outputFormat.open(1, 1);
	for (int i = 0; i < 100; i++) {
		User user = new User();
		user.setName("testUser");
		user.setFavoriteNumber(1);
		user.setFavoriteColor("blue");
		user.setTypeBoolTest(true);
		user.setTypeArrayString(Collections.emptyList());
		user.setTypeArrayBoolean(Collections.emptyList());
		user.setTypeEnum(Colors.BLUE);
		user.setTypeMap(Collections.emptyMap());
		user.setTypeBytes(ByteBuffer.allocate(10));
		user.setTypeDate(LocalDate.parse("2014-03-01"));
		user.setTypeTimeMillis(LocalTime.parse("12:12:12"));
		user.setTypeTimeMicros(123456);
		user.setTypeTimestampMillis(DateTime.parse("2014-03-01T12:12:12.321Z"));
		user.setTypeTimestampMicros(123456L);
		// 20.00
		user.setTypeDecimalBytes(ByteBuffer.wrap(BigDecimal.valueOf(2000, 2).unscaledValue().toByteArray()));
		// 20.00
		user.setTypeDecimalFixed(new Fixed2(BigDecimal.valueOf(2000, 2).unscaledValue().toByteArray()));

		outputFormat.writeRecord(user);
	}
	outputFormat.close();
}
 
Example 6
Source File: AvroOutputFormatTest.java    From flink with Apache License 2.0 5 votes vote down vote up
private void output(final AvroOutputFormat<User> outputFormat) throws IOException {
	outputFormat.configure(new Configuration());
	outputFormat.open(1, 1);
	for (int i = 0; i < 100; i++) {
		User user = new User();
		user.setName("testUser");
		user.setFavoriteNumber(1);
		user.setFavoriteColor("blue");
		user.setTypeBoolTest(true);
		user.setTypeArrayString(Collections.emptyList());
		user.setTypeArrayBoolean(Collections.emptyList());
		user.setTypeEnum(Colors.BLUE);
		user.setTypeMap(Collections.emptyMap());
		user.setTypeBytes(ByteBuffer.allocate(10));
		user.setTypeDate(LocalDate.parse("2014-03-01"));
		user.setTypeTimeMillis(LocalTime.parse("12:12:12"));
		user.setTypeTimeMicros(123456);
		user.setTypeTimestampMillis(DateTime.parse("2014-03-01T12:12:12.321Z"));
		user.setTypeTimestampMicros(123456L);
		// 20.00
		user.setTypeDecimalBytes(ByteBuffer.wrap(BigDecimal.valueOf(2000, 2).unscaledValue().toByteArray()));
		// 20.00
		user.setTypeDecimalFixed(new Fixed2(BigDecimal.valueOf(2000, 2).unscaledValue().toByteArray()));

		outputFormat.writeRecord(user);
	}
	outputFormat.close();
}
 
Example 7
Source File: AvroRecordInputFormatTest.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
public static void writeTestFile(File testFile) throws IOException {
	ArrayList<CharSequence> stringArray = new ArrayList<>();
	stringArray.add(TEST_ARRAY_STRING_1);
	stringArray.add(TEST_ARRAY_STRING_2);

	ArrayList<Boolean> booleanArray = new ArrayList<>();
	booleanArray.add(TEST_ARRAY_BOOLEAN_1);
	booleanArray.add(TEST_ARRAY_BOOLEAN_2);

	HashMap<CharSequence, Long> longMap = new HashMap<>();
	longMap.put(TEST_MAP_KEY1, TEST_MAP_VALUE1);
	longMap.put(TEST_MAP_KEY2, TEST_MAP_VALUE2);

	Address addr = new Address();
	addr.setNum(TEST_NUM);
	addr.setStreet(TEST_STREET);
	addr.setCity(TEST_CITY);
	addr.setState(TEST_STATE);
	addr.setZip(TEST_ZIP);

	User user1 = new User();

	user1.setName(TEST_NAME);
	user1.setFavoriteNumber(256);
	user1.setTypeDoubleTest(123.45d);
	user1.setTypeBoolTest(true);
	user1.setTypeArrayString(stringArray);
	user1.setTypeArrayBoolean(booleanArray);
	user1.setTypeEnum(TEST_ENUM_COLOR);
	user1.setTypeMap(longMap);
	user1.setTypeNested(addr);
	user1.setTypeBytes(ByteBuffer.allocate(10));
	user1.setTypeDate(LocalDate.parse("2014-03-01"));
	user1.setTypeTimeMillis(LocalTime.parse("12:12:12"));
	user1.setTypeTimeMicros(123456);
	user1.setTypeTimestampMillis(DateTime.parse("2014-03-01T12:12:12.321Z"));
	user1.setTypeTimestampMicros(123456L);
	// 20.00
	user1.setTypeDecimalBytes(ByteBuffer.wrap(BigDecimal.valueOf(2000, 2).unscaledValue().toByteArray()));
	// 20.00
	user1.setTypeDecimalFixed(new Fixed2(BigDecimal.valueOf(2000, 2).unscaledValue().toByteArray()));

	// Construct via builder
	User user2 = User.newBuilder()
			.setName("Charlie")
			.setFavoriteColor("blue")
			.setFavoriteNumber(null)
			.setTypeBoolTest(false)
			.setTypeDoubleTest(1.337d)
			.setTypeNullTest(null)
			.setTypeLongTest(1337L)
			.setTypeArrayString(new ArrayList<>())
			.setTypeArrayBoolean(new ArrayList<>())
			.setTypeNullableArray(null)
			.setTypeEnum(Colors.RED)
			.setTypeMap(new HashMap<>())
			.setTypeFixed(null)
			.setTypeUnion(null)
			.setTypeNested(
					Address.newBuilder().setNum(TEST_NUM).setStreet(TEST_STREET)
							.setCity(TEST_CITY).setState(TEST_STATE).setZip(TEST_ZIP)
							.build())
			.setTypeBytes(ByteBuffer.allocate(10))
			.setTypeDate(LocalDate.parse("2014-03-01"))
			.setTypeTimeMillis(LocalTime.parse("12:12:12"))
			.setTypeTimeMicros(123456)
			.setTypeTimestampMillis(DateTime.parse("2014-03-01T12:12:12.321Z"))
			.setTypeTimestampMicros(123456L)
			// 20.00
			.setTypeDecimalBytes(ByteBuffer.wrap(BigDecimal.valueOf(2000, 2).unscaledValue().toByteArray()))
			// 20.00
			.setTypeDecimalFixed(new Fixed2(BigDecimal.valueOf(2000, 2).unscaledValue().toByteArray()))
			.build();
	DatumWriter<User> userDatumWriter = new SpecificDatumWriter<>(User.class);
	DataFileWriter<User> dataFileWriter = new DataFileWriter<>(userDatumWriter);
	dataFileWriter.create(user1.getSchema(), testFile);
	dataFileWriter.append(user1);
	dataFileWriter.append(user2);
	dataFileWriter.close();
}
 
Example 8
Source File: AvroRecordInputFormatTest.java    From flink with Apache License 2.0 4 votes vote down vote up
public static void writeTestFile(File testFile) throws IOException {
	ArrayList<CharSequence> stringArray = new ArrayList<>();
	stringArray.add(TEST_ARRAY_STRING_1);
	stringArray.add(TEST_ARRAY_STRING_2);

	ArrayList<Boolean> booleanArray = new ArrayList<>();
	booleanArray.add(TEST_ARRAY_BOOLEAN_1);
	booleanArray.add(TEST_ARRAY_BOOLEAN_2);

	HashMap<CharSequence, Long> longMap = new HashMap<>();
	longMap.put(TEST_MAP_KEY1, TEST_MAP_VALUE1);
	longMap.put(TEST_MAP_KEY2, TEST_MAP_VALUE2);

	Address addr = new Address();
	addr.setNum(TEST_NUM);
	addr.setStreet(TEST_STREET);
	addr.setCity(TEST_CITY);
	addr.setState(TEST_STATE);
	addr.setZip(TEST_ZIP);

	User user1 = new User();

	user1.setName(TEST_NAME);
	user1.setFavoriteNumber(256);
	user1.setTypeDoubleTest(123.45d);
	user1.setTypeBoolTest(true);
	user1.setTypeArrayString(stringArray);
	user1.setTypeArrayBoolean(booleanArray);
	user1.setTypeEnum(TEST_ENUM_COLOR);
	user1.setTypeMap(longMap);
	user1.setTypeNested(addr);
	user1.setTypeBytes(ByteBuffer.allocate(10));
	user1.setTypeDate(LocalDate.parse("2014-03-01"));
	user1.setTypeTimeMillis(LocalTime.parse("12:12:12"));
	user1.setTypeTimeMicros(123456);
	user1.setTypeTimestampMillis(DateTime.parse("2014-03-01T12:12:12.321Z"));
	user1.setTypeTimestampMicros(123456L);
	// 20.00
	user1.setTypeDecimalBytes(ByteBuffer.wrap(BigDecimal.valueOf(2000, 2).unscaledValue().toByteArray()));
	// 20.00
	user1.setTypeDecimalFixed(new Fixed2(BigDecimal.valueOf(2000, 2).unscaledValue().toByteArray()));

	// Construct via builder
	User user2 = User.newBuilder()
			.setName("Charlie")
			.setFavoriteColor("blue")
			.setFavoriteNumber(null)
			.setTypeBoolTest(false)
			.setTypeDoubleTest(1.337d)
			.setTypeNullTest(null)
			.setTypeLongTest(1337L)
			.setTypeArrayString(new ArrayList<>())
			.setTypeArrayBoolean(new ArrayList<>())
			.setTypeNullableArray(null)
			.setTypeEnum(Colors.RED)
			.setTypeMap(new HashMap<>())
			.setTypeFixed(null)
			.setTypeUnion(null)
			.setTypeNested(
					Address.newBuilder().setNum(TEST_NUM).setStreet(TEST_STREET)
							.setCity(TEST_CITY).setState(TEST_STATE).setZip(TEST_ZIP)
							.build())
			.setTypeBytes(ByteBuffer.allocate(10))
			.setTypeDate(LocalDate.parse("2014-03-01"))
			.setTypeTimeMillis(LocalTime.parse("12:12:12"))
			.setTypeTimeMicros(123456)
			.setTypeTimestampMillis(DateTime.parse("2014-03-01T12:12:12.321Z"))
			.setTypeTimestampMicros(123456L)
			// 20.00
			.setTypeDecimalBytes(ByteBuffer.wrap(BigDecimal.valueOf(2000, 2).unscaledValue().toByteArray()))
			// 20.00
			.setTypeDecimalFixed(new Fixed2(BigDecimal.valueOf(2000, 2).unscaledValue().toByteArray()))
			.build();
	DatumWriter<User> userDatumWriter = new SpecificDatumWriter<>(User.class);
	DataFileWriter<User> dataFileWriter = new DataFileWriter<>(userDatumWriter);
	dataFileWriter.create(user1.getSchema(), testFile);
	dataFileWriter.append(user1);
	dataFileWriter.append(user2);
	dataFileWriter.close();
}
 
Example 9
Source File: AvroRecordInputFormatTest.java    From flink with Apache License 2.0 4 votes vote down vote up
public static void writeTestFile(File testFile) throws IOException {
	ArrayList<CharSequence> stringArray = new ArrayList<>();
	stringArray.add(TEST_ARRAY_STRING_1);
	stringArray.add(TEST_ARRAY_STRING_2);

	ArrayList<Boolean> booleanArray = new ArrayList<>();
	booleanArray.add(TEST_ARRAY_BOOLEAN_1);
	booleanArray.add(TEST_ARRAY_BOOLEAN_2);

	HashMap<CharSequence, Long> longMap = new HashMap<>();
	longMap.put(TEST_MAP_KEY1, TEST_MAP_VALUE1);
	longMap.put(TEST_MAP_KEY2, TEST_MAP_VALUE2);

	Address addr = new Address();
	addr.setNum(TEST_NUM);
	addr.setStreet(TEST_STREET);
	addr.setCity(TEST_CITY);
	addr.setState(TEST_STATE);
	addr.setZip(TEST_ZIP);

	User user1 = new User();

	user1.setName(TEST_NAME);
	user1.setFavoriteNumber(256);
	user1.setTypeDoubleTest(123.45d);
	user1.setTypeBoolTest(true);
	user1.setTypeArrayString(stringArray);
	user1.setTypeArrayBoolean(booleanArray);
	user1.setTypeEnum(TEST_ENUM_COLOR);
	user1.setTypeMap(longMap);
	user1.setTypeNested(addr);
	user1.setTypeBytes(ByteBuffer.allocate(10));
	user1.setTypeDate(LocalDate.parse("2014-03-01"));
	user1.setTypeTimeMillis(LocalTime.parse("12:12:12"));
	user1.setTypeTimeMicros(123456);
	user1.setTypeTimestampMillis(DateTime.parse("2014-03-01T12:12:12.321Z"));
	user1.setTypeTimestampMicros(123456L);
	// 20.00
	user1.setTypeDecimalBytes(ByteBuffer.wrap(BigDecimal.valueOf(2000, 2).unscaledValue().toByteArray()));
	// 20.00
	user1.setTypeDecimalFixed(new Fixed2(BigDecimal.valueOf(2000, 2).unscaledValue().toByteArray()));

	// Construct via builder
	User user2 = User.newBuilder()
			.setName("Charlie")
			.setFavoriteColor("blue")
			.setFavoriteNumber(null)
			.setTypeBoolTest(false)
			.setTypeDoubleTest(1.337d)
			.setTypeNullTest(null)
			.setTypeLongTest(1337L)
			.setTypeArrayString(new ArrayList<>())
			.setTypeArrayBoolean(new ArrayList<>())
			.setTypeNullableArray(null)
			.setTypeEnum(Colors.RED)
			.setTypeMap(new HashMap<>())
			.setTypeFixed(null)
			.setTypeUnion(null)
			.setTypeNested(
					Address.newBuilder().setNum(TEST_NUM).setStreet(TEST_STREET)
							.setCity(TEST_CITY).setState(TEST_STATE).setZip(TEST_ZIP)
							.build())
			.setTypeBytes(ByteBuffer.allocate(10))
			.setTypeDate(LocalDate.parse("2014-03-01"))
			.setTypeTimeMillis(LocalTime.parse("12:12:12"))
			.setTypeTimeMicros(123456)
			.setTypeTimestampMillis(DateTime.parse("2014-03-01T12:12:12.321Z"))
			.setTypeTimestampMicros(123456L)
			// 20.00
			.setTypeDecimalBytes(ByteBuffer.wrap(BigDecimal.valueOf(2000, 2).unscaledValue().toByteArray()))
			// 20.00
			.setTypeDecimalFixed(new Fixed2(BigDecimal.valueOf(2000, 2).unscaledValue().toByteArray()))
			.build();
	DatumWriter<User> userDatumWriter = new SpecificDatumWriter<>(User.class);
	DataFileWriter<User> dataFileWriter = new DataFileWriter<>(userDatumWriter);
	dataFileWriter.create(user1.getSchema(), testFile);
	dataFileWriter.append(user1);
	dataFileWriter.append(user2);
	dataFileWriter.close();
}