From 9ad28d7389f2acb85287f8cab510295ef63967bc Mon Sep 17 00:00:00 2001 From: taozhi8833998 Date: Wed, 20 Nov 2024 19:12:39 +0800 Subject: [PATCH] refactor: as can be ignore when UNNEST in athena --- pegjs/athena.pegjs | 2 +- test/athena.spec.js | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/pegjs/athena.pegjs b/pegjs/athena.pegjs index d40944cb..12985183 100644 --- a/pegjs/athena.pegjs +++ b/pegjs/athena.pegjs @@ -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, diff --git a/test/athena.spec.js b/test/athena.spec.js index c62afd69..b76865ee 100644 --- a/test/athena.spec.js +++ b/test/athena.spec.js @@ -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`") }) }) \ No newline at end of file