Loading xml data into hive table :org.apache.hadoop.hive.ql.metadata.HiveException

后端 未结 6 2212
借酒劲吻你
借酒劲吻你 2021-02-06 14:48

I\'m trying to load XML data into Hive but I\'m getting an error :

java.lang.RuntimeException: org.apache.hadoop.hive.ql.metadata.HiveException: Hive Runt

6条回答
  •  悲&欢浪女
    2021-02-06 14:59

    Find Jar here -- > Brickhouse ,

    sample example here --> Example

    similar example in stackoverflow - here

    Solution:

    --Load xml data to table
    DROP table xmltable;
    Create TABLE xmltable(xmldata string) STORED AS TEXTFILE;
    LOAD DATA lOCAL INPATH '/home/vijay/data-input.xml' OVERWRITE INTO TABLE xmltable;
    
    -- check contents
    SELECT * from xmltable;
    
    -- create view
    Drop view  MyxmlView;
    CREATE VIEW MyxmlView(id, genre, price) AS
    SELECT
     xpath(xmldata, 'catalog/book/id/text()'),
     xpath(xmldata, 'catalog/book/genre/text()'),
     xpath(xmldata, 'catalog/book/price/text()')
    FROM xmltable;
    
    -- check view
    SELECT id, genre,price FROM MyxmlView;
    
    
    ADD jar /home/vijay/brickhouse-0.7.0-SNAPSHOT.jar;  --Add brickhouse jar 
    
    CREATE TEMPORARY FUNCTION array_index AS 'brickhouse.udf.collect.ArrayIndexUDF';
    CREATE TEMPORARY FUNCTION numeric_range AS 'brickhouse.udf.collect.NumericRange';
    
    SELECT 
       array_index( id, n ) as my_id,
       array_index( genre, n ) as my_genre,
       array_index( price, n ) as my_price
    from MyxmlView
    lateral view numeric_range( size( id )) MyxmlView as n;
    

    Output:

    hive > SELECT
         >    array_index( id, n ) as my_id,
         >    array_index( genre, n ) as my_genre,
         >    array_index( price, n ) as my_price
         > from MyxmlView
         > lateral view numeric_range( size( id )) MyxmlView as n;
    Automatically selecting local only mode for query
    Total MapReduce jobs = 1
    Launching Job 1 out of 1
    Number of reduce tasks is set to 0 since there's no reduce operator
    Execution log at: /tmp/vijay/.log
    Job running in-process (local Hadoop)
    Hadoop job information for null: number of mappers: 0; number of reducers: 0
    2014-07-09 05:36:45,220 null map = 0%,  reduce = 0%
    2014-07-09 05:36:48,226 null map = 100%,  reduce = 0%
    Ended Job = job_local_0001
    Execution completed successfully
    Mapred Local Task Succeeded . Convert the Join into MapJoin
    OK
    my_id      my_genre      my_price
    11      Computer        44
    44      Fantasy 5
    

    Time taken: 8.541 seconds, Fetched: 2 row(s)

    Adding-more-info as requested by Question owner:

    enter image description here enter image description here

提交回复
热议问题