我在MySQL服务器中有一个表名MySQL,其中有两个字段EmpID (INT)和Details (nvarchar)。Details字段包含类似于JSON的字符串
{ "name": "Michel","address":{"house no":"12","street":"Johnson road","city":"New Delhi","country":"INDIA"}}
{ "name": "John","address":{"house no":"99","street":"Johnson road","city":"London","country":"UK"}}我希望将Details字段JSON数据导入到hive表EmpHiveStore中,并对hive表进行如下查询
SELECT name,address.street from EmpHiveStore;有没有办法使用sqoop将JSON字段数据导入Hive表?
谢谢。
发布于 2016-07-27 07:11:47
Sqoop在这里的工作是将数据从关系数据库管理系统(在您的例子中是MySQL)导入到Hive。
为此,需要使用sqoop导入命令。
sqoop import \
--connect jdbc:mysql://mysql.example.com/testdb \
--username root \
--password root \
--table EmpData \
--columns Details \
--hive-import \
--hive-table EmpHiveStore如果不存在,这将创建蜂巢表。Sqoop的工作在这里完成,。Hive将把这些数据存储在字符串中。在Hive中没有特殊的JSON类型。所以,您将无法执行这样的查询
SELECT name,address.street from EmpHiveStore;直接通过蜂巢。
您可以使用
show create table EmpHiveStore;表中只有1列,它有JSON数据。所以它基本上是HDFS中的一个JSON文件。
https://stackoverflow.com/questions/38604707
复制相似问题