Skip to content

Commit 301cd41

Browse files
add support for year as a primary key (#3059)
* add YEAR mapping * orrect expectedData for YEAR column * fix spotless error
1 parent cdd3164 commit 301cd41

File tree

5 files changed

+22
-1
lines changed

5 files changed

+22
-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("YEAR", IndexType.NUMERIC)
379380
.build();
380381

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");
283+
ImmutableList.of("float", "integer", "bit", "char", "varbinary", "binary", "year");
284284
ImmutableList<SourceColumnIndexInfo> expectedSourceColumnIndexInfos =
285285
ImmutableList.of(
286286
SourceColumnIndexInfo.builder()
@@ -344,6 +344,15 @@ public void testDiscoverIndexesBasic() throws SQLException, RetriableSchemaDisco
344344
.setIndexType(IndexType.BINARY)
345345
.setOrdinalPosition(4)
346346
.build());
347+
SourceColumnIndexInfo.builder()
348+
.setColumnName("testColYear")
349+
.setIndexName("primary")
350+
.setIsUnique(true)
351+
.setIsPrimary(true)
352+
.setCardinality(100L)
353+
.setIndexType(IndexType.NUMERIC)
354+
.setOrdinalPosition(6)
355+
.build();
347356

348357
final JdbcSchemaReference sourceSchemaReference =
349358
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
@@ -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("year_pk", createRows("year_pk", "1901", "2000"));
280281
return expectedData;
281282
}
282283

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,10 @@ CREATE TABLE timestamp_pk_table (
291291
timestamp_pk_col TIMESTAMP(6) NOT NULL,
292292
CONSTRAINT PRIMARY KEY (id)
293293
);
294+
CREATE TABLE year_pk_table (
295+
id YEAR PRIMARY KEY,
296+
year_pk_col YEAR NOT NULL
297+
);
294298

295299
ALTER TABLE `bigint_table` MODIFY `id` INT AUTO_INCREMENT;
296300
ALTER TABLE `bigint_unsigned_table` MODIFY `id` INT AUTO_INCREMENT;
@@ -448,6 +452,7 @@ INSERT INTO `timestamp_pk_table` (`id`, `timestamp_pk_col`) VALUES ('1970-01-01
448452
SET time_zone = 'Asia/Kolkata';
449453
INSERT INTO `timestamp_pk_table` (`id`, `timestamp_pk_col`) VALUES ('2005-01-01 05:31:54.123456', '2005-01-01 05:31:54.123456');
450454
SET time_zone = SYSTEM;
455+
INSERT INTO `year_pk_table` (`id`, `year_pk_col`) VALUES (1901, 1901), (2000, 2000);
451456

452457
INSERT INTO `bigint_table` (`bigint_col`) VALUES (NULL);
453458
INSERT INTO `bigint_unsigned_table` (`bigint_unsigned_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
@@ -322,3 +322,8 @@ CREATE TABLE IF NOT EXISTS timestamp_pk_table (
322322
id TIMESTAMP NOT NULL,
323323
timestamp_pk_col TIMESTAMP NOT NULL,
324324
) PRIMARY KEY(id);
325+
326+
CREATE TABLE IF NOT EXISTS year_pk_table (
327+
id INT64 NOT NULL,
328+
year_pk_col INT64 NOT NULL,
329+
) PRIMARY KEY(id);

0 commit comments

Comments
 (0)