【发布时间】:2018-09-05 14:19:19
【问题描述】:
我正在尝试使用 Sqoop 将表从 SQL 服务器导入 Hive。以下是我正在使用的命令:
sqoop import --connect "jdbc:jtds:sqlserver://xxxxxxxxxx:1433;integratedSecurity=false;databaseName=xxxx;domain=xxxx" --username user -P --table notifications --split-by Id --hive-import --create-hive-table --hive-table testing.notifications --as-parquetfile --verbose
hive 表不存在,想法是使用我的 sqoop 命令创建它。但是,当我运行命令时,出现以下错误:
18/09/05 08:40:21 INFO manager.SqlManager: Executing SQL statement: SELECT t.* FROM [notifications] AS t WHERE 1=0
18/09/05 08:40:21 DEBUG manager.SqlManager: Found column Id of type [-5, 19, 0]
18/09/05 08:40:21 DEBUG manager.SqlManager: Found column Dt of type [93, 23, 3]
18/09/05 08:40:21 DEBUG manager.SqlManager: Found column path of type [12, 300, 0]
18/09/05 08:40:21 DEBUG manager.SqlManager: Found column type of type [12, 1000, 0]
18/09/05 08:40:21 DEBUG manager.SqlManager: Found column message of type [2005, 2147483647, 0]
18/09/05 08:40:21 DEBUG manager.SqlManager: Found column person of type [12, 100, 0]
18/09/05 08:40:21 DEBUG manager.SqlManager: Found column stage of type [12, 100, 0]
18/09/05 08:40:21 DEBUG manager.SqlManager: Found column lastModified of type [93, 23, 3]
18/09/05 08:40:21 DEBUG util.ClassLoaderStack: Restoring classloader: sun.misc.Launcher$AppClassLoader@64c64813
18/09/05 08:40:21 ERROR tool.ImportTool: Import failed: Cannot convert SQL type 2005
但是,当我从命令中删除 --as-parquetfile 参数时,它可以正常工作。使用 --as-parquetfile 有什么问题?
我需要表格是镶木地板,我尝试使用--query 参数将Dt 和lastModified 列在timestamp 中(我猜时间戳是[93, 23, 3] 代表的)格式像这样的字符串:
--query "select Id, convert(varchar(25),Dt,120) as Dt, path, type, message, person, stage, convert(varchar(25),lastModified,120) as lastModified from dbo.notifications"
日志确认Dt 和lastModified 的数据类型已被修改:
18/09/05 09:30:12 INFO manager.SqlManager: Executing SQL statement: select Id, convert(varchar(25),Dt,120) as Dt, path, type, message, person, stage, convert(varchar(25),lastModified,120) as lastModified from dbo.notifications WHERE (1 = 0)
18/09/05 09:30:12 DEBUG manager.SqlManager: Found column Id of type [-5, 19, 0]
18/09/05 09:30:12 DEBUG manager.SqlManager: Found column Dt of type [12, 25, 0]
18/09/05 09:30:12 DEBUG manager.SqlManager: Found column path of type [12, 300, 0]
18/09/05 09:30:12 DEBUG manager.SqlManager: Found column type of type [12, 1000, 0]
18/09/05 09:30:12 DEBUG manager.SqlManager: Found column message of type [2005, 2147483647, 0]
18/09/05 09:30:12 DEBUG manager.SqlManager: Found column person of type [12, 100, 0]
18/09/05 09:30:12 DEBUG manager.SqlManager: Found column stage of type [12, 100, 0]
18/09/05 09:30:12 DEBUG manager.SqlManager: Found column lastModified of type [12, 25, 0]
但它仍然失败并出现同样的错误。
我不确定是哪一列导致了错误。我也不确定我是否可以使用--map-column-hive 与--as-parquetfile 一起使用。
任何帮助将不胜感激。谢谢!
【问题讨论】:
-
抛出的错误是
Cannot convert SQL type 2005,而你只有一列类型为2005:Found column message of type [2005, 2147483647, 0]。所以这是你的罪魁祸首。它可能是一个varchar(max)、nvarchar(max),或者,天堂禁止,text类型的列,Sqoop 需要帮助来解释。不过,在镶木地板问题上,我对你没用。 -
经过一些调试,我自己也得出了同样的结论。我现在将
message列转换为varchar(200),它运行良好!我看到 SQL 服务器中message的数据类型是varchar和max_length = -1。这是否意味着它是varchar(max)?知道是什么导致了这种数据类型的错误吗? @EricBrandt -
注意 200 的长度。If a string value being converted/assigned to a varchar value exceeds the length specifier, the string is silently truncated.。至于为什么,引擎之间的类型转换经常存在问题。 Hive 没有像 varchar(max) 那样完全 的数据类型。字符串很接近,但还不够接近,无法进行隐式转换。 OTOH,它支持数组,而 SQL Server 不支持。这只是让 ETL 为我们带来乐趣的其中一件事。
标签: sql-server hive sqoop parquet