Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,6 @@

# Derby log
**/derby.log*

# build log
**/build.log*

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,7 @@ public ImmutableMap<String, ImmutableMap<String, SourceColumnType>> discoverTabl
return result.build();
}

@VisibleForTesting
protected static void convertException(Exception e) {
public static void convertException(Exception e) {
Throwable cause = e;
while (cause != null) {
if (cause instanceof SchemaDiscoveryException) {
Expand Down Expand Up @@ -226,6 +225,10 @@ protected static <T> List<List<T>> partitionWork(List<T> items, int batchSize) {
return Lists.partition(items, batchSize);
}

public static long getParallelism() {
return THREAD_POOL_SIZE;
}

private <T> T doRetries(SchemaDiscoveryOperation<T> operation) throws SchemaDiscoveryException {

BackOff backoff = this.fluentBackoff.backoff();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,14 @@ private static PCollection<SourceTableReference> getSourceTableReference(
"CreateZeroCounts." + groupName,
Create.of(
tableReferences.stream()
.map(ref -> KV.of(ref.sourceTableName(), 0L))
.map(ref -> KV.of(ref.sourceTableSchemaUUID(), 0L))
.collect(Collectors.toList())))
.setCoder(KvCoder.of(StringUtf8Coder.of(), VarLongCoder.of()));

// 2. Actual counts from the reader.
PCollection<KV<String, Long>> actualCounts =
groupRows
.apply("ExtractTableNames." + groupName, ParDo.of(new ExtractTableNameFn()))
.apply("ExtractTableNames." + groupName, ParDo.of(new ExtractTableIdFn()))
.apply("CountPerTable." + groupName, Count.perElement());

// 3. Aggregate and Emit Completions.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,9 @@
* DoFn to extract the table name from a {@link SourceRow} and delimit it to match the format used
* in {@link SourceTableReference}.
*/
class ExtractTableNameFn extends DoFn<SourceRow, String> {
class ExtractTableIdFn extends DoFn<SourceRow, String> {
@ProcessElement
public void processElement(@Element SourceRow row, OutputReceiver<String> out) {
out.output(delimitIdentifier(row.tableName()));
}

private String delimitIdentifier(String identifier) {
return "\"" + identifier.replaceAll("\"", "\"\"") + "\"";
out.output(row.tableSchemaUUID());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class GroupCompletionDoFn extends DoFn<KV<String, Long>, SourceTableReference> {
public GroupCompletionDoFn(ImmutableList<SourceTableReference> tableReferences) {
this.tableReferencesMap =
tableReferences.stream()
.collect(Collectors.toMap(SourceTableReference::sourceTableName, ref -> ref));
.collect(Collectors.toMap(SourceTableReference::sourceTableSchemaUUID, ref -> ref));
}

@ProcessElement
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ public void testSchemaDiscoveryImpl() throws RetriableSchemaDiscoveryException {
.isEqualTo(ImmutableMap.of("testTable", ImmutableMap.of()));
verify(mockRetriableSchemaDiscovery, times(expectedCallsCount))
.discoverTableSchema(any(), any(), any());
assertThat(SchemaDiscoveryImpl.getParallelism()).isEqualTo(4L);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

/** Test class for {@link ExtractTableNameFn}. */
/** Test class for {@link ExtractTableIdFn}. */
@RunWith(JUnit4.class)
public class ExtractTableNameFnTest implements Serializable {
public class ExtractTableIdFnTest implements Serializable {
@Rule public final transient TestPipeline pipeline = TestPipeline.create();

@Test
Expand All @@ -48,9 +48,9 @@ public void testExtractTableNameFn_simpleName() {
.build();

PCollection<String> output =
pipeline.apply(Create.of(row)).apply(ParDo.of(new ExtractTableNameFn()));
pipeline.apply(Create.of(row)).apply(ParDo.of(new ExtractTableIdFn()));

PAssert.that(output).containsInAnyOrder("\"table1\"");
PAssert.that(output).containsInAnyOrder(tableSchema.tableSchemaUUID());
pipeline.run();
}

Expand All @@ -66,10 +66,10 @@ public void testExtractTableNameFn_withQuotes() {
.build();

PCollection<String> output =
pipeline.apply(Create.of(row)).apply(ParDo.of(new ExtractTableNameFn()));
pipeline.apply(Create.of(row)).apply(ParDo.of(new ExtractTableIdFn()));

// Delimit logic: table"with"quotes -> "table""with""quotes"
PAssert.that(output).containsInAnyOrder("\"table\"\"with\"\"quotes\"");
// tableSchemaUUID is unique and stable
PAssert.that(output).containsInAnyOrder(tableSchema.tableSchemaUUID());
pipeline.run();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void testGroupCompletionDoFn_matchingTable() {
GroupCompletionDoFn fn = new GroupCompletionDoFn(tableReferences);

PCollection<SourceTableReference> output =
pipeline.apply(Create.of(KV.of("table1", 100L))).apply(ParDo.of(fn));
pipeline.apply(Create.of(KV.of(ref1.sourceTableSchemaUUID(), 100L))).apply(ParDo.of(fn));

PAssert.that(output).containsInAnyOrder(ref1.toBuilder().setRecordCount(100L).build());
pipeline.run();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,9 @@ public void shardedDbConfigContainerMySqlTest() {
sourceDbToSpannerOptions.setUsername(testUser);
sourceDbToSpannerOptions.setPassword(testPassword);
sourceDbToSpannerOptions.setTables("table1,table2");
mockedStaticJdbcIoWrapper.when(() -> JdbcIoWrapper.of(any())).thenReturn(mockJdbcIoWrapper);
mockedStaticJdbcIoWrapper
.when(() -> JdbcIoWrapper.of((JdbcIOWrapperConfig) any()))
.thenReturn(mockJdbcIoWrapper);

Shard shard =
new Shard("shard1", "localhost", "3306", "user", "password", null, null, null, null);
Expand Down
Loading