Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,11 @@ private Map<String, Object> fetchSpannerRecord(
*/
private void marshalSpannerValues(
ObjectNode newValuesJsonNode, String tableName, String colName, Struct row) {
if (row.isNull(colName)) {
newValuesJsonNode.putNull(colName);
return;
}

// TODO(b/430495490): Add support for string arrays on Spanner side.
switch (ddl.table(tableName).column(colName).type().getCode()) {
case FLOAT32:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,24 @@ private void writeRowsInSpanner() {
.to(Value.bytes(ByteArray.copyFrom("varbinary")))
.set("bit_column")
.to(Value.bytes(ByteArray.copyFrom("a")))
.set("null_string_column")
.to((String) null)
.set("null_int_column")
.to((Long) null)
.set("null_date_column")
.to((Date) null)
.set("null_float_64_column")
.to((Double) null)
.set("null_float_32_column")
.to((Float) null)
.set("null_numeric_column")
.to((BigDecimal) null)
.set("null_timestamp_column")
.to((Timestamp) null)
.set("null_blob_column")
.to((ByteArray) null)
.set("null_bool_column")
.to((Boolean) null)
.build();
spannerResourceManager.write(m);

Expand Down Expand Up @@ -423,6 +441,15 @@ private void assertReadRowInMySQL(Map<String, Object> row)
() ->
assertThat(row.get("varbinary_column"))
.isEqualTo("varbinary".getBytes(StandardCharsets.UTF_8)),
() -> assertThat(row.get("bit_column")).isEqualTo("a".getBytes(StandardCharsets.UTF_8)));
() -> assertThat(row.get("bit_column")).isEqualTo("a".getBytes(StandardCharsets.UTF_8)),
() -> assertThat(row.get("null_string_column")).isNull(),
() -> assertThat(row.get("null_int_column")).isNull(),
() -> assertThat(row.get("null_date_column")).isNull(),
() -> assertThat(row.get("null_float_64_column")).isNull(),
() -> assertThat(row.get("null_float_32_column")).isNull(),
() -> assertThat(row.get("null_numeric_column")).isNull(),
() -> assertThat(row.get("null_timestamp_column")).isNull(),
() -> assertThat(row.get("null_blob_column")).isNull(),
() -> assertThat(row.get("null_bool_column")).isNull());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,12 @@ private void mockSpannerReadRow() {
when(mockRow.getValue("accountId")).thenReturn(Value.string("Id1"));
when(mockRow.getValue("accountName")).thenReturn(Value.string("xyz"));
when(mockRow.getValue("migration_shard_id")).thenReturn(Value.string("shard1"));
when(mockRow.isNull("string_col_null")).thenReturn(true);
when(mockRow.getValue("accountNumber")).thenReturn(Value.int64(1));
when(mockRow.isNull("int_64_col_null")).thenReturn(true);
when(mockRow.getValue("bytesCol"))
.thenReturn(Value.bytes(ByteArray.copyFrom("GOOGLE".getBytes())));
when(mockRow.isNull("bytes_col_null")).thenReturn(true);
when(mockRow.getDouble("float_64_col")).thenReturn(0.5);
when(mockRow.getValue("float_64_col")).thenReturn(Value.float64(0.5));
when(mockRow.getDouble("float_64_col_nan")).thenReturn(Double.NaN);
Expand All @@ -119,6 +122,7 @@ private void mockSpannerReadRow() {
when(mockRow.getDouble("float_64_col_neg_infinity")).thenReturn(Double.NEGATIVE_INFINITY);
when(mockRow.getValue("float_64_col_neg_infinity"))
.thenReturn(Value.float64(Double.NEGATIVE_INFINITY));
when(mockRow.isNull("float_64_col_null")).thenReturn(true);
when(mockRow.getValue("float_32_col")).thenReturn(Value.float32(0.5f));
when(mockRow.getFloat("float_32_col")).thenReturn(0.5f);
when(mockRow.getFloat("float_32_col_nan")).thenReturn(Float.NaN);
Expand All @@ -129,8 +133,11 @@ private void mockSpannerReadRow() {
when(mockRow.getFloat("float_32_col_neg_infinity")).thenReturn(Float.NEGATIVE_INFINITY);
when(mockRow.getValue("float_32_col_neg_infinity"))
.thenReturn(Value.float32(Float.NEGATIVE_INFINITY));
when(mockRow.isNull("float_32_col_null")).thenReturn(true);
when(mockRow.getBoolean("bool_col")).thenReturn(true);
when(mockRow.getValue("bool_col")).thenReturn(Value.bool(true));
when(mockRow.isNull("bool_col_null")).thenReturn(true);
when(mockRow.isNull("timestamp_col_null")).thenReturn(true);

// Mock readRow
when(mockReadOnlyTransaction.readRow(eq("tableName"), any(Key.class), any(Iterable.class)))
Expand Down Expand Up @@ -224,7 +231,7 @@ public void testProcessElementInsertModForMultiShard() throws Exception {
assignShardIdFn.processElement(processContext);

String newValuesJson =
"{\"float_32_col_nan\":\"NaN\",\"bool_col\":true,\"accountName\":\"xyz\",\"float_64_col_neg_infinity\":\"-Infinity\",\"float_32_col_neg_infinity\":\"-Infinity\",\"accountNumber\":\"1\",\"bytesCol\":\"R09PR0xF\",\"accountId\":\"Id1\",\"migration_shard_id\":\"shard1\",\"float_64_col\":0.5,\"float_32_col_infinity\":\"Infinity\",\"float_32_col\":0.5,\"float_64_col_infinity\":\"Infinity\",\"float_64_col_nan\":\"NaN\"}";
"{\"bool_col_null\":null,\"float_32_col_nan\":\"NaN\",\"bool_col\":true,\"timestamp_col_null\":null,\"accountName\":\"xyz\",\"float_64_col_neg_infinity\":\"-Infinity\",\"float_32_col_neg_infinity\":\"-Infinity\",\"bytes_col_null\":null,\"string_col_null\":null,\"accountNumber\":\"1\",\"bytesCol\":\"R09PR0xF\",\"accountId\":\"Id1\",\"migration_shard_id\":\"shard1\",\"int_64_col_null\":null,\"float_64_col\":0.5,\"float_32_col_infinity\":\"Infinity\",\"float_32_col\":0.5,\"float_64_col_infinity\":\"Infinity\",\"float_64_col_null\":null,\"float_64_col_nan\":\"NaN\",\"float_32_col_null\":null}";

record.setMod(
new Mod(record.getMod().getKeysJson(), record.getMod().getOldValuesJson(), newValuesJson));
Expand Down Expand Up @@ -264,7 +271,7 @@ public void testProcessElementDeleteModForMultiShard() throws Exception {
Long key = keyStr.hashCode() % 10000L;

String newValuesJson =
"{\"float_32_col_nan\":\"NaN\",\"bool_col\":true,\"accountName\":\"xyz\",\"float_64_col_neg_infinity\":\"-Infinity\",\"float_32_col_neg_infinity\":\"-Infinity\",\"accountNumber\":\"1\",\"bytesCol\":\"R09PR0xF\",\"accountId\":\"Id1\",\"migration_shard_id\":\"shard1\",\"float_64_col\":0.5,\"float_32_col_infinity\":\"Infinity\",\"float_32_col\":0.5,\"float_64_col_infinity\":\"Infinity\",\"float_64_col_nan\":\"NaN\"}";
"{\"bool_col_null\":null,\"float_32_col_nan\":\"NaN\",\"bool_col\":true,\"timestamp_col_null\":null,\"accountName\":\"xyz\",\"float_64_col_neg_infinity\":\"-Infinity\",\"float_32_col_neg_infinity\":\"-Infinity\",\"bytes_col_null\":null,\"string_col_null\":null,\"accountNumber\":\"1\",\"bytesCol\":\"R09PR0xF\",\"accountId\":\"Id1\",\"migration_shard_id\":\"shard1\",\"int_64_col_null\":null,\"float_64_col\":0.5,\"float_32_col_infinity\":\"Infinity\",\"float_32_col\":0.5,\"float_64_col_infinity\":\"Infinity\",\"float_64_col_null\":null,\"float_64_col_nan\":\"NaN\",\"float_32_col_null\":null}";

record.setMod(
new Mod(record.getMod().getKeysJson(), record.getMod().getOldValuesJson(), newValuesJson));
Expand Down Expand Up @@ -806,9 +813,16 @@ private static Ddl getTestDdl() {
.string()
.max()
.endColumn()
.column("string_col_null")
.string()
.max()
.endColumn()
.column("accountNumber")
.int64()
.endColumn()
.column("int_64_col_null")
.int64()
.endColumn()
.column("bytesCol")
.bytes()
.endColumn()
Expand All @@ -824,16 +838,7 @@ private static Ddl getTestDdl() {
.column("float_64_col_neg_infinity")
.float64()
.endColumn()
.column("float_64_col")
.float64()
.endColumn()
.column("float_64_col_nan")
.float64()
.endColumn()
.column("float_64_col_infinity")
.float64()
.endColumn()
.column("float_64_col_neg_infinity")
.column("float_64_col_null")
.float64()
.endColumn()
.column("float_32_col")
Expand All @@ -848,9 +853,21 @@ private static Ddl getTestDdl() {
.column("float_32_col_neg_infinity")
.float32()
.endColumn()
.column("float_32_col_null")
.float32()
.endColumn()
.column("bool_col")
.bool()
.endColumn()
.column("bool_col_null")
.bool()
.endColumn()
.column("bytes_col_null")
.bytes()
.endColumn()
.column("timestamp_col_null")
.timestamp()
.endColumn()
// Non-stored Generated Column should not affect any flows
.column("non_stored_gen_column")
.int64()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,16 @@ CREATE TABLE `AllDatatypeColumns` (
`other_bool_column` tinyint(1),
`binary_column` binary(10),
`varbinary_column` varbinary(20),
`bit_column` bit(7),
`bit_column` bit(7),
`null_string_column` varchar(128),
`null_int_column` bigint,
`null_date_column` date,
`null_float_64_column` double,
`null_float_32_column` float(10,2),
`null_numeric_column` decimal(10,2),
`null_timestamp_column` timestamp,
`null_blob_column` varbinary(20),
`null_bool_column` tinyint(1),
PRIMARY KEY (`varchar_column`)
);

Expand Down
Loading
Loading