From 604d7df2afa54e445a4d310e5293d8d19901d565 Mon Sep 17 00:00:00 2001 From: dark0dave <52840419+dark0dave@users.noreply.github.com> Date: Mon, 17 Oct 2022 21:32:47 +0100 Subject: [PATCH] feat(shortsAndBigDecimals): add shorts and big decimals (#1674) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(shortsAndBigDecimals): add shorts and big decimals Signed-off-by: dark0dave * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md Signed-off-by: dark0dave Co-authored-by: Owl Bot Co-authored-by: Neenu Shaji --- .../storage/v1/JsonToProtoMessage.java | 28 ++++++- .../BQTableSchemaToProtoDescriptorTest.java | 38 ++++++--- .../storage/v1/JsonToProtoMessageTest.java | 76 +++++++++++------- .../BQTableSchemaToProtoDescriptorTest.java | 39 +++++++--- .../v1beta2/JsonToProtoMessageTest.java | 77 ++++++++++++------- .../src/test/proto/jsonTest.proto | 26 ++++--- 6 files changed, 188 insertions(+), 96 deletions(-) diff --git a/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1/JsonToProtoMessage.java b/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1/JsonToProtoMessage.java index 50b4a9d105..eebe7538aa 100644 --- a/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1/JsonToProtoMessage.java +++ b/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1/JsonToProtoMessage.java @@ -308,7 +308,7 @@ private static void fillField( BigDecimalByteStringEncoder.encodeToNumericByteString( new BigDecimal((String) val))); return; - } else if (val instanceof Integer || val instanceof Long) { + } else if (val instanceof Short || val instanceof Integer || val instanceof Long) { protoMsg.setField( fieldDescriptor, BigDecimalByteStringEncoder.encodeToNumericByteString( @@ -320,6 +320,11 @@ private static void fillField( BigDecimalByteStringEncoder.encodeToNumericByteString( new BigDecimal(String.valueOf(val)))); return; + } else if (val instanceof BigDecimal) { + protoMsg.setField( + fieldDescriptor, + BigDecimalByteStringEncoder.encodeToNumericByteString((BigDecimal) val)); + return; } } else if (fieldSchema.getType() == TableFieldSchema.Type.BIGNUMERIC) { if (val instanceof String) { @@ -328,7 +333,7 @@ private static void fillField( BigDecimalByteStringEncoder.encodeToBigNumericByteString( new BigDecimal((String) val))); return; - } else if (val instanceof Integer || val instanceof Long) { + } else if (val instanceof Short || val instanceof Integer || val instanceof Long) { protoMsg.setField( fieldDescriptor, BigDecimalByteStringEncoder.encodeToBigNumericByteString( @@ -340,6 +345,11 @@ private static void fillField( BigDecimalByteStringEncoder.encodeToBigNumericByteString( new BigDecimal(String.valueOf(val)))); return; + } else if (val instanceof BigDecimal) { + protoMsg.setField( + fieldDescriptor, + BigDecimalByteStringEncoder.encodeToNumericByteString((BigDecimal) val)); + return; } } } @@ -542,7 +552,7 @@ private static void fillRepeatedField( BigDecimalByteStringEncoder.encodeToNumericByteString( new BigDecimal((String) val))); added = true; - } else if (val instanceof Integer || val instanceof Long) { + } else if (val instanceof Short || val instanceof Integer || val instanceof Long) { protoMsg.addRepeatedField( fieldDescriptor, BigDecimalByteStringEncoder.encodeToNumericByteString( @@ -554,6 +564,11 @@ private static void fillRepeatedField( BigDecimalByteStringEncoder.encodeToNumericByteString( new BigDecimal(String.valueOf(val)))); added = true; + } else if (val instanceof BigDecimal) { + protoMsg.addRepeatedField( + fieldDescriptor, + BigDecimalByteStringEncoder.encodeToNumericByteString((BigDecimal) val)); + added = true; } } else if (fieldSchema != null && fieldSchema.getType() == TableFieldSchema.Type.BIGNUMERIC) { @@ -563,7 +578,7 @@ private static void fillRepeatedField( BigDecimalByteStringEncoder.encodeToBigNumericByteString( new BigDecimal((String) val))); added = true; - } else if (val instanceof Integer || val instanceof Long) { + } else if (val instanceof Short || val instanceof Integer || val instanceof Long) { protoMsg.addRepeatedField( fieldDescriptor, BigDecimalByteStringEncoder.encodeToBigNumericByteString( @@ -575,6 +590,11 @@ private static void fillRepeatedField( BigDecimalByteStringEncoder.encodeToBigNumericByteString( new BigDecimal(String.valueOf(val)))); added = true; + } else if (val instanceof BigDecimal) { + protoMsg.addRepeatedField( + fieldDescriptor, + BigDecimalByteStringEncoder.encodeToNumericByteString((BigDecimal) val)); + added = true; } } if (!added) { diff --git a/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/BQTableSchemaToProtoDescriptorTest.java b/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/BQTableSchemaToProtoDescriptorTest.java index c59c1397b1..111e435533 100644 --- a/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/BQTableSchemaToProtoDescriptorTest.java +++ b/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/BQTableSchemaToProtoDescriptorTest.java @@ -233,6 +233,12 @@ public void testStructComplex() throws Exception { .setMode(TableFieldSchema.Mode.NULLABLE) .setName("test_numeric_str") .build(); + final TableFieldSchema TEST_NUMERIC_SHORT = + TableFieldSchema.newBuilder() + .setType(TableFieldSchema.Type.NUMERIC) + .setMode(TableFieldSchema.Mode.NULLABLE) + .setName("test_numeric_short") + .build(); final TableFieldSchema TEST_NUMERIC_INT = TableFieldSchema.newBuilder() .setType(TableFieldSchema.Type.NUMERIC) @@ -269,6 +275,12 @@ public void testStructComplex() throws Exception { .setMode(TableFieldSchema.Mode.REPEATED) .setName("test_bignumeric_str") .build(); + final TableFieldSchema TEST_BIGNUMERIC_SHORT = + TableFieldSchema.newBuilder() + .setType(TableFieldSchema.Type.BIGNUMERIC) + .setMode(TableFieldSchema.Mode.NULLABLE) + .setName("test_bignumeric_short") + .build(); final TableFieldSchema TEST_BIGNUMERIC_INT = TableFieldSchema.newBuilder() .setType(TableFieldSchema.Type.BIGNUMERIC) @@ -324,18 +336,20 @@ public void testStructComplex() throws Exception { .addFields(14, TEST_TIME_STR) .addFields(15, TEST_NUMERIC_REPEATED) .addFields(16, TEST_NUMERIC_STR) - .addFields(17, TEST_NUMERIC_INT) - .addFields(18, TEST_NUMERIC_LONG) - .addFields(19, TEST_NUMERIC_FLOAT) - .addFields(20, TEST_NUMERIC_DOUBLE) - .addFields(21, TEST_BIGNUMERIC) - .addFields(22, TEST_BIGNUMERIC_STR) - .addFields(23, TEST_BIGNUMERIC_INT) - .addFields(24, TEST_BIGNUMERIC_LONG) - .addFields(25, TEST_BIGNUMERIC_FLOAT) - .addFields(26, TEST_BIGNUMERIC_DOUBLE) - .addFields(27, TEST_INTERVAL) - .addFields(28, TEST_JSON) + .addFields(17, TEST_NUMERIC_SHORT) + .addFields(18, TEST_NUMERIC_INT) + .addFields(19, TEST_NUMERIC_LONG) + .addFields(20, TEST_NUMERIC_FLOAT) + .addFields(21, TEST_NUMERIC_DOUBLE) + .addFields(22, TEST_BIGNUMERIC) + .addFields(23, TEST_BIGNUMERIC_STR) + .addFields(24, TEST_BIGNUMERIC_SHORT) + .addFields(25, TEST_BIGNUMERIC_INT) + .addFields(26, TEST_BIGNUMERIC_LONG) + .addFields(27, TEST_BIGNUMERIC_FLOAT) + .addFields(28, TEST_BIGNUMERIC_DOUBLE) + .addFields(29, TEST_INTERVAL) + .addFields(30, TEST_JSON) .build(); final Descriptor descriptor = BQTableSchemaToProtoDescriptor.convertBQTableSchemaToProtoDescriptor(tableSchema); diff --git a/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/JsonToProtoMessageTest.java b/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/JsonToProtoMessageTest.java index 3abb527ca2..463208302d 100644 --- a/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/JsonToProtoMessageTest.java +++ b/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/JsonToProtoMessageTest.java @@ -410,6 +410,12 @@ public class JsonToProtoMessageTest { .setMode(TableFieldSchema.Mode.NULLABLE) .setName("test_numeric_str") .build(); + private final TableFieldSchema TEST_NUMERIC_SHORT = + TableFieldSchema.newBuilder() + .setType(TableFieldSchema.Type.NUMERIC) + .setMode(TableFieldSchema.Mode.NULLABLE) + .setName("test_numeric_short") + .build(); private final TableFieldSchema TEST_NUMERIC_INT = TableFieldSchema.newBuilder() .setType(TableFieldSchema.Type.NUMERIC) @@ -446,6 +452,12 @@ public class JsonToProtoMessageTest { .setMode(TableFieldSchema.Mode.REPEATED) .setName("test_bignumeric_str") .build(); + private final TableFieldSchema TEST_BIGNUMERIC_SHORT = + TableFieldSchema.newBuilder() + .setType(TableFieldSchema.Type.BIGNUMERIC) + .setMode(TableFieldSchema.Mode.NULLABLE) + .setName("test_bignumeric_short") + .build(); private final TableFieldSchema TEST_BIGNUMERIC_INT = TableFieldSchema.newBuilder() .setType(TableFieldSchema.Type.BIGNUMERIC) @@ -501,18 +513,20 @@ public class JsonToProtoMessageTest { .addFields(14, TEST_TIME_STR) .addFields(15, TEST_NUMERIC_REPEATED) .addFields(16, TEST_NUMERIC_STR) - .addFields(17, TEST_NUMERIC_INT) - .addFields(18, TEST_NUMERIC_LONG) - .addFields(19, TEST_NUMERIC_FLOAT) - .addFields(20, TEST_NUMERIC_DOUBLE) - .addFields(21, TEST_BIGNUMERIC) - .addFields(22, TEST_BIGNUMERIC_STR) - .addFields(23, TEST_BIGNUMERIC_INT) - .addFields(24, TEST_BIGNUMERIC_LONG) - .addFields(25, TEST_BIGNUMERIC_FLOAT) - .addFields(26, TEST_BIGNUMERIC_DOUBLE) - .addFields(27, TEST_INTERVAL) - .addFields(28, TEST_JSON) + .addFields(17, TEST_NUMERIC_SHORT) + .addFields(18, TEST_NUMERIC_INT) + .addFields(19, TEST_NUMERIC_LONG) + .addFields(20, TEST_NUMERIC_FLOAT) + .addFields(21, TEST_NUMERIC_DOUBLE) + .addFields(22, TEST_BIGNUMERIC) + .addFields(23, TEST_BIGNUMERIC_STR) + .addFields(24, TEST_BIGNUMERIC_SHORT) + .addFields(25, TEST_BIGNUMERIC_INT) + .addFields(26, TEST_BIGNUMERIC_LONG) + .addFields(27, TEST_BIGNUMERIC_FLOAT) + .addFields(28, TEST_BIGNUMERIC_DOUBLE) + .addFields(29, TEST_INTERVAL) + .addFields(30, TEST_JSON) .build(); @Test @@ -903,27 +917,31 @@ public void testStructComplex() throws Exception { new BigDecimal("-99999999999999999999999999999.999999999"))) .setTestNumericStr( BigDecimalByteStringEncoder.encodeToNumericByteString(new BigDecimal("12.4"))) - .setTestNumericInt( + .setTestNumericShort( BigDecimalByteStringEncoder.encodeToNumericByteString(new BigDecimal(1))) + .setTestNumericInt( + BigDecimalByteStringEncoder.encodeToNumericByteString(new BigDecimal(2))) .setTestNumericLong( - BigDecimalByteStringEncoder.encodeToNumericByteString(new BigDecimal(1L))) + BigDecimalByteStringEncoder.encodeToNumericByteString(new BigDecimal(3L))) .setTestNumericFloat( - BigDecimalByteStringEncoder.encodeToNumericByteString(new BigDecimal(1f))) + BigDecimalByteStringEncoder.encodeToNumericByteString(new BigDecimal(4f))) .setTestNumericDouble( - BigDecimalByteStringEncoder.encodeToNumericByteString(new BigDecimal(1D))) + BigDecimalByteStringEncoder.encodeToNumericByteString(new BigDecimal(5D))) .setTestBignumeric( BigDecimalByteStringEncoder.encodeToBigNumericByteString( new BigDecimal("578960446186580977117854925043439539266.3"))) .addTestBignumericStr( BigDecimalByteStringEncoder.encodeToBigNumericByteString(new BigDecimal("1.23"))) - .setTestBignumericInt( + .setTestBignumericShort( BigDecimalByteStringEncoder.encodeToBigNumericByteString(new BigDecimal(1))) + .setTestBignumericInt( + BigDecimalByteStringEncoder.encodeToBigNumericByteString(new BigDecimal(2))) .setTestBignumericLong( - BigDecimalByteStringEncoder.encodeToBigNumericByteString(new BigDecimal(1L))) + BigDecimalByteStringEncoder.encodeToBigNumericByteString(new BigDecimal(3L))) .setTestBignumericFloat( - BigDecimalByteStringEncoder.encodeToBigNumericByteString(new BigDecimal(1f))) + BigDecimalByteStringEncoder.encodeToBigNumericByteString(new BigDecimal(4f))) .setTestBignumericDouble( - BigDecimalByteStringEncoder.encodeToBigNumericByteString(new BigDecimal(1D))) + BigDecimalByteStringEncoder.encodeToBigNumericByteString(new BigDecimal(5D))) .setTestInterval("0-0 0 0:0:0.000005") .addTestJson("{'a':'b'}") .build(); @@ -968,19 +986,21 @@ public void testStructComplex() throws Exception { json.put("test_time", CivilTimeEncoder.encodePacked64TimeMicros(LocalTime.of(1, 0, 1))); json.put("test_time_str", "20:51:10.1234"); json.put("test_numeric_str", "12.4"); - json.put("test_numeric_int", 1); - json.put("test_numeric_long", 1L); - json.put("test_numeric_float", 1f); - json.put("test_numeric_double", 1D); + json.put("test_numeric_short", 1); + json.put("test_numeric_int", 2); + json.put("test_numeric_long", 3L); + json.put("test_numeric_float", 4f); + json.put("test_numeric_double", 5D); json.put( "test_bignumeric", BigDecimalByteStringEncoder.encodeToBigNumericByteString( new BigDecimal("578960446186580977117854925043439539266.3"))); json.put("test_bignumeric_str", new JSONArray(new String[] {"1.23"})); - json.put("test_bignumeric_int", 1); - json.put("test_bignumeric_long", 1L); - json.put("test_bignumeric_float", 1f); - json.put("test_bignumeric_double", 1D); + json.put("test_bignumeric_short", 1); + json.put("test_bignumeric_int", 2); + json.put("test_bignumeric_long", 3L); + json.put("test_bignumeric_float", 4f); + json.put("test_bignumeric_double", 5D); json.put("test_interval", "0-0 0 0:0:0.000005"); json.put("test_json", new JSONArray(new String[] {"{'a':'b'}"})); DynamicMessage protoMsg = diff --git a/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1beta2/BQTableSchemaToProtoDescriptorTest.java b/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1beta2/BQTableSchemaToProtoDescriptorTest.java index ec92606cb2..8e08418237 100644 --- a/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1beta2/BQTableSchemaToProtoDescriptorTest.java +++ b/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1beta2/BQTableSchemaToProtoDescriptorTest.java @@ -233,6 +233,12 @@ public void testStructComplex() throws Exception { .setMode(TableFieldSchema.Mode.NULLABLE) .setName("test_numeric_str") .build(); + final TableFieldSchema TEST_NUMERIC_SHORT = + TableFieldSchema.newBuilder() + .setType(TableFieldSchema.Type.NUMERIC) + .setMode(TableFieldSchema.Mode.NULLABLE) + .setName("test_numeric_short") + .build(); final TableFieldSchema TEST_NUMERIC_INT = TableFieldSchema.newBuilder() .setType(TableFieldSchema.Type.NUMERIC) @@ -269,6 +275,13 @@ public void testStructComplex() throws Exception { .setMode(TableFieldSchema.Mode.REPEATED) .setName("test_bignumeric_str") .build(); + + final TableFieldSchema TEST_BIGNUMERIC_SHORT = + TableFieldSchema.newBuilder() + .setType(TableFieldSchema.Type.NUMERIC) + .setMode(TableFieldSchema.Mode.NULLABLE) + .setName("test_bignumeric_short") + .build(); final TableFieldSchema TEST_BIGNUMERIC_INT = TableFieldSchema.newBuilder() .setType(TableFieldSchema.Type.NUMERIC) @@ -324,18 +337,20 @@ public void testStructComplex() throws Exception { .addFields(14, TEST_TIME_STR) .addFields(15, TEST_NUMERIC_REPEATED) .addFields(16, TEST_NUMERIC_STR) - .addFields(17, TEST_NUMERIC_INT) - .addFields(18, TEST_NUMERIC_LONG) - .addFields(19, TEST_NUMERIC_FLOAT) - .addFields(20, TEST_NUMERIC_DOUBLE) - .addFields(21, TEST_BIGNUMERIC) - .addFields(22, TEST_BIGNUMERIC_STR) - .addFields(23, TEST_BIGNUMERIC_INT) - .addFields(24, TEST_BIGNUMERIC_FLOAT) - .addFields(25, TEST_BIGNUMERIC_DOUBLE) - .addFields(26, TEST_BIGNUMERIC_LONG) - .addFields(27, TEST_INTERVAL) - .addFields(28, TEST_JSON) + .addFields(17, TEST_NUMERIC_SHORT) + .addFields(18, TEST_NUMERIC_INT) + .addFields(19, TEST_NUMERIC_LONG) + .addFields(20, TEST_NUMERIC_FLOAT) + .addFields(21, TEST_NUMERIC_DOUBLE) + .addFields(22, TEST_BIGNUMERIC) + .addFields(23, TEST_BIGNUMERIC_STR) + .addFields(24, TEST_BIGNUMERIC_SHORT) + .addFields(25, TEST_BIGNUMERIC_INT) + .addFields(26, TEST_BIGNUMERIC_FLOAT) + .addFields(27, TEST_BIGNUMERIC_DOUBLE) + .addFields(28, TEST_BIGNUMERIC_LONG) + .addFields(29, TEST_INTERVAL) + .addFields(30, TEST_JSON) .build(); final Descriptor descriptor = BQTableSchemaToProtoDescriptor.convertBQTableSchemaToProtoDescriptor(tableSchema); diff --git a/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1beta2/JsonToProtoMessageTest.java b/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1beta2/JsonToProtoMessageTest.java index f6f20323cc..bcdeda813b 100644 --- a/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1beta2/JsonToProtoMessageTest.java +++ b/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1beta2/JsonToProtoMessageTest.java @@ -386,6 +386,12 @@ public class JsonToProtoMessageTest { .setMode(TableFieldSchema.Mode.NULLABLE) .setName("test_numeric_str") .build(); + private final TableFieldSchema TEST_NUMERIC_SHORT = + TableFieldSchema.newBuilder() + .setType(TableFieldSchema.Type.NUMERIC) + .setMode(TableFieldSchema.Mode.NULLABLE) + .setName("test_numeric_short") + .build(); private final TableFieldSchema TEST_NUMERIC_INT = TableFieldSchema.newBuilder() .setType(TableFieldSchema.Type.NUMERIC) @@ -422,6 +428,13 @@ public class JsonToProtoMessageTest { .setMode(TableFieldSchema.Mode.REPEATED) .setName("test_bignumeric_str") .build(); + + private final TableFieldSchema TEST_BIGNUMERIC_SHORT = + TableFieldSchema.newBuilder() + .setType(TableFieldSchema.Type.NUMERIC) + .setMode(TableFieldSchema.Mode.NULLABLE) + .setName("test_bignumeric_short") + .build(); private final TableFieldSchema TEST_BIGNUMERIC_INT = TableFieldSchema.newBuilder() .setType(TableFieldSchema.Type.NUMERIC) @@ -477,18 +490,20 @@ public class JsonToProtoMessageTest { .addFields(14, TEST_TIME_STR) .addFields(15, TEST_NUMERIC_REPEATED) .addFields(16, TEST_NUMERIC_STR) - .addFields(17, TEST_NUMERIC_INT) - .addFields(18, TEST_NUMERIC_LONG) - .addFields(19, TEST_NUMERIC_FLOAT) - .addFields(20, TEST_NUMERIC_DOUBLE) - .addFields(21, TEST_BIGNUMERIC) - .addFields(22, TEST_BIGNUMERIC_STR) - .addFields(23, TEST_BIGNUMERIC_INT) - .addFields(24, TEST_BIGNUMERIC_LONG) - .addFields(25, TEST_BIGNUMERIC_FLOAT) - .addFields(26, TEST_BIGNUMERIC_DOUBLE) - .addFields(27, TEST_INTERVAL) - .addFields(28, TEST_JSON) + .addFields(17, TEST_NUMERIC_SHORT) + .addFields(18, TEST_NUMERIC_INT) + .addFields(19, TEST_NUMERIC_LONG) + .addFields(20, TEST_NUMERIC_FLOAT) + .addFields(21, TEST_NUMERIC_DOUBLE) + .addFields(22, TEST_BIGNUMERIC) + .addFields(23, TEST_BIGNUMERIC_STR) + .addFields(24, TEST_BIGNUMERIC_SHORT) + .addFields(25, TEST_BIGNUMERIC_INT) + .addFields(26, TEST_BIGNUMERIC_LONG) + .addFields(27, TEST_BIGNUMERIC_FLOAT) + .addFields(28, TEST_BIGNUMERIC_DOUBLE) + .addFields(29, TEST_INTERVAL) + .addFields(30, TEST_JSON) .build(); @Test @@ -791,26 +806,30 @@ public void testStructComplex() throws Exception { new BigDecimal("-99999999999999999999999999999.999999999"))) .setTestNumericStr( BigDecimalByteStringEncoder.encodeToNumericByteString(new BigDecimal("12.4"))) - .setTestNumericInt( + .setTestNumericShort( BigDecimalByteStringEncoder.encodeToNumericByteString(new BigDecimal(1))) + .setTestNumericInt( + BigDecimalByteStringEncoder.encodeToNumericByteString(new BigDecimal(2))) .setTestNumericLong( - BigDecimalByteStringEncoder.encodeToNumericByteString(new BigDecimal(1L))) + BigDecimalByteStringEncoder.encodeToNumericByteString(new BigDecimal(3L))) .setTestNumericFloat( - BigDecimalByteStringEncoder.encodeToNumericByteString(new BigDecimal(1f))) + BigDecimalByteStringEncoder.encodeToNumericByteString(new BigDecimal(4f))) .setTestNumericDouble( - BigDecimalByteStringEncoder.encodeToNumericByteString(new BigDecimal(1D))) + BigDecimalByteStringEncoder.encodeToNumericByteString(new BigDecimal(5D))) .setTestBignumeric( BigDecimalByteStringEncoder.encodeToNumericByteString(new BigDecimal("2.3"))) .addTestBignumericStr( BigDecimalByteStringEncoder.encodeToNumericByteString(new BigDecimal("1.23"))) - .setTestBignumericInt( + .setTestBignumericShort( BigDecimalByteStringEncoder.encodeToNumericByteString(new BigDecimal(1))) + .setTestBignumericInt( + BigDecimalByteStringEncoder.encodeToNumericByteString(new BigDecimal(2))) .setTestBignumericLong( - BigDecimalByteStringEncoder.encodeToNumericByteString(new BigDecimal(1L))) + BigDecimalByteStringEncoder.encodeToNumericByteString(new BigDecimal(3L))) .setTestBignumericFloat( - BigDecimalByteStringEncoder.encodeToNumericByteString(new BigDecimal(1f))) + BigDecimalByteStringEncoder.encodeToNumericByteString(new BigDecimal(4f))) .setTestBignumericDouble( - BigDecimalByteStringEncoder.encodeToNumericByteString(new BigDecimal(1D))) + BigDecimalByteStringEncoder.encodeToNumericByteString(new BigDecimal(5D))) .setTestInterval("0-0 0 0:0:0.000005") .addTestJson("{'a':'b'}") .build(); @@ -855,18 +874,20 @@ public void testStructComplex() throws Exception { json.put("test_time", CivilTimeEncoder.encodePacked64TimeMicros(LocalTime.of(1, 0, 1))); json.put("test_time_str", "20:51:10.1234"); json.put("test_numeric_str", "12.4"); - json.put("test_numeric_int", 1); - json.put("test_numeric_long", 1L); - json.put("test_numeric_float", 1f); - json.put("test_numeric_double", 1D); + json.put("test_numeric_short", 1); + json.put("test_numeric_int", 2); + json.put("test_numeric_long", 3L); + json.put("test_numeric_float", 4f); + json.put("test_numeric_double", 5D); json.put( "test_bignumeric", BigDecimalByteStringEncoder.encodeToNumericByteString(BigDecimal.valueOf(2.3))); json.put("test_bignumeric_str", new JSONArray(new String[] {"1.23"})); - json.put("test_bignumeric_int", 1); - json.put("test_bignumeric_long", 1L); - json.put("test_bignumeric_float", 1f); - json.put("test_bignumeric_double", 1D); + json.put("test_bignumeric_short", 1); + json.put("test_bignumeric_int", 2); + json.put("test_bignumeric_long", 3L); + json.put("test_bignumeric_float", 4f); + json.put("test_bignumeric_double", 5D); json.put("test_interval", "0-0 0 0:0:0.000005"); json.put("test_json", new JSONArray(new String[] {"{'a':'b'}"})); DynamicMessage protoMsg = diff --git a/google-cloud-bigquerystorage/src/test/proto/jsonTest.proto b/google-cloud-bigquerystorage/src/test/proto/jsonTest.proto index 0b9292e03a..03209d9c81 100644 --- a/google-cloud-bigquerystorage/src/test/proto/jsonTest.proto +++ b/google-cloud-bigquerystorage/src/test/proto/jsonTest.proto @@ -21,18 +21,20 @@ message ComplexRoot { optional int64 test_time_str = 15; repeated bytes test_numeric_repeated = 16; optional bytes test_numeric_str = 17; - optional bytes test_numeric_int = 18; - optional bytes test_numeric_long = 19; - optional bytes test_numeric_float = 20; - optional bytes test_numeric_double = 21; - optional bytes test_bignumeric = 22; - repeated bytes test_bignumeric_str = 23; - optional bytes test_bignumeric_int = 24; - optional bytes test_bignumeric_long = 25; - optional bytes test_bignumeric_float = 26; - optional bytes test_bignumeric_double = 27; - optional string test_interval = 28; - repeated string test_json = 29; + optional bytes test_numeric_short = 18; + optional bytes test_numeric_int = 19; + optional bytes test_numeric_long = 20; + optional bytes test_numeric_float = 21; + optional bytes test_numeric_double = 22; + optional bytes test_bignumeric = 23; + repeated bytes test_bignumeric_str = 24; + optional bytes test_bignumeric_short = 25; + optional bytes test_bignumeric_int = 26; + optional bytes test_bignumeric_long = 27; + optional bytes test_bignumeric_float = 28; + optional bytes test_bignumeric_double = 29; + optional string test_interval = 30; + repeated string test_json = 31; } message CasingComplex {