use of com.google.cloud.teleport.v2.templates.spanner.ddl.Column in project DataflowTemplates by GoogleCloudPlatform.
the class FailsafeModJsonToTableRowTransformerTest method testFailsafeModJsonToTableRowFailedSnapshotRead.
// Test the case where the snapshot read to Spanner fails and we can capture the failures from
// transformDeadLetterOut of FailsafeModJsonToTableRow.
@Test
public void testFailsafeModJsonToTableRowFailedSnapshotRead() throws Exception {
ObjectNode fakePkColJsonNode = new ObjectNode(JsonNodeFactory.instance);
fakePkColJsonNode.put("fakePkCol", true);
ObjectNode fakeNonPkColJsonNode = new ObjectNode(JsonNodeFactory.instance);
fakeNonPkColJsonNode.put("fakeNonPkCol", true);
Mod mod = new Mod(fakePkColJsonNode.toString(), fakeNonPkColJsonNode.toString(), Timestamp.ofTimeSecondsAndNanos(1650908264L, 925679000), "1", true, "00000001", TEST_SPANNER_TABLE, ModType.INSERT, 1L, 1L);
TestStream<String> testSream = TestStream.create(SerializableCoder.of(String.class)).addElements(mod.toJson()).advanceWatermarkTo(Instant.now()).advanceWatermarkToInfinity();
Pipeline p = Pipeline.create();
PCollection<FailsafeElement<String, String>> input = p.apply(testSream).apply(ParDo.of(new DoFn<String, FailsafeElement<String, String>>() {
@ProcessElement
public void process(@Element String input, OutputReceiver<FailsafeElement<String, String>> receiver) {
receiver.output(FailsafeElement.of(input, input));
}
})).setCoder(SpannerChangeStreamsToBigQuery.FAILSAFE_ELEMENT_CODER);
PCollectionTuple out = input.apply("Mod JSON To TableRow", failsafeModJsonToTableRow);
PAssert.that(out.get(failsafeModJsonToTableRow.transformOut)).empty();
String expectedPayload = "{\"keysJson\":\"{\\\"fakePkCol\\\":true}\"," + "\"newValuesJson\":\"{\\\"fakeNonPkCol\\\":true}\"," + "\"commitTimestampSeconds\":1650908264,\"commitTimestampNanos\":925679000," + "\"serverTransactionId\":\"1\",\"isLastRecordInTransactionInPartition\":true," + "\"recordSequence\":\"00000001\",\"tableName\":\"AllTypes\",\"modType\":\"INSERT\"," + "\"numberOfRecordsInTransaction\":1,\"numberOfPartitionsInTransaction\":1}";
PAssert.that(out.get(failsafeModJsonToTableRow.transformDeadLetterOut).apply(ParDo.of(new DoFn<FailsafeElement<String, String>, String>() {
@ProcessElement
public void process(@Element FailsafeElement<String, String> input, OutputReceiver<String> receiver) {
receiver.output(String.format("originalPayload=%s, payload=%s, errorMessage=%s", input.getOriginalPayload(), input.getPayload(), input.getErrorMessage()));
}
}))).containsInAnyOrder(ImmutableList.of(String.format("originalPayload=%s, payload=%s, errorMessage=Cannot find value for key column" + " BooleanPkCol", expectedPayload, expectedPayload)));
p.run().waitUntilFinish();
}
use of com.google.cloud.teleport.v2.templates.spanner.ddl.Column in project DataflowTemplates by GoogleCloudPlatform.
the class DeleteBigQueryDataFnTest method testTransform_withDeleteSourceDataEnabled_doesntTruncateSpecialPartitions.
/**
* Test that DeleteBigQueryDataFn doesn't attempt to delete special BigQuery partitions even if
* {@code deleteSourceData = true}.
*
* <p>As per <a
* href="https://cloud.google.com/bigquery/docs/managing-partitioned-tables#delete_a_partition">
* this documentation</a>, special partitions "__NULL__" and "__UNPARTITIONED__" cannot be
* deleted.
*/
@Test
@Category(NeedsRunner.class)
public void testTransform_withDeleteSourceDataEnabled_doesntTruncateSpecialPartitions() {
Options options = TestPipeline.testingPipelineOptions().as(Options.class);
options.setDeleteSourceData(true);
BigQueryTablePartition.Builder builder = BigQueryTablePartition.builder().setLastModificationTime(System.currentTimeMillis() * 1000);
BigQueryTablePartition p1 = builder.setPartitionName("__NULL__").build();
BigQueryTablePartition p2 = builder.setPartitionName("__UNPARTITIONED__").build();
BigQueryTablePartition p3 = builder.setPartitionName("NORMAL_PARTITION").build();
BigQueryTable t1 = table.toBuilder().setPartitions(Arrays.asList(p1, p2, p3)).setPartitioningColumn("column-name-doesnt-matter").build();
DeleteBigQueryDataFn fn = new DeleteBigQueryDataFn().withTestBqClientFactory(() -> bqMock);
testPipeline.apply("CreateInput", Create.of(KV.of(t1, p1), KV.of(t1, p2), KV.of(t1, p3)).withCoder(fnCoder)).apply("TestDeleteBigQueryDataFn", ParDo.of(fn));
testPipeline.run(options);
verify(bqMock, times(1)).delete(TableId.of("pr1", "d1", "t1$NORMAL_PARTITION"));
verifyNoMoreInteractions(bqMock);
}
use of com.google.cloud.teleport.v2.templates.spanner.ddl.Column in project DataflowTemplates by GoogleCloudPlatform.
the class ShadowTableCreatorTest method canConstructShadowTableForOracle.
@Test
public void canConstructShadowTableForOracle() {
Ddl testDdl = ProcessInformationSchemaTest.getTestDdl();
ShadowTableCreator shadowTableCreator = new ShadowTableCreator("oracle", "shadow_");
Table shadowTable = shadowTableCreator.constructShadowTable(testDdl, "Users_interleaved");
/* Verify
* (1) name of shadow table
* (2) primary keys columns are same as data tables
* (3) Has oracle sequence information column in addition to primary keys columns
*/
assertEquals(shadowTable.name(), "shadow_Users_interleaved");
assertThat(shadowTable.primaryKeys(), is(testDdl.table("Users_interleaved").primaryKeys()));
Set<String> columns = shadowTable.columns().stream().map(c -> c.name()).collect(Collectors.toSet());
Set<String> expectedColumns = testDdl.table("Users_interleaved").primaryKeys().stream().map(c -> c.name()).collect(Collectors.toSet());
expectedColumns.add("timestamp");
expectedColumns.add("scn");
assertThat(columns, is(expectedColumns));
}
use of com.google.cloud.teleport.v2.templates.spanner.ddl.Column in project DataflowTemplates by GoogleCloudPlatform.
the class SpannerStreamingWriteIntegrationTest method createTablesForTest.
private void createTablesForTest() throws Exception {
Ddl ddl = Ddl.builder().createTable("Table1").column("id").int64().endColumn().column("data").int64().endColumn().primaryKey().asc("id").end().endTable().createTable("Table1_interleaved").column("id").int64().endColumn().column("id2").int64().endColumn().column("data2").int64().endColumn().primaryKey().asc("id").desc("id2").end().interleaveInParent("Table1").endTable().build();
spannerServer.createDatabase(testDb, ddl.statements());
}
use of com.google.cloud.teleport.v2.templates.spanner.ddl.Column in project DataflowTemplates by GoogleCloudPlatform.
the class DeleteBigQueryDataFnTest method testTransform_withDeleteSourceDataDisabled_doesntTruncateData.
@Test
@Category(NeedsRunner.class)
public void testTransform_withDeleteSourceDataDisabled_doesntTruncateData() {
Options options = TestPipeline.testingPipelineOptions().as(Options.class);
options.setDeleteSourceData(false);
BigQueryTable partitionedTable = table.toBuilder().setPartitions(Collections.singletonList(partition)).setPartitioningColumn("column-name-doesnt-matter").build();
DeleteBigQueryDataFn fn = new DeleteBigQueryDataFn().withTestBqClientFactory(() -> bqMock);
PCollection<Void> actual = testPipeline.apply("CreateInput", Create.of(KV.of(partitionedTable, partition), KV.of(table, (BigQueryTablePartition) null)).withCoder(fnCoder)).apply("TestDeleteBigQueryDataFn", ParDo.of(fn));
PAssert.that(actual).empty();
testPipeline.run(options);
verifyNoMoreInteractions(bqMock);
}
Aggregations