Java Code Examples for org.apache.beam.sdk.io.TextIO#Write
The following examples show how to use
org.apache.beam.sdk.io.TextIO#Write .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InvoicingPipeline.java From nomulus with Apache License 2.0 | 6 votes |
/** Returns an IO transform that writes the overall invoice to a single CSV file. */ private TextIO.Write writeInvoice(ValueProvider<String> yearMonthProvider) { return TextIO.write() .to( NestedValueProvider.of( yearMonthProvider, yearMonth -> String.format( "%s/%s/%s/%s-%s", billingBucketUrl, BillingModule.INVOICES_DIRECTORY, yearMonth, invoiceFilePrefix, yearMonth))) .withHeader(InvoiceGroupingKey.invoiceHeader()) .withoutSharding() .withSuffix(".csv"); }
Example 2
Source File: DynamicOneFilePerWindow.java From dlp-dataflow-deidentification with Apache License 2.0 | 5 votes |
@Override public PDone expand(PCollection<KV<String, String>> input) { PCollection<String> contents = input.apply( ParDo.of( new DoFn<KV<String, String>, String>() { @ProcessElement public void processElement(ProcessContext c) { filenamePrefix = String.format("%s%s", filenamePrefix, c.element().getKey()); LOG.info("File Prefix {}", filenamePrefix); c.output(c.element().getValue()); } })); ResourceId resource = FileBasedSink.convertToFileResourceIfPossible(filenamePrefix); TextIO.Write write = TextIO.write() .to(new PerWindowFiles(resource)) .withTempDirectory(resource.getCurrentDirectory()) .withWindowedWrites(); if (numShards != null) { write = write.withNumShards(numShards); } return contents.apply(write); }
Example 3
Source File: WriteOneFilePerWindow.java From dlp-dataflow-deidentification with Apache License 2.0 | 5 votes |
@Override public PDone expand(PCollection<String> input) { ResourceId resource = FileBasedSink.convertToFileResourceIfPossible(filenamePrefix); TextIO.Write write = TextIO.write() .to(new PerWindowFiles(resource)) .withTempDirectory(resource.getCurrentDirectory()) .withWindowedWrites(); if (numShards != null) { write = write.withNumShards(numShards); } return input.apply(write); }
Example 4
Source File: WriteOneFilePerWindow.java From incubator-nemo with Apache License 2.0 | 5 votes |
@Override public PDone expand(final PCollection<String> input) { final ResourceId resource = FileBasedSink.convertToFileResourceIfPossible(filenamePrefix); TextIO.Write write = TextIO.write() .to(new PerWindowFiles(resource)) .withTempDirectory(resource.getCurrentDirectory()) .withWindowedWrites(); if (numShards != null) { write = write.withNumShards(numShards); } return input.apply(write); }
Example 5
Source File: WriteOneFilePerWindow.java From deployment-examples with MIT License | 5 votes |
@Override public PDone expand(PCollection<String> input) { ResourceId resource = FileBasedSink.convertToFileResourceIfPossible(filenamePrefix); TextIO.Write write = TextIO.write() .to(new PerWindowFiles(resource)) .withTempDirectory(resource.getCurrentDirectory()) .withWindowedWrites(); if (numShards != null) { write = write.withNumShards(numShards); } return input.apply(write); }
Example 6
Source File: WriteOneFilePerWindow.java From beam with Apache License 2.0 | 5 votes |
@Override public PDone expand(PCollection<String> input) { ResourceId resource = FileBasedSink.convertToFileResourceIfPossible(filenamePrefix); TextIO.Write write = TextIO.write() .to(new PerWindowFiles(resource)) .withTempDirectory(resource.getCurrentDirectory()) .withWindowedWrites(); if (numShards != null) { write = write.withNumShards(numShards); } return input.apply(write); }
Example 7
Source File: BeamOutputTransform.java From hop with Apache License 2.0 | 4 votes |
@Override public PDone expand( PCollection<HopRow> input ) { try { // Only initialize once on this node/vm // BeamHop.init(transformPluginClasses, xpPluginClasses); // Inflate the metadata on the node where this is running... // IRowMeta rowMeta = JsonRowMeta.fromJson( rowMetaJson ); // This is the end of a computing chain, we write out the results // We write a bunch of Strings, one per line basically // PCollection<String> stringCollection = input.apply( transformName, ParDo.of( new HopToStringFn( transformName, outputLocation, separator, enclosure, rowMetaJson, transformPluginClasses, xpPluginClasses ) ) ); // We need to transform these lines into a file and then we're PDone // TextIO.Write write = TextIO.write(); if ( StringUtils.isNotEmpty(outputLocation)) { String outputPrefix = outputLocation; if (!outputPrefix.endsWith( File.separator)) { outputPrefix+=File.separator; } if (StringUtils.isNotEmpty( filePrefix )) { outputPrefix+=filePrefix; } write = write.to( outputPrefix ); } if (StringUtils.isNotEmpty( fileSuffix )) { write = write.withSuffix( fileSuffix ); } // For streaming data sources... // if (windowed) { write = write.withWindowedWrites().withNumShards( 4 ); // TODO config } stringCollection.apply(write); // Get it over with // return PDone.in(input.getPipeline()); } catch ( Exception e ) { numErrors.inc(); LOG.error( "Error in beam output transform", e ); throw new RuntimeException( "Error in beam output transform", e ); } }
Example 8
Source File: BeamOutputTransform.java From kettle-beam with Apache License 2.0 | 4 votes |
@Override public PDone expand( PCollection<KettleRow> input ) { try { // Only initialize once on this node/vm // BeamKettle.init(stepPluginClasses, xpPluginClasses); // Inflate the metadata on the node where this is running... // RowMetaInterface rowMeta = JsonRowMeta.fromJson( rowMetaJson ); // This is the end of a computing chain, we write out the results // We write a bunch of Strings, one per line basically // PCollection<String> stringCollection = input.apply( stepname, ParDo.of( new KettleToStringFn( stepname, outputLocation, separator, enclosure, rowMetaJson, stepPluginClasses, xpPluginClasses ) ) ); // We need to transform these lines into a file and then we're PDone // TextIO.Write write = TextIO.write(); if ( StringUtils.isNotEmpty(outputLocation)) { String outputPrefix = outputLocation; if (!outputPrefix.endsWith( File.separator)) { outputPrefix+=File.separator; } if (StringUtils.isNotEmpty( filePrefix )) { outputPrefix+=filePrefix; } write = write.to( outputPrefix ); } if (StringUtils.isNotEmpty( fileSuffix )) { write = write.withSuffix( fileSuffix ); } // For streaming data sources... // if (windowed) { write = write.withWindowedWrites().withNumShards( 4 ); // TODO config } stringCollection.apply(write); // Get it over with // return PDone.in(input.getPipeline()); } catch ( Exception e ) { numErrors.inc(); LOG.error( "Error in beam output transform", e ); throw new RuntimeException( "Error in beam output transform", e ); } }
Example 9
Source File: TextTableProvider.java From beam with Apache License 2.0 | 4 votes |
private TextIO.Write writeJsonToDlf() { return TextIO.write().withDelimiter(new char[] {}).to(deadLetterFile()); }