Skip to content

Add support for Iceberg MR / InputFormat and OutputFormat APIs #170

Closed

Description

@rdsr

It would be great if we added support for InputFormat and OutputFormat APIs. There's already an InputFormat written but it is specific to Pig and under the iceberg-pig module. @rdblue what's your take if we make the necessary changes in that InputFormat and maybe implement an OutputFormat and have these as part of an iceberg-mr module ?

Activity

  1. rdblue commented on Apr 23, 2019

    @rdblue
    Contributor

    I'd be up for reviewing this.

  2. guilload commented on Aug 7, 2019

    @guilload
    Contributor

    Hey,

    I started working on an MR InputFormat for Iceberg since there’s some overlap with the InputFormat I’m working on for Hive. I have a few questions:

    – Thoughts on using GenericRecord as data container for both the Input and Output formats?

    – IcebergPigInputFormat declares a public constructor IcebergPigInputFormat(Table table) but I don’t think that’s an option for MR since the JobSubmitter class instantiates the input format via reflection without constructor arguments. How do we solve this? Have the user pass the canonical name of the Catalog class they want to use along with a table identifier in the job config and then instantiate the catalog via reflection and finally load the table?

    – Regarding serialization, IcebergPigInputFormat relies on Java serialization via org.apache.pig.impl.util.ObjectSerializer, shall I reuse the same approach or use a different serialization mechanism?

    Thanks!

  3. rdblue commented on Aug 7, 2019

    @rdblue
    Contributor

    IcebergPigInputFormat relies on Java serialization via org.apache.pig.impl.util.ObjectSerializer, shall I reuse the same approach or use a different serialization mechanism?

    I don't think a generic InputFormat should rely on Pig, so using Java serialization where necessary is a better choice.

    Also, there are some situations where you'd want to use other options:

    • Classes that have JSON parsers, like Schema and PartitionSpec should serialize to/from JSON because that produces a human-readable string
    • Classes with a serialization requirement from MR should use that. For example, InputSplit needs to be Writeable, so I would expect an IcebergInputSplit to correctly serialize itself using the Writeable interface.

    Thoughts on using GenericRecord as data container for both the Input and Output formats?

    I'd use Iceberg's Record interface instead. GenericRecord is the implementation class. It's also the name of an Avro class, which we shouldn't expose.

    IcebergPigInputFormat declares a public constructor IcebergPigInputFormat(Table table) but I don’t think that’s an option for MR since the JobSubmitter class instantiates the input format via reflection without constructor arguments. How do we solve this?

    The easiest solution is to use HiveCatalogs like we do in Spark and set the configuration on the catalog that gets returned. The drawback there is that we didn't intend to use HiveCatalogs for very long because Spark has a catalog plugin system coming in 3.0 to handle this.

    Another option is instantiating using a no-arg constructor and setting Configuration if the Catalog implements Configurable. That sounds reasonable to me, but is not very generic.

    Last, you could add a ServiceLoader that acts as a factory for catalogs. Then you could load a service by name and call getCatalog(Configuration) on it.

  4. rdsr commented on Aug 7, 2019

    @rdsr
    ContributorAuthor

    All good points.

    I'd use Iceberg's Record interface instead. GenericRecord is the implementation class. It's also the name of an Avro class, which we shouldn't expose

    For this I think it should be possible to parameterize [using generics] the container and provide a default implementation for Iceberg's Record type. Users may want to directly read Avro data or in their own container, they shouldn't have to re-convert from Iceberg's Record to, say, Avro.

  5. guilload commented on Aug 8, 2019

    @guilload
    Contributor

    Ok, thanks for the pointers. That's helpful. I'll start with HiveCatalogs and we can revisit later.

    One last question regarding generic container. Let's assume a user wants to user a custom container: FooRecord. For each file format, the user will have to provide a "value reader function", for instance a Schema -> OrcValueReader<FooRecord> function and a MessageType -> ParquetValueReader<FooRecord> function.

    What the interface for providing those custom value reader functions should look like? For instance, parquet-mr relies on the ReadSupport interface to solve a similar problem and ships with a default GroupReadSupport implementation.

    Here's my WIP branch:
    guilload#1

  6. rdblue commented on Aug 8, 2019

    @rdblue
    Contributor

    @guilload, good points about the reader functions. This is an area where we haven't invested more time because we are currently only supporting a small set of in-memory representations. What I would like is to eventually make a way to plug in representations for struct, map, and list and have a generic way to support those across data formats.

    Consider struct, for example. Iceberg uses an interface, StructLike, to work with struct objects. So if we write a ValueReader for Parquet and a ValueReader for Avro that supports a StructLike, we could then add an interface like this for plugging in a custom type:

    interface DataModel<S extends StructLike, M extends Map, L extends List> {
      S newStruct();
      M newMap();
      L newList();
    }
    

    Some of the value readers are already generic and can also convert from an intermediate representation to a final representation. If we supported intermediate and final representations, then your final type wouldn't even need to implement StructLike. You could use a wrapper to translate from StructLike to your record's API and then return your record.

  7. teabot commented on Jan 8, 2020

    @teabot

    @guilload Has this work progressed any further since 8 Aug 2019? I ask because we are considering tackling the integration with Hive and do not wish to duplicate efforts.

  8. rdsr commented on Feb 22, 2020

    @rdsr
    ContributorAuthor

    @guilload, do you plan to work on this? We are planning to do some work for Hive read support using these MR apis. Let us know if you need any help with this, or we can even build on top of your work.

  9. rdsr commented on Mar 3, 2020

    @rdsr
    ContributorAuthor

    fyi, I'm taking this patch up and working on an initial version using @guilload patch as base

  10. massdosage commented on Mar 3, 2020

    @massdosage
    Contributor

    Hey there, along with @teabot and @cmathiesen we've started working on this and have managed to get the read path working from Hive on an Iceberg table using an InputFormat. We had to make quite a few changes to the original patch as it was using a different Hive API to that one that appears to be in use in Hive 2.x. Maybe it was targetting Hive 3.x? We have run into a number of issues with version conflicts between Hive, Spark, Iceberg, Guava and Avro but managed to get it working as a separate (Maven) project. We attempted to integrate it with Iceberg as a new module (although maybe adding it to the existing iceberg-hive would be better) but couldn't get Gradle to isolate the versions for just the new subproject. We'd be happy to share what we've done so far, we just need to figure out where best to put it so others can take a look.

  11. rdsr commented on Mar 3, 2020

    @rdsr
    ContributorAuthor

    @massdosage that's great to hear.

    We had to make quite a few changes to the original patch as it was using a different Hive API

    Which patch is this ? @guilload patch was only for MR input format AFAIK.

    My take would be that the MR API patches should go into the iceberg-mr module. The Hive StorageHandler API can possibly go into iceberg-hive, but I guess you may be using a different version of Hive then Iceberg. This can be a non-issue if the StorageHandler API has not changed across different versions of Hive.
    Nevertheless, it would be great if you can have the patch out. We can review it and take it from there.
    Thanks again all of you for your work on this!

  12. massdosage commented on Mar 3, 2020

    @massdosage
    Contributor

    Yes, the InputFormat in the other patch was using org.apache.hadoop.mapreduce.InputFormat; but in order to get this working with Hive 2.3.x we had to use org.apache.hadoop.mapred.InputFormat. We can get the code up onto GitHub to show and then you could pull the parts you want into Iceberg if it looks useful. We'll try get that done in a day or two.

    Our other attempt at it was in an iceberg-mr subproject but ended in version lock hell, it's quite possible that there are some Gradle tricks to manage versions that we're not aware of as we're not big Gradle users. The "work in progress" code for that is here: https://github.com/ExpediaGroup/incubator-iceberg/blob/hive-read-support/mr/src/main/java/org/apache/iceberg/mr/IcebergInputFormat.java. We also are aware that there are probably way better ways to get to the Iceberg metadata instead of the path/string manipulation we are currently doing but we're not entirely aware of all the ins and outs of the Iceberg APIs.

  13. rdblue commented on Mar 3, 2020

    @rdblue
    Contributor

    Is an update to Hive 2.3 the main blocker for getting this into the Apache repo? If so, maybe we should look at upgrading Hive earlier.

  14. colinmjj commented on Mar 4, 2020

    @colinmjj

    hi, @rdsr @massdosage @rdblue
    I also did some investigation on Hive integrate with Iceberg, the target of investigation is to integrate Hive with possible plugin,eg, HiveStorageHandler, but got some block issues:
    file/folder of data has different organization, in Hive, there is:

    • warehouse
      • dbname.db
        • table
          • partition
            • datafile

    in Iceberg, it maybe:

    • catalog_base
      • metadata
        • manifest
      • datafile

    It's wired to have both folder in warehouse, so I suppose iceberg table may be existed as Hive external table, and define the metadata folder as table location which will be used in InputFormat.

    Partition is also a problem. Partition is existed as a folder in Hive, but it's "hidden partition" in Iceberg. There is no plugin like InputFormat to solve this, and iceberg can't work properly now. For example, "show partition", "select c1 from t where partition_col = 'p1'".
    I think Hive has to be modified to deal with the partition things, eg, "alter table add partition", "show partition", etc.

    Our scene is writing Iceberg with Flink and Hive can read the data ASAP, as an option solution, maybe create a toolkit which can transfer IcebergTable to Hive table is suitable for our case.
    Do we have the same target on Hive integration in this MR?

  15. teabot commented on Mar 4, 2020

    @teabot
  16. 2 remaining items

  17. massdosage commented on Mar 4, 2020

    @massdosage
    Contributor

    Is an update to Hive 2.3 the main blocker for getting this into the Apache repo? If so, maybe we should look at upgrading Hive earlier.

    It's not just that, the problem is that Hive 2.3 relies on versions of Guava and Avro that are older than the versions in Iceberg. So if you run the InputFormat using Hive's libraries there are all kinds of "method not found" and other exceptions thrown. As I said, we couldn't get Gradle to allow us to override and shadow things properly within Iceberg itself which is why we created the above project separately. We then also needed to make these changes to Iceberg to shade the libraries it is using that cause problems with Hive: master...ExpediaGroup:build-hiveberg-modules

    It would be nice to find some way to do all the above within Iceberg itself and then move the "hiveberg" code over there.

  18. rdsr commented on Mar 4, 2020

    @rdsr
    ContributorAuthor

    @massdosage
    I think it would be good if we can break this up into multiple tasks
    1st would be to get the InputFormat working and get that checked in. I glanced at the your patch, currently its in-memory record representation/container is tied to Avro. We should try to make it generic. There's a discussion on this above. Happy to help review this if you'd like to take this up, or else I can even take that up if you like [ as we are also planning to have our Hive story for Iceberg sorted out]
    Then we see how to build the mapred version of the InputFormat API. Maybe just a wrapper on top of MRv1 could do?
    Lastly we can take up writing the Hive SerDe code . I guess this must have already done by you so shouldn't be too much of an issue

  19. massdosage commented on Mar 4, 2020

    @massdosage
    Contributor

    Sure, we have some tickets indicating next steps and the Avro tie-in is something we're aware of and would like to sort out. @cmathiesen is working on ExpediaGroup/hiveberg#3 right now, we would love input from others on this (and anything else in the current implementation).

    As for a mapreduce version, I'm not sure that's even possible with Hive 2? (see https://snippetessay.wordpress.com/2017/10/20/mapred-vs-mapreduce-the-api-question-of-hadoop-and-impact-on-the-ecosystem/). We tried that first and it didn't work so went for mapred, maybe mapreduce works with Hive 3? But yes, having the common logic somewhere and then wrappers for mapred and mapreduce sounds like a good idea.

    We don't currently have a SerDe but have a ticket for what we've thought of there so far - ExpediaGroup/hiveberg#2

  20. teabot commented on Mar 4, 2020

    @teabot

    We don't currently have a SerDe but have a ticket for what we've thought of there so far - ExpediaGroup/hiveberg#2

    To be clear, we do have SerDe integration using the standard AvroSerDe as we could start with this 'out of the box', however we will clearly need to implement an Iceberg specific SerDe.

  21. jerryshao commented on Mar 5, 2020

    @jerryshao
    Contributor

    Seems like we're focusing on read path currently.

    I have a question about write path, are we also targeting the write path? For the write path, I'm curious how do we pass the metadata operations to Iceberg, like create DDL, I'm not sure if Hive has a similar catalog plugin like Spark.

  22. massdosage commented on Mar 5, 2020

    @massdosage
    Contributor

    Yes, our focus currently is on the read path. We would like to work on the write path next but it will probably be quite a bit more complicated.

  23. jerryshao commented on Mar 5, 2020

    @jerryshao
    Contributor

    Sorry I still have several questions about the implementation of read path, would like know how you think about this.

    1. Are we going to implement as a storage handler (non-native table) or just input/output format? From what I understanding, seems like HiveStorageHandler is more suitable.
    2. How do we get filter expressions from Hive and map to Iceberg' internal ones, also to push the expressions? Spark will get the filter expressions to reader, not sure if Hive has such thing.
    3. How do we leverage Iceberg's catalog (HiveCatalog for example)? In the current implementation, it only uses HadoopTables with location property, not sure how do we leverage Iceberg's catalog implementation.
  24. teabot commented on Mar 5, 2020

    @teabot
  25. rdsr commented on Mar 7, 2020

    @rdsr
    ContributorAuthor

    Thanks @teabot @massdosage . Let me know if you guys need any help and if I can pick up a something. This is on our roadmap as well

  26. jerryshao commented on Mar 13, 2020

    @jerryshao
    Contributor

    I've create a PR to build Iceberg against Hive 2.3.6 #841 , I think with this we don't have to maintain Hive support out of Iceberg, the work here could be moved to Iceberg.

  27. teabot commented on Mar 13, 2020

    @teabot

    I've create a PR to build Iceberg against Hive 2.3.6 #841 , I think with this we don't have to maintain Hive support out of Iceberg, the work here could be moved to Iceberg.

    Excellent! When this PR is merged we'll attempt to move our work from ExpediaGroup/hiveberg#2 and into appropriate submodule(s) in the Iceberg project.

  28. pvary commented on Jan 8, 2021

    @pvary
    Contributor

    Is this an issue we could close as the read path is already committed and the work on write path is also on the way under different issues/PRs?

    Thanks,
    Peter

  29. rdblue commented on Jan 9, 2021

    @rdblue
    Contributor

    I agree, this is mostly done now and this is also not very specific. We should open more specific issues for any other gaps where we intend to add features, like a non-Hive OutputFormat.

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