-
Notifications
You must be signed in to change notification settings - Fork 3k
StreamingOffset Of Structured streaming read for Iceberg #2092
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| int version = JsonUtil.getInt(VERSION, node); | ||
| if (version > CURR_VERSION) { | ||
| throw new IOException(String.format("Cannot deserialize a JSON offset from version %d. %d is not compatible " + | ||
| "with the version of Iceberg %d and cannot be used. Please use a compatible version of Iceberg " + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bit confusing because it's not the Iceberg version, but the Streaming Offset Version. Maybe just phrase it instead "This version of iceberg only supports version $curversion"
| * snapshot. | ||
| * snapshot_fully_processed: Denote whether the current snapshot is fully processed, to avoid revisiting the processed | ||
| * snapshot. | ||
| */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Somewhat of a nit: Can you please make this a proper javadoc comment, such as using @param before the constructor parameters, listing out all of the constructor parameters in order, as well as formatting the constructor parameters the way that they are in the code (i.e. using camel case and not snake case)? I would say also that the line This StreamingOffset consists of: will be unnecessary if you do that.
|
Thanks @RussellSpitzer @kbendick review this PR. |
|
hi @aokolnychyi @rdblue please take a look at this PR at your convenience. |
| } | ||
|
|
||
| static StreamingOffset fromJson(String json) { | ||
| Preconditions.checkNotNull(json, "The input JSON string is null"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: it might be best to have a more explanatory message in the Preconditions check. Something like The input JSON string representation of a StreamingOffset cannot be null. I'll leave that up to you / the others to decide as it's a minor nit.
| // The version of StreamingOffset. The offset was created with a version number | ||
| // used to validate when deserializing from json string. | ||
| int version = JsonUtil.getInt(VERSION, node); | ||
| if (version > CURR_VERSION) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we not plan to support version 2 snapshot files yet? I suppose that makes sense given the need to process deletes etc with the version 2 snapshots, but looking to understand what other reasons might exist for not supporting them yet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right now, I think we want to focus on v1 data. But I think this version is actually referring to the version of the offset JSON, in case we need to change it later.
| private static final String SNAPSHOT_ID = "snapshot_id"; | ||
| private static final String INDEX = "index"; | ||
| private static final String SCAN_ALL_FILES = "scan_all_files"; | ||
| private static final String SNAPSHOT_FULLY_PROCESSED = "snapshot_fully_processed"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that data and delete files can report the row position within a manifest, I don't think that we need to use SNAPSHOT_FULLY_PROCESSED anymore. Even if manifests are filtered, the position will be reliable. So by using position for the index field in this offset, we can check whether a given manifest has been completely processed by comparing the index with the number of entries in the manifest.
I think that getting rid of this field and using a simpler offset is a good improvement.
| * @param snapshotId The current processed snapshot id. | ||
| * @param index The index of last scanned file in snapshot. | ||
| * @param scanAllFiles Denote whether to scan all files in a snapshot, currently we only | ||
| * scan all files in the starting snapshot. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Docs should not refer to currently. If you want to give context for why this might be used, then use "for example". "Whether to scan all files in a snapshot; for example, to read all data when starting a stream"
| * revisiting the processed snapshot. | ||
| */ | ||
| StreamingOffset(long snapshotId, int index, boolean scanAllFiles, | ||
| boolean snapshotFullyProcessed) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: looks like this newline is unnecessary.
| } | ||
|
|
||
| static StreamingOffset fromJson(String json) { | ||
| Preconditions.checkNotNull(json, "The input JSON string representation of a StreamingOffset cannot be null"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error messages typically follow the pattern "Invalid ..." or "Cannot (action): (reason) [suggestion]". Here, there is no suggestion for fixing it, so it would be something like "Cannot parse offset JSON: null".
|
|
||
| return new StreamingOffset(snapshotId, index, shouldScanAllFiles, snapshotFullyProcessed); | ||
| } catch (IOException e) { | ||
| throw new IllegalStateException(String.format("Failed to parse StreamingOffset from JSON string %s", json), e); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be IllegalArgumentException instead. There is no state in this static method.
|
|
||
| import static org.apache.iceberg.types.Types.NestedField.optional; | ||
|
|
||
| public abstract class TestStructuredStreamingRead { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This class has no tests? Can you remove it?
| // used to validate when deserializing from json string. | ||
| int version = JsonUtil.getInt(VERSION, node); | ||
| if (version > CURR_VERSION) { | ||
| throw new IOException(String.format("This version of iceberg only supports version %s", CURR_VERSION)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should not throw IOException, I think it would be IllegalArgumentException, which means you could use a Precondition. Also, I'd prefer to have the error message follow conventions:
Preconditions.check(version == CURR_VERSION,
"Cannot parse offset JSON: offset version %s is not supported", version);| public ExpectedException exceptionRule = ExpectedException.none(); | ||
|
|
||
| @BeforeClass | ||
| public static void startSpark() throws IOException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR introduces a simple class that can serialize/deserialize itself using JSON.
I don't see any value in having a test that creates a Spark session and does dataframe operations. I think what needs to be tested is that you can create an offset, get the expected values from the getter methods, serialize, and deserialize correctly. Those don't involve Spark, so I don't see a reason to slow down tests overall by adding Spark tests here.
Can you remove the Spark code and do some basic tests for serialization?
|
Thanks for updating this, @XuQianJin-Stars. I think the implementation looks good now. We just need to fix up the tests. Thanks! |
d26b839 to
c1fba28
Compare
|
hi @rdblueThanks again, I have updating it. |
|
hi @rdblue would you please take another look at this PR at your convenience. |
|
Will do. Thanks for pinging me. |
|
Looks good now. I'll merge this. Thanks @XuQianJin-Stars! |
An implementation of Spark Structured Streaming Offset, to track the current processed files of Iceberg table, This PR is a split of the PR-796 of Structured streaming read for Iceberg.