Claus Ibsen created CAMEL-27191:
-----------------------------------

             Summary: camel-google-bigquery - useAsInsertId fails on a 
non-String field
                 Key: CAMEL-27191
                 URL: https://issues.apache.org/jira/browse/CAMEL-27191
             Project: Camel
          Issue Type: Bug
          Components: camel-google-bigquery
            Reporter: Claus Ibsen


h3. What happens

{{useAsInsertId}} names the field of each row whose value is sent as the row's 
insert ID. The producer casts that value to {{String}}, so a numeric (or any 
non-String) id fails the exchange and nothing is sent:

{code}
from("direct:in")
    .setBody(constant(Map.of("num", 42, "name", "a")))
    .to("google-bigquery:my-project:my_dataset:my_table?useAsInsertId=num");
{code}

{noformat}
java.lang.ClassCastException: class java.lang.Integer cannot be cast to class 
java.lang.String (java.lang.Integer and java.lang.String are in module 
java.base of loader 'bootstrap')
        at 
org.apache.camel.component.google.bigquery.GoogleBigQueryProducer.createRowRequest(GoogleBigQueryProducer.java:243)
        at 
org.apache.camel.component.google.bigquery.GoogleBigQueryProducer.process(GoogleBigQueryProducer.java:202)
{noformat}

Numeric ids are common (order numbers, sequence ids), and a row parsed from 
JSON has them as {{Integer}}/{{Long}}. The insert ID header 
({{CamelGoogleBigQueryInsertId}}) is already read with a conversion 
({{getHeader(..., String.class)}}).

h3. Where

{{components/camel-google/camel-google-bigquery/src/main/java/org/apache/camel/component/google/bigquery/GoogleBigQueryProducer.java}},
 {{createRowRequest}}:

{code:java}
insertId = (String) (object.get(configuration.getUseAsInsertId()));
{code}

h3. Suggested fix

Convert instead of casting, e.g. {{Object v = object.get(...); insertId = v != 
null ? v.toString() : null;}} (or the Camel type converter), and add a test 
with a numeric field.



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to