Sqoop将mysql表中新添加的列导入现有配置单元表

Sqoop将mysql表中新添加的列导入现有配置单元表,mysql,hive,sqoop,Mysql,Hive,Sqoop,我在mysql中进行了如下表测试: id name address 1 Km sky 2 hd heaven 3 Ab null 4 en null 现在我完成了一个sqoop导入,如下所示 sqoop import--connect jdbc:mysql://XXXXXX/testing --username XXXX --password XXXX --query "select * from testing.test where \$CONDITIONS" --nu

我在mysql中进行了如下表测试:

id  name  address
1  Km  sky
2  hd  heaven
3  Ab  null
4  en  null
现在我完成了一个sqoop导入,如下所示

sqoop import--connect jdbc:mysql://XXXXXX/testing --username XXXX --password XXXX --query "select * from  testing.test where \$CONDITIONS" --null-string '' --null-non-string '' -m 1\ 
--hive-import --hive-database testing --hive-table test --create-hive-table --target-dir  /user/hive/warehouse/testing.db/test
我得到了预期的结果

然后我们在mysql表中添加了一个新列,增加了2行

id  name  address  nation

1  Km  sky  null
2  hd  heaven  null
3  Ab  null  null
4  en  null  null
5  abc efd  USA
6  fge cde  UK
现在,我希望更新包含上述列和行的现有配置单元表。我已经完成了以下sqoop工作

Sqoop作业:

sqoop job --create sqoop_test -- import --connect jdbc:mysql:xxxxxxx/testing --username XXXXX --password XXXX --query "SELECT * from testing.test WHERE \$CONDITIONS" --incremental append\ 
--check-column id --last-value "3" --split-by 'id' --target-dir  /user/hive/warehouse/testing.db/test 
但是,当我查询配置单元表时,新行的结果为null,而新列不会显示。如下

id  name  address

NULL  NULL  NULL
NULL  NULL  NULL
1  Km  sky
2  hd  heaven
3  Ab  
4  en  
如何将新列追加到配置单元中的现有表中,并将新行添加到配置单元中的现有表中


或者我使用的方法是完全错误的。请让我知道

您的假设是错误的,原因是您正在导入具有不同布局的数据。您创建的第一个表有3列,在第二个导入中,您将导入4列,因此,配置单元无法解析这些新记录,只需为所有列打印null。如果您没有很好的理由以文本文件格式导入数据,我建议您在avro中创建表,并使用schema evolution功能添加新列

在avro中导入数据时,Sqoop会自动为您生成模式。因此,您只需要创建一个指向导入数据的表并使用生成的模式。在将来使用新字段导入的情况下,您将需要使用有效的默认值添加这些字段,或者使用默认值使其为空,如下所示,例如对于字符串列

{ "name": "newcolumnname", "type": [ "null", "string" ], "default": "null" },
或者甚至指定其他有效的默认值

{ "name": "newcolumnname", "type": [ "string" ], "default": "val1" }, //default value 1
{ "name": "newcolumnname", "type": [ "string" ], "default": "" }, //default value empty

对于模式演化,可以使用avro数据类型。对于增量数据,在sqoop中使用增量模式lastmodified进行更新。