Skip to content

Use Iceberg tables as sources for Spark Structured Streaming #179

Closed

Description

@aokolnychyi

We can use snapshot history to support reading from an Iceberg table as a streaming source.

Activity

  1. prodeezy commented on May 10, 2019

    @prodeezy
    Contributor

    Sounds like something we might be interested in as well. Can you add more detail as to how you envision this will be used?

  2. aokolnychyi commented on May 11, 2019

    @aokolnychyi
    ContributorAuthor

    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.
  3. aokolnychyi commented on May 11, 2019

    @aokolnychyi
    ContributorAuthor

    @prodeezy would you be interested to work on this?

  4. prodeezy commented on May 15, 2019

    @prodeezy
    Contributor

    Looks interesting to me to work on! I'm currently discussing this internally for approval.

  5. aokolnychyi commented on May 19, 2019

    @aokolnychyi
    ContributorAuthor

    @prodeezy sure, let me know the outcome.

  6. aokolnychyi commented on May 20, 2019

    @aokolnychyi
    ContributorAuthor

    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.

  7. goldentriangle commented on Jul 3, 2019

    @goldentriangle

    @prodeezy is there an ETA for this feature to be completed?

  8. prodeezy commented on Jul 5, 2019

    @prodeezy
    Contributor
  9. prabcs commented on Jul 22, 2019

    @prabcs

    👋, 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.

  10. aokolnychyi commented on Aug 5, 2019

    @aokolnychyi
    ContributorAuthor

    I am thinking to pick this up in the near future. Let me know if there is anybody already working on this.

  11. timmylicheng commented on Aug 6, 2019

    @timmylicheng
    Contributor
  12. aokolnychyi commented on Aug 6, 2019

    @aokolnychyi
    ContributorAuthor

    @timmylicheng do you already have a prototype? Want to submit a PR?

  13. aokolnychyi commented on Aug 6, 2019

    @aokolnychyi
    ContributorAuthor

    @prabcs, yeah, I also raised a similar question. I believe the micro-batch size should be configurable.

  14. timmylicheng commented on Aug 7, 2019

    @timmylicheng
    Contributor
  15. prabcs commented on Aug 7, 2019

    @prabcs
  16. aokolnychyi commented on Nov 16, 2019

    @aokolnychyi
    ContributorAuthor

    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.
  17. rdblue commented on Nov 19, 2019

    @rdblue
    Contributor

    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.

  18. jerryshao commented on Dec 25, 2019

    @jerryshao
    Contributor

    @aokolnychyi are you currently working on this feature? IIUC this seems depends on #315 .

  19. jerryshao commented on Jan 19, 2020

    @jerryshao
    Contributor

    @aokolnychyi are you currently working on this issue, if not I'd like to take a shot on it.

  20. aokolnychyi commented on Jan 21, 2020

    @aokolnychyi
    ContributorAuthor

    @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?

  21. jerryshao commented on Jan 21, 2020

    @jerryshao
    Contributor

    @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.

  22. aokolnychyi commented on Jan 21, 2020

    @aokolnychyi
    ContributorAuthor

    @jerryshao, that's great. Looking forward to it.

  23. aokolnychyi commented on Jan 21, 2020

    @aokolnychyi
    ContributorAuthor

    @jerryshao, a quick question on the comment above. Spark Offset has to be serialized to JSON. Are you storing files directly in that offset JSON file?

  24. jerryshao commented on Jan 21, 2020

    @jerryshao
    Contributor

    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.

  25. jerryshao commented on Feb 13, 2020

    @jerryshao
    Contributor

    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.

  26. joan38 commented on Aug 23, 2022

    @joan38
    Contributor

    Hi, Is this solved with #2660?

  27. aokolnychyi commented on Nov 18, 2023

    @aokolnychyi
    ContributorAuthor

    Yes, this has been resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions