Skip to content

Commit

Permalink
refactor: as can be ignore when UNNEST in athena
Browse files Browse the repository at this point in the history
  • Loading branch information
taozhi8833998 committed Nov 20, 2024
1 parent befa43c commit 9ad28d7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pegjs/athena.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -1102,7 +1102,7 @@ with_offset
}

from_unnest_item
= 'UNNEST'i __ LPAREN __ a:expr? __ RPAREN __ alias:alias_clause? __ wf:with_offset? {
= 'UNNEST'i __ LPAREN __ a:expr? __ RPAREN __ alias:(func_call / alias_clause)? __ wf:with_offset? {
return {
type: 'unnest',
expr: a,
Expand Down
5 changes: 5 additions & 0 deletions test/athena.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,5 +332,10 @@ describe('athena', () => {
WHERE
i.field = 'status'`
expect(getParsedSql(sql)).to.be.equal("SELECT `j`.`id`, `h`.`created` AS `change_time`, `i`.`fromstring` AS `from_status`, `i`.`tostring` AS `to_status` FROM `bronze_prod`.`jira_issues` AS `j` CROSS JOIN UNNEST(`j`.`changelog`.`histories`) AS T(`h`) CROSS JOIN UNNEST(`h`.`items`) AS T(`i`) WHERE `i`.`field` = 'status'")
sql = `SELECT id, array_agg(json_extract_scalar(elem, '$.value')) er_teams
FROM "bronze_prod"."jira_issues"
CROSS JOIN UNNEST(cast(json_extract(json_parse(fields), '$.customfield_10100') AS array(json))) AS t(elem)
GROUP BY id`
expect(getParsedSql(sql)).to.be.equal("SELECT `id`, array_agg(json_extract_scalar(`elem`, '$.value')) AS `er_teams` FROM `bronze_prod`.`jira_issues` CROSS JOIN UNNEST(CAST(json_extract(json_parse(`fields`), '$.customfield_10100') AS ARRAY(JSON))) AS t(`elem`) GROUP BY `id`")
})
})

0 comments on commit 9ad28d7

Please sign in to comment.