You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2019/03/19 02:12:49 UTC

[GitHub] [pulsar] ambition119 commented on a change in pull request #3856: [pulsar-client] add Date/Time/Timestamp schema

ambition119 commented on a change in pull request #3856: [pulsar-client] add Date/Time/Timestamp schema
URL: https://github.com/apache/pulsar/pull/3856#discussion_r266706372
 
 

 ##########
 File path: pulsar-client/src/test/java/org/apache/pulsar/client/impl/schema/AvroSchemaTest.java
 ##########
 @@ -152,4 +159,43 @@ public void testEncodeAndDecode() {
         assertEquals(object2, foo2);
     }
 
+    @Test
+    public void testDateAndTimestamp() {
+        RecordSchemaBuilder recordSchemaBuilder =
+              SchemaBuilder.record("org.apache.pulsar.client.impl.schema.generic.NasaMission");
+        recordSchemaBuilder.field("id")
+              .type(SchemaType.INT32);
+        recordSchemaBuilder.field("name")
+              .type(SchemaType.STRING);
+        recordSchemaBuilder.field("create_year")
+              .type(SchemaType.DATE);
+        recordSchemaBuilder.field("create_time")
+              .type(SchemaType.TIME);
+        recordSchemaBuilder.field("create_timestamp")
+              .type(SchemaType.TIMESTAMP);
+        SchemaInfo schemaInfo = recordSchemaBuilder.build(
+              SchemaType.AVRO
+        );
+
+        org.apache.avro.Schema recordSchema = new org.apache.avro.Schema.Parser().parse(
+              new String(schemaInfo.getSchema(), UTF_8)
+        );
+        AvroSchema<NasaMission> avroSchema = AvroSchema.of(NasaMission.class, null);
+        assertEquals(recordSchema, avroSchema.schema);
+
+        NasaMission nasaMission = NasaMission.newBuilder()
+              .setId(1001)
+              .setName("one")
+              .setCreateYear(new LocalDate(1552707517258L))
+              .setCreateTime(new LocalTime(1552707517258L))
+              .setCreateTimestamp(new DateTime(1552707517258L))
+              .build();
 
 Review comment:
   @sijie The use of joda is because avro's [Logical Types]( http://avro.apache.org/docs/1.8.2/idl.html) support date types, and the underlying is joda, which is consistent with [avro field.](FieldSchemaBuilderImpl.java)
   Of course, I can also remove the support of avro filed and change it to java.sql.X.

----------------------------------------------------------------
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