我试图使用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
合作。
任何帮助,将不胜感激。谢谢!
经过一些调试,我能够弄清楚问题。我意识到错误消息:ERROR tool.ImportTool: Import failed: Cannot convert SQL type 2005
具有导致问题的列的数据类型,即我的情况下的2005对应于源表中的message
列。 message
列是varchar
与max_length = -1
是varchar(max)
。
我把它投到了varchar(200)
,这解决了我的问题。
但是,我不知道为什么只有在我的sqoop命令中使用--as-parquetfile
参数时才出现此问题。我很想听到关于这个问题的更多讨论。
谢谢。