Search in sources :

Example 6 with CheckpointedPosition

use of org.apache.flink.connector.file.src.util.CheckpointedPosition in project flink by apache.

the class FileSourceSplitStateTest method testStateStartsWithSplitValues.

@Test
public void testStateStartsWithSplitValues() {
    final FileSourceSplit split = getTestSplit(new CheckpointedPosition(123L, 456L));
    final FileSourceSplitState state = new FileSourceSplitState(split);
    assertEquals(123L, state.getOffset());
    assertEquals(456L, state.getRecordsToSkipAfterOffset());
}
Also used : CheckpointedPosition(org.apache.flink.connector.file.src.util.CheckpointedPosition) Test(org.junit.Test)

Example 7 with CheckpointedPosition

use of org.apache.flink.connector.file.src.util.CheckpointedPosition in project flink by apache.

the class AdapterTestBase method testClosesStreamIfReaderRestoreFails.

@Test
public void testClosesStreamIfReaderRestoreFails() throws Exception {
    // setup
    final Path testPath = new Path("testFs:///testpath-1");
    final CloseTestingInputStream in = new CloseTestingInputStream();
    final TestingFileSystem testFs = TestingFileSystem.createForFileStatus("testFs", TestingFileSystem.TestFileStatus.forFileWithStream(testPath, 1024, in));
    testFs.register();
    // test
    final BulkFormat<Integer, FileSourceSplit> adapter = wrapWithAdapter(createFormatFailingInInstantiation());
    final FileSourceSplit split = new FileSourceSplit("id", testPath, 0, 1024, 0, 1024, new String[0], new CheckpointedPosition(0L, 5L));
    try {
        adapter.restoreReader(new Configuration(), split);
    } catch (IOException ignored) {
    }
    // assertions
    assertTrue(in.closed);
    // cleanup
    testFs.unregister();
}
Also used : Path(org.apache.flink.core.fs.Path) FileSourceSplit(org.apache.flink.connector.file.src.FileSourceSplit) Configuration(org.apache.flink.configuration.Configuration) TestingFileSystem(org.apache.flink.connector.file.src.testutils.TestingFileSystem) CheckpointedPosition(org.apache.flink.connector.file.src.util.CheckpointedPosition) IOException(java.io.IOException) Test(org.junit.Test)

Example 8 with CheckpointedPosition

use of org.apache.flink.connector.file.src.util.CheckpointedPosition in project flink by apache.

the class ParquetVectorizedInputFormat method restoreReader.

@Override
public ParquetReader restoreReader(final Configuration config, final SplitT split) throws IOException {
    assert split.getReaderPosition().isPresent();
    final CheckpointedPosition checkpointedPosition = split.getReaderPosition().get();
    Preconditions.checkArgument(checkpointedPosition.getOffset() == CheckpointedPosition.NO_OFFSET, "The offset of CheckpointedPosition should always be NO_OFFSET");
    ParquetReader reader = createReader(config, split);
    reader.seek(checkpointedPosition.getRecordsAfterOffset());
    return reader;
}
Also used : CheckpointedPosition(org.apache.flink.connector.file.src.util.CheckpointedPosition)

Example 9 with CheckpointedPosition

use of org.apache.flink.connector.file.src.util.CheckpointedPosition in project flink by apache.

the class FileSourceSplitStateTest method testNewSplitTakesModifiedOffsetAndCount.

@Test
public void testNewSplitTakesModifiedOffsetAndCount() {
    final FileSourceSplit split = getTestSplit();
    final FileSourceSplitState state = new FileSourceSplitState(split);
    state.setPosition(1234L, 7566L);
    final Optional<CheckpointedPosition> position = state.toFileSourceSplit().getReaderPosition();
    assertTrue(position.isPresent());
    assertEquals(new CheckpointedPosition(1234L, 7566L), position.get());
}
Also used : CheckpointedPosition(org.apache.flink.connector.file.src.util.CheckpointedPosition) Test(org.junit.Test)

Example 10 with CheckpointedPosition

use of org.apache.flink.connector.file.src.util.CheckpointedPosition in project flink by apache.

the class FileSourceSplitSerializerTest method serializeSplitWithReaderPosition.

@Test
public void serializeSplitWithReaderPosition() throws Exception {
    final FileSourceSplit split = new FileSourceSplit("random-id", new Path("hdfs://namenode:14565/some/path/to/a/file"), 100_000_000, 64_000_000, System.currentTimeMillis(), 200_000_000, new String[] { "host1", "host2", "host3" }, new CheckpointedPosition(7665391L, 100L));
    final FileSourceSplit deSerialized = serializeAndDeserialize(split);
    assertSplitsEqual(split, deSerialized);
}
Also used : Path(org.apache.flink.core.fs.Path) CheckpointedPosition(org.apache.flink.connector.file.src.util.CheckpointedPosition) Test(org.junit.Test)

Aggregations

CheckpointedPosition (org.apache.flink.connector.file.src.util.CheckpointedPosition)12 Path (org.apache.flink.core.fs.Path)5 Test (org.junit.Test)4 FileSourceSplit (org.apache.flink.connector.file.src.FileSourceSplit)3 IOException (java.io.IOException)2 Configuration (org.apache.flink.configuration.Configuration)2 BulkFormat (org.apache.flink.connector.file.src.reader.BulkFormat)2 RowData (org.apache.flink.table.data.RowData)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 FileRecordFormat (org.apache.flink.connector.file.src.reader.FileRecordFormat)1 StreamFormat (org.apache.flink.connector.file.src.reader.StreamFormat)1 TestingFileSystem (org.apache.flink.connector.file.src.testutils.TestingFileSystem)1 FileStatus (org.apache.flink.core.fs.FileStatus)1 DataInputDeserializer (org.apache.flink.core.memory.DataInputDeserializer)1 DataOutputSerializer (org.apache.flink.core.memory.DataOutputSerializer)1 GenericRowData (org.apache.flink.table.data.GenericRowData)1 BigIntType (org.apache.flink.table.types.logical.BigIntType)1 BooleanType (org.apache.flink.table.types.logical.BooleanType)1 DecimalType (org.apache.flink.table.types.logical.DecimalType)1