Skip to content
This repository was archived by the owner on Feb 24, 2026. It is now read-only.
This repository was archived by the owner on Feb 24, 2026. It is now read-only.

BigQuery Storage Write API: JsonStreamWriter cannot transform BigDecimal with 9+ decimals to BigNumeric #2013

Description

Environment details

  1. OS type and version: OSX 11.6.3
  2. Java version: OpenSDK 11
  3. version(s): v2.28.3 and later

Steps to reproduce

  1. Define a TableSchema with a field of type BIGNUMERIC
  2. Serialize a JSON message to Proto containing more than 9 decimals, eg. the number 24.6789012345

Code example

This unit test could be added to JsonToProtoMessageTest to reproduce it:

@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);
  }

Stack trace

[ERROR] com.google.cloud.bigquery.storage.v1.JsonToProtoMessageTest.testBigDecimalToBigNumericConversion  Time elapsed: 0.007 s  <<< ERROR!
com.google.cloud.bigquery.storage.v1.Exceptions$FieldParseError: ByteString scale cannot exceed 9: 24.6789012345
	at com.google.cloud.bigquery.storage.v1.JsonToProtoMessage.convertJsonToProtoMessageImpl(JsonToProtoMessage.java:247)
	at com.google.cloud.bigquery.storage.v1.JsonToProtoMessage.convertJsonToProtoMessage(JsonToProtoMessage.java:139)
	at com.google.cloud.bigquery.storage.v1.JsonToProtoMessageTest.testBigDecimalToBigNumericConversion(JsonToProtoMessageTest.java:1437)
...

Any additional information below

On the following lines, encodeToBigNumericByteString should be called instead of encodeToNumericByteString:

If you agree on this proposed approach, we can create PR with the following fix:
main...tradecloud:java-bigquerystorage:TC-8710-serialize-bigdecimal

Activity

  1. added 2 commits that reference this issue on Mar 8, 2023
    e0f7e34
    40ac0bf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    api: bigquerystorageIssues related to the googleapis/java-bigquerystorage API.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions