use of com.google.cloud.teleport.spanner.ddl.Ddl in project DataflowTemplates by GoogleCloudPlatform.
the class SpannerRecordConverterTest method pgSimple.
@Test
public void pgSimple() {
Ddl ddl = Ddl.builder(Dialect.POSTGRESQL).createTable("users").column("id").pgInt8().notNull().endColumn().column("email").pgVarchar().size(15).notNull().endColumn().column("name").pgVarchar().max().endColumn().primaryKey().asc("id").end().endTable().build();
Schema schema = converter.convert(ddl).iterator().next();
SpannerRecordConverter recordConverter = new SpannerRecordConverter(schema, Dialect.POSTGRESQL);
Struct struct = Struct.newBuilder().set("id").to(1L).set("email").to("abc@google.com").set("name").to("John Doe").build();
GenericRecord avroRecord = recordConverter.convert(struct);
assertThat(avroRecord.get("id"), equalTo(1L));
assertThat(avroRecord.get("email"), equalTo("abc@google.com"));
assertThat(avroRecord.get("name"), equalTo("John Doe"));
}
use of com.google.cloud.teleport.spanner.ddl.Ddl in project DataflowTemplates by GoogleCloudPlatform.
the class SpannerRecordConverterTest method pgDateTimestamptz.
@Test
public void pgDateTimestamptz() {
Ddl ddl = Ddl.builder(Dialect.POSTGRESQL).createTable("users").column("id").pgInt8().notNull().endColumn().column("ts").pgTimestamptz().endColumn().column("date").pgDate().endColumn().primaryKey().asc("id").end().endTable().build();
Schema schema = converter.convert(ddl).iterator().next();
SpannerRecordConverter recordConverter = new SpannerRecordConverter(schema, Dialect.POSTGRESQL);
Struct struct = Struct.newBuilder().set("id").to(1L).set("ts").to(Timestamp.ofTimeMicroseconds(10)).set("date").to(Date.fromYearMonthDay(2018, 2, 2)).build();
GenericRecord avroRecord = recordConverter.convert(struct);
assertThat(avroRecord.get("id"), equalTo(1L));
assertThat(avroRecord.get("ts"), equalTo("1970-01-01T00:00:00.000010000Z"));
assertThat(avroRecord.get("date"), equalTo("2018-02-02"));
}
use of com.google.cloud.teleport.spanner.ddl.Ddl in project DataflowTemplates by GoogleCloudPlatform.
the class SpannerTableFilterTest method individualTableSelection_selectsOnlyChosenTable.
@Test
public void individualTableSelection_selectsOnlyChosenTable() 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("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, ImmutableList.of(usersTable)).stream().map(t -> t.name()).collect(Collectors.toList());
List<String> expectedFilteredTables = ImmutableList.of(usersTable);
assertEquals(expectedFilteredTables, filteredTables);
}
use of com.google.cloud.teleport.spanner.ddl.Ddl in project DataflowTemplates by GoogleCloudPlatform.
the class SpannerTableFilterTest method multipleForeignKeyTableFilterSelection_selectsChosenAndAllReferencedTables.
@Test
public void multipleForeignKeyTableFilterSelection_selectsChosenAndAllReferencedTables() throws Exception {
Ddl ddl = Ddl.builder().createTable("Ref1").column("id1").int64().endColumn().column("id2").int64().endColumn().primaryKey().asc("id1").asc("id2").end().endTable().createTable("Ref2").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 two foreign key constraints
// referencing `Ref1` and `Ref2` )
ddl.addNewReferencedTable("Child", "Ref1");
ddl.addNewReferencedTable("Child", "Ref2");
List<String> filteredTables = getFilteredTables(ddl, ImmutableList.of(childTable)).stream().map(t -> t.name()).collect(Collectors.toList());
List<String> expectedFilteredTables = ImmutableList.of(childTable, refOneTable, refTwoTable);
Collections.sort(filteredTables);
assertEquals(expectedFilteredTables, filteredTables);
}
use of com.google.cloud.teleport.spanner.ddl.Ddl in project DataflowTemplates by GoogleCloudPlatform.
the class SpannerTableFilterTest method filterWithAllAncestorsSelection_selectsChosenTableWithAllParents.
@Test
public void filterWithAllAncestorsSelection_selectsChosenTableWithAllParents() throws Exception {
Ddl ddl = Ddl.builder().createTable("table_c").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("table_b").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().primaryKey().asc("first_name").desc("last_name").asc("id").end().interleaveInParent("table_c").onDeleteCascade().endTable().createTable("table_a").column("first_name").string().max().endColumn().column("last_name").string().size(5).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("table_b").onDeleteCascade().endTable().build();
List<String> filteredTables = getFilteredTables(ddl, ImmutableList.of(tableA)).stream().map(t -> t.name()).collect(Collectors.toList());
List<String> expectedFilteredTables = ImmutableList.of(tableA, tableB, tableC);
Collections.sort(filteredTables);
assertEquals(expectedFilteredTables, filteredTables);
}
Aggregations