You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2022/08/15 17:22:42 UTC

[camel] branch camel-3.18.x updated: CAMEL-18393 Camel-bigquery: NPE if select * is requested (#8162)

This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch camel-3.18.x
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/camel-3.18.x by this push:
     new efa3eefccb3 CAMEL-18393 Camel-bigquery: NPE if select * is requested (#8162)
efa3eefccb3 is described below

commit efa3eefccb3fb1f0e0bb6f83a31739172992eadf
Author: JiriOndrusek <on...@gmail.com>
AuthorDate: Mon Aug 15 19:21:50 2022 +0200

    CAMEL-18393 Camel-bigquery: NPE if select * is requested (#8162)
---
 .../google/bigquery/sql/GoogleBigQuerySQLProducer.java         | 10 ++++++++--
 .../camel-google-bigquery/src/test/resources/sql/delete.sql    |  2 +-
 .../camel-google-bigquery/src/test/resources/sql/insert.sql    |  2 +-
 3 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/components/camel-google/camel-google-bigquery/src/main/java/org/apache/camel/component/google/bigquery/sql/GoogleBigQuerySQLProducer.java b/components/camel-google/camel-google-bigquery/src/main/java/org/apache/camel/component/google/bigquery/sql/GoogleBigQuerySQLProducer.java
index da98cca893d..82fae9bcedb 100644
--- a/components/camel-google/camel-google-bigquery/src/main/java/org/apache/camel/component/google/bigquery/sql/GoogleBigQuerySQLProducer.java
+++ b/components/camel-google/camel-google-bigquery/src/main/java/org/apache/camel/component/google/bigquery/sql/GoogleBigQuerySQLProducer.java
@@ -108,12 +108,18 @@ public class GoogleBigQuerySQLProducer extends DefaultProducer {
             Job job = bigquery.create(JobInfo.of(queryJobId, queryJobConfiguration)).waitFor();
             JobStatistics.QueryStatistics statistics = job.getStatistics();
             TableResult result = job.getQueryResults();
-            long numAffectedRows = statistics.getNumDmlAffectedRows();
+            Long numAffectedRows = statistics.getNumDmlAffectedRows();
 
             if (LOG.isTraceEnabled()) {
                 LOG.trace("Query {} - Affected rows {} - Result {}", translatedQuery, numAffectedRows, result);
             }
-            return numAffectedRows;
+
+            //numAffectedRows is present only for DML statements INSERT, UPDATE or DELETE.
+            if (numAffectedRows != null) {
+                return numAffectedRows;
+            }
+            //in other cases (SELECT), the number of affected rows is returned
+            return result.getTotalRows();
         } catch (JobException e) {
             throw new Exception("Query " + translatedQuery + " failed: " + e.getErrors(), e);
         } catch (BigQueryException e) {
diff --git a/components/camel-google/camel-google-bigquery/src/test/resources/sql/delete.sql b/components/camel-google/camel-google-bigquery/src/test/resources/sql/delete.sql
index 1a05bfd0845..48cb4fe0394 100644
--- a/components/camel-google/camel-google-bigquery/src/test/resources/sql/delete.sql
+++ b/components/camel-google/camel-google-bigquery/src/test/resources/sql/delete.sql
@@ -15,4 +15,4 @@
 -- limitations under the License.
 --
 
-delete from test.test_sql_table where id = :id
\ No newline at end of file
+delete from test_dataset.test_sql_table where id = :id
\ No newline at end of file
diff --git a/components/camel-google/camel-google-bigquery/src/test/resources/sql/insert.sql b/components/camel-google/camel-google-bigquery/src/test/resources/sql/insert.sql
index 05d19bd1964..5eb41d41b17 100644
--- a/components/camel-google/camel-google-bigquery/src/test/resources/sql/insert.sql
+++ b/components/camel-google/camel-google-bigquery/src/test/resources/sql/insert.sql
@@ -15,5 +15,5 @@
 -- limitations under the License.
 --
 
-insert into test.test_sql_table (col1, col2)
+insert into test_dataset.test_sql_table (col1, col2)
 values (@col1, @col2)
\ No newline at end of file