sqoop导入mysql带json字段显示不全或乱码

原来是在hive的建表结构如下:

CREATE external TABLE IF NOT EXISTS ods_test_delta(
 id string COMMENT "", 
 create_date string COMMENT "创建时间",
 jsonValue string COMMENT "带json的字段",
 update_date string COMMENT "更新时间",
 del_flag string COMMENT "删除标志"
) COMMENT "测试表"
partitioned by (dt string)
row format delimited
fields terminated by '\u0001'
lines terminated by '\n'
stored as textfile
LOCATION '/data/warehouse/warehouse/ods/ods_test_delta/';

在做ods抽取数据到dwd层时,发现带json的字段显示不全,怀疑是fields terminated影响了。后来想到的一个方法,不预先创建hive的表结构,直接用sqoop导入,发现没有显示不全或乱码。

进入hive的命令行,输入

show create table ods_test_delta
CREATE external TABLE IF NOT EXISTS ods_test_delta(
 id string COMMENT "", 
 create_date string COMMENT "创建时间",
 jsonValue string COMMENT "带json的字段",
 update_date string COMMENT "更新时间",
 del_flag string COMMENT "删除标志"
) COMMENT "测试表"
partitioned by (dt string)
ROW FORMAT SERDE 
  'org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe'
WITH SERDEPROPERTIES ( 
  'field.delim'='', 
  'line.delim'='\n', 
  'serialization.format'='')
STORED AS INPUTFORMAT 
  'org.apache.hadoop.mapred.TextInputFormat'
OUTPUTFORMAT 
  'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'
LOCATION '/data/warehouse/warehouse/ods/ods_test_delta/';

用上面的表结构进行创建hive的表结构,经测试没有json显示不全的问题。

关注公众号“大模型全栈程序员”回复“小程序”获取1000个小程序打包源码。更多免费资源在http://www.gitweixin.com/?p=2627

发表评论

邮箱地址不会被公开。 必填项已用*标注