1818import static com .google .cloud .teleport .v2 .spanner .migrations .constants .Constants .CASSANDRA_SOURCE_TYPE ;
1919import static com .google .cloud .teleport .v2 .spanner .migrations .constants .Constants .MYSQL_SOURCE_TYPE ;
2020
21+ import com .datastax .oss .driver .api .core .CqlSession ;
2122import com .google .cloud .Timestamp ;
2223import com .google .cloud .teleport .metadata .Template ;
2324import com .google .cloud .teleport .metadata .TemplateCategory ;
4142import com .google .cloud .teleport .v2 .spanner .migrations .utils .SecretManagerAccessorImpl ;
4243import com .google .cloud .teleport .v2 .spanner .migrations .utils .SessionFileReader ;
4344import com .google .cloud .teleport .v2 .spanner .migrations .utils .ShardFileReader ;
45+ import com .google .cloud .teleport .v2 .spanner .sourceddl .CassandraInformationSchemaScanner ;
46+ import com .google .cloud .teleport .v2 .spanner .sourceddl .MySqlInformationSchemaScanner ;
47+ import com .google .cloud .teleport .v2 .spanner .sourceddl .SourceInformationSchemaScanner ;
48+ import com .google .cloud .teleport .v2 .spanner .sourceddl .SourceSchema ;
4449import com .google .cloud .teleport .v2 .templates .SpannerToSourceDb .Options ;
4550import com .google .cloud .teleport .v2 .templates .changestream .TrimmedShardedDataChangeRecord ;
4651import com .google .cloud .teleport .v2 .templates .constants .Constants ;
52+ import com .google .cloud .teleport .v2 .templates .dbutils .processor .SourceProcessorFactory ;
53+ import com .google .cloud .teleport .v2 .templates .exceptions .ConnectionException ;
54+ import com .google .cloud .teleport .v2 .templates .exceptions .UnsupportedSourceException ;
4755import com .google .cloud .teleport .v2 .templates .transforms .AssignShardIdFn ;
4856import com .google .cloud .teleport .v2 .templates .transforms .ConvertChangeStreamErrorRecordToFailsafeElementFn ;
4957import com .google .cloud .teleport .v2 .templates .transforms .ConvertDlqRecordToTrimmedShardedDataChangeRecordFn ;
5664import com .google .cloud .teleport .v2 .transforms .DLQWriteTransform ;
5765import com .google .cloud .teleport .v2 .values .FailsafeElement ;
5866import com .google .common .base .Strings ;
67+ import java .sql .Connection ;
5968import java .util .ArrayList ;
6069import java .util .Arrays ;
6170import java .util .List ;
@@ -551,6 +560,33 @@ public static PipelineResult run(Options options) {
551560 LOG .info ("Cassandra config is: {}" , shards .get (0 ));
552561 shardingMode = Constants .SHARDING_MODE_SINGLE_SHARD ;
553562 }
563+ SourceInformationSchemaScanner scanner = null ;
564+ try {
565+ SourceProcessorFactory .initializeConnectionHelper (
566+ options .getSourceType (), shards , connectionPoolSizePerWorker );
567+ if (options .getSourceType ().equals (MYSQL_SOURCE_TYPE )) {
568+ Connection connection =
569+ (Connection )
570+ SourceProcessorFactory .getConnectionToShard (options .getSourceType (), shards .get (0 ));
571+ scanner = new MySqlInformationSchemaScanner (connection , shards .get (0 ).getDbName ());
572+ } else {
573+ CqlSession session =
574+ (CqlSession )
575+ SourceProcessorFactory .getConnectionToShard (options .getSourceType (), shards .get (0 ));
576+ scanner =
577+ new CassandraInformationSchemaScanner (
578+ session , ((CassandraShard ) shards .get (0 )).getKeySpaceName ());
579+ }
580+ } catch (UnsupportedSourceException e ) {
581+ LOG .error ("Unsupported source type: {}" , options .getSourceType ());
582+ throw new IllegalArgumentException (e );
583+ } catch (ConnectionException e ) {
584+ LOG .error ("Error getting connection to shard: {}" , shards .get (0 ));
585+ throw new IllegalArgumentException (e );
586+ }
587+ SourceSchema sourceSchema = scanner .scan ();
588+ LOG .info ("Source schema: {}" , sourceSchema );
589+
554590 if (shards .size () == 1 && !options .getIsShardedMigration ()) {
555591 shardingMode = Constants .SHARDING_MODE_SINGLE_SHARD ;
556592 Shard shard = shards .get (0 );
@@ -562,6 +598,7 @@ public static PipelineResult run(Options options) {
562598 }
563599
564600 if (options .getSourceType ().equals (CASSANDRA_SOURCE_TYPE )) {
601+ // TODO: Remove this once session file support is removed.
565602 Map <String , SpannerTable > spannerTableMap =
566603 SpannerSchema .convertDDLTableToSpannerTable (ddl .allTables ());
567604 Map <String , NameAndCols > spannerTableNameColsMap =
0 commit comments