Skip to content

Commit 342837d

Browse files
nmemondgpalanisamyYopp
authored andcommitted
Spanner bulk data migration: Support Bool as a primary key by mapping it to IndexType.Numeric (GoogleCloudPlatform#3112)
* support BOOL type mapped as NUMERIC (Int64) * update Spanner schema and expected data for BOOL columns * fix spotless error * fix Spotless error * Update mysql-spanner-schema.sql * Fix bool_pk expected data to use boolean values --------- Co-authored-by: gpalanisamyYopp <gayathri.palanisamy@improving.com>
1 parent bed749e commit 342837d

File tree

5 files changed

+25
-1
lines changed

5 files changed

+25
-1
lines changed

v2/sourcedb-to-spanner/src/main/java/com/google/cloud/teleport/v2/source/reader/io/jdbc/dialectadapter/mysql/MysqlDialectAdapter.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,7 @@ private ImmutableMap<String, SourceColumnType> getTableCols(
376376
.put("TINYTEXT", IndexType.STRING)
377377
.put("DATETIME", IndexType.TIME_STAMP)
378378
.put("TIMESTAMP", IndexType.TIME_STAMP)
379+
.put("BOOL", IndexType.NUMERIC)
379380
.put("YEAR", IndexType.NUMERIC)
380381
.build();
381382

v2/sourcedb-to-spanner/src/test/java/com/google/cloud/teleport/v2/source/reader/io/jdbc/dialectadapter/mysql/MysqlDialectAdapterTest.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ public void testDiscoverTablesRsException() throws SQLException {
280280
public void testDiscoverIndexesBasic() throws SQLException, RetriableSchemaDiscoveryException {
281281
ImmutableList<String> testTables = ImmutableList.of("testTable1");
282282
ImmutableList<String> colTypes =
283-
ImmutableList.of("float", "integer", "bit", "char", "varbinary", "binary", "year");
283+
ImmutableList.of("float", "integer", "bit", "char", "varbinary", "binary", "year", "bool");
284284
ImmutableList<SourceColumnIndexInfo> expectedSourceColumnIndexInfos =
285285
ImmutableList.of(
286286
SourceColumnIndexInfo.builder()
@@ -343,6 +343,15 @@ public void testDiscoverIndexesBasic() throws SQLException, RetriableSchemaDisco
343343
.setCardinality(42L)
344344
.setIndexType(IndexType.BINARY)
345345
.setOrdinalPosition(4)
346+
.build(),
347+
SourceColumnIndexInfo.builder()
348+
.setColumnName("testColBool")
349+
.setIndexName("primary")
350+
.setIsUnique(true)
351+
.setIsPrimary(true)
352+
.setCardinality(2L)
353+
.setIndexType(IndexType.NUMERIC)
354+
.setOrdinalPosition(5)
346355
.build());
347356
SourceColumnIndexInfo.builder()
348357
.setColumnName("testColYear")

v2/sourcedb-to-spanner/src/test/java/com/google/cloud/teleport/v2/templates/MySQLDataTypesIT.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ private Map<String, List<Map<String, Object>>> getExpectedData() {
277277
"2005-01-01T00:01:54.123456000Z",
278278
"2037-12-30T23:59:59Z",
279279
"2038-01-18T23:59:59Z"));
280+
expectedData.put("bool_pk", createRows("bool_pk", false, true));
280281
expectedData.put("year_pk", createRows("year_pk", "1901", "2000"));
281282
return expectedData;
282283
}

v2/sourcedb-to-spanner/src/test/resources/DataTypesIT/mysql-data-types.sql

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,12 @@ CREATE TABLE year_pk_table (
296296
year_pk_col YEAR NOT NULL
297297
);
298298

299+
CREATE TABLE bool_pk_table (
300+
id BOOL PRIMARY KEY,
301+
bool_pk_col BOOL NOT NULL
302+
);
303+
304+
299305
ALTER TABLE `bigint_table` MODIFY `id` INT AUTO_INCREMENT;
300306
ALTER TABLE `bigint_unsigned_table` MODIFY `id` INT AUTO_INCREMENT;
301307
ALTER TABLE `binary_table` MODIFY `id` INT AUTO_INCREMENT;
@@ -454,6 +460,8 @@ INSERT INTO `timestamp_pk_table` (`id`, `timestamp_pk_col`) VALUES ('2005-01-01
454460
SET time_zone = SYSTEM;
455461
INSERT INTO `year_pk_table` (`id`, `year_pk_col`) VALUES (1901, 1901), (2000, 2000);
456462

463+
INSERT INTO `bool_pk_table` (`id`, `bool_pk_col`) VALUES (TRUE, TRUE), (FALSE, FALSE);
464+
457465
INSERT INTO `bigint_table` (`bigint_col`) VALUES (NULL);
458466
INSERT INTO `bigint_unsigned_table` (`bigint_unsigned_col`) VALUES (NULL);
459467
INSERT INTO `binary_table` (`binary_col`) VALUES (NULL);

v2/sourcedb-to-spanner/src/test/resources/DataTypesIT/mysql-spanner-schema.sql

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,11 @@ CREATE TABLE IF NOT EXISTS timestamp_pk_table (
323323
timestamp_pk_col TIMESTAMP NOT NULL,
324324
) PRIMARY KEY(id);
325325

326+
CREATE TABLE IF NOT EXISTS bool_pk_table (
327+
id BOOL NOT NULL,
328+
bool_pk_col BOOL NOT NULL,
329+
) PRIMARY KEY(id);
330+
326331
CREATE TABLE IF NOT EXISTS year_pk_table (
327332
id INT64 NOT NULL,
328333
year_pk_col INT64 NOT NULL,

0 commit comments

Comments
 (0)