Skip to content

Commit 0302648

Browse files
support BOOL type mapped as NUMERIC (Int64)
1 parent 4894f74 commit 0302648

File tree

5 files changed

+26
-1
lines changed

5 files changed

+26
-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
@@ -375,6 +375,7 @@ private ImmutableMap<String, SourceColumnType> getTableCols(
375375
.put("TINYTEXT", IndexType.STRING)
376376
.put("DATETIME", IndexType.TIME_STAMP)
377377
.put("TIMESTAMP", IndexType.TIME_STAMP)
378+
.put("BOOL", IndexType.NUMERIC)
378379
.build();
379380

380381
/**

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

Lines changed: 11 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", "char", "varbinary", "binary");
283+
ImmutableList.of("float", "integer", "char", "varbinary", "binary", "bool");
284284
ImmutableList<SourceColumnIndexInfo> expectedSourceColumnIndexInfos =
285285
ImmutableList.of(
286286
SourceColumnIndexInfo.builder()
@@ -335,6 +335,16 @@ public void testDiscoverIndexesBasic() throws SQLException, RetriableSchemaDisco
335335
.setIndexType(IndexType.BINARY)
336336
.setOrdinalPosition(4)
337337
.build());
338+
SourceColumnIndexInfo.builder()
339+
.setColumnName("testColBool")
340+
.setIndexName("primary")
341+
.setIsUnique(true)
342+
.setIsPrimary(true)
343+
.setCardinality(2L)
344+
.setIndexType(IndexType.NUMERIC)
345+
.setOrdinalPosition(5)
346+
.build(),
347+
338348

339349
final JdbcSchemaReference sourceSchemaReference =
340350
JdbcSchemaReference.builder().setDbName("testDB").build();

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
@@ -273,6 +273,7 @@ private Map<String, List<Map<String, Object>>> getExpectedData() {
273273
"2005-01-01T00:01:54.123456000Z",
274274
"2037-12-30T23:59:59Z",
275275
"2038-01-18T23:59:59Z"));
276+
expectedData.put("bool_pk", createRows("bool_pk", "0", "2", "1"));
276277
return expectedData;
277278
}
278279

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
@@ -272,6 +272,12 @@ CREATE TABLE timestamp_pk_table (
272272
CONSTRAINT PRIMARY KEY (id)
273273
);
274274

275+
CREATE TABLE bool_pk_table (
276+
id BOOL PRIMARY KEY,
277+
bool_pk_col BOOL NOT NULL
278+
);
279+
280+
275281
ALTER TABLE `bigint_table` MODIFY `id` INT AUTO_INCREMENT;
276282
ALTER TABLE `bigint_unsigned_table` MODIFY `id` INT AUTO_INCREMENT;
277283
ALTER TABLE `binary_table` MODIFY `id` INT AUTO_INCREMENT;
@@ -423,6 +429,8 @@ SET time_zone = 'Asia/Kolkata';
423429
INSERT INTO `timestamp_pk_table` (`id`, `timestamp_pk_col`) VALUES ('2005-01-01 05:31:54.123456', '2005-01-01 05:31:54.123456');
424430
SET time_zone = SYSTEM;
425431

432+
INSERT INTO `bool_pk_table` (`id`, `bool_pk_col`) VALUES (TRUE, TRUE), (FALSE, FALSE);
433+
426434
INSERT INTO `bigint_table` (`bigint_col`) VALUES (NULL);
427435
INSERT INTO `bigint_unsigned_table` (`bigint_unsigned_col`) VALUES (NULL);
428436
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
@@ -300,3 +300,8 @@ CREATE TABLE IF NOT EXISTS timestamp_pk_table (
300300
id TIMESTAMP NOT NULL,
301301
timestamp_pk_col TIMESTAMP NOT NULL,
302302
) PRIMARY KEY(id);
303+
304+
CREATE TABLE IF NOT EXISTS bool_pk_table (
305+
id INT64 NOT NULL,
306+
bool_pk_col INT64 NOT NULL,
307+
) PRIMARY KEY(id);

0 commit comments

Comments
 (0)