filipniziol
Esteemed Contributor

Hi @binsel ,

Yes, you need to unpack the CRates array as well

 

WITH first_explode AS (
  SELECT  
    uv.rowData:Id AS Id,
    uv.rowData:Result:BodyType AS BodyType,
    uv.rowData:Result:ProdType AS ProdType,
    v.value AS result_set
  FROM unpivot_valtype AS uv,
  LATERAL variant_explode(uv.rowData:Result:ResultSets) AS v
),
second_explode AS (
  SELECT
    fe.Id,
    fe.BodyType,
    fe.ProdType,
    vv.key AS R,
    vv.value AS r_value
  FROM first_explode fe,
  LATERAL variant_explode(fe.result_set) AS vv
),
third_explode AS (
  SELECT
    se.Id,
    se.BodyType,
    se.ProdType,
    se.R,
    se.r_value:AInt AS AInt,
    se.r_value:EffPrice AS EffPrice,
    se.r_value:EffRate AS EffRate,
    c.value AS c_rate
  FROM second_explode se,
  LATERAL variant_explode(se.r_value:CRates) AS c
)
SELECT
  Id,
  BodyType,
  ProdType,
  R,
  AInt,
  c_rate:RateA AS RateA,
  c_rate:RateB AS RateB,
  c_rate:RateC AS RateC,
  EffPrice,
  EffRate
FROM
  third_explode;

filipniziol_0-1733211624644.png

 

View solution in original post