将数据加载到一个空的impala表中,其中帐户数据按区号分区

rggaifut  于 2021-06-26  发布在  Impala
关注(0)|答案(1)|浏览(358)

我试图将数据从一个名为accounts的表复制到一个名为accounts\u by \u area \u code的空表中。我在accounts\u by\u area code\u中有以下字段:acct\u num int、first\u name string、last\u name string、phone\u number string。该表按区号(电话号码的前3位)进行分区。
我需要使用select语句将区号提取到insert into table命令中以复制specifi将列添加到新表中,按区号动态分区。
这是我最后一次尝试:

impala-shell -q "INSERT INTO TABLE accounts_by_areacode (acct_num, first_name, last_name, phone_number, areacode) PARTITION (areacode) SELECT STRLEFT (phone_number,3) AS areacode FROM accounts;"

这将生成错误:analysisexception:column permutation和partition子句提到的列(5)多于select/values子句和partition子句返回的列(1)。我不相信我甚至有基本的语法正确,所以任何帮助将是伟大的,因为我是新的 Impala 。

2eafrhcq

2eafrhcq1#

impala根据数据动态创建分区。所以不确定为什么要创建带有分区的空表,因为插入新数据时会自动创建它。
不过,我认为可以用这样的分区创建空表- impala-shell -q "INSERT INTO TABLE accounts_by_areacode (acct_num) PARTITION (areacode) SELECT CAST(NULL as STRING), STRLEFT (phone_number,3) AS areacode FROM accounts;"

相关问题