Skip to content

Commit cb13298

Browse files
committed
Move schema utils to test folder and resolve comments
1 parent 142b0f1 commit cb13298

File tree

10 files changed

+327
-389
lines changed

10 files changed

+327
-389
lines changed

v2/spanner-common/src/main/java/com/google/cloud/teleport/v2/spanner/migrations/utils/SchemaUtils.java

Lines changed: 0 additions & 159 deletions
This file was deleted.

v2/spanner-common/src/test/java/com/google/cloud/teleport/v2/spanner/migrations/utils/SchemaUtilsTest.java

Lines changed: 0 additions & 135 deletions
This file was deleted.

v2/spanner-to-sourcedb/src/main/java/com/google/cloud/teleport/v2/templates/SpannerToSourceDb.java

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -563,25 +563,7 @@ public static PipelineResult run(Options options) {
563563
LOG.info("Cassandra config is: {}", shards.get(0));
564564
shardingMode = Constants.SHARDING_MODE_SINGLE_SHARD;
565565
}
566-
SourceSchemaScanner scanner = null;
567-
SourceSchema sourceSchema = null;
568-
try {
569-
if (options.getSourceType().equals(MYSQL_SOURCE_TYPE)) {
570-
Connection connection = createJdbcConnection(shards.get(0));
571-
scanner = new MySqlInformationSchemaScanner(connection, shards.get(0).getDbName());
572-
sourceSchema = scanner.scan();
573-
connection.close();
574-
} else {
575-
try (CqlSession session = createCqlSession((CassandraShard) shards.get(0))) {
576-
scanner =
577-
new CassandraInformationSchemaScanner(
578-
session, ((CassandraShard) shards.get(0)).getKeySpaceName());
579-
sourceSchema = scanner.scan();
580-
}
581-
}
582-
} catch (SQLException e) {
583-
throw new RuntimeException("Unable to discover jdbc schema", e);
584-
}
566+
SourceSchema sourceSchema = fetchSourceSchema(options, shards);
585567
LOG.info("Source schema: {}", sourceSchema);
586568

587569
if (shards.size() == 1 && !options.getIsShardedMigration()) {
@@ -892,4 +874,27 @@ private static CqlSession createCqlSession(CassandraShard cassandraShard) {
892874
builder.withConfigLoader(configLoader);
893875
return builder.build();
894876
}
877+
878+
private static SourceSchema fetchSourceSchema(Options options, List<Shard> shards) {
879+
SourceSchemaScanner scanner = null;
880+
SourceSchema sourceSchema = null;
881+
try {
882+
if (options.getSourceType().equals(MYSQL_SOURCE_TYPE)) {
883+
Connection connection = createJdbcConnection(shards.get(0));
884+
scanner = new MySqlInformationSchemaScanner(connection, shards.get(0).getDbName());
885+
sourceSchema = scanner.scan();
886+
connection.close();
887+
} else {
888+
try (CqlSession session = createCqlSession((CassandraShard) shards.get(0))) {
889+
scanner =
890+
new CassandraInformationSchemaScanner(
891+
session, ((CassandraShard) shards.get(0)).getKeySpaceName());
892+
sourceSchema = scanner.scan();
893+
}
894+
}
895+
} catch (SQLException e) {
896+
throw new RuntimeException("Unable to discover jdbc schema", e);
897+
}
898+
return sourceSchema;
899+
}
895900
}

v2/spanner-to-sourcedb/src/main/java/com/google/cloud/teleport/v2/templates/dbutils/dml/CassandraDMLGenerator.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,18 +81,18 @@ public DMLGeneratorResponse getDMLStatement(DMLGeneratorRequest dmlGeneratorRequ
8181

8282
String spannerTableName = dmlGeneratorRequest.getSpannerTableName();
8383
Schema schema = dmlGeneratorRequest.getSchema();
84-
Ddl ddl = dmlGeneratorRequest.getDdl();
84+
Ddl spannerDdl = dmlGeneratorRequest.getSpannerDdl();
8585
SourceSchema sourceSchema = dmlGeneratorRequest.getSourceSchema();
86-
if (schema == null || ddl == null || sourceSchema == null) {
86+
if (schema == null || spannerDdl == null || sourceSchema == null) {
8787
LOG.warn(
8888
"Schema, Ddl and SourceSchema must be not null, respectively found {},{},{}.",
8989
schema,
90-
ddl,
90+
spannerDdl,
9191
sourceSchema);
9292
return new DMLGeneratorResponse("");
9393
}
9494

95-
Table spannerTable = ddl.table(spannerTableName);
95+
Table spannerTable = spannerDdl.table(spannerTableName);
9696
if (spannerTable == null) {
9797
LOG.warn("Spanner table {} not found. Dropping the record.", spannerTableName);
9898
return new DMLGeneratorResponse("");

0 commit comments

Comments
 (0)