use of com.google.cloud.teleport.spanner.ddl.Ddl in project DataflowTemplates by GoogleCloudPlatform.
the class SpannerRecordConverterTest method nulls.
@Test
public void nulls() {
Ddl ddl = Ddl.builder().createTable("users").column("id").int64().notNull().endColumn().column("age").int64().endColumn().column("name").string().max().endColumn().column("bytes").bytes().max().endColumn().column("date").date().endColumn().column("ts").timestamp().endColumn().primaryKey().asc("id").end().endTable().build();
Schema schema = converter.convert(ddl).iterator().next();
SpannerRecordConverter recordConverter = new SpannerRecordConverter(schema);
Struct struct = Struct.newBuilder().set("id").to(1L).set("age").to((Long) null).set("name").to((String) null).set("bytes").to((ByteArray) null).set("date").to((Date) null).set("ts").to((Timestamp) null).build();
GenericRecord avroRecord = recordConverter.convert(struct);
assertThat(avroRecord.get("id"), equalTo(1L));
assertThat(avroRecord.get("age"), is((Long) null));
assertThat(avroRecord.get("name"), is((String) null));
assertThat(avroRecord.get("bytes"), is((ByteArray) null));
assertThat(avroRecord.get("date"), is((String) null));
assertThat(avroRecord.get("ts"), is((String) null));
}
use of com.google.cloud.teleport.spanner.ddl.Ddl in project DataflowTemplates by GoogleCloudPlatform.
the class SpannerTableFilterTest method foreignKeyAndParentTableFilterSelection_selectsAllNecessaryTables.
@Test
public void foreignKeyAndParentTableFilterSelection_selectsAllNecessaryTables() throws Exception {
Ddl ddl = Ddl.builder().createTable("table_a").column("id1").int64().endColumn().column("id2").int64().endColumn().primaryKey().asc("id1").asc("id2").end().endTable().createTable("table_b").column("id1").int64().endColumn().column("id2").int64().endColumn().column("id3").int64().endColumn().primaryKey().asc("id1").asc("id2").asc("id3").end().endTable().createTable("table_c").column("id1").int64().endColumn().column("id2").int64().endColumn().column("id3").int64().endColumn().primaryKey().asc("id1").asc("id2").asc("id3").end().interleaveInParent("table_b").endTable().build();
// Add to referencedTable field (i.e. `table_c` would have a foreign key constraint
// referencing `table_a` )
ddl.addNewReferencedTable("table_c", "table_a");
List<String> filteredTables = getFilteredTables(ddl, ImmutableList.of(tableC)).stream().map(t -> t.name()).collect(Collectors.toList());
List<String> expectedFilteredTables = ImmutableList.of(tableA, tableB, tableC);
Collections.sort(filteredTables);
assertEquals(expectedFilteredTables, filteredTables);
}
use of com.google.cloud.teleport.spanner.ddl.Ddl in project DataflowTemplates by GoogleCloudPlatform.
the class SpannerTableFilterTest method circularForeignKeyTableFilterSelection_selectsBothTables.
@Test
public void circularForeignKeyTableFilterSelection_selectsBothTables() throws Exception {
Ddl ddl = Ddl.builder().createTable("table_a").column("id1").int64().endColumn().column("id2").int64().endColumn().primaryKey().asc("id1").asc("id2").end().endTable().createTable("table_b").column("id1").int64().endColumn().column("id2").int64().endColumn().column("id3").int64().endColumn().primaryKey().asc("id1").asc("id2").asc("id3").end().endTable().build();
// Add to referencedTable field (i.e. `table_a` would have a foreign key constraint
// referencing `table_b` and vice versa )
ddl.addNewReferencedTable("table_a", "table_b");
ddl.addNewReferencedTable("table_b", "table_a");
List<String> filteredTables = getFilteredTables(ddl, ImmutableList.of(tableB)).stream().map(t -> t.name()).collect(Collectors.toList());
List<String> expectedFilteredTables = ImmutableList.of(tableA, tableB);
Collections.sort(filteredTables);
assertEquals(expectedFilteredTables, filteredTables);
}
use of com.google.cloud.teleport.spanner.ddl.Ddl in project DataflowTemplates by GoogleCloudPlatform.
the class SpannerTableFilterTest method emptyTableSelection_selectsAllDbTables.
/* Basic test that provides no table names to getFilteredTables() */
@Test
public void emptyTableSelection_selectsAllDbTables() throws Exception {
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("Orders").column("id").int64().notNull().endColumn().column("name").string().max().endColumn().column("age").int64().endColumn().primaryKey().asc("id").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();
List<String> filteredTables = getFilteredTables(ddl, Collections.emptyList()).stream().map(t -> t.name()).collect(Collectors.toList());
List<String> expectedFilteredTables = ImmutableList.of(allTypesTable, ordersTable, usersTable);
Collections.sort(filteredTables);
assertEquals(expectedFilteredTables, filteredTables);
}
use of com.google.cloud.teleport.spanner.ddl.Ddl in project DataflowTemplates by GoogleCloudPlatform.
the class SpannerTableFilterTest method basicForeignKeyTableFilterSelection_selectsChosenAndReferencedTable.
@Test
public void basicForeignKeyTableFilterSelection_selectsChosenAndReferencedTable() throws Exception {
Ddl ddl = Ddl.builder().createTable("Ref1").column("id1").int64().endColumn().column("id2").int64().endColumn().primaryKey().asc("id1").asc("id2").end().endTable().createTable("Child").column("id1").int64().endColumn().column("id2").int64().endColumn().column("id3").int64().endColumn().primaryKey().asc("id1").asc("id2").asc("id3").end().endTable().build();
// Add to referencedTable field (i.e. `Child` would have a foreign key constraint
// referencing `Ref1`)
ddl.addNewReferencedTable("Child", "Ref1");
List<String> filteredTables = getFilteredTables(ddl, ImmutableList.of(childTable)).stream().map(t -> t.name()).collect(Collectors.toList());
List<String> expectedFilteredTables = ImmutableList.of(childTable, refOneTable);
Collections.sort(filteredTables);
assertEquals(expectedFilteredTables, filteredTables);
}
Aggregations