Java Code Examples for org.apache.beam.sdk.io.FileBasedSink.OutputFileHints

The following examples show how to use org.apache.beam.sdk.io.FileBasedSink.OutputFileHints. These examples are extracted from open source projects. 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
@Override
public ResourceId windowedFilename(
    int shardNumber,
    int numShards,
    BoundedWindow window,
    PaneInfo paneInfo,
    OutputFileHints outputFileHints) {
  IntervalWindow intervalWindow = (IntervalWindow) window;
  String filename =
      String.format(
          "%s-%s-of-%s%s",
          filenamePrefixForWindow(intervalWindow),
          shardNumber,
          numShards,
          outputFileHints.getSuggestedFilenameSuffix());
  return baseFilename
      .getCurrentDirectory()
      .resolve(filename, StandardResolveOptions.RESOLVE_FILE);
}
 
Example 2
@Override
public ResourceId windowedFilename(
    int shardNumber,
    int numShards,
    BoundedWindow window,
    PaneInfo paneInfo,
    OutputFileHints outputFileHints) {
  IntervalWindow intervalWindow = (IntervalWindow) window;
  String filename =
      String.format(
          "%s-%s-of-%s%s",
          filenamePrefixForWindow(intervalWindow),
          shardNumber,
          numShards,
          outputFileHints.getSuggestedFilenameSuffix());
  return baseFilename
      .getCurrentDirectory()
      .resolve(filename, StandardResolveOptions.RESOLVE_FILE);
}
 
Example 3
Source Project: deployment-examples   Source File: WriteToText.java    License: MIT License 6 votes vote down vote up
@Override
public ResourceId windowedFilename(
    int shardNumber,
    int numShards,
    BoundedWindow window,
    PaneInfo paneInfo,
    OutputFileHints outputFileHints) {
  IntervalWindow intervalWindow = (IntervalWindow) window;
  String filename =
      String.format(
          "%s-%s-of-%s%s",
          filenamePrefixForWindow(intervalWindow),
          shardNumber,
          numShards,
          outputFileHints.getSuggestedFilenameSuffix());
  return prefix.getCurrentDirectory().resolve(filename, StandardResolveOptions.RESOLVE_FILE);
}
 
Example 4
Source Project: deployment-examples   Source File: WriteOneFilePerWindow.java    License: MIT License 6 votes vote down vote up
@Override
public ResourceId windowedFilename(
    int shardNumber,
    int numShards,
    BoundedWindow window,
    PaneInfo paneInfo,
    OutputFileHints outputFileHints) {
  IntervalWindow intervalWindow = (IntervalWindow) window;
  String filename =
      String.format(
          "%s-%s-of-%s%s",
          filenamePrefixForWindow(intervalWindow),
          shardNumber,
          numShards,
          outputFileHints.getSuggestedFilenameSuffix());
  return baseFilename
      .getCurrentDirectory()
      .resolve(filename, StandardResolveOptions.RESOLVE_FILE);
}
 
Example 5
Source Project: DataflowTemplates   Source File: WindowedFilenamePolicy.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * The windowed filename method will construct filenames per window according to the baseFile,
 * suffix, and shardTemplate supplied. Directories with date templates in them will automatically
 * have their values resolved. For example the outputDirectory of /YYYY/MM/DD would resolve to
 * /2017/01/08 on January 8th, 2017.
 */
@Override
public ResourceId windowedFilename(
        int shardNumber,
        int numShards,
        BoundedWindow window,
        PaneInfo paneInfo,
        OutputFileHints outputFileHints) {

    ResourceId outputFile =
            resolveWithDateTemplates(outputDirectory, window)
                    .resolve(outputFilenamePrefix.get(), StandardResolveOptions.RESOLVE_FILE);

    DefaultFilenamePolicy policy =
            DefaultFilenamePolicy.fromStandardParameters(
                    StaticValueProvider.of(outputFile), shardTemplate.get(), suffix.get(), true);
    ResourceId result =
            policy.windowedFilename(shardNumber, numShards, window, paneInfo, outputFileHints);
    LOG.debug("Windowed file name policy created: {}", result.toString());
    return result;
}
 
Example 6
Source Project: DataflowTemplates   Source File: WindowedFilenamePolicy.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * The windowed filename method will construct filenames per window according to the baseFile,
 * suffix, and shardTemplate supplied. Directories with date templates in them will automatically
 * have their values resolved. For example the outputDirectory of /YYYY/MM/DD would resolve to
 * /2017/01/08 on January 8th, 2017.
 */
@Override
public ResourceId windowedFilename(
    int shardNumber,
    int numShards,
    BoundedWindow window,
    PaneInfo paneInfo,
    OutputFileHints outputFileHints) {

  ResourceId outputFile =
      resolveWithDateTemplates(outputDirectory, window)
          .resolve(outputFilenamePrefix.get(), StandardResolveOptions.RESOLVE_FILE);

  DefaultFilenamePolicy policy =
      DefaultFilenamePolicy.fromStandardParameters(
          StaticValueProvider.of(outputFile), shardTemplate.get(), suffix.get(), true);
  ResourceId result =
      policy.windowedFilename(shardNumber, numShards, window, paneInfo, outputFileHints);
  LOG.debug("Windowed file name policy created: {}", result.toString());
  return result;
}
 
Example 7
Source Project: beam   Source File: WriteToText.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public ResourceId windowedFilename(
    int shardNumber,
    int numShards,
    BoundedWindow window,
    PaneInfo paneInfo,
    OutputFileHints outputFileHints) {
  IntervalWindow intervalWindow = (IntervalWindow) window;
  String filename =
      String.format(
          "%s-%s-of-%s%s",
          filenamePrefixForWindow(intervalWindow),
          shardNumber,
          numShards,
          outputFileHints.getSuggestedFilenameSuffix());
  return prefix.getCurrentDirectory().resolve(filename, StandardResolveOptions.RESOLVE_FILE);
}
 
Example 8
Source Project: beam   Source File: WriteOneFilePerWindow.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public ResourceId windowedFilename(
    int shardNumber,
    int numShards,
    BoundedWindow window,
    PaneInfo paneInfo,
    OutputFileHints outputFileHints) {
  IntervalWindow intervalWindow = (IntervalWindow) window;
  String filename =
      String.format(
          "%s-%s-of-%s%s",
          filenamePrefixForWindow(intervalWindow),
          shardNumber,
          numShards,
          outputFileHints.getSuggestedFilenameSuffix());
  return baseFilename
      .getCurrentDirectory()
      .resolve(filename, StandardResolveOptions.RESOLVE_FILE);
}
 
Example 9
Source Project: beam   Source File: DefaultFilenamePolicy.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public ResourceId windowedFilename(
    int shardNumber,
    int numShards,
    BoundedWindow window,
    PaneInfo paneInfo,
    OutputFileHints outputFileHints) {
  String paneStr = paneInfoToString(paneInfo);
  String windowStr = windowToString(window);
  return constructName(
      params.baseFilename.get(),
      params.shardTemplate,
      params.suffix + outputFileHints.getSuggestedFilenameSuffix(),
      shardNumber,
      numShards,
      paneStr,
      windowStr);
}
 
Example 10
Source Project: beam   Source File: WriteFilesTest.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public ResourceId windowedFilename(
    int shardNumber,
    int numShards,
    BoundedWindow window,
    PaneInfo paneInfo,
    OutputFileHints outputFileHints) {
  DecimalFormat df = new DecimalFormat("0000");
  IntervalWindow intervalWindow = (IntervalWindow) window;
  String filename =
      String.format(
          "%s-%s-of-%s%s%s",
          filenamePrefixForWindow(intervalWindow),
          df.format(shardNumber),
          df.format(numShards),
          outputFileHints.getSuggestedFilenameSuffix(),
          suffix);
  return baseFilename
      .getCurrentDirectory()
      .resolve(filename, StandardResolveOptions.RESOLVE_FILE);
}
 
Example 11
Source Project: beam   Source File: WriteFilesTest.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public ResourceId unwindowedFilename(
    int shardNumber, int numShards, OutputFileHints outputFileHints) {
  DecimalFormat df = new DecimalFormat("0000");
  String prefix =
      baseFilename.isDirectory() ? "" : firstNonNull(baseFilename.getFilename(), "");
  String filename =
      String.format(
          "%s-%s-of-%s%s%s",
          prefix,
          df.format(shardNumber),
          df.format(numShards),
          outputFileHints.getSuggestedFilenameSuffix(),
          suffix);
  return baseFilename
      .getCurrentDirectory()
      .resolve(filename, StandardResolveOptions.RESOLVE_FILE);
}
 
Example 12
Source Project: beam   Source File: AvroIOTest.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public ResourceId windowedFilename(
    int shardNumber,
    int numShards,
    BoundedWindow window,
    PaneInfo paneInfo,
    OutputFileHints outputFileHints) {
  String filenamePrefix =
      outputFilePrefix.isDirectory() ? "" : firstNonNull(outputFilePrefix.getFilename(), "");

  IntervalWindow interval = (IntervalWindow) window;
  String windowStr =
      String.format("%s-%s", interval.start().toString(), interval.end().toString());
  String filename =
      String.format(
          "%s-%s-%s-of-%s-pane-%s%s%s.avro",
          filenamePrefix,
          windowStr,
          shardNumber,
          numShards,
          paneInfo.getIndex(),
          paneInfo.isLast() ? "-last" : "",
          outputFileHints.getSuggestedFilenameSuffix());
  return outputFilePrefix.getCurrentDirectory().resolve(filename, RESOLVE_FILE);
}
 
Example 13
Source Project: DataflowTemplates   Source File: WindowedFilenamePolicy.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Unwindowed writes are unsupported by this filename policy so an {@link
 * UnsupportedOperationException} will be thrown if invoked.
 */
@Override
public ResourceId unwindowedFilename(
        int shardNumber, int numShards, OutputFileHints outputFileHints) {
    throw new UnsupportedOperationException(
            "There is no windowed filename policy for "
                    + "unwindowed file output. Please use the WindowedFilenamePolicy with windowed "
                    + "writes or switch filename policies.");
}
 
Example 14
Source Project: DataflowTemplates   Source File: WindowedFilenamePolicy.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Unwindowed writes are unsupported by this filename policy so an {@link
 * UnsupportedOperationException} will be thrown if invoked.
 */
@Override
public ResourceId unwindowedFilename(
    int shardNumber, int numShards, OutputFileHints outputFileHints) {
  throw new UnsupportedOperationException(
      "There is no windowed filename policy for "
          + "unwindowed file output. Please use the WindowedFilenamePolicy with windowed "
          + "writes or switch filename policies.");
}
 
Example 15
Source Project: beam   Source File: DefaultFilenamePolicy.java    License: Apache License 2.0 5 votes vote down vote up
@Override
@Nullable
public ResourceId unwindowedFilename(
    int shardNumber, int numShards, OutputFileHints outputFileHints) {
  return constructName(
      params.baseFilename.get(),
      params.shardTemplate,
      params.suffix + outputFileHints.getSuggestedFilenameSuffix(),
      shardNumber,
      numShards,
      null,
      null);
}
 
Example 16
Source Project: beam   Source File: WriteFilesTranslationTest.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public ResourceId windowedFilename(
    int shardNumber,
    int numShards,
    BoundedWindow window,
    PaneInfo paneInfo,
    OutputFileHints outputFileHints) {
  throw new UnsupportedOperationException("Should never be called.");
}
 
Example 17
@Override
public ResourceId unwindowedFilename(
    int shardNumber, int numShards, OutputFileHints outputFileHints) {
  throw new UnsupportedOperationException("Unsupported.");
}
 
Example 18
@Override
public ResourceId unwindowedFilename(
    int shardNumber, int numShards, OutputFileHints outputFileHints) {
  throw new UnsupportedOperationException("Unsupported.");
}
 
Example 19
Source Project: deployment-examples   Source File: WriteToText.java    License: MIT License 4 votes vote down vote up
@Override
public ResourceId unwindowedFilename(
    int shardNumber, int numShards, OutputFileHints outputFileHints) {
  throw new UnsupportedOperationException("Unsupported.");
}
 
Example 20
Source Project: deployment-examples   Source File: WriteOneFilePerWindow.java    License: MIT License 4 votes vote down vote up
@Override
public ResourceId unwindowedFilename(
    int shardNumber, int numShards, OutputFileHints outputFileHints) {
  throw new UnsupportedOperationException("Unsupported.");
}
 
Example 21
Source Project: beam   Source File: WriteToText.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public ResourceId unwindowedFilename(
    int shardNumber, int numShards, OutputFileHints outputFileHints) {
  throw new UnsupportedOperationException("Unsupported.");
}
 
Example 22
Source Project: beam   Source File: WriteOneFilePerWindow.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public ResourceId unwindowedFilename(
    int shardNumber, int numShards, OutputFileHints outputFileHints) {
  throw new UnsupportedOperationException("Unsupported.");
}
 
Example 23
Source Project: beam   Source File: AvroIOTest.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public ResourceId unwindowedFilename(
    int shardNumber, int numShards, OutputFileHints outputFileHints) {
  throw new UnsupportedOperationException("Expecting windowed outputs only");
}
 
Example 24
Source Project: beam   Source File: WriteFilesTranslationTest.java    License: Apache License 2.0 4 votes vote down vote up
@Nullable
@Override
public ResourceId unwindowedFilename(
    int shardNumber, int numShards, OutputFileHints outputFileHints) {
  throw new UnsupportedOperationException("Should never be called.");
}