sijie commented on a change in pull request #3856: [pulsar-client] add
Date/Time/Timestamp schema
URL: https://github.com/apache/pulsar/pull/3856#discussion_r266712152
##########
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:
there are two different things.
1) DATE/TIMESTAMP/TIME in GenericRecord or GenericRecordSchema: in this
case, you just need introduce 3 schema types, you don't really need to
implement the schema interfaces. since we are delegating to the underlying
implementation on interpreting the objects as corresponding types and do the
serialization and deserialization. If AVRO supports joda, we can allow user
passing joda time types when building a generic record from
GenericRecordBuilder. This doesn't require introducing a new joda dependency on
client-api. As the joda dependency will come as part of AVRO.
2) DATE/TIMESTAMP/TIME schema implementations (where each message is a date,
timestamp or time): only in this case you need to implement the `Schema`
interface. I would avoid introducing a joda dependency in client-api. If people
want to implement a JODA schema, people can just implement a JodaDateSchema.
technically for #3831 , we only need 1) but not 2). but if you want to
introduce the implementations for those types, I would prefer using java
standard types but not joda types.
----------------------------------------------------------------
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:
[email protected]
With regards,
Apache Git Services