You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Use Iceberg tables as sources for Spark Structured Streaming #179
I think it is possible to leverage the snapshot log in Iceberg to use Iceberg tables as streaming sources for Structured Streaming. This would mean streaming out data from all of the files present in the table as well as from new files that arrive after the stream is started.
There are some things to think about:
What should happen if we detect deleted files while we are streaming data out?
What do we consider as one batch? For example, we will need to stream out data from all of the files present in the table when we start a query. This might be a lot of data, so we need to split it into multiple batches. The split can be based on either the number of files/records or even estimated size.
Another point to consider is how we compute diffs between snapshots. This operation should be efficient. For example, we consumed all of the data at a given point in time and then a new batch came in. We should be able to identify new files easily.
👋, I'm going through iceberg and it seems quite interesting. I have couple of questions on this issue.
What do we consider as one batch?
With Spark's Structured Streaming, need to consider the size of a microbatch as well. The size of a microbatch can be defined at the query level. Typically, that would mean reading that number of records from the stream (FileStream) in this case. The File Source in Spark Structured Streaming can read new files per batch. So, the design of a streaming Iceberg File Source can be based on that.
--
[NIV] Corinthians 13:8
Love never fails. But where there are prophecies, they will cease; where
there are tongues,they will be stilled; where there is knowledge, it will
pass away.
Li Cheng
SDE in Amazon Web Service/ Simple Storage Solution (S3)
Electrical & System Engineering
Washington University in St. Louis
--
[NIV] Corinthians 13:8
Love never fails. But where there are prophecies, they will cease; where
there are tongues,they will be stilled; where there is knowledge, it will
pass away.
Li Cheng
SDE in Amazon Web Service/ Simple Storage Solution (S3)
Electrical & System Engineering
Washington University in St. Louis
I haven't heard from anyone for a while. I would like to pick this up myself unless someone has a prototype to share.
Here are my thoughts:
When we start a stream, we should be able to stream out all currently present data in addition to what will arrive later.
As we might start a stream on a table with a lot of content, we should be able to split data into multiple batches either based on the number of files/records or based on batch size. Also, we need to take into account that files in the current snapshot could be added by already expired snapshots and we might not have metadata for those snapshots.
It should be possible to configure what operations are possible on the table while we are streaming out. We can have a config per operation or a list of allowed operations.
If the operation is not supported, then throw an exception.
If add, then stream the added data out (allowed by default).
If rewrite, then ignore such snapshots (allowed by default).
If delete, then ignore such snapshots (NOT allowed by default). Sometimes, we can delete data without impacting the correctness of a stream.
If overwrite, then stream the data out (NOT allowed by default). Consumers will have to deal with duplicates as we use this operation for eager updates.
we should be able to stream out all currently present data in addition to what will arrive later.
Agreed, but I think it would be easier to start from a particular snapshot for now, and add the ability to process all existing data as a follow-up.
we need to take into account that files in the current snapshot could be added by already expired snapshots and we might not have metadata for those snapshots.
Yes. To start with, I'd recommend ordering partition tuples and processing a partition at a time. Partitions are often time-based and correlated with the write pattern, so this approach will probably provide a smooth transition to from partitions to snapshots.
We can have a config per operation or a list of allowed operations.
This proposal sounds good to me. For overwrite, it seems like we will need a delta format to express what happened to a row as well as to pass the row contents.
@jerryshao, sorry for the delay. I am still not up to speed after holidays.
I've started thinking about it and it would be great to leverage #315. However, the last time I checked that PR (a long time ago) I didn't see a way to split a large batch commit into multiple output streaming micro-batches. For example, if a batch job inserts a couple of TBs, you might not want to stream this out of your table in one micro-batch. That got me thinking about keeping some sort of indexing (e.g. manifest name + ordinal position of the last processed file in that manifest) to split large batches. The same logic potentially can be used if we want to stream all of the data from a batch table using Structured Streaming. I haven't thought much about this idea afterwards. Maybe, there is a better way or maybe we can start without that.
@jerryshao, I'll be glad if you pick this up. Did you have any specific ideas?
@aokolnychyi I've already started a simple workable version of streaming read, hopes that I can share it soon.
About batch size control, what I did currently is to control the number of files read per batch, and record them as a Spark Offset, so that Spark could continue from restart. I haven't sorted out all the details, I would start building a simple version first, and then refine all the details.
No, I will not store files directly in the offset json file, what I currently do is to store file paths, like what spark did to FileStreamSource, when the offset is loaded in, I will compare and filter out the files which are already processed. I'm currently still in prototyping, the content of Offset may be changed.
I just submitted an initial workable version of streaming read, I would like see the comments about the current solution, if this is a feasible solution, what should be changed.
Activity
prodeezy commentedon May 10, 2019
Sounds like something we might be interested in as well. Can you add more detail as to how you envision this will be used?
aokolnychyi commentedon May 11, 2019
I think it is possible to leverage the snapshot log in Iceberg to use Iceberg tables as streaming sources for Structured Streaming. This would mean streaming out data from all of the files present in the table as well as from new files that arrive after the stream is started.
There are some things to think about:
aokolnychyi commentedon May 11, 2019
@prodeezy would you be interested to work on this?
prodeezy commentedon May 15, 2019
Looks interesting to me to work on! I'm currently discussing this internally for approval.
aokolnychyi commentedon May 19, 2019
@prodeezy sure, let me know the outcome.
aokolnychyi commentedon May 20, 2019
Another point to consider is how we compute diffs between snapshots. This operation should be efficient. For example, we consumed all of the data at a given point in time and then a new batch came in. We should be able to identify new files easily.
goldentriangle commentedon Jul 3, 2019
@prodeezy is there an ETA for this feature to be completed?
prodeezy commentedon Jul 5, 2019
prabcs commentedon Jul 22, 2019
👋, I'm going through iceberg and it seems quite interesting. I have couple of questions on this issue.
With Spark's Structured Streaming, need to consider the size of a microbatch as well. The size of a microbatch can be defined at the query level. Typically, that would mean reading that number of records from the stream (FileStream) in this case. The File Source in Spark Structured Streaming can read new files per batch. So, the design of a streaming Iceberg File Source can be based on that.
aokolnychyi commentedon Aug 5, 2019
I am thinking to pick this up in the near future. Let me know if there is anybody already working on this.
timmylicheng commentedon Aug 6, 2019
aokolnychyi commentedon Aug 6, 2019
@timmylicheng do you already have a prototype? Want to submit a PR?
aokolnychyi commentedon Aug 6, 2019
@prabcs, yeah, I also raised a similar question. I believe the micro-batch size should be configurable.
timmylicheng commentedon Aug 7, 2019
prabcs commentedon Aug 7, 2019
aokolnychyi commentedon Nov 16, 2019
I haven't heard from anyone for a while. I would like to pick this up myself unless someone has a prototype to share.
Here are my thoughts:
add, then stream the added data out (allowed by default).rewrite, then ignore such snapshots (allowed by default).delete, then ignore such snapshots (NOT allowed by default). Sometimes, we can delete data without impacting the correctness of a stream.overwrite, then stream the data out (NOT allowed by default). Consumers will have to deal with duplicates as we use this operation for eager updates.rdblue commentedon Nov 19, 2019
Agreed, but I think it would be easier to start from a particular snapshot for now, and add the ability to process all existing data as a follow-up.
Yes. To start with, I'd recommend ordering partition tuples and processing a partition at a time. Partitions are often time-based and correlated with the write pattern, so this approach will probably provide a smooth transition to from partitions to snapshots.
This proposal sounds good to me. For overwrite, it seems like we will need a delta format to express what happened to a row as well as to pass the row contents.
jerryshao commentedon Dec 25, 2019
@aokolnychyi are you currently working on this feature? IIUC this seems depends on #315 .
jerryshao commentedon Jan 19, 2020
@aokolnychyi are you currently working on this issue, if not I'd like to take a shot on it.
aokolnychyi commentedon Jan 21, 2020
@jerryshao, sorry for the delay. I am still not up to speed after holidays.
I've started thinking about it and it would be great to leverage #315. However, the last time I checked that PR (a long time ago) I didn't see a way to split a large batch commit into multiple output streaming micro-batches. For example, if a batch job inserts a couple of TBs, you might not want to stream this out of your table in one micro-batch. That got me thinking about keeping some sort of indexing (e.g. manifest name + ordinal position of the last processed file in that manifest) to split large batches. The same logic potentially can be used if we want to stream all of the data from a batch table using Structured Streaming. I haven't thought much about this idea afterwards. Maybe, there is a better way or maybe we can start without that.
@jerryshao, I'll be glad if you pick this up. Did you have any specific ideas?
jerryshao commentedon Jan 21, 2020
@aokolnychyi I've already started a simple workable version of streaming read, hopes that I can share it soon.
About batch size control, what I did currently is to control the number of files read per batch, and record them as a Spark
Offset, so that Spark could continue from restart. I haven't sorted out all the details, I would start building a simple version first, and then refine all the details.aokolnychyi commentedon Jan 21, 2020
@jerryshao, that's great. Looking forward to it.
aokolnychyi commentedon Jan 21, 2020
@jerryshao, a quick question on the comment above. Spark
Offsethas to be serialized to JSON. Are you storing files directly in that offset JSON file?jerryshao commentedon Jan 21, 2020
No, I will not store files directly in the offset json file, what I currently do is to store file paths, like what spark did to FileStreamSource, when the offset is loaded in, I will compare and filter out the files which are already processed. I'm currently still in prototyping, the content of
Offsetmay be changed.jerryshao commentedon Feb 13, 2020
I just submitted an initial workable version of streaming read, I would like see the comments about the current solution, if this is a feasible solution, what should be changed.
Spark3 structured streaming micro_batch read support
joan38 commentedon Aug 23, 2022
Hi, Is this solved with #2660?
aokolnychyi commentedon Nov 18, 2023
Yes, this has been resolved.