Skip to main content

snowflake_flatten_projection_to_unnest

Function snowflake_flatten_projection_to_unnest 

Source
pub fn snowflake_flatten_projection_to_unnest(
    expr: Expression,
) -> Result<Expression>
Expand description

Snowflake-specific rewrite to mirror Python sqlglot’s explode_projection_to_unnest behavior when FLATTEN appears in a nested LATERAL within a SELECT projection.

This intentionally rewrites:

  • LATERAL FLATTEN(INPUT => x) alias into:
  • LATERAL IFF(_u.pos = _u_2.pos_2, _u_2.entity, NULL) AS alias(SEQ, KEY, PATH, INDEX, VALUE, THIS) and appends CROSS JOIN TABLE(FLATTEN(…)) range/entity joins plus alignment predicates to the containing SELECT.