Skip to content

Commit

Permalink
feat(shortsAndBigDecimals): add shorts and big decimals (#1674)
Browse files Browse the repository at this point in the history
* feat(shortsAndBigDecimals): add shorts and big decimals

Signed-off-by: dark0dave <[email protected]>

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

Signed-off-by: dark0dave <[email protected]>
Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
Co-authored-by: Neenu Shaji <[email protected]>
  • Loading branch information
3 people authored Oct 17, 2022
1 parent 5159cf0 commit 604d7df
Show file tree
Hide file tree
Showing 6 changed files with 188 additions and 96 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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) {
Expand All @@ -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(
Expand All @@ -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;
}
}
}
Expand Down Expand Up @@ -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(
Expand All @@ -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) {
Expand All @@ -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(
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down
Loading

0 comments on commit 604d7df

Please sign in to comment.