use of com.google.cloud.teleport.spanner.ddl.Ddl in project DataflowTemplates by GoogleCloudPlatform.
the class CopyDbTest method randomPgSchema.
@Test
public void randomPgSchema() throws Exception {
Ddl ddl = RandomDdlGenerator.builder(Dialect.POSTGRESQL).setMaxViews(2).build().generate();
System.out.println(ddl.prettyPrint());
createAndPopulate(ddl, 100);
runTest(Dialect.POSTGRESQL);
}
use of com.google.cloud.teleport.spanner.ddl.Ddl in project DataflowTemplates by GoogleCloudPlatform.
the class CopyDbTest method randomSchemaNoData.
@Test
public void randomSchemaNoData() throws Exception {
Ddl ddl = RandomDdlGenerator.builder().build().generate();
createAndPopulate(ddl, 0);
runTest();
}
use of com.google.cloud.teleport.spanner.ddl.Ddl in project DataflowTemplates by GoogleCloudPlatform.
the class CopyDbTest method runTest.
private void runTest(Dialect dialect) {
String tmpDirPath = tmpDir.getRoot().getAbsolutePath();
ValueProvider.StaticValueProvider<String> destination = ValueProvider.StaticValueProvider.of(tmpDirPath);
ValueProvider.StaticValueProvider<String> jobId = ValueProvider.StaticValueProvider.of("jobid");
ValueProvider.StaticValueProvider<String> source = ValueProvider.StaticValueProvider.of(tmpDirPath + "/jobid");
SpannerConfig sourceConfig = spannerServer.getSpannerConfig(sourceDb);
exportPipeline.apply("Export", new ExportTransform(sourceConfig, destination, jobId));
PipelineResult exportResult = exportPipeline.run();
exportResult.waitUntilFinish();
SpannerConfig destConfig = spannerServer.getSpannerConfig(destinationDb);
importPipeline.apply("Import", new ImportTransform(destConfig, source, ValueProvider.StaticValueProvider.of(true), ValueProvider.StaticValueProvider.of(true), ValueProvider.StaticValueProvider.of(true), ValueProvider.StaticValueProvider.of(true), ValueProvider.StaticValueProvider.of(30)));
PipelineResult importResult = importPipeline.run();
importResult.waitUntilFinish();
PCollection<Long> mismatchCount = comparePipeline.apply("Compare", new CompareDatabases(sourceConfig, destConfig));
PAssert.that(mismatchCount).satisfies((x) -> {
assertEquals(Lists.newArrayList(x), Lists.newArrayList(0L));
return null;
});
PipelineResult compareResult = comparePipeline.run();
compareResult.waitUntilFinish();
Ddl sourceDdl = readDdl(sourceDb, dialect);
Ddl destinationDdl = readDdl(destinationDb, dialect);
assertThat(sourceDdl.prettyPrint(), equalToCompressingWhiteSpace(destinationDdl.prettyPrint()));
}
use of com.google.cloud.teleport.spanner.ddl.Ddl in project DataflowTemplates by GoogleCloudPlatform.
the class CopyDbTest method readDdl.
/* Returns the Ddl representing a Spanner database for given a String for the database name */
private Ddl readDdl(String db, Dialect dialect) {
DatabaseClient dbClient = spannerServer.getDbClient(db);
Ddl ddl;
try (ReadOnlyTransaction ctx = dbClient.readOnlyTransaction()) {
ddl = new InformationSchemaScanner(ctx, dialect).scan();
}
return ddl;
}
use of com.google.cloud.teleport.spanner.ddl.Ddl in project DataflowTemplates by GoogleCloudPlatform.
the class CopyDbTest method allTypesSchema.
@Test
public void allTypesSchema() throws Exception {
// spotless:off
Ddl ddl = Ddl.builder().createTable("Users").column("first_name").string().max().endColumn().column("last_name").string().size(5).endColumn().column("age").int64().endColumn().primaryKey().asc("first_name").desc("last_name").end().endTable().createTable("AllTYPES").column("first_name").string().max().endColumn().column("last_name").string().size(5).endColumn().column("id").int64().notNull().endColumn().column("bool_field").bool().endColumn().column("int64_field").int64().endColumn().column("float64_field").float64().endColumn().column("string_field").string().max().endColumn().column("bytes_field").bytes().max().endColumn().column("timestamp_field").timestamp().endColumn().column("date_field").date().endColumn().column("arr_bool_field").type(Type.array(Type.bool())).endColumn().column("arr_int64_field").type(Type.array(Type.int64())).endColumn().column("arr_float64_field").type(Type.array(Type.float64())).endColumn().column("arr_string_field").type(Type.array(Type.string())).max().endColumn().column("arr_bytes_field").type(Type.array(Type.bytes())).max().endColumn().column("arr_timestamp_field").type(Type.array(Type.timestamp())).endColumn().column("arr_date_field").type(Type.array(Type.date())).endColumn().primaryKey().asc("first_name").desc("last_name").asc("id").end().interleaveInParent("Users").onDeleteCascade().endTable().build();
// spotless:on
createAndPopulate(ddl, 100);
runTest();
}
Aggregations