insert语句配置单元中包含语句emr aws

laawzig2  于 2021-06-24  发布在  Hive
关注(0)|答案(1)|浏览(271)

配置单元无法识别insert命令中的with语句。我怎样才能让hive明白这一点?
我已经创建了外部配置单元表来存储此查询中引用的所有数据。所有的执行都很好,数据是可用的。这是将输出插入到churn\u date\u out表中的查询的实际内容。
为了将这个输出集放入表中,我使用了insert命令,然后通过with函数来构建输出数据。但是,一旦启动,hive就不喜欢with语句。
with语句彼此级联,最终输出从revenue块中选择。只要我们能弄清楚如何让Hive喜欢with语句,这些都不是真正相关的。
我真的很感激任何想法!谢谢您。

FAILED: ParseException line 2:0 cannot recognize input near 'WITH' 'customers' 'AS' in statement

INSERT OVERWRITE TABLE churn_data_out partition (month) (
WITH customers AS (
  SELECT c.cust_nm,
         aef.cust_key,
         min(date (SUBSTR(cast(cal.brdcsts_yr_mo_nbr AS VARCHAR),1,4) || '-' || SUBSTR(cast(cal.brdcst_yr_mo_nbr AS VARCHAR),5,6) || '-01')) AS first_payment,
         max(date (SUBSTR(cast(cal.brdcst_yr_mo_nbr AS VARCHAR),1,4) || '-' || SUBSTR(cast(cal.brdcst_yr_mo_nbr AS VARCHAR),5,6) || '-01')) AS last_payment
  FROM am_ad_event_fact_in as aef
INNER JOIN am_calendar_dim cal
    ON date_parse(aef.ad_evnt_start_dt, '%Y-%m-%d') = cal.clndr_dt
        AND cal.BRDCST_YR_NBR >= 2015
INNER JOIN am_eda_customer_dim c
    ON (aef.cust_key = c.cust_key)
  GROUP BY 1,2),

  months AS (
    SELECT month
FROM (SELECT sequence(date '2010-01-01', current_date, interval '1' month)
) AS x (i)
CROSS JOIN UNNEST(i) AS t (month)
),

athenasux AS (
  SELECT *
  FROM (customers as c
    INNER JOIN months as month
              ON (c.first_payment <= month))),

revenue AS (
    SELECT a.*,
    row_number() over (partition by a.cust_nm order by month) AS months_as_customer,
    max(case when aef.prio_cd >= 40 then 1 else 0 end) p40plus,
    sum(case when aef.spot_rate_nbr is null then 0 else aef.spot_rate_nbr end) as rev,
    count(aef.ad_evnt_key) as spots,
    count(distinct aef.ord_nbr) as num_orders,
    count(distinct syscode) num_syscodes
    FROM athenasux as a
    LEFT JOIN am_ad_event_fact_in as aef
    ON (aef.cust_key = a.cust_key
    AND date_parse(aef.ad_evnt_start_dt, '%Y-%m-%d') = a.month)
    GROUP BY a.cust_nm, a.cust_key, a.month, a.first_payment, a.last_payment
  )

SELECT *,
    sum(rev) over (partition by cust_key, cust_nm order by month
        rows between unbounded preceding and current row) rev_rt,
    sum(num_orders) over (partition by cust_key, cust_nm order by month
        rows between unbounded preceding and current row) num_orders_rt,
    sum(spots) over (partition by cust_key, cust_nm order by month
        rows between unbounded preceding and current row) spots_rt,
    sum(num_syscodes) over (partition by cust_key, cust_nm order by month
        rows between unbounded preceding and current row) num_syscodes_rt
FROM revenue
);
sirbozc5

sirbozc51#

语法方面, insert 应在所有cte的末尾和最后一个cte的开头使用 SELECT .

with cte1 as (...)
,cte2 as (...)
INSERT INTO ...
SELECT ....

相关问题