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 2020/05/15 12:23:20 UTC

[GitHub] [pulsar] 315157973 opened a new pull request #6968: Fixes #6929 KeyValue schema supports nested generics type

315157973 opened a new pull request #6968:
URL: https://github.com/apache/pulsar/pull/6968


   <!--
   ### Contribution Checklist
     
     - Name the pull request in the form "[Issue XYZ][component] Title of the pull request", where *XYZ* should be replaced by the actual issue number.
       Skip *Issue XYZ* if there is no associated github issue for this pull request.
       Skip *component* if you are unsure about which is the best component. E.g. `[docs] Fix typo in produce method`.
   
     - Fill out the template below to describe the changes contributed by the pull request. That will give reviewers the context they need to do the review.
     
     - Each pull request should address only one issue, not mix up code from multiple issues.
     
     - Each commit in the pull request has a meaningful commit message
   
     - Once all items of the checklist are addressed, remove the above text and this checklist, leaving only the filled out template below.
   
   **(The sections below can be removed for hotfixes of typos)**
   -->
   
   *(If this PR fixes a github issue, please add `Fixes #<xyz>`.)*
   
   Fixes #<xyz>
   
   *(or if this PR is one task of a github issue, please add `Master Issue: #<xyz>` to link to the master issue.)*
   
   Master Issue: #<xyz>
   
   ### Motivation
   
   
   *Explain here the context, and why you're making that change. What is the problem you're trying to solve.*
   
   ### Modifications
   
   *Describe the modifications you've done.*
   
   ### Verifying this change
   
   - [ ] Make sure that the change passes the CI checks.
   
   *(Please pick either of the following options)*
   
   This change is a trivial rework / code cleanup without any test coverage.
   
   *(or)*
   
   This change is already covered by existing tests, such as *(please describe tests)*.
   
   *(or)*
   
   This change added tests and can be verified as follows:
   
   *(example:)*
     - *Added integration tests for end-to-end deployment with large payloads (10MB)*
     - *Extended integration test for recovery after broker failure*
   
   ### Does this pull request potentially affect one of the following parts:
   
   *If `yes` was chosen, please highlight the changes*
   
     - Dependencies (does it add or upgrade a dependency): (yes / no)
     - The public API: (yes / no)
     - The schema: (yes / no / don't know)
     - The default values of configurations: (yes / no)
     - The wire protocol: (yes / no)
     - The rest endpoints: (yes / no)
     - The admin cli options: (yes / no)
     - Anything that affects deployment: (yes / no / don't know)
   
   ### Documentation
   
     - Does this pull request introduce a new feature? (yes / no)
     - If yes, how is the feature documented? (not applicable / docs / JavaDocs / not documented)
     - If a feature is not applicable for documentation, explain why?
     - If a feature is not documented yet in this PR, please create a followup issue for adding the documentation
   


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



[GitHub] [pulsar] jiazhai commented on pull request #6968: Fixes #6929 KeyValue schema supports nested generics type

Posted by GitBox <gi...@apache.org>.
jiazhai commented on pull request #6968:
URL: https://github.com/apache/pulsar/pull/6968#issuecomment-650666827


   @315157973 Thanks for the fix. Seems there is some conflict. Would you please help merge your branch with the latest master?


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



[GitHub] [pulsar] 315157973 commented on pull request #6968: Fixes #6929 KeyValue schema supports nested generics type

Posted by GitBox <gi...@apache.org>.
315157973 commented on pull request #6968:
URL: https://github.com/apache/pulsar/pull/6968#issuecomment-631358959


   > @315157973 the direction of this change looks great in general. However, I am not sure adding `Type functionGenericType` into the source and sink configs is the best solution. The schema should be inferred from the argument type in the runtime. They shouldn't be tracked in the configs. Can you find a different way to get the type at runtime?
   
   When the parameter is passed, only the Class type string of the schema is passed, and the generic type is directly discarded. The only thing we can get later is the Class string, we can't get generics.If we pass the real type instead. However, more parameter types will be modified.
   
   JavaInstanceRunnable initializes the schema when calling “setupInput” and “setupOutput” methods. 
   We must determine the schema before producers and consumers create。(Source and Sink)
   I don’t understand what stage the “runtime” refers to.
   
   If we feel that unified processing in topicSchema is not good, how about special treatment for KeyValue after "topicSchema.getSchema" is completed. This way we don't need to change the number of parameters in topicSchema. 


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



[GitHub] [pulsar] 315157973 removed a comment on pull request #6968: Fixes #6929 KeyValue schema supports nested generics type

Posted by GitBox <gi...@apache.org>.
315157973 removed a comment on pull request #6968:
URL: https://github.com/apache/pulsar/pull/6968#issuecomment-631358959


   > @315157973 the direction of this change looks great in general. However, I am not sure adding `Type functionGenericType` into the source and sink configs is the best solution. The schema should be inferred from the argument type in the runtime. They shouldn't be tracked in the configs. Can you find a different way to get the type at runtime?
   
   When the parameter is passed, only the Class type string of the schema is passed, and the generic type is directly discarded. The only thing we can get later is the Class string, we can't get generics.If we pass the real type instead. However, more parameter types will be modified.
   
   JavaInstanceRunnable initializes the schema when calling “setupInput” and “setupOutput” methods. 
   We must determine the schema before producers and consumers create。(Source and Sink)
   I don’t understand what stage the “runtime” refers to.
   
   If we feel that unified processing in topicSchema is not good, how about special treatment for KeyValue after "topicSchema.getSchema" is completed. This way we don't need to change the number of parameters in topicSchema. 


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



[GitHub] [pulsar] 315157973 closed pull request #6968: Fixes #6929 KeyValue schema supports nested generics type

Posted by GitBox <gi...@apache.org>.
315157973 closed pull request #6968:
URL: https://github.com/apache/pulsar/pull/6968






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



[GitHub] [pulsar] 315157973 commented on pull request #6968: Fixes #6929 KeyValue schema supports nested generics type

Posted by GitBox <gi...@apache.org>.
315157973 commented on pull request #6968:
URL: https://github.com/apache/pulsar/pull/6968#issuecomment-653118135


   Through the generic parameters of function, we can parse out the Java type. If other schemas are nested inside the keyValue schema, for example: 
   ```KeyValueSchema.of(Schema.JSON(A.class), Schema.AVRO(B.class))```
   We can't know the type of complex schema nested inside, especially when there is no schem information in the broker. I now use JSON by default.
   Is there any good solution for this situation?
   
   @sijie 


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



[GitHub] [pulsar] 315157973 closed pull request #6968: Fixes #6929 KeyValue schema supports nested generics type

Posted by GitBox <gi...@apache.org>.
315157973 closed pull request #6968:
URL: https://github.com/apache/pulsar/pull/6968






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



[GitHub] [pulsar] 315157973 commented on pull request #6968: Fixes #6929 KeyValue schema supports nested generics type

Posted by GitBox <gi...@apache.org>.
315157973 commented on pull request #6968:
URL: https://github.com/apache/pulsar/pull/6968#issuecomment-653077530


   There are still some problems, I will fix it soon


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



[GitHub] [pulsar] 315157973 removed a comment on pull request #6968: Fixes #6929 KeyValue schema supports nested generics type

Posted by GitBox <gi...@apache.org>.
315157973 removed a comment on pull request #6968:
URL: https://github.com/apache/pulsar/pull/6968#issuecomment-653077530


   There are still some problems, I will fix it soon


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



[GitHub] [pulsar] codelipenghui commented on pull request #6968: Fixes #6929 KeyValue schema supports nested generics type

Posted by GitBox <gi...@apache.org>.
codelipenghui commented on pull request #6968:
URL: https://github.com/apache/pulsar/pull/6968#issuecomment-638609304


   move to 2.7.0 first


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



[GitHub] [pulsar] 315157973 closed pull request #6968: Fixes #6929 KeyValue schema supports nested generics type

Posted by GitBox <gi...@apache.org>.
315157973 closed pull request #6968:
URL: https://github.com/apache/pulsar/pull/6968


   


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



[GitHub] [pulsar] sijie commented on a change in pull request #6968: Fixes #6929 KeyValue schema supports nested generics type

Posted by GitBox <gi...@apache.org>.
sijie commented on a change in pull request #6968:
URL: https://github.com/apache/pulsar/pull/6968#discussion_r448753907



##########
File path: pulsar-client-api/src/main/java/org/apache/pulsar/client/api/Schema.java
##########
@@ -369,4 +369,35 @@ default void configureSchemaInfo(String topic, String componentName,
     static GenericSchema<GenericRecord> generic(SchemaInfo schemaInfo) {
         return DefaultImplementation.getGenericSchema(schemaInfo);
     }
+
+    static Schema getDefaultSchema(Class<?> clazz) {
+        if (Byte[].class.equals(clazz)) {
+            return Schema.BYTES;
+        } else if (ByteBuffer.class.equals(clazz)) {
+            return Schema.BYTEBUFFER;
+        } else if (String.class.equals(clazz)) {
+            return Schema.STRING;
+        } else if (Byte.class.equals(clazz)) {
+            return Schema.INT8;
+        } else if (Short.class.equals(clazz)) {
+            return Schema.INT16;
+        } else if (Integer.class.equals(clazz)) {
+            return Schema.INT32;
+        } else if (Long.class.equals(clazz)) {
+            return Schema.INT64;
+        } else if (Boolean.class.equals(clazz)) {
+            return Schema.BOOL;
+        } else if (Float.class.equals(clazz)) {
+            return Schema.FLOAT;
+        } else if (Double.class.equals(clazz)) {
+            return Schema.DOUBLE;
+        } else if (Date.class.equals(clazz)) {
+            return Schema.DATE;
+        } else if (Time.class.equals(clazz)) {
+            return Schema.TIME;
+        } else if (Timestamp.class.equals(clazz)) {
+            return Schema.TIMESTAMP;
+        }
+        throw new IllegalArgumentException("Schema class type is incorrect");

Review comment:
       How does this handle a POJO class?




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



[GitHub] [pulsar] 315157973 commented on pull request #6968: Fixes #6929 KeyValue schema supports nested generics type

Posted by GitBox <gi...@apache.org>.
315157973 commented on pull request #6968:
URL: https://github.com/apache/pulsar/pull/6968#issuecomment-632138279


   > @315157973 the direction of this change looks great in general. However, I am not sure adding `Type functionGenericType` into the source and sink configs is the best solution. The schema should be inferred from the argument type in the runtime. They shouldn't be tracked in the configs. Can you find a different way to get the type at runtime?
   
   Get it from the context instead


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



[GitHub] [pulsar] 315157973 commented on a change in pull request #6968: Fixes #6929 KeyValue schema supports nested generics type

Posted by GitBox <gi...@apache.org>.
315157973 commented on a change in pull request #6968:
URL: https://github.com/apache/pulsar/pull/6968#discussion_r448973014



##########
File path: pulsar-client-api/src/main/java/org/apache/pulsar/client/api/Schema.java
##########
@@ -369,4 +369,35 @@ default void configureSchemaInfo(String topic, String componentName,
     static GenericSchema<GenericRecord> generic(SchemaInfo schemaInfo) {
         return DefaultImplementation.getGenericSchema(schemaInfo);
     }
+
+    static Schema getDefaultSchema(Class<?> clazz) {
+        if (Byte[].class.equals(clazz)) {
+            return Schema.BYTES;
+        } else if (ByteBuffer.class.equals(clazz)) {
+            return Schema.BYTEBUFFER;
+        } else if (String.class.equals(clazz)) {
+            return Schema.STRING;
+        } else if (Byte.class.equals(clazz)) {
+            return Schema.INT8;
+        } else if (Short.class.equals(clazz)) {
+            return Schema.INT16;
+        } else if (Integer.class.equals(clazz)) {
+            return Schema.INT32;
+        } else if (Long.class.equals(clazz)) {
+            return Schema.INT64;
+        } else if (Boolean.class.equals(clazz)) {
+            return Schema.BOOL;
+        } else if (Float.class.equals(clazz)) {
+            return Schema.FLOAT;
+        } else if (Double.class.equals(clazz)) {
+            return Schema.DOUBLE;
+        } else if (Date.class.equals(clazz)) {
+            return Schema.DATE;
+        } else if (Time.class.equals(clazz)) {
+            return Schema.TIME;
+        } else if (Timestamp.class.equals(clazz)) {
+            return Schema.TIMESTAMP;
+        }
+        throw new IllegalArgumentException("Schema class type is incorrect");

Review comment:
       > How does this handle a POJO class?
   
   Powerful, debug with naked eyes !




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



[GitHub] [pulsar] codelipenghui commented on pull request #6968: Fixes #6929 KeyValue schema supports nested generics type

Posted by GitBox <gi...@apache.org>.
codelipenghui commented on pull request #6968:
URL: https://github.com/apache/pulsar/pull/6968#issuecomment-636556404


   ping @sijie Please help review this PR again.


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



[GitHub] [pulsar] 315157973 commented on pull request #6968: Fixes #6929 KeyValue schema supports nested generics type

Posted by GitBox <gi...@apache.org>.
315157973 commented on pull request #6968:
URL: https://github.com/apache/pulsar/pull/6968#issuecomment-653901448


   The internal nested schema type of keyValue can be customized by user through customSchemaInputs and customSchemaOutputs. If there is no customization, the schema defaults to the parameter type of Function, and the schema of the POJO defaults to JSON.


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