Search in sources :

Example 6 with Type

use of com.google.cloud.teleport.spanner.common.Type in project DataflowTemplates by GoogleCloudPlatform.

the class SpannerTableFilterTest method basicInterleavedTableFilterSelection_selectsChosenAndParentTables.

@Test
public void basicInterleavedTableFilterSelection_selectsChosenAndParentTables() 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(allTypesTable)).stream().map(t -> t.name()).collect(Collectors.toList());
    List<String> expectedFilteredTables = ImmutableList.of(allTypesTable, usersTable);
    Collections.sort(filteredTables);
    assertEquals(expectedFilteredTables, filteredTables);
}
Also used : SpannerTableFilter.getFilteredTables(com.google.cloud.teleport.spanner.SpannerTableFilter.getFilteredTables) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) RunWith(org.junit.runner.RunWith) Test(org.junit.Test) JUnit4(org.junit.runners.JUnit4) Type(com.google.cloud.teleport.spanner.common.Type) Ddl(com.google.cloud.teleport.spanner.ddl.Ddl) Collections(java.util.Collections) Collectors(java.util.stream.Collectors) Assert.assertEquals(org.junit.Assert.assertEquals) Ddl(com.google.cloud.teleport.spanner.ddl.Ddl) Test(org.junit.Test)

Example 7 with Type

use of com.google.cloud.teleport.spanner.common.Type in project DataflowTemplates by GoogleCloudPlatform.

the class SpannerTableFilterTest method filterWithPartialAncestorsSelection_selectsChosenAndParentTable.

@Test
public void filterWithPartialAncestorsSelection_selectsChosenAndParentTable() 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(tableB)).stream().map(t -> t.name()).collect(Collectors.toList());
    List<String> expectedFilteredTables = ImmutableList.of(tableB, tableC);
    Collections.sort(filteredTables);
    assertEquals(expectedFilteredTables, filteredTables);
}
Also used : SpannerTableFilter.getFilteredTables(com.google.cloud.teleport.spanner.SpannerTableFilter.getFilteredTables) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) RunWith(org.junit.runner.RunWith) Test(org.junit.Test) JUnit4(org.junit.runners.JUnit4) Type(com.google.cloud.teleport.spanner.common.Type) Ddl(com.google.cloud.teleport.spanner.ddl.Ddl) Collections(java.util.Collections) Collectors(java.util.stream.Collectors) Assert.assertEquals(org.junit.Assert.assertEquals) Ddl(com.google.cloud.teleport.spanner.ddl.Ddl) Test(org.junit.Test)

Example 8 with Type

use of com.google.cloud.teleport.spanner.common.Type in project DataflowTemplates by GoogleCloudPlatform.

the class RandomDdlGenerator method generateColumn.

private Column generateColumn(Type.Code[] codes, int arrayPercentage) {
    int length = 1 + getRandom().nextInt(getMaxIdLength());
    String name = generateIdentifier(length);
    Type type = generateType(codes, arrayPercentage);
    int size = -1;
    boolean nullable = getRandom().nextBoolean();
    return Column.builder(getDialect()).name(name).type(type).size(size).notNull(nullable).autoBuild();
}
Also used : Type(com.google.cloud.teleport.spanner.common.Type)

Example 9 with Type

use of com.google.cloud.teleport.spanner.common.Type 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);
}
Also used : SpannerTableFilter.getFilteredTables(com.google.cloud.teleport.spanner.SpannerTableFilter.getFilteredTables) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) RunWith(org.junit.runner.RunWith) Test(org.junit.Test) JUnit4(org.junit.runners.JUnit4) Type(com.google.cloud.teleport.spanner.common.Type) Ddl(com.google.cloud.teleport.spanner.ddl.Ddl) Collections(java.util.Collections) Collectors(java.util.stream.Collectors) Assert.assertEquals(org.junit.Assert.assertEquals) Ddl(com.google.cloud.teleport.spanner.ddl.Ddl) Test(org.junit.Test)

Aggregations

Type (com.google.cloud.teleport.spanner.common.Type)9 Ddl (com.google.cloud.teleport.spanner.ddl.Ddl)7 List (java.util.List)7 Collectors (java.util.stream.Collectors)7 Test (org.junit.Test)7 ImmutableList (com.google.common.collect.ImmutableList)6 SpannerTableFilter.getFilteredTables (com.google.cloud.teleport.spanner.SpannerTableFilter.getFilteredTables)5 Collections (java.util.Collections)5 Assert.assertEquals (org.junit.Assert.assertEquals)5 RunWith (org.junit.runner.RunWith)5 JUnit4 (org.junit.runners.JUnit4)5 Schema (org.apache.avro.Schema)3 ByteArray (com.google.cloud.ByteArray)2 Date (com.google.cloud.Date)2 Timestamp (com.google.cloud.Timestamp)2 Dialect (com.google.cloud.spanner.Dialect)2 Struct (com.google.cloud.spanner.Struct)2 NumericUtils (com.google.cloud.teleport.spanner.common.NumericUtils)2 Lists (com.google.common.collect.Lists)2 ByteBuffer (java.nio.ByteBuffer)2