Sqoop导出到SQL Server:模式?

时间:2016-07-25 18:00:45

标签: sql-server hadoop hdfs sqoop

我想将HDFS中的数据导出到架构my_schema中的SQL Server表。

我像导入命令一样尝试--schema

sqoop export \
--libjars /opt/mapr/sqoop/sqoop-1.4.6/lib/sqljdbc4.jar \
--connect "jdbc:sqlserver://MY-SERVER-DNS;database=my_db;" \
--schema "myschema" \
--table "my_table" \
--export-dir /path/to/my/hdfs/dir

ERROR tool.BaseSqoopTool: Unrecognized argument: --schema

--table "schema.table"

sqoop export \
--libjars /opt/mapr/sqoop/sqoop-1.4.6/lib/sqljdbc4.jar \
--connect "jdbc:sqlserver://MY-SERVER-DNS;database=my_db;" \
--table "my_schema.my_table" \
--export-dir /path/to/my/hdfs/dir

INFO manager.SqlManager: 
Executing SQL statement: SELECT t.* FROM [my_schema.my_table] AS t WHERE 1=0 

ERROR manager.SqlManager: Error executing statement: 
com.microsoft.sqlserver.jdbc.SQLServerException:
Invalid object name 'my_schema.my_table'.

有没有办法用sqoop做到这一点?还是另一种技术?

编辑:

sqoop export \
--libjars /opt/mapr/sqoop/sqoop-1.4.6/lib/sqljdbc4.jar \
--connect "jdbc:sqlserver://MY-SERVER-DNS;database=my_db;schema=my_schema;" \
--table "my_table" \
--export-dir /path/to/my/hdfs/dir

INFO manager.SqlManager: Executing SQL statement: SELECT t.* FROM [my_table] AS t WHERE 1=0
16/07/25 10:46:21 ERROR manager.SqlManager: 
Error executing statement: com.microsoft.sqlserver.jdbc.SQLServerException:
Invalid object name 'my_table'.

这不承认架构。

1 个答案:

答案 0 :(得分:7)

在连接字符串中提供架构:

jdbc:sqlserver://MY-SERVER-DNS;databaseName=my_db;schema=my_schema;

所以你的导出sqoop命令应该是:

sqoop export \
--libjars /opt/mapr/sqoop/sqoop-1.4.6/lib/sqljdbc4.jar \
--connect "jdbc:sqlserver://MY-SERVER-DNS;databaseName=my_db;schema=my_schema;" \
--table "my_table" \
--export-dir /path/to/my/hdfs/dir

<强> ALSO:

Custom schemas are supported for both import and export job - 根据sqoop指南中的语法,--schema应作为-- --schema传递:

所以你的导出sqoop命令应该是:

sqoop export \
--libjars /opt/mapr/sqoop/sqoop-1.4.6/lib/sqljdbc4.jar \
--connect "jdbc:sqlserver://MY-SERVER-DNS;databaseName=my_db;" \
--export-dir /path/to/my/hdfs/dir
--table "my_table" \
-- --schema my_schema \