use of com.google.cloud.teleport.spanner.ddl.Ddl in project DataflowTemplates by GoogleCloudPlatform.
the class CopyDbTest method emptyTables.
@Test
public void emptyTables() 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").endTable().build();
createAndPopulate(ddl, 10);
// Add empty tables.
Ddl emptyTables = Ddl.builder().createTable("empty_one").column("first").string().max().endColumn().column("second").string().size(5).endColumn().column("value").int64().endColumn().primaryKey().asc("first").desc("second").end().endTable().createTable("empty_two").column("first").string().max().endColumn().column("second").string().size(5).endColumn().column("value").int64().endColumn().column("another_value").int64().endColumn().primaryKey().asc("first").end().endTable().build();
// spotless:on
spannerServer.updateDatabase(sourceDb, emptyTables.createTableStatements());
runTest();
}
use of com.google.cloud.teleport.spanner.ddl.Ddl in project DataflowTemplates by GoogleCloudPlatform.
the class CopyDbTest method randomSchema.
@Test
public void randomSchema() throws Exception {
Ddl ddl = RandomDdlGenerator.builder().build().generate();
createAndPopulate(ddl, 100);
runTest();
}
use of com.google.cloud.teleport.spanner.ddl.Ddl in project DataflowTemplates by GoogleCloudPlatform.
the class CopyDbTest method databaseOptions.
@Test
public void databaseOptions() throws Exception {
Ddl.Builder ddlBuilder = Ddl.builder();
// Table Content
// spotless:off
ddlBuilder.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("EmploymentData").column("first_name").string().max().endColumn().column("last_name").string().size(5).endColumn().column("id").int64().notNull().endColumn().column("age").int64().endColumn().column("address").string().max().endColumn().primaryKey().asc("first_name").desc("last_name").asc("id").end().interleaveInParent("Users").onDeleteCascade().endTable();
// spotless:on
// Allowed and well-formed database option
List<Export.DatabaseOption> dbOptionList = new ArrayList<>();
dbOptionList.add(Export.DatabaseOption.newBuilder().setOptionName("version_retention_period").setOptionValue("\"6d\"").build());
// Disallowed database option
dbOptionList.add(Export.DatabaseOption.newBuilder().setOptionName("optimizer_version").setOptionValue("1").build());
// Misformed database option
dbOptionList.add(Export.DatabaseOption.newBuilder().setOptionName("123version").setOptionValue("xyz").build());
ddlBuilder.mergeDatabaseOptions(dbOptionList);
Ddl ddl = ddlBuilder.build();
createAndPopulate(ddl, 100);
runTest();
Ddl destinationDdl = readDdl(destinationDb, Dialect.GOOGLE_STANDARD_SQL);
List<String> destDbOptions = destinationDdl.setOptionsStatements(destinationDb);
assertThat(destDbOptions.size(), is(1));
assertThat(destDbOptions.get(0), is("ALTER DATABASE `" + destinationDb + "` SET OPTIONS ( version_retention_period = \"6d\" )"));
}
use of com.google.cloud.teleport.spanner.ddl.Ddl in project DataflowTemplates by GoogleCloudPlatform.
the class CopySchemaTest method copyRandomSchema.
@Test
public void copyRandomSchema() {
Ddl ddl = RandomDdlGenerator.builder().setMaxPkComponents(2).setMaxBranchPerLevel(new int[] { 5, 4, 3, 2, 2, 3, 3 }).setMaxViews(3).build().generate();
try {
ddl.prettyPrint(System.out);
} catch (IOException e) {
e.printStackTrace();
}
DdlToAvroSchemaConverter ddlToAvro = new DdlToAvroSchemaConverter("spanner", "test", false);
AvroSchemaToDdlConverter avroToDdl = new AvroSchemaToDdlConverter();
Collection<Schema> schemas = ddlToAvro.convert(ddl);
Ddl copied = avroToDdl.toDdl(schemas);
assertThat(copied.prettyPrint(), equalToCompressingWhiteSpace(ddl.prettyPrint()));
}
use of com.google.cloud.teleport.spanner.ddl.Ddl in project DataflowTemplates by GoogleCloudPlatform.
the class CopySchemaTest method pgCopyRandomSchema.
@Test
public void pgCopyRandomSchema() {
Ddl ddl = RandomDdlGenerator.builder(Dialect.POSTGRESQL).setMaxPkComponents(2).setMaxBranchPerLevel(new int[] { 5, 4, 3, 2, 2, 3, 3 }).setMaxViews(3).build().generate();
try {
ddl.prettyPrint(System.out);
} catch (IOException e) {
throw new RuntimeException(e);
}
DdlToAvroSchemaConverter ddlToAvro = new DdlToAvroSchemaConverter("spanner", "test", false);
AvroSchemaToDdlConverter avroToDdl = new AvroSchemaToDdlConverter(Dialect.POSTGRESQL);
Collection<Schema> schemas = ddlToAvro.convert(ddl);
Ddl copied = avroToDdl.toDdl(schemas);
assertThat(copied.prettyPrint(), equalToCompressingWhiteSpace(ddl.prettyPrint()));
}
Aggregations