Skip to content

Commit 911bc19

Browse files
Merge pull request taozhi8833998#2229 from taozhi8833998/refactor-unnest-athena
refactor: as can be ignore when UNNEST in athena
2 parents dbef224 + 9ad28d7 commit 911bc19

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

pegjs/athena.pegjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1102,7 +1102,7 @@ with_offset
11021102
}
11031103

11041104
from_unnest_item
1105-
= 'UNNEST'i __ LPAREN __ a:expr? __ RPAREN __ alias:alias_clause? __ wf:with_offset? {
1105+
= 'UNNEST'i __ LPAREN __ a:expr? __ RPAREN __ alias:(func_call / alias_clause)? __ wf:with_offset? {
11061106
return {
11071107
type: 'unnest',
11081108
expr: a,

test/athena.spec.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,5 +332,10 @@ describe('athena', () => {
332332
WHERE
333333
i.field = 'status'`
334334
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'")
335+
sql = `SELECT id, array_agg(json_extract_scalar(elem, '$.value')) er_teams
336+
FROM "bronze_prod"."jira_issues"
337+
CROSS JOIN UNNEST(cast(json_extract(json_parse(fields), '$.customfield_10100') AS array(json))) AS t(elem)
338+
GROUP BY id`
339+
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`")
335340
})
336341
})

0 commit comments

Comments
 (0)