Sqoop 从 hive 导出到 oracle,具有不同的列名、列数和列顺序 [英] Sqoop export from hive to oracle with different col names, number of columns and order of columns

查看:51
本文介绍了Sqoop 从 hive 导出到 oracle,具有不同的列名、列数和列顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

场景就像,我有一个包含 10 列的配置单元表.我想使用 Sqoop 将 hive 表中的数据导出到 oracle 表中.

The scenario is like, I have a hive table with 10 columns . I want to export the data from my hive table to an oracle table using Sqoop.

但是目标 oracle 表有 30 个列的名称与 hive 表列的名称不同.此外,oracle 表中的列位置与 hive 表中的不同.

But the target oracle table has 30 columns having different names than hive table columns. Also, the column positions in oracle table are not same as in hive table.

谁能建议我如何为这种情况编写 Sqoop 导出命令?

Can anyone please suggest how can I write the Sqoop export command for this case?

推荐答案

首先,不能直接从 hive 导出数据到 oracle.

First of all, you can't export data directly from hive to oracle.

您需要将 hive 表导出到 HDFS

You need to EXPORT hive table to HDFS

  • 示例命令:

  • sample command:

export table mytable to 'some_hdfs_location'

或者使用 hive 表的 HDFS 数据位置.

Or use HDFS data location of your hive table.

  • 查看位置的命令

  • command to check the location

show create table mytable

现在您有了 Hive 表的数据位置.

So now you have location of data for your Hive table.

您可以在 Sqoop 导出命令中使用 --columns 标签来选择列的顺序和数量.

You can use --columns tag in Sqoop Export command to choose column order and number.

列名不同没有问题.

我举个简单的例子

现在您有包含列的 hive 表 - c1、c2、c3

Now you have hive table with columns - c1, c2, c3

和 Oracle 表 - col1、col2、col3、col4、col5

and Oracle table - col1, col2, col3, col4, col5

我想用 col2 映射 c1,用 col5 映射 c2,用 col1 映射 c3.

I want to map c1 with col2, c2 with col5, c3 with col1.

我将在我的 sqoop 命令中使用 --columns "col2,col5,col1".

I will use --columns "col2,col5,col1" in my sqoop command.

根据 Sqoop docs

默认情况下,选择表中的所有列进行导出.您可以选择列的子集并使用 --columns 参数控制它们的顺序.这应该包括要导出的列的逗号分隔列表.例如:--columns "col1,col2,col3".请注意,未包含在 --columns 参数中的列需要定义默认值或允许 NULL 值.否则,您的数据库将拒绝导入的数据,从而导致 Sqoop 作业失败.

By default, all columns within a table are selected for export. You can select a subset of columns and control their ordering by using the --columns argument. This should include a comma-delimited list of columns to export. For example: --columns "col1,col2,col3". Note that columns that are not included in the --columns parameter need to have either defined default value or allow NULL values. Otherwise your database will reject the imported data which in turn will make Sqoop job fail.

这篇关于Sqoop 从 hive 导出到 oracle,具有不同的列名、列数和列顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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