Skip to content

Commit

Permalink
Merge pull request #2218 from taozhi8833998/refactor-listagg-func-sno…
Browse files Browse the repository at this point in the history
…wflake

refactor: support listagg function in snowflake
  • Loading branch information
taozhi8833998 authored Nov 14, 2024
2 parents 4052b28 + b7fb639 commit ef06368
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pegjs/snowflake.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -3704,7 +3704,7 @@ KW_SUM_MAX_MIN_AVG
= KW_SUM / KW_MAX / KW_MIN / KW_AVG

aggr_fun_count
= name:(KW_COUNT / KW_GROUP_CONCAT) __ LPAREN __ arg:count_arg __ RPAREN __ bc:over_partition? {
= name:(KW_COUNT / KW_GROUP_CONCAT / 'LISTAGG'i) __ LPAREN __ arg:count_arg __ RPAREN __ bc:over_partition? {
// => { type: 'aggr_func'; name: 'COUNT' | 'GROUP_CONCAT'; args:count_arg; over: over_partition }
return {
type: 'aggr_func',
Expand Down Expand Up @@ -3740,7 +3740,7 @@ concat_separator
= kw:COMMA __ s:literal_string {
// => { symbol: ','; delimiter: literal_string; }
return {
symbol: ke,
symbol: kw,
delimiter: s
}
}
Expand Down
7 changes: 7 additions & 0 deletions test/snowflake.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,13 @@ describe('snowflake', () => {
'SELECT "bi_json"."limit" AS "limit" FROM "modelc"'
]
},
{
title: 'listagg function',
sql: [
'select listagg(distinct id, ", ") as ids from foo;',
'SELECT listagg(DISTINCT "id", ", ") AS "ids" FROM "foo"'
]
},
]
SQL_LIST.forEach(sqlInfo => {
const { title, sql } = sqlInfo
Expand Down

0 comments on commit ef06368

Please sign in to comment.