Hive Create Multi small files for each insert in HDFS

前端 未结 3 628
轻奢々
轻奢々 2020-12-14 13:19

following is already been achieved

  1. Kafka Producer pulling data from twitter using Spark Streaming.
  2. Kafka Consumer ingesting data into Hive External t
相关标签:
3条回答
  • 2020-12-14 14:05

    [take 2] OK, so you can't properly "stream" data into Hive. But you can add a periodic compaction post-processing job...

    • create your table with 3 partitions e.g. (role='collectA'), (role='collectB'), (role='archive')
    • point your Spark inserts to (role='activeA')
    • at some point, switch to (role='activeB')
    • then dump every record that you have collected in the "A" partition into "archive", hoping that Hive default config will do a good job of limiting fragmentation

      INSERT INTO TABLE twitter_data PARTITION (role='archive') SELECT ... FROM twitter_data WHERE role='activeA' ; TRUNCATE TABLE twitter_data PARTITION (role='activeA') ;

    • at some point, switch back to "A" etc.

    One last word: if Hive still creates too many files on each compaction job, then try tweaking some parameters in your session, just before the INSERT e.g.

    set hive.merge.mapfiles =true;
    set hive.merge.mapredfiles =true;
    set hive.merge.smallfiles.avgsize=1024000000;
    
    0 讨论(0)
  • 2020-12-14 14:09

    you can use these options together.

    1. turn on acid
    2. create orc table K with transactional property.
    3. insert many times into K. by streaming or just use insert dml.
    4. hive will automatically create small delta files
    5. minor ir major compactions will happen
    6. small files will be merged to large file.
    0 讨论(0)
  • 2020-12-14 14:14

    Hive was designed for massive batch processing, not for transactions. That's why you have at least one data file for each LOAD or INSERT-SELECT command. And that's also why you have no INSERT-VALUES command, hence the lame syntax displayed in your post as a necessary workaround.

    Well... that was true until transaction support was introduced. In a nutshell you need (a) Hive V0.14 and later (b) an ORC table (c) transaction support enabled on that table (i.e. locks, periodic background compaction, etc)

    The wiki about Streaming data ingest in Hive might be a good start.

    0 讨论(0)
提交回复
热议问题