何时使用 Sqoop --create-hive-table [英] When to use Sqoop --create-hive-table

查看:49
本文介绍了何时使用 Sqoop --create-hive-table的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能说出 create-hive-table 和 & 之间的区别?hive-import 方法?两者都会创建一个hive表,但每个的意义是什么?

Can anyone tell the difference between create-hive-table & hive-import method? Both will create a hive table, but still what is the significance of each?

推荐答案

hive-import 命令:
hive-import 命令会自动为 hive Metastore 中的填充表填充元数据.如果 Hive 中的表还不存在,Sqoop将简单地根据为您的表或查询获取的元数据创建它.如果该表已经存在,Sqoop 会将数据导入到现有表中.如果您要创建新的 Hive 表,Sqoop 会将源表中每一列的数据类型转换为与 Hive 兼容的类型.
create-hive-table 命令:
Sqoop 可以根据现有关系数据源中的表生成 hive 表(使用 create-hive-table 命令).如果设置,则如果目标配置单元表存在,则作业将失败.默认情况下,此属性为 false.

使用create-hive-table命令涉及三个步骤:将数据导入HDFS,创建hive表,然后将HDFS数据加载到Hive中.这可以通过使用 hive-import 缩短为一步.

hive-import 期间,Sqoop 将首先将正常的 HDFS 导入到临时位置.成功导入后,Sqoop 会生成两个查询:一个用于创建表,另一个用于从临时位置加载数据.您可以使用 --target-dir--warehouse-dir 参数指定任何临时位置.

hive-import command:
hive-import commands automatically populates the metadata for the populating tables in hive metastore. If the table in Hive does not exist yet, Sqoop will simply create it based on the metadata fetched for your table or query. If the table already exists, Sqoop will import data into the existing table. If you’re creating a new Hive table, Sqoop will convert the data types of each column from your source table to a type compatible with Hive.
create-hive-table command:
Sqoop can generate a hive table (using create-hive-tablecommand) based on the table from an existing relational data source. If set, then the job will fail if the target hive table exists. By default this property is false.

Using create-hive-table command involves three steps: importing data into HDFS, creating hive table and then loading the HDFS data into Hive. This can be shortened to one step by using hive-import.

During a hive-import, Sqoop will first do a normal HDFS import to a temporary location. After a successful import, Sqoop generates two queries: one for creating a table and another one for loading the data from a temporary location. You can specify any temporary location using either the --target-dir or --warehouse-dir parameter.

为上面的描述添加了一个例子

使用 create-hive-table 命令:
涉及三个步骤:

Using create-hive-table command:
Involves three steps:

  1. 从 RDBMS 导入数据到 HDFS

  1. Importing data from RDBMS to HDFS

sqoop import --connect jdbc:mysql://localhost:3306/hadoopexample --tableEmployees --split-by empid -m 1;

使用create-hive-table命令创建hive表

Creating hive table using create-hive-table command

sqoop create-hive-table --connect jdbc:mysql://localhost:3306/hadoopexample --table员工 --fields-terminated-by ',';

将数据加载到 Hive

Loading data into Hive

蜂巢>将数据 inpath "employees" 加载到表雇员中;将数据加载到表 default.employees表 default.employees stats: [numFiles=1, totalSize=70]行耗时:2.269 秒蜂巢>从员工中选择*;行1001 emp1 1011002 emp2 1021003 emp3 1011004 emp4 1011005 emp5 103耗时:0.334 秒,获取:5 行

使用 hive-import 命令:

sqoop import --connect jdbc:mysql://localhost:3306/hadoopexample --table Department --split-by deptid -m 1 --hive-import;

这篇关于何时使用 Sqoop --create-hive-table的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆