Presto 查询无法将数据插入 Hive

Posted

技术标签:

【中文标题】Presto 查询无法将数据插入 Hive【英文标题】:Presto query fails to insert data into Hive 【发布时间】:2018-10-12 12:32:28 【问题描述】:

我正在尝试将数据插入配置单元。为此,我使用 Presto。

这是我的查询:

insert into card_transactions_part_buck partition(tran_year,tran_month,tran_day)
select tran_id,
tran_uid,
tran_date,
tran_category,
tran_category_id,
tran_type,
tran_type_id,
tran_ingress_ip_address,
tran_ingress_api_name,
tran_ingress_api_id,
platform,
platform_id,
card_type,
card_type_id,
amount,re_amount,
fxrate,
currency,
currency_id,
term_provider,
term_provider_id,
term_merchant,
term_merchant_id,
term_spendcode,
term_spendcode_id,
term_ip_address,
term_country,
term_country_id,
term_countrycode,
term_stateregion,
term_stateregion_id,
term_city,term_city_id,
term_postcode,
cust_first_name,
cust_last_name,
cust_email,
cust_ip_address,
cust_city,
cust_city_id,
cust_postcost,
cust_country,
cust_country_id,
cust_address,
SUBSTR(tran_date,0,4) as tran_year,
SUBSTR(tran_date,6,2) as tran_month,
SUBSTR(tran_date,9,2) as tran_day
from card_transactions;

我收到以下异常:

Query 20180502_113622_00037_xt6fw failed: line 1:41: extraneous input 'partition' expecting '.', '(', 'SELECT', 'TABLE', 'VALUES', 'WITH'

当我在 Hive shell 中运行相同的查询时,它工作得非常好。

【问题讨论】:

【参考方案1】:

你不需要partition(tran_year,tran_month,tran_day)

insert into card_transactions_part_buck 
select 
tran_id,
tran_uid,
tran_date,
tran_category,
tran_category_id,
tran_type,
tran_type_id,
tran_ingress_ip_address,
tran_ingress_api_name,
tran_ingress_api_id,
platform,
platform_id,
card_type,
card_type_id,
amount,re_amount,
fxrate,
currency,
currency_id,
term_provider,
term_provider_id,
term_merchant,
term_merchant_id,
term_spendcode,
term_spendcode_id,
term_ip_address,
term_country,
term_country_id,
term_countrycode,
term_stateregion,
term_stateregion_id,
term_city,term_city_id,
term_postcode,
cust_first_name,
cust_last_name,
cust_email,
cust_ip_address,
cust_city,
cust_city_id,
cust_postcost,
cust_country,
cust_country_id,
cust_address,
SUBSTR(tran_date,0,4) as tran_year,
SUBSTR(tran_date,6,2) as tran_month,
SUBSTR(tran_date,9,2) as tran_day
from card_transactions;

【讨论】:

以上是关于Presto 查询无法将数据插入 Hive的主要内容,如果未能解决你的问题,请参考以下文章

hive add columns后新插入列数据为空,但是用presto查询的时候却有数据

presto和hive将查询结果保存到本地的方法

presto和hive将查询结果保存到本地的方法

DWS层销售主题宽表实现

无法使用 CSV 文件中的 Presto 创建 Hive 表

Hive 插入查询,如 SQL