Search in sources :

Example 36 with Metadata

use of org.apache.beam.sdk.io.fs.MatchResult.Metadata in project beam by apache.

the class FileBasedSourceTest method testSplitAtFraction.

@Test
public void testSplitAtFraction() throws Exception {
    PipelineOptions options = PipelineOptionsFactory.create();
    File file = createFileWithData("file", createStringDataset(3, 100));
    Metadata metadata = FileSystems.matchSingleFileSpec(file.getPath());
    TestFileBasedSource source = new TestFileBasedSource(metadata, 1, 0, file.length(), null);
    // Shouldn't be able to split while unstarted.
    assertSplitAtFractionFails(source, 0, 0.7, options);
    assertSplitAtFractionSucceedsAndConsistent(source, 1, 0.7, options);
    assertSplitAtFractionSucceedsAndConsistent(source, 30, 0.7, options);
    assertSplitAtFractionFails(source, 0, 0.0, options);
    assertSplitAtFractionFails(source, 70, 0.3, options);
    assertSplitAtFractionFails(source, 100, 1.0, options);
    assertSplitAtFractionFails(source, 100, 0.99, options);
    assertSplitAtFractionSucceedsAndConsistent(source, 100, 0.995, options);
}
Also used : PipelineOptions(org.apache.beam.sdk.options.PipelineOptions) Metadata(org.apache.beam.sdk.io.fs.MatchResult.Metadata) File(java.io.File) Test(org.junit.Test)

Example 37 with Metadata

use of org.apache.beam.sdk.io.fs.MatchResult.Metadata in project beam by apache.

the class FileBasedSourceTest method testToStringFile.

@Test
public void testToStringFile() throws Exception {
    File f = createFileWithData("foo", Collections.emptyList());
    Metadata metadata = FileSystems.matchSingleFileSpec(f.getPath());
    TestFileBasedSource source = new TestFileBasedSource(metadata, 1, 0, 10, null);
    assertEquals(String.format("%s range [0, 10)", f.getAbsolutePath()), source.toString());
}
Also used : Metadata(org.apache.beam.sdk.io.fs.MatchResult.Metadata) File(java.io.File) Test(org.junit.Test)

Example 38 with Metadata

use of org.apache.beam.sdk.io.fs.MatchResult.Metadata in project beam by apache.

the class FileBasedSourceTest method testSplitAtFractionExhaustive.

@Test
public void testSplitAtFractionExhaustive() throws Exception {
    PipelineOptions options = PipelineOptionsFactory.create();
    // Smaller file for exhaustive testing.
    File file = createFileWithData("file", createStringDataset(3, 20));
    Metadata metadata = FileSystems.matchSingleFileSpec(file.getPath());
    TestFileBasedSource source = new TestFileBasedSource(metadata, 1, 0, file.length(), null);
    assertSplitAtFractionExhaustive(source, options);
}
Also used : PipelineOptions(org.apache.beam.sdk.options.PipelineOptions) Metadata(org.apache.beam.sdk.io.fs.MatchResult.Metadata) File(java.io.File) Test(org.junit.Test)

Example 39 with Metadata

use of org.apache.beam.sdk.io.fs.MatchResult.Metadata in project beam by apache.

the class MetadataCoderV2Test method testEncodeDecodeWithCustomLastModifiedMills.

@Test
public void testEncodeDecodeWithCustomLastModifiedMills() throws Exception {
    Path filePath = tmpFolder.newFile("somefile").toPath();
    Metadata metadata = Metadata.builder().setResourceId(FileSystems.matchNewResource(filePath.toString(), false)).setIsReadSeekEfficient(true).setSizeBytes(1024).setLastModifiedMillis(1541097000L).build();
    CoderProperties.coderDecodeEncodeEqual(MetadataCoderV2.of(), metadata);
}
Also used : Path(java.nio.file.Path) Metadata(org.apache.beam.sdk.io.fs.MatchResult.Metadata) Test(org.junit.Test)

Example 40 with Metadata

use of org.apache.beam.sdk.io.fs.MatchResult.Metadata in project beam by apache.

the class MetadataCoderV2Test method testEncodeDecodeWithDefaultLastModifiedMills.

@Test
public void testEncodeDecodeWithDefaultLastModifiedMills() throws Exception {
    Path filePath = tmpFolder.newFile("somefile").toPath();
    Metadata metadata = Metadata.builder().setResourceId(FileSystems.matchNewResource(filePath.toString(), false)).setIsReadSeekEfficient(true).setSizeBytes(1024).build();
    CoderProperties.coderDecodeEncodeEqual(MetadataCoderV2.of(), metadata);
}
Also used : Path(java.nio.file.Path) Metadata(org.apache.beam.sdk.io.fs.MatchResult.Metadata) Test(org.junit.Test)

Aggregations

Metadata (org.apache.beam.sdk.io.fs.MatchResult.Metadata)42 Test (org.junit.Test)22 File (java.io.File)16 ArrayList (java.util.ArrayList)14 PipelineOptions (org.apache.beam.sdk.options.PipelineOptions)9 MatchResult (org.apache.beam.sdk.io.fs.MatchResult)6 VisibleForTesting (org.apache.beam.vendor.guava.v26_0_jre.com.google.common.annotations.VisibleForTesting)6 IOException (java.io.IOException)5 Path (java.nio.file.Path)5 AvroMetadata (org.apache.beam.sdk.io.AvroSource.AvroMetadata)5 Reader (java.io.Reader)4 List (java.util.List)4 ImmutableList (org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.ImmutableList)4 BufferedReader (java.io.BufferedReader)3 Matcher (java.util.regex.Matcher)3 Pattern (java.util.regex.Pattern)3 GenericRecord (org.apache.avro.generic.GenericRecord)3 FileReader (java.io.FileReader)2 HashSet (java.util.HashSet)2 FileStatus (org.apache.hadoop.fs.FileStatus)2