Skip to content

Commit

Permalink
fix(bigdecimal): Convert BigDecimal to BigNumeric instead of Numeric (#…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
Roy de Bokx authored Mar 8, 2023
1 parent 7a95553 commit e0f7e34
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ implementation 'com.google.cloud:google-cloud-bigquerystorage'
If you are using Gradle without BOM, add this to your dependencies:

```Groovy
implementation 'com.google.cloud:google-cloud-bigquerystorage:2.33.0'
implementation 'com.google.cloud:google-cloud-bigquerystorage:2.33.1'
```

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

```Scala
libraryDependencies += "com.google.cloud" % "google-cloud-bigquerystorage" % "2.33.0"
libraryDependencies += "com.google.cloud" % "google-cloud-bigquerystorage" % "2.33.1"
```

## Authentication
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ private static void fillField(
} else if (val instanceof BigDecimal) {
protoMsg.setField(
fieldDescriptor,
BigDecimalByteStringEncoder.encodeToNumericByteString((BigDecimal) val));
BigDecimalByteStringEncoder.encodeToBigNumericByteString((BigDecimal) val));
return;
}
}
Expand Down Expand Up @@ -603,7 +603,7 @@ private static void fillRepeatedField(
} else if (val instanceof BigDecimal) {
protoMsg.addRepeatedField(
fieldDescriptor,
BigDecimalByteStringEncoder.encodeToNumericByteString((BigDecimal) val));
BigDecimalByteStringEncoder.encodeToBigNumericByteString((BigDecimal) val));
added = true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -984,7 +984,7 @@ public void testStructComplex() throws Exception {
BigDecimalByteStringEncoder.encodeToNumericByteString(new BigDecimal(5D)))
.setTestBignumeric(
BigDecimalByteStringEncoder.encodeToBigNumericByteString(
new BigDecimal("578960446186580977117854925043439539266.3")))
new BigDecimal("578960446186580977117854925043439539266.3222222222")))
.addTestBignumericStr(
BigDecimalByteStringEncoder.encodeToBigNumericByteString(new BigDecimal("1.23")))
.setTestBignumericShort(
Expand Down Expand Up @@ -1047,9 +1047,7 @@ public void testStructComplex() throws Exception {
json.put("test_numeric_float", 4f);
json.put("test_numeric_double", 5D);
json.put(
"test_bignumeric",
BigDecimalByteStringEncoder.encodeToBigNumericByteString(
new BigDecimal("578960446186580977117854925043439539266.3")));
"test_bignumeric", new BigDecimal("578960446186580977117854925043439539266.3222222222"));
json.put("test_bignumeric_str", new JSONArray(new String[] {"1.23"}));
json.put("test_bignumeric_short", 1);
json.put("test_bignumeric_int", 2);
Expand Down Expand Up @@ -1415,6 +1413,31 @@ public void testDoubleAndFloatToNumericConversion() {
assertEquals(expectedProto, protoMsg);
}

@Test
public void testBigDecimalToBigNumericConversion() {
TableSchema ts =
TableSchema.newBuilder()
.addFields(
0,
TableFieldSchema.newBuilder()
.setName("bignumeric")
.setType(TableFieldSchema.Type.BIGNUMERIC)
.setMode(TableFieldSchema.Mode.REPEATED)
.build())
.build();
TestBignumeric expectedProto =
TestBignumeric.newBuilder()
.addBignumeric(
BigDecimalByteStringEncoder.encodeToBigNumericByteString(
new BigDecimal("24.6789012345")))
.build();
JSONObject json = new JSONObject();
json.put("bignumeric", Collections.singletonList(new BigDecimal("24.6789012345")));
DynamicMessage protoMsg =
JsonToProtoMessage.convertJsonToProtoMessage(TestBignumeric.getDescriptor(), ts, json);
assertEquals(expectedProto, protoMsg);
}

@Test
public void testDoubleAndFloatToRepeatedBigNumericConversion() {
TableSchema ts =
Expand Down

0 comments on commit e0f7e34

Please sign in to comment.