Skip to content

Commit e0f7e34

Browse files
authored
fix(bigdecimal): Convert BigDecimal to BigNumeric instead of Numeric (#2031)
- [x] Make sure to open an issue as a [bug/issue](https://togithub.com/googleapis/java-bigquerystorage/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 #2013
1 parent 7a95553 commit e0f7e34

3 files changed

Lines changed: 31 additions & 8 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@ implementation 'com.google.cloud:google-cloud-bigquerystorage'
5656
If you are using Gradle without BOM, add this to your dependencies:
5757

5858
```Groovy
59-
implementation 'com.google.cloud:google-cloud-bigquerystorage:2.33.0'
59+
implementation 'com.google.cloud:google-cloud-bigquerystorage:2.33.1'
6060
```
6161

6262
If you are using SBT, add this to your dependencies:
6363

6464
```Scala
65-
libraryDependencies += "com.google.cloud" % "google-cloud-bigquerystorage" % "2.33.0"
65+
libraryDependencies += "com.google.cloud" % "google-cloud-bigquerystorage" % "2.33.1"
6666
```
6767

6868
## Authentication

google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1/JsonToProtoMessage.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ private static void fillField(
355355
} else if (val instanceof BigDecimal) {
356356
protoMsg.setField(
357357
fieldDescriptor,
358-
BigDecimalByteStringEncoder.encodeToNumericByteString((BigDecimal) val));
358+
BigDecimalByteStringEncoder.encodeToBigNumericByteString((BigDecimal) val));
359359
return;
360360
}
361361
}
@@ -603,7 +603,7 @@ private static void fillRepeatedField(
603603
} else if (val instanceof BigDecimal) {
604604
protoMsg.addRepeatedField(
605605
fieldDescriptor,
606-
BigDecimalByteStringEncoder.encodeToNumericByteString((BigDecimal) val));
606+
BigDecimalByteStringEncoder.encodeToBigNumericByteString((BigDecimal) val));
607607
added = true;
608608
}
609609
}

google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/JsonToProtoMessageTest.java

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -984,7 +984,7 @@ public void testStructComplex() throws Exception {
984984
BigDecimalByteStringEncoder.encodeToNumericByteString(new BigDecimal(5D)))
985985
.setTestBignumeric(
986986
BigDecimalByteStringEncoder.encodeToBigNumericByteString(
987-
new BigDecimal("578960446186580977117854925043439539266.3")))
987+
new BigDecimal("578960446186580977117854925043439539266.3222222222")))
988988
.addTestBignumericStr(
989989
BigDecimalByteStringEncoder.encodeToBigNumericByteString(new BigDecimal("1.23")))
990990
.setTestBignumericShort(
@@ -1047,9 +1047,7 @@ public void testStructComplex() throws Exception {
10471047
json.put("test_numeric_float", 4f);
10481048
json.put("test_numeric_double", 5D);
10491049
json.put(
1050-
"test_bignumeric",
1051-
BigDecimalByteStringEncoder.encodeToBigNumericByteString(
1052-
new BigDecimal("578960446186580977117854925043439539266.3")));
1050+
"test_bignumeric", new BigDecimal("578960446186580977117854925043439539266.3222222222"));
10531051
json.put("test_bignumeric_str", new JSONArray(new String[] {"1.23"}));
10541052
json.put("test_bignumeric_short", 1);
10551053
json.put("test_bignumeric_int", 2);
@@ -1415,6 +1413,31 @@ public void testDoubleAndFloatToNumericConversion() {
14151413
assertEquals(expectedProto, protoMsg);
14161414
}
14171415

1416+
@Test
1417+
public void testBigDecimalToBigNumericConversion() {
1418+
TableSchema ts =
1419+
TableSchema.newBuilder()
1420+
.addFields(
1421+
0,
1422+
TableFieldSchema.newBuilder()
1423+
.setName("bignumeric")
1424+
.setType(TableFieldSchema.Type.BIGNUMERIC)
1425+
.setMode(TableFieldSchema.Mode.REPEATED)
1426+
.build())
1427+
.build();
1428+
TestBignumeric expectedProto =
1429+
TestBignumeric.newBuilder()
1430+
.addBignumeric(
1431+
BigDecimalByteStringEncoder.encodeToBigNumericByteString(
1432+
new BigDecimal("24.6789012345")))
1433+
.build();
1434+
JSONObject json = new JSONObject();
1435+
json.put("bignumeric", Collections.singletonList(new BigDecimal("24.6789012345")));
1436+
DynamicMessage protoMsg =
1437+
JsonToProtoMessage.convertJsonToProtoMessage(TestBignumeric.getDescriptor(), ts, json);
1438+
assertEquals(expectedProto, protoMsg);
1439+
}
1440+
14181441
@Test
14191442
public void testDoubleAndFloatToRepeatedBigNumericConversion() {
14201443
TableSchema ts =

0 commit comments

Comments
 (0)