You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by "turcsanyip (via GitHub)" <gi...@apache.org> on 2023/08/02 22:42:01 UTC

[GitHub] [nifi] turcsanyip commented on pull request #7489: NIFI-11823 - fix NUMERIC support in PutBigQuery

turcsanyip commented on PR #7489:
URL: https://github.com/apache/nifi/pull/7489#issuecomment-1663063462

   Thanks @pvillard31 for your detailed explanation!
   
   I did not check the result in the BigQuery table, just saw that `long` was successful, and that's why I thought `int` should work too. Now I understand that none of `int`, `long`, `float` or `double` can be inserted into a `NUMERIC` field with the current code because it creates a different binary representation.
   
   What we can do (if we want to support cross-type conversions, e.g. `int` to `numeric`) is to convert the Java `int`, `long`, etc. values into `BigDecimal` first, and then use `BigDecimalByteStringEncoder` (as for the values originally in `BigDecimal`).
   
   Something like this:
   ```
               case BYTES:
                   if (value instanceof Integer) {
                       value = new BigDecimal((int) value);
                   } else if (value instanceof Long) {
                       value = new BigDecimal((long) value);
                   } else if (value instanceof Float || value instanceof Double) {
                       value = new BigDecimal(value.toString());
                   }
   
                   if (value instanceof BigDecimal) {
                       if (tableSchema.getFields(field.getIndex()).getType().equals(Type.BIGNUMERIC)) {
                           value = BigDecimalByteStringEncoder.encodeToBigNumericByteString((BigDecimal) value);
                       } else if (tableSchema.getFields(field.getIndex()).getType().equals(Type.NUMERIC)) {
                           value = BigDecimalByteStringEncoder.encodeToNumericByteString((BigDecimal) value);
                       }
                   }
   ```
   


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

To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org