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/03/26 06:45:27 UTC

[GitHub] [pulsar] lynnmatrix opened a new issue #6612: Failed to decode long type fields in json schema message

lynnmatrix opened a new issue #6612: Failed to decode long type fields in json schema message
URL: https://github.com/apache/pulsar/issues/6612
 
 
   **Describe the bug**
   If message sent in json schema, long field will be decoded as int if its value below Integer.MAX_VALUE, other wise decoded as string.
   For example, the json message below: 
   ```json
   {
       "timestamp": 1585204833128
   }
   ```
   will be decoded as 
   
   ```json
   {
       "timestamp": "1585204833128"
   }
   ```
   
   **To Reproduce**
   
   **Expected behavior**
   Long type fields encoded in json schema will be decoded as long.
   
   **Screenshots**
   
   **Desktop (please complete the following information):**
   
   
   **Additional context**
   
   

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

[GitHub] [pulsar] sijie commented on issue #6612: Failed to decode long type fields in json schema message

Posted by GitBox <gi...@apache.org>.
sijie commented on issue #6612: Failed to decode long type fields in json schema message
URL: https://github.com/apache/pulsar/issues/6612#issuecomment-604267346
 
 
   @lynnmatrix Can you submit a pull request to fix it?

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

[GitHub] [pulsar] lynnmatrix commented on issue #6612: Failed to decode long type fields in json schema message

Posted by GitBox <gi...@apache.org>.
lynnmatrix commented on issue #6612: Failed to decode long type fields in json schema message
URL: https://github.com/apache/pulsar/issues/6612#issuecomment-604267922
 
 
   OK @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


With regards,
Apache Git Services

[GitHub] [pulsar] sijie closed issue #6612: Failed to decode long type fields in json schema message

Posted by GitBox <gi...@apache.org>.
sijie closed issue #6612: Failed to decode long type fields in json schema message
URL: https://github.com/apache/pulsar/issues/6612
 
 
   

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

[GitHub] [pulsar] lynnmatrix commented on issue #6612: Failed to decode long type fields in json schema message

Posted by GitBox <gi...@apache.org>.
lynnmatrix commented on issue #6612: Failed to decode long type fields in json schema message
URL: https://github.com/apache/pulsar/issues/6612#issuecomment-604261397
 
 
   GenericJsonRecord.java
   ```java
       public Object getField(String fieldName) {
           JsonNode fn = this.jn.get(fieldName);
           if (fn.isContainerNode()) {
               AtomicInteger idx = new AtomicInteger(0);
               List<Field> fields = (List)Lists.newArrayList(fn.fieldNames()).stream().map((f) -> {
                   return new Field(f, idx.getAndIncrement());
               }).collect(Collectors.toList());
               return new GenericJsonRecord(this.schemaVersion, fields, fn);
           } else if (fn.isBoolean()) {
               return fn.asBoolean();
           } else if (fn.isInt()) {
               return fn.asInt();
           } else if (fn.isFloatingPointNumber()) {
               return fn.asDouble();
           } else {
               return fn.isDouble() ? fn.asDouble() : fn.asText();
           }
       }
   ```
   GenericJsonRecord::getField does not check whether the field is long type, as decode long field by 'fn.asText()'

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

[GitHub] [pulsar] lynnmatrix edited a comment on issue #6612: Failed to decode long type fields in json schema message

Posted by GitBox <gi...@apache.org>.
lynnmatrix edited a comment on issue #6612: Failed to decode long type fields in json schema message
URL: https://github.com/apache/pulsar/issues/6612#issuecomment-604261397
 
 
   GenericJsonRecord.java
   ```java
       public Object getField(String fieldName) {
           JsonNode fn = this.jn.get(fieldName);
           if (fn.isContainerNode()) {
               AtomicInteger idx = new AtomicInteger(0);
               List<Field> fields = (List)Lists.newArrayList(fn.fieldNames()).stream().map((f) -> {
                   return new Field(f, idx.getAndIncrement());
               }).collect(Collectors.toList());
               return new GenericJsonRecord(this.schemaVersion, fields, fn);
           } else if (fn.isBoolean()) {
               return fn.asBoolean();
           } else if (fn.isInt()) {
               return fn.asInt();
           } else if (fn.isFloatingPointNumber()) {
               return fn.asDouble();
           } else {
               return fn.isDouble() ? fn.asDouble() : fn.asText();
           }
       }
   ```
   GenericJsonRecord::getField does not check whether the field is long type, and decode long field by 'fn.asText()'

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