Sql 在Insert语句配置单元中包含语句EMR AWS

Sql 在Insert语句配置单元中包含语句EMR AWS,sql,amazon-web-services,hive,hdfs,amazon-emr,Sql,Amazon Web Services,Hive,Hdfs,Amazon Emr,配置单元无法识别INSERT命令中的WITH语句。 我怎样才能让hive明白这一点 我已经创建了外部配置单元表来存储此查询中引用的所有数据。所有操作都执行良好,并且数据可用。这是查询的实际内容,将输出插入到chorn_date_out表中 为了将这个输出集放入表中,我使用了一个insert命令,然后通过with函数构建输出数据。但是,一旦启动,Hive就不喜欢WITH语句 WITH语句彼此级联,最终输出从收益块中选择。只要我们能够弄清楚如何让Hive喜欢WITH语句,所有这些都不是真正相关的 我

配置单元无法识别INSERT命令中的WITH语句。 我怎样才能让hive明白这一点

我已经创建了外部配置单元表来存储此查询中引用的所有数据。所有操作都执行良好,并且数据可用。这是查询的实际内容,将输出插入到chorn_date_out表中

为了将这个输出集放入表中,我使用了一个insert命令,然后通过with函数构建输出数据。但是,一旦启动,Hive就不喜欢WITH语句

WITH语句彼此级联,最终输出从收益块中选择。只要我们能够弄清楚如何让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
);
语法方面,应在所有cte的末尾和最后一次选择的开头使用insert


谢谢,通过将insert语句移动到最后一个select语句,它将得到令人兴奋的新错误。我会通知你的。
with cte1 as (...)
,cte2 as (...)
INSERT INTO ...
SELECT ....