How to Store Binary Data in Hive?

前端 未结 1 1405
挽巷
挽巷 2021-01-25 02:29

I am learning Hive.

Could anyone please give me an example query regarding how to store binary data (For e.g., Images) in Hive.

Thanks in Advance...

相关标签:
1条回答
  • 2021-01-25 03:28

    In Hive you store Files in HDFS and add metadata to tell Hive which kind of field are you waiting to be in each position in the file( separator and delimitators in text file, rows in different binary formats...)

    You can generate your own output and use it with Input and Outpu formats. Can convert images to, as example BASE64 like an attachment and use a TextFile.... Lot of possibilities, but not a "query" to store images.

    You could have, to continue the TextFile Example but is not the "best method", a file with this format:

    1;image1.jpg;65400;<BASE64_DATA>

    And load in hive:

    CREATE TABLE img_store(
       id INT
       , filename STRING
       , size BIGINT
       , data STRING
    );
    LOAD DATA INPATH '/where/your/file/is/in/HDFS' 
    INTO TABLE img_Store;
    

    If you use a version of Hive +0.8 you can use the DataType BINARY in the table definition and load it.

    Regards.

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