在HIVE表中加载JSON文件

在HIVE表中加载JSON文件

本文介绍了在HIVE表中加载JSON文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个如下所示的JSON文件,我想将其以已解析的格式加载到HIVE表中,我可以使用哪些可能的选项.

I have a JSON file like below, which I want to load in a HIVE table with parsed format, what are possible options I can go for.

如果是AVRO,那么我可以直接使用AvroSerDe.但是在这种情况下,源文件是JSON.

If it is AVRO then I could have used directly AvroSerDe. But the source file in this case is JSON.

{
   "subscriberId":"vfd1234-07e1-4054-9b64-83a5a20744db",
   "cartId":"1234edswe-6a9c-493c-bcd0-7fb71995beef",
   "cartStatus":"default",
   "salesChannel":"XYZ",
   "accountId":"12345",
   "channelNumber":"12",
   "timestamp":"Dec 12, 2013 8:30:00 AM",
   "promotions":[
      {
         "promotionId":"NEWID1234",
         "promotionContent":{
            "has_termsandconditions":[
               "TC_NFLMAXDEFAULT16R103578"
            ],
            "sequenceNumber":"305",
            "quantity":"1",
            "promotionLevel":"basic",
            "promotionDuration":"1",
            "endDate":"1283142400000",
            "description":"Regular Season One Payment",
            "active":"true",
            "disableInOfferPanel":"true",
            "displayInCart":"true",
            "type":"promotion",
            "frequencyOfCharge":"weekly",
            "promotionId":"NEWID1234",
            "promotionIndicator":"No",
            "shoppingCartTitle":"Regular Season One Payment",
            "discountedPrice":"0",
            "preselectedInOfferPanel":"false",
            "price":"9.99",
            "name":"Regular Season One Payment",
            "have":[
               "CatNFLSundayMax"
            ],
            "ID":"NEWID1234",
            "startDate":"1451365600000",
            "displayInOfferPanel":"true"
         }
      }
   ]
}

我确实尝试过使用org.openx.data.jsonserde.JsonSerDe创建一个表,但是它没有向我显示数据.

I did tried to create a table using org.openx.data.jsonserde.JsonSerDe, but it is not showing me the data.

CREATE EXTERNAL TABLE test1
(
SUBSCRIBER_ID string,
CART_ID string,
CART_STAT_NAME string,
SLS_CHAN_NAME string,
ACCOUNT_ID string,
CHAN_NBR string,
TX_TMSTMP string,
PROMOTION ARRAY<STRING>
)
ROW FORMAT SERDE 'org.openx.data.jsonserde.JsonSerDe'
LOCATION '<HDFS location where the json file is place in single line>';

推荐答案

如果您阅读官方文件

当您使用配置单元0.12及更高版本时,请使用hive-hcatalog-core

when you are using hive 0.12 and later, use hive-hcatalog-core,

您应该首先添加jar hive-hcatalog-core

you should first add the jar hive-hcatalog-core,

ADD JAR /path/to/jar/;

您可以从 mvn存储库或手动找到它.

you can either download it from mvn repository or find it manually.

那么配置单元表应该看起来像

then the hive table should look like

CREATE EXTERNAL TABLE test1
(
SUBSCRIBER_ID string,
CART_ID string,
CART_STAT_NAME string,
SLS_CHAN_NAME string,
ACCOUNT_ID string,
CHAN_NBR string,
TX_TMSTMP string,
PROMOTION ARRAY<STRING>
)
ROW FORMAT SERDE
  'org.apache.hive.hcatalog.data.JsonSerDe'
LOCATION '<HDFS location where the json file is place in single line>';

这篇关于在HIVE表中加载JSON文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!