为什么这个查询无法执行?

Why is this query not able to execute?

查询继续但未执行,关于如何帮助它解决的任何想法?

在 Snowflake 中使用来自 KnoemaEconomy Data Atlas 数据集。

with payment as (
  select *
  from DATA_WAREHOUSE.ANALYTICS.PAYMENTS
),

fx_rates as (
  select
    date("Date") as date,
    split("Currency Name", '/')[0] as from_currency,
    "Value" as rate
  from economy_data_atlas.economy.exratescc2018
  where date > (select MIN(processed_at) from payment )
    and from_currency in (select distinct target_currency from payment)
    and "Currency Unit" = 'USD'
    and "Indicator Name" = 'Close'
    and "Frequency" = 'D'
)


select
  payment.payout_guid as payout_id,
  payment.status,

  payment.source_amount,
  IFF(
    source_currency = target_currency,
    source_amount,
    ROUND(
      payment.source_amount * source_fx_rates_usd.rate,
      2
    )
  ) as source_amount_usd

from payment
left join fx_rates as source_fx_rates_usd on source_fx_rates_usd.date = date(payment.processed_at) and source_fx_rates_usd.from_currency = payment.source_currency

在这种情况下,临时 table 可能会帮助您修剪大量 table(也就是避免复杂 CTE 的原因之一)

我会 re-write 你的 SQL 喜欢:

with payment as (
    select *
        ,date(payment.processed_at) as _payment_date
    from DATA_WAREHOUSE.ANALYTICS.PAYMENTS
), distinct_targets as (
    select distinct target_currency 
    from payment 
), fx_rates as (
    select
        date("Date") as date,
        split_part("Currency Name", '/', 0) as from_currency,
        "Value" as rate
    from economy_data_atlas.economy.exratescc2018
    join distinct_targets dt
        on from_currency = dt.target_currency
    where date > (
        select MIN(processed_at) 
        from payment 
    )
    and "Currency Unit" = 'USD'
    and "Indicator Name" = 'Close'
    and "Frequency" = 'D'
)
select
      p.payout_guid as payout_id,
      p.status,
      p.source_amount,
      IFF(
        source_currency = target_currency,
        source_amount,
        ROUND( p.source_amount * sfx.rate, 2 )
      ) as source_amount_usd
from payment as p
left join fx_rates as sfx 
    on sfx.date = p._payment_date
    and sfx.from_currency = p.source_currency
left join fx_rates as tfx 
    on tfx.date = p._payment_date 
    and tfx.from_currency = p.target_currency

所以我能理解。我注意到您加入了 fx_rates 两次,但两者的加入逻辑完全相同。所以这 100% 毫无意义.. 鉴于 tfx 没有被使用,我猜就是这样。

接下来要看的是您的进程完成数据加载的程度。了解还有多少数据要加载。