From 436ee8ebe9104f6ca721f1a14bd409158c7bdb5a Mon Sep 17 00:00:00 2001 From: Obada Alabbadi <76101898+obada-ab@users.noreply.github.com> Date: Tue, 3 Oct 2023 10:42:13 +0200 Subject: [PATCH] fix: getDouble in read API path (#2919) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly: - [X] Make sure to open an issue as a [bug/issue](https://togithub.com/googleapis/java-bigquery/issues/new/choose) before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea - [X] Ensure the tests and linter pass - [X] Code coverage does not decrease (if any source code was changed) - [X] Appropriate docs were updated (if necessary) Fixes #2905 ☕️ --- README.md | 6 +++--- .../java/com/google/cloud/bigquery/BigQueryResultImpl.java | 2 +- .../java/com/google/cloud/bigquery/it/ITBigQueryTest.java | 5 +++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 80b1ce1a9..80d18fd30 100644 --- a/README.md +++ b/README.md @@ -60,13 +60,13 @@ implementation 'com.google.cloud:google-cloud-bigquery' If you are using Gradle without BOM, add this to your dependencies: ```Groovy -implementation 'com.google.cloud:google-cloud-bigquery:2.33.0' +implementation 'com.google.cloud:google-cloud-bigquery:2.33.1' ``` If you are using SBT, add this to your dependencies: ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-bigquery" % "2.33.0" +libraryDependencies += "com.google.cloud" % "google-cloud-bigquery" % "2.33.1" ``` @@ -351,7 +351,7 @@ Java is a registered trademark of Oracle and/or its affiliates. [kokoro-badge-link-5]: http://storage.googleapis.com/cloud-devrel-public/java/badges/java-bigquery/java11.html [stability-image]: https://img.shields.io/badge/stability-stable-green [maven-version-image]: https://img.shields.io/maven-central/v/com.google.cloud/google-cloud-bigquery.svg -[maven-version-link]: https://central.sonatype.com/artifact/com.google.cloud/google-cloud-bigquery/2.33.0 +[maven-version-link]: https://central.sonatype.com/artifact/com.google.cloud/google-cloud-bigquery/2.33.1 [authentication]: https://github.com/googleapis/google-cloud-java#authentication [auth-scopes]: https://developers.google.com/identity/protocols/oauth2/scopes [predefined-iam-roles]: https://cloud.google.com/iam/docs/understanding-roles#predefined_roles diff --git a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryResultImpl.java b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryResultImpl.java index 2a2aba7cd..e944efceb 100644 --- a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryResultImpl.java +++ b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryResultImpl.java @@ -337,7 +337,7 @@ public double getDouble(String fieldName) throws SQLException { throw new SQLException(String.format("Field %s not found", fieldName)); } Object curVal = curRow.get(fieldName); - return curVal == null ? 0.0d : ((BigDecimal) curVal).doubleValue(); + return curVal == null ? 0.0d : new BigDecimal(curVal.toString()).doubleValue(); } } diff --git a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java index 549066c5f..1ff859745 100644 --- a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java +++ b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java @@ -3230,7 +3230,7 @@ public void testReadAPIIterationAndOrderAsync() throws SQLException, ExecutionException, InterruptedException { // use read API to read 300K records and check the order String query = - "SELECT date, county, state_name, confirmed_cases, deaths FROM " + "SELECT date, county, state_name, confirmed_cases, deaths / 10 FROM " + TABLE_ID_LARGE.getTable() + " where date is not null and county is not null and state_name is not null order by confirmed_cases asc limit 300000"; @@ -3255,7 +3255,8 @@ public void testReadAPIIterationAndOrderAsync() assertNotNull(rs.getString(1)); assertNotNull(rs.getString(2)); assertTrue(rs.getInt(3) >= 0); - assertTrue(rs.getInt(4) >= 0); + assertTrue(rs.getDouble(3) >= 0); + assertTrue(rs.getDouble(4) >= 0); // check if the records are sorted assertTrue(rs.getInt(3) >= lasConfirmedCases);