Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(bigdecimal): Convert BigDecimal to BigNumeric instead of Numeric #2031

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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