You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2019/07/18 07:24:25 UTC

[GitHub] [flink] wuchong commented on a change in pull request #9139: [FLINK-13304][table-runtime-blink] Fix implementation of getString and getBinary method in NestedRow and add tests for complex data formats

wuchong commented on a change in pull request #9139: [FLINK-13304][table-runtime-blink] Fix implementation of getString and getBinary method in NestedRow and add tests for complex data formats
URL: https://github.com/apache/flink/pull/9139#discussion_r304761647
 
 

 ##########
 File path: flink-table/flink-table-runtime-blink/src/test/java/org/apache/flink/table/dataformat/BinaryRowTest.java
 ##########
 @@ -428,6 +457,109 @@ public void testGeneric() {
 		assertEquals(hahah, generic2);
 	}
 
+	@Test
+	public void testGenericObject() throws Exception {
+
+		GenericTypeInfo<MyObj> info = new GenericTypeInfo<>(MyObj.class);
+		TypeSerializer<MyObj> genericSerializer = info.createSerializer(new ExecutionConfig());
+
+		BinaryRow row = new BinaryRow(4);
+		BinaryRowWriter writer = new BinaryRowWriter(row);
+		writer.writeInt(0, 0);
+
+		BinaryGeneric<MyObj> myObj1 = new BinaryGeneric<>(new MyObj(0, 1), genericSerializer);
+		writer.writeGeneric(1, myObj1);
+		BinaryGeneric<MyObj> myObj2 = new BinaryGeneric<>(new MyObj(123, 5.0), genericSerializer);
+		myObj2.ensureMaterialized();
+		writer.writeGeneric(2, myObj2);
+		BinaryGeneric<MyObj> myObj3 = new BinaryGeneric<>(new MyObj(1, 1), genericSerializer);
+		writer.writeGeneric(3, myObj3);
+		writer.complete();
+
+		assertTestGenericObjectRow(row, genericSerializer);
+
+		// getBytes from var-length memorySegments.
+		BinaryRowSerializer serializer = new BinaryRowSerializer(4);
+		MemorySegment[] memorySegments = new MemorySegment[3];
+		ArrayList<MemorySegment> memorySegmentList = new ArrayList<>();
+		for (int i = 0; i < 3; i++) {
+			memorySegments[i] = MemorySegmentFactory.wrap(new byte[64]);
+			memorySegmentList.add(memorySegments[i]);
+		}
+		RandomAccessOutputView out = new RandomAccessOutputView(memorySegments, 64);
+		serializer.serializeToPages(row, out);
+
+		BinaryRow mapRow = serializer.mapFromPages(new RandomAccessInputView(memorySegmentList, 64));
+		assertTestGenericObjectRow(mapRow, genericSerializer);
+	}
+
+	@Test
+	public void testDateAndTime() {
+		BinaryRow row = new BinaryRow(7);
+		BinaryRowWriter writer = new BinaryRowWriter(row);
+
+		LocalDate localDate = LocalDate.of(2019, 7, 16);
+		LocalTime localTime = LocalTime.of(17, 31);
+		LocalDateTime localDateTime = LocalDateTime.of(localDate, localTime);
+
+		writer.writeInt(0, 0);
+		writer.writeGeneric(1, new BinaryGeneric<>(new Date(123), SqlDateSerializer.INSTANCE));
+		writer.writeGeneric(2, new BinaryGeneric<>(new Time(456), SqlTimeSerializer.INSTANCE));
+		writer.writeGeneric(3, new BinaryGeneric<>(new Timestamp(789), SqlTimestampSerializer.INSTANCE));
+		writer.writeGeneric(4, new BinaryGeneric<>(localDate, LocalDateSerializer.INSTANCE));
+		writer.writeGeneric(5, new BinaryGeneric<>(localTime, LocalTimeSerializer.INSTANCE));
+		writer.writeGeneric(6, new BinaryGeneric<>(localDateTime, LocalDateTimeSerializer.INSTANCE));
 
 Review comment:
   Is this on purpose that we write `LocalDateTime` as a generic object into BinaryRow? 
   If yes, please rename test name to `testDateAndTimeAsGenericObject`.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services