kbendick commented on a change in pull request #3039:
URL: https://github.com/apache/iceberg/pull/3039#discussion_r703964671
##########
File path: spark/src/main/java/org/apache/iceberg/spark/SparkReadOptions.java
##########
@@ -53,4 +53,7 @@ private SparkReadOptions() {
// skip snapshots of type delete while reading stream out of iceberg table
public static final String STREAMING_SKIP_DELETE_SNAPSHOTS =
"streaming-skip-delete-snapshots";
+
+ // Timestamp in milliseconds; start a stream from the snapshot that occurs
after this timestamp
+ public static final String STREAM_FROM_TIMESTAMP = "stream-from-timestamp";
Review comment:
Cool. Between your explanation and Sreerams, that's fine.
The rest is unrelated. Sreeram's also provided the motivation for me. Thank
you!
##########
File path:
spark3/src/test/java/org/apache/iceberg/spark/source/TestStructuredStreamingRead3.java
##########
@@ -165,6 +166,86 @@ public void
testReadStreamOnIcebergTableWithMultipleSnapshots() throws Exception
Assertions.assertThat(actual).containsExactlyInAnyOrderElementsOf(Iterables.concat(expected));
}
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testReadingStreamFromTimestamp() throws Exception {
+ List<SimpleRecord> dataBeforeTimestamp = Lists.newArrayList(
+ new SimpleRecord(-2, "minustwo"),
+ new SimpleRecord(-1, "minusone"),
+ new SimpleRecord(0, "zero"));
+ appendData(dataBeforeTimestamp, tableIdentifier, "parquet");
+
+ table.refresh();
+ long streamStartTimestamp = table.currentSnapshot().timestampMillis() + 1;
+
+ List<List<SimpleRecord>> expected = TEST_DATA_MULTIPLE_SNAPSHOTS;
+ appendDataAsMultipleSnapshots(expected, tableIdentifier);
+
+ table.refresh();
+
+ Dataset<Row> df = spark.readStream()
+ .format("iceberg")
+ .option(SparkReadOptions.STREAM_FROM_TIMESTAMP,
Long.toString(streamStartTimestamp))
+ .load(tableIdentifier);
+ List<SimpleRecord> actual = processAvailable(df);
+
+
Assertions.assertThat(actual).containsExactlyInAnyOrderElementsOf(Iterables.concat(expected));
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testReadingStreamFromTimestampStartWithExistingTimestamp()
throws Exception {
+ List<SimpleRecord> dataBeforeTimestamp = Lists.newArrayList(
+ new SimpleRecord(-2, "minustwo"),
+ new SimpleRecord(-1, "minusone"),
+ new SimpleRecord(0, "zero"));
+ appendData(dataBeforeTimestamp, tableIdentifier, "parquet");
+
+ table.refresh();
+ long seedDataTimestamp = table.currentSnapshot().timestampMillis();
+
+ List<List<SimpleRecord>> expected = TEST_DATA_MULTIPLE_SNAPSHOTS;
+ appendDataAsMultipleSnapshots(expected, tableIdentifier);
+
+ table.refresh();
+
+ // Find most recent available timestamp after seedDataTimestamp
+ Snapshot mostRecentSnapshotAfterSeedData = table.currentSnapshot();
+ while (mostRecentSnapshotAfterSeedData.parentId() != null
+ &&
table.snapshot(mostRecentSnapshotAfterSeedData.parentId()).timestampMillis() >
seedDataTimestamp) {
+ mostRecentSnapshotAfterSeedData =
table.snapshot(mostRecentSnapshotAfterSeedData.parentId());
+ }
Review comment:
Nit. You could just do one append, refresh, get the timestamp, then do
multiple snapshots.
But this is fine too.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]