Search in sources :

Example 6 with TestRow

use of org.apache.beam.sdk.io.common.TestRow in project beam by apache.

the class StreamingSnowflakeIOIT method writeStreamToSnowflake.

private void writeStreamToSnowflake() {
    TestStream<TestRow> stringsStream = TestStream.create(SerializableCoder.of(TestRow.class)).advanceWatermarkTo(Instant.now()).addElements(testRows.get(0), testRows.subList(1, testRows.size()).toArray(new TestRow[0])).advanceWatermarkToInfinity();
    pipeline.apply(stringsStream).apply("Write SnowflakeIO", SnowflakeIO.<TestRow>write().withDataSourceConfiguration(dc).withUserDataMapper(getTestRowDataMapper()).withSnowPipe(options.getSnowPipe()).withStorageIntegrationName(storageIntegrationName).withStagingBucketName(stagingBucketName).withFlushTimeLimit(Duration.millis(18000)).withFlushRowLimit(50000).withDebugMode(StreamingLogLevel.ERROR));
    PipelineResult pipelineResult = pipeline.run(options);
    pipelineResult.waitUntilFinish();
}
Also used : TestRow(org.apache.beam.sdk.io.common.TestRow) PipelineResult(org.apache.beam.sdk.PipelineResult)

Example 7 with TestRow

use of org.apache.beam.sdk.io.common.TestRow in project beam by apache.

the class BatchSnowflakeIOIT method runRead.

private PipelineResult runRead() {
    PCollection<TestRow> namesAndIds = pipelineRead.apply(SnowflakeIO.<TestRow>read().withDataSourceConfiguration(dataSourceConfiguration).fromTable(tableName).withStagingBucketName(stagingBucketName).withStorageIntegrationName(storageIntegrationName).withCsvMapper(getTestRowCsvMapper()).withCoder(SerializableCoder.of(TestRow.class)));
    PAssert.thatSingleton(namesAndIds.apply("Count All", Count.globally())).isEqualTo((long) numberOfRecords);
    PCollection<String> consolidatedHashcode = namesAndIds.apply(ParDo.of(new TestRow.SelectNameFn())).apply("Hash row contents", Combine.globally(new HashingFn()).withoutDefaults());
    PAssert.that(consolidatedHashcode).containsInAnyOrder(TestRow.getExpectedHashForRowCount(numberOfRecords));
    return pipelineRead.run();
}
Also used : TestRow(org.apache.beam.sdk.io.common.TestRow) SnowflakeString(org.apache.beam.sdk.io.snowflake.data.text.SnowflakeString) HashingFn(org.apache.beam.sdk.io.common.HashingFn)

Aggregations

TestRow (org.apache.beam.sdk.io.common.TestRow)7 HashingFn (org.apache.beam.sdk.io.common.HashingFn)5 GenerateSequence (org.apache.beam.sdk.io.GenerateSequence)3 DeterministicallyConstructTestRowFn (org.apache.beam.sdk.io.common.TestRow.DeterministicallyConstructTestRowFn)3 TestRow.getExpectedHashForRowCount (org.apache.beam.sdk.io.common.TestRow.getExpectedHashForRowCount)3 PAssert (org.apache.beam.sdk.testing.PAssert)3 TestPipeline (org.apache.beam.sdk.testing.TestPipeline)3 Combine (org.apache.beam.sdk.transforms.Combine)3 Count (org.apache.beam.sdk.transforms.Count)3 MapElements (org.apache.beam.sdk.transforms.MapElements)3 ParDo (org.apache.beam.sdk.transforms.ParDo)3 PCollection (org.apache.beam.sdk.values.PCollection)3 TypeDescriptors.strings (org.apache.beam.sdk.values.TypeDescriptors.strings)3 ClassRule (org.junit.ClassRule)3 Rule (org.junit.Rule)3 Test (org.junit.Test)3 ExternalResource (org.junit.rules.ExternalResource)3 RunWith (org.junit.runner.RunWith)3 JUnit4 (org.junit.runners.JUnit4)3 Map (java.util.Map)2