use of com.google.cloud.teleport.v2.transforms.DeleteBigQueryDataFn.Options in project DataflowTemplates by GoogleCloudPlatform.
the class GCSToSplunkTest method testGCSToSplunkReadUdf.
@Test
public void testGCSToSplunkReadUdf() {
// Arrange
String stringifiedJsonRecord = "{\"id\":\"007\",\"state\":\"CA\",\"price\":26.23}";
SplunkEvent expectedSplunkEvent = SplunkEvent.newBuilder().withEvent(stringifiedJsonRecord).create();
CoderRegistry coderRegistry = pipeline.getCoderRegistry();
coderRegistry.registerCoderForClass(SplunkEvent.class, SplunkEventCoder.of());
coderRegistry.registerCoderForType(FAILSAFE_ELEMENT_CODER.getEncodedTypeDescriptor(), FAILSAFE_ELEMENT_CODER);
GCSToSplunkOptions options = PipelineOptionsFactory.create().as(GCSToSplunkOptions.class);
options.setJavascriptTextTransformGcsPath(TRANSFORM_FILE_PATH);
options.setJavascriptTextTransformFunctionName("transform");
options.setContainsHeaders(false);
options.setInputFileSpec(NO_HEADER_CSV_FILE_PATH);
// Act
PCollectionTuple readCsvOut = pipeline.apply("Read CSV", readFromCsv(options));
PCollectionTuple transformedLines = readCsvOut.apply("Convert to JSON", convertToFailsafeAndMaybeApplyUdf(options));
PCollectionTuple splunkEventTuple = transformedLines.get(UDF_OUT).apply("Convert to Splunk Event", convertToSplunkEvent());
// Assert
PAssert.that(transformedLines.get(UDF_OUT)).satisfies(collection -> {
FailsafeElement element = collection.iterator().next();
assertThat(element.getPayload()).isEqualTo(stringifiedJsonRecord);
return null;
});
PAssert.that(transformedLines.get(UDF_ERROR_OUT)).empty();
PAssert.that(splunkEventTuple.get(SPLUNK_EVENT_OUT)).containsInAnyOrder(expectedSplunkEvent);
PAssert.that(splunkEventTuple.get(SPLUNK_EVENT_ERROR_OUT)).empty();
// Execute pipeline
pipeline.run();
}
use of com.google.cloud.teleport.v2.transforms.DeleteBigQueryDataFn.Options in project DataflowTemplates by GoogleCloudPlatform.
the class FileFormatConversionTest method testCsvToAvroE2E.
/**
* Tests if the Csv to Avro pipeline transforms data correctly and stores it in an Avro file.
*/
@Test
public void testCsvToAvroE2E() {
FileFormatConversionOptions options = PipelineOptionsFactory.create().as(FileFormatConversionOptions.class);
String tempDir = temporaryFolder.getRoot().getAbsolutePath() + "/";
options.setInputFileFormat(CSV);
options.setOutputFileFormat(AVRO);
options.setInputFileSpec(CSV_FILE_PATH);
options.setOutputBucket(tempDir);
options.setContainsHeaders(true);
options.setSchema(SCHEMA_FILE_PATH);
options.setDelimiter("|");
Schema schema = SchemaUtils.getAvroSchema(SCHEMA_FILE_PATH);
GenericRecord genericRecords = new GenericData.Record(schema);
genericRecords.put("id", "007");
genericRecords.put("state", "CA");
genericRecords.put("price", 26.23);
mainPipeline.apply("TestCsvToAvro", FileFormatConversionFactory.FileFormat.newBuilder().setOptions(options).setInputFileFormat(CSV).setOutputFileFormat(AVRO).build());
mainPipeline.run();
PCollection<GenericRecord> readAvroFile = readPipeline.apply("ReadAvroFile", AvroConverters.ReadAvroFile.newBuilder().withInputFileSpec(tempDir + "*").withSchema(SCHEMA_FILE_PATH).build());
PAssert.that(readAvroFile).containsInAnyOrder(genericRecords);
readPipeline.run();
}
use of com.google.cloud.teleport.v2.transforms.DeleteBigQueryDataFn.Options in project DataflowTemplates by GoogleCloudPlatform.
the class FileFormatConversionTest method testCsvToAvroWithEmptyField.
/**
* Tests if the Csv to Avro pipeline can handle empty fields in the Csv file.
*/
@Test
public void testCsvToAvroWithEmptyField() {
FileFormatConversionOptions options = PipelineOptionsFactory.create().as(FileFormatConversionOptions.class);
String tempDir = temporaryFolder.getRoot().getAbsolutePath() + "/";
options.setInputFileFormat(CSV);
options.setOutputFileFormat(AVRO);
options.setInputFileSpec(CSV_FILE_WITH_MISSING_FIELD_PATH);
options.setOutputBucket(tempDir);
options.setContainsHeaders(true);
options.setSchema(SCHEMA_FILE_TWO_PATH);
Schema schema = SchemaUtils.getAvroSchema(SCHEMA_FILE_TWO_PATH);
GenericRecord genericRecords = new GenericData.Record(schema);
genericRecords.put("id", "007");
genericRecords.put("state", "CA");
genericRecords.put("price", null);
mainPipeline.apply("TestCsvToAvroWithEmptyField", FileFormatConversionFactory.FileFormat.newBuilder().setOptions(options).setInputFileFormat(CSV).setOutputFileFormat(AVRO).build());
mainPipeline.run();
PCollection<GenericRecord> readAvroFile = readPipeline.apply("ReadAvroFile", AvroConverters.ReadAvroFile.newBuilder().withInputFileSpec(tempDir + "*").withSchema(SCHEMA_FILE_TWO_PATH).build());
PAssert.that(readAvroFile).containsInAnyOrder(genericRecords);
readPipeline.run();
}
use of com.google.cloud.teleport.v2.transforms.DeleteBigQueryDataFn.Options in project DataflowTemplates by GoogleCloudPlatform.
the class FileFormatConversionTest method testInvalidFileFormat.
/**
* Tests {@link FileFormatConversion#run(FileFormatConversionOptions)} throws an exception if an
* invalid file format is provided.
*/
@Test
public void testInvalidFileFormat() {
expectedException.expect(RuntimeException.class);
expectedException.expectMessage("Provide correct input/output file format.");
FileFormatConversionOptions options = PipelineOptionsFactory.create().as(FileFormatConversionOptions.class);
options.setInputFileFormat("INVALID");
options.setOutputFileFormat(AVRO);
FileFormatConversion.run(options);
}
use of com.google.cloud.teleport.v2.transforms.DeleteBigQueryDataFn.Options in project DataflowTemplates by GoogleCloudPlatform.
the class FileFormatConversionTest method testSameInputAndOutputFileFormat.
/**
* Tests {@link FileFormatConversion#run(FileFormatConversionOptions)} throws an exception if the
* same input and output file formats are provided.
*/
@Test
public void testSameInputAndOutputFileFormat() {
expectedException.expect(RuntimeException.class);
expectedException.expectMessage("Provide correct input/output file format.");
FileFormatConversionOptions options = PipelineOptionsFactory.create().as(FileFormatConversionOptions.class);
options.setInputFileFormat(AVRO);
options.setOutputFileFormat(AVRO);
FileFormatConversion.run(options);
}
Aggregations