use of com.google.cloud.teleport.v2.transforms.BeamRowToGenericRecordFn in project DataflowTemplates by GoogleCloudPlatform.
the class DataplexJdbcIngestion method buildGcsPipeline.
@VisibleForTesting
static void buildGcsPipeline(Pipeline pipeline, DataplexJdbcIngestionOptions options, DynamicDataSourceConfiguration dataSourceConfig, String targetRootPath) {
// Auto inferring beam schema
Schema beamSchema = Schemas.jdbcSchemaToBeamSchema(dataSourceConfig.buildDatasource(), options.getQuery());
// Convert to Avro Schema
org.apache.avro.Schema avroSchema = AvroUtils.toAvroSchema(beamSchema);
// Read from JdbcIO and convert ResultSet to Beam Row
PCollection<Row> resultRows = pipeline.apply("Read from JdbcIO", DynamicJdbcIO.<Row>read().withDataSourceConfiguration(dataSourceConfig).withQuery(options.getQuery()).withCoder(RowCoder.of(beamSchema)).withRowMapper(BeamSchemaUtil.of(beamSchema)));
// Convert Beam Row to GenericRecord
PCollection<GenericRecord> genericRecords = resultRows.apply("convert to GenericRecord", ParDo.of(new BeamRowToGenericRecordFn(avroSchema))).setCoder(AvroCoder.of(avroSchema));
// Write to GCS bucket
PCollection<PartitionMetadata> metadata = genericRecords.apply("Write to GCS", new GenericRecordsToGcsPartitioned(targetRootPath, Schemas.serialize(avroSchema), options.getParitionColumn(), options.getPartitioningScheme(), options.getFileFormat()));
}
Aggregations