use of com.google.cloud.teleport.v2.templates.spanner.ddl.Table in project DataflowTemplates by GoogleCloudPlatform.
the class ChangeEventConvertor method changeEventToShadowTableMutationBuilder.
static Mutation.WriteBuilder changeEventToShadowTableMutationBuilder(Ddl ddl, JsonNode changeEvent, String shadowTablePrefix) throws ChangeEventConvertorException {
String tableName = changeEvent.get(DatastreamConstants.EVENT_TABLE_NAME_KEY).asText();
String shadowTableName = shadowTablePrefix + tableName;
try {
Table table = ddl.table(shadowTableName);
ImmutableList<IndexColumn> keyColumns = table.primaryKeys();
List<String> keyColumnNames = keyColumns.stream().map(IndexColumn::name).map(colName -> colName.toLowerCase()).collect(Collectors.toList());
Set<String> requiredKeyColumnNames = new HashSet<>(keyColumnNames);
Mutation.WriteBuilder builder = Mutation.newInsertOrUpdateBuilder(shadowTableName);
populateMutationBuilderWithEvent(table, builder, changeEvent, keyColumnNames, requiredKeyColumnNames);
return builder;
} catch (Exception e) {
throw new ChangeEventConvertorException(e);
}
}
use of com.google.cloud.teleport.v2.templates.spanner.ddl.Table in project DataflowTemplates by GoogleCloudPlatform.
the class ProcessInformationSchemaIntegrationTest method canCreateShadowTablesForAllDataTables.
@Test
public void canCreateShadowTablesForAllDataTables() throws Exception {
SpannerConfig sourceConfig = spannerServer.getSpannerConfig(testDb);
Ddl testDdl = getTestDdlBuilder().build();
createDb(testDdl);
testPipeline.apply("Process Information Schema", new ProcessInformationSchema(sourceConfig, /*shouldCreateShadowTables=*/
true, "shadow", "oracle"));
PipelineResult testResult = testPipeline.run();
testResult.waitUntilFinish();
Ddl finalDdl = readDdl(testDb);
Table shadowTable = finalDdl.table("shadow_Table");
Table shadowTableInterleaved = finalDdl.table("shadow_Table_interleaved");
assertNotNull(shadowTable);
assertNotNull(shadowTableInterleaved);
assertEquals(4, finalDdl.allTables().size());
assertThat(shadowTable.primaryKeys(), is(testDdl.table("Table").primaryKeys()));
assertEquals(shadowTable.columns().size(), testDdl.table("Table").primaryKeys().size() + 2);
assertThat(shadowTableInterleaved.primaryKeys(), is(testDdl.table("Table_interleaved").primaryKeys()));
assertEquals(shadowTableInterleaved.columns().size(), testDdl.table("Table_interleaved").primaryKeys().size() + 2);
}
use of com.google.cloud.teleport.v2.templates.spanner.ddl.Table in project DataflowTemplates by GoogleCloudPlatform.
the class ProcessInformationSchemaIntegrationTest method canCreateMissingShadowTables.
@Test
public void canCreateMissingShadowTables() throws Exception {
SpannerConfig sourceConfig = spannerServer.getSpannerConfig(testDb);
Ddl testDdl = getTestDdlBuilder().createTable("shadow_Table").column("ID").int64().endColumn().column("version").int64().endColumn().primaryKey().asc("ID").end().endTable().build();
createDb(testDdl);
testPipeline.apply("Process Information Schema", new ProcessInformationSchema(sourceConfig, /*shouldCreateShadowTables=*/
true, "shadow", "oracle"));
PipelineResult testResult = testPipeline.run();
testResult.waitUntilFinish();
Ddl finalDdl = readDdl(testDb);
assertEquals(4, finalDdl.allTables().size());
Table shadowTable = finalDdl.table("shadow_Table");
Table shadowTableInterleaved = finalDdl.table("shadow_Table_interleaved");
assertNotNull(shadowTable);
assertNotNull(shadowTableInterleaved);
assertThat(shadowTableInterleaved.primaryKeys(), is(testDdl.table("Table_interleaved").primaryKeys()));
assertEquals(shadowTableInterleaved.columns().size(), testDdl.table("Table_interleaved").primaryKeys().size() + 2);
}
use of com.google.cloud.teleport.v2.templates.spanner.ddl.Table in project DataflowTemplates by GoogleCloudPlatform.
the class ProcessInformationSchemaIntegrationTest method canFlagProtectShadowTableCreation.
@Test
public void canFlagProtectShadowTableCreation() throws Exception {
SpannerConfig sourceConfig = spannerServer.getSpannerConfig(testDb);
Ddl testDdl = getTestDdlBuilder().build();
createDb(testDdl);
testPipeline.apply("Read Information Schema", new ProcessInformationSchema(sourceConfig, /*shouldCreateShadowTables=*/
false, "shadow", "oracle"));
PipelineResult testResult = testPipeline.run();
testResult.waitUntilFinish();
Ddl finalDdl = readDdl(testDb);
Table shadowTable = finalDdl.table("shadow_Table");
Table shadowTableInterleaved = finalDdl.table("shadow_Table_interleaved");
assertNull(shadowTable);
assertNull(shadowTableInterleaved);
assertEquals(2, finalDdl.allTables().size());
}
use of com.google.cloud.teleport.v2.templates.spanner.ddl.Table in project DataflowTemplates by GoogleCloudPlatform.
the class ShadowTableCreatorTest method canConstructShadowTableForMySql.
@Test
public void canConstructShadowTableForMySql() {
Ddl testDdl = ProcessInformationSchemaTest.getTestDdl();
ShadowTableCreator shadowTableCreator = new ShadowTableCreator("mysql", "shadow_");
Table shadowTable = shadowTableCreator.constructShadowTable(testDdl, "Users_interleaved");
/* Verify
* (1) name of shadow table
* (2) primary keys columns are same as data tables
* (3) Has mysql sequence information in addition to primary keys columns
*/
assertEquals(shadowTable.name(), "shadow_Users_interleaved");
assertThat(shadowTable.primaryKeys(), is(testDdl.table("Users_interleaved").primaryKeys()));
Set<String> columns = shadowTable.columns().stream().map(c -> c.name()).collect(Collectors.toSet());
Set<String> expectedColumns = testDdl.table("Users_interleaved").primaryKeys().stream().map(c -> c.name()).collect(Collectors.toSet());
expectedColumns.add("timestamp");
expectedColumns.add("log_file");
expectedColumns.add("log_position");
assertThat(columns, is(expectedColumns));
}
Aggregations