简体   繁体   English

如何使用sqoop将mySql服务器中的JSON字段数据导入到Hive表中

[英]How can I import JSON field data from mySql server into Hive table using sqoop

I have a table name EmpData in MySQL server with two field as EmpID (INT) and Details (nvarchar) . 我在MySQL服务器中有一个表名EmpData ,其中两个字段分别为EmpID (INT)Details (nvarchar) Details field contain JSON string like 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"}}

I want to import Details field JSON data into hive table EmpHiveStore and query on hive table like 我想将Details字段JSON数据导入到蜂巢表EmpHiveStore并像这样对蜂巢表进行查询

SELECT name,address.street from EmpHiveStore;

Is there any way to import JSON field data into Hive table using sqoop? 有什么方法可以使用sqoop将JSON字段数据导入到Hive表中?

Thank You. 谢谢。

Sqoop's job here is to import data from RDBMS( MySQL in your case ) to Hive. Sqoop的工作是将数据从RDBMS( 在您的情况下MySQL )导入到Hive。

You need to use sqoop import command for this 您需要为此使用sqoop import命令

sqoop import \
--connect jdbc:mysql://mysql.example.com/testdb \
--username root \
--password root \
--table EmpData \
--columns Details \
--hive-import \
--hive-table EmpHiveStore

This will create hive table if not exists. 如果不存在,这将创建配置单元表。 Sqoop's job is done here . Sqoop的工作在这里完成 Hive will store this data in the String. Hive会将这些数据存储在String中。 There is no special JSON type in Hive. Hive中没有特殊的JSON类型 So, you won't be able to perform query like 因此,您将无法执行以下查询

SELECT name,address.street from EmpHiveStore;

directly via hive. 直接通过蜂巢。

You can get the location of data using 您可以使用获取数据的位置

show create table EmpHiveStore;

You have only 1 column in your table and it has JSON data. 您的表中只有1列,并且它具有JSON数据。 So it's basically a JSON file in HDFS. 因此,它基本上是HDFS中的JSON文件。

You want to query into nested JSON. 您想查询嵌套的JSON。 You need another tool that allows you to perform queries like this. 您需要另一个工具来执行这样的查询。 You can explore SQL query engine like Drill and Spark SQL for this. 您可以为此探索SQL查询引擎,例如DrillSpark SQL

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM