Skip to content

Commit 7912fd5

Browse files
committed
feat: support range expr as window frame in snowflake
1 parent 048aba4 commit 7912fd5

13 files changed

Lines changed: 207 additions & 110 deletions

pegjs/athena.pegjs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1320,10 +1320,21 @@ window_specification_frameless
13201320

13211321
window_frame_clause
13221322
= kw:KW_ROWS __ s:(window_frame_following / window_frame_preceding) {
1323-
return `rows ${s.value}`
1323+
return {
1324+
type: 'rows',
1325+
expr: s
1326+
}
13241327
}
1325-
/ KW_ROWS __ KW_BETWEEN __ p:window_frame_preceding __ KW_AND __ f:window_frame_following {
1326-
return `rows between ${p.value} and ${f.value}`
1328+
/ KW_ROWS __ op:KW_BETWEEN __ p:window_frame_preceding __ KW_AND __ f:window_frame_following {
1329+
const left = {
1330+
type: 'origin',
1331+
value: 'rows',
1332+
}
1333+
const right = {
1334+
type: 'expr_list',
1335+
value: [p, f]
1336+
}
1337+
return createBinaryExpr(op, left, right)
13271338
}
13281339

13291340
window_frame_following
@@ -1344,14 +1355,13 @@ window_frame_preceding
13441355

13451356
window_frame_current_row
13461357
= 'CURRENT'i __ 'ROW'i {
1347-
// => { type: 'single_quote_string'; value: string }
1348-
return { type: 'single_quote_string', value: 'current row' }
1358+
return { type: 'origin', value: 'current row' }
13491359
}
13501360

13511361
window_frame_value
13521362
= s:'UNBOUNDED'i {
13531363
// => literal_string
1354-
return { type: 'single_quote_string', value: s.toUpperCase() }
1364+
return { type: 'origin', value: s.toUpperCase() }
13551365
}
13561366
/ literal_numeric
13571367

pegjs/bigquery.pegjs

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2022,16 +2022,22 @@ window_specification
20222022
}
20232023

20242024
window_frame_clause
2025-
= 'RANGE'i __ KW_BETWEEN 'UNBOUNDED'i __ 'PRECEDING'i __ KW_AND __ 'CURRENT'i __ 'ROW' {
2026-
return 'range between unbounded preceding and current row'
2027-
}
2028-
/ kw:KW_ROWS __ s:(window_frame_following / window_frame_preceding) {
2029-
// => string
2030-
return `rows ${s.value}`
2025+
= kw:KW_ROWS __ s:(window_frame_following / window_frame_preceding) {
2026+
return {
2027+
type: 'rows',
2028+
expr: s
2029+
}
20312030
}
2032-
/ KW_ROWS __ KW_BETWEEN __ p:window_frame_preceding __ KW_AND __ f:window_frame_following {
2033-
// => string
2034-
return `rows between ${p.value} and ${f.value}`
2031+
/ k:(KW_ROWS / 'RANGE'i) __ op:KW_BETWEEN __ p:window_frame_preceding __ KW_AND __ f:window_frame_following {
2032+
const left = {
2033+
type: 'origin',
2034+
value: k.toLowerCase(),
2035+
}
2036+
const right = {
2037+
type: 'expr_list',
2038+
value: [p, f]
2039+
}
2040+
return createBinaryExpr(op, left, right)
20352041
}
20362042

20372043
window_frame_following
@@ -2052,14 +2058,12 @@ window_frame_preceding
20522058

20532059
window_frame_current_row
20542060
= 'CURRENT'i __ 'ROW'i {
2055-
// => { type: 'single_quote_string'; value: string }
2056-
return { type: 'single_quote_string', value: 'current row', ...getLocationObject() }
2061+
return { type: 'origin', value: 'current row', ...getLocationObject() }
20572062
}
20582063

20592064
window_frame_value
20602065
= s:'UNBOUNDED'i {
2061-
// => literal_string
2062-
return { type: 'single_quote_string', value: s.toUpperCase(), ...getLocationObject() }
2066+
return { type: 'origin', value: s.toUpperCase(), ...getLocationObject() }
20632067
}
20642068
/ literal_numeric
20652069

pegjs/hive.pegjs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1297,10 +1297,21 @@ window_specification_frameless
12971297

12981298
window_frame_clause
12991299
= kw:KW_ROWS __ s:(window_frame_following / window_frame_preceding) {
1300-
return `rows ${s.value}`
1300+
return {
1301+
type: 'rows',
1302+
expr: s
1303+
}
13011304
}
1302-
/ KW_ROWS __ KW_BETWEEN __ p:window_frame_preceding __ KW_AND __ f:window_frame_following {
1303-
return `rows between ${p.value} and ${f.value}`
1305+
/ KW_ROWS __ op:KW_BETWEEN __ p:window_frame_preceding __ KW_AND __ f:window_frame_following {
1306+
const left = {
1307+
type: 'origin',
1308+
value: 'rows',
1309+
}
1310+
const right = {
1311+
type: 'expr_list',
1312+
value: [p, f]
1313+
}
1314+
return createBinaryExpr(op, left, right)
13041315
}
13051316

13061317
window_frame_following
@@ -1321,14 +1332,12 @@ window_frame_preceding
13211332

13221333
window_frame_current_row
13231334
= 'CURRENT'i __ 'ROW'i {
1324-
// => { type: 'single_quote_string'; value: string }
1325-
return { type: 'single_quote_string', value: 'current row' }
1335+
return { type: 'origin', value: 'current row' }
13261336
}
13271337

13281338
window_frame_value
13291339
= s:'UNBOUNDED'i {
1330-
// => literal_string
1331-
return { type: 'single_quote_string', value: s.toUpperCase() }
1340+
return { type: 'origin', value: s.toUpperCase() }
13321341
}
13331342
/ literal_numeric
13341343

pegjs/mariadb.pegjs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3098,12 +3098,21 @@ window_specification_frameless
30983098

30993099
window_frame_clause
31003100
= kw:KW_ROWS __ s:(window_frame_following / window_frame_preceding) {
3101-
// => string
3102-
return `rows ${s.value}`
3101+
return {
3102+
type: 'rows',
3103+
expr: s
3104+
}
31033105
}
3104-
/ KW_ROWS __ KW_BETWEEN __ p:window_frame_preceding __ KW_AND __ f:window_frame_following {
3105-
// => string
3106-
return `rows between ${p.value} and ${f.value}`
3106+
/ KW_ROWS __ op:KW_BETWEEN __ p:window_frame_preceding __ KW_AND __ f:window_frame_following {
3107+
const left = {
3108+
type: 'origin',
3109+
value: 'rows',
3110+
}
3111+
const right = {
3112+
type: 'expr_list',
3113+
value: [p, f]
3114+
}
3115+
return createBinaryExpr(op, left, right)
31073116
}
31083117

31093118
window_frame_following
@@ -3124,14 +3133,12 @@ window_frame_preceding
31243133

31253134
window_frame_current_row
31263135
= 'CURRENT'i __ 'ROW'i {
3127-
// => { type: 'single_quote_string'; value: string }
3128-
return { type: 'single_quote_string', value: 'current row' }
3136+
return { type: 'origin', value: 'current row' }
31293137
}
31303138

31313139
window_frame_value
31323140
= s:'UNBOUNDED'i {
3133-
// => literal_string
3134-
return { type: 'single_quote_string', value: s.toUpperCase() }
3141+
return { type: 'origin', value: s.toUpperCase() }
31353142
}
31363143
/ literal_numeric
31373144

pegjs/mysql.pegjs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3388,12 +3388,21 @@ window_specification_frameless
33883388

33893389
window_frame_clause
33903390
= kw:KW_ROWS __ s:(window_frame_following / window_frame_preceding) {
3391-
// => string
3392-
return `rows ${s.value}`
3391+
return {
3392+
type: 'rows',
3393+
expr: s
3394+
}
33933395
}
3394-
/ KW_ROWS __ KW_BETWEEN __ p:window_frame_preceding __ KW_AND __ f:window_frame_following {
3395-
// => string
3396-
return `rows between ${p.value} and ${f.value}`
3396+
/ KW_ROWS __ op:KW_BETWEEN __ p:window_frame_preceding __ KW_AND __ f:window_frame_following {
3397+
const left = {
3398+
type: 'origin',
3399+
value: 'rows',
3400+
}
3401+
const right = {
3402+
type: 'expr_list',
3403+
value: [p, f]
3404+
}
3405+
return createBinaryExpr(op, left, right)
33973406
}
33983407

33993408
window_frame_following
@@ -3414,12 +3423,12 @@ window_frame_preceding
34143423

34153424
window_frame_current_row
34163425
= 'CURRENT'i __ 'ROW'i {
3417-
return { type: 'single_quote_string', value: 'current row', ...getLocationObject() }
3426+
return { type: 'origin', value: 'current row', ...getLocationObject() }
34183427
}
34193428

34203429
window_frame_value
34213430
= s:'UNBOUNDED'i {
3422-
return { type: 'single_quote_string', value: s.toUpperCase(), ...getLocationObject() }
3431+
return { type: 'origin', value: s.toUpperCase(), ...getLocationObject() }
34233432
}
34243433
/ literal_numeric
34253434

pegjs/noql.pegjs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3224,12 +3224,21 @@ window_specification_frameless
32243224

32253225
window_frame_clause
32263226
= kw:KW_ROWS __ s:(window_frame_following / window_frame_preceding) {
3227-
// => string
3228-
return `rows ${s.value}`
3227+
return {
3228+
type: 'rows',
3229+
expr: s
3230+
}
32293231
}
3230-
/ KW_ROWS __ KW_BETWEEN __ p:window_frame_preceding __ KW_AND __ f:window_frame_following {
3231-
// => string
3232-
return `rows between ${p.value} and ${f.value}`
3232+
/ KW_ROWS __ op:KW_BETWEEN __ p:window_frame_preceding __ KW_AND __ f:window_frame_following {
3233+
const left = {
3234+
type: 'origin',
3235+
value: 'rows',
3236+
}
3237+
const right = {
3238+
type: 'expr_list',
3239+
value: [p, f]
3240+
}
3241+
return createBinaryExpr(op, left, right)
32333242
}
32343243

32353244
window_frame_following
@@ -3250,14 +3259,13 @@ window_frame_preceding
32503259

32513260
window_frame_current_row
32523261
= 'CURRENT'i __ 'ROW'i {
3253-
// => { type: 'single_quote_string'; value: string }
3254-
return { type: 'single_quote_string', value: 'current row' }
3262+
return { type: 'origin', value: 'current row' }
32553263
}
32563264

32573265
window_frame_value
32583266
= s:'UNBOUNDED'i {
32593267
// => literal_string
3260-
return { type: 'single_quote_string', value: s.toUpperCase() }
3268+
return { type: 'origin', value: s.toUpperCase() }
32613269
}
32623270
/ literal_numeric
32633271

pegjs/postgresql.pegjs

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3758,12 +3758,23 @@ window_specification_frameless
37583758

37593759
window_frame_clause
37603760
= kw:KW_ROWS __ s:(window_frame_following / window_frame_preceding) {
3761-
// => string
3762-
return `rows ${s.value}`
3761+
// => { type: 'row'; expr: window_frame_following / window_frame_preceding }
3762+
return {
3763+
type: 'rows',
3764+
expr: s
3765+
}
37633766
}
3764-
/ KW_ROWS __ KW_BETWEEN __ p:window_frame_preceding __ KW_AND __ f:window_frame_following {
3765-
// => string
3766-
return `rows between ${p.value} and ${f.value}`
3767+
/ KW_ROWS __ op:KW_BETWEEN __ p:window_frame_preceding __ KW_AND __ f:window_frame_following {
3768+
// => binary_expr
3769+
const left = {
3770+
type: 'origin',
3771+
value: 'rows',
3772+
}
3773+
const right = {
3774+
type: 'expr_list',
3775+
value: [p, f]
3776+
}
3777+
return createBinaryExpr(op, left, right)
37673778
}
37683779

37693780
window_frame_following
@@ -3784,14 +3795,14 @@ window_frame_preceding
37843795

37853796
window_frame_current_row
37863797
= 'CURRENT'i __ 'ROW'i {
3787-
// => { type: 'single_quote_string'; value: string }
3788-
return { type: 'single_quote_string', value: 'current row' }
3798+
// => { type: 'origin'; value: string }
3799+
return { type: 'origin', value: 'current row' }
37893800
}
37903801

37913802
window_frame_value
37923803
= s:'UNBOUNDED'i {
3793-
// => literal_string
3794-
return { type: 'single_quote_string', value: s.toUpperCase() }
3804+
// => { type: 'origin'; value: string }
3805+
return { type: 'origin', value: s.toUpperCase() }
37953806
}
37963807
/ literal_numeric
37973808

pegjs/redshift.pegjs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3253,12 +3253,21 @@ window_specification_frameless
32533253

32543254
window_frame_clause
32553255
= kw:KW_ROWS __ s:(window_frame_following / window_frame_preceding) {
3256-
// => string
3257-
return `rows ${s.value}`
3256+
return {
3257+
type: 'rows',
3258+
expr: s
3259+
}
32583260
}
3259-
/ KW_ROWS __ KW_BETWEEN __ p:window_frame_preceding __ KW_AND __ f:window_frame_following {
3260-
// => string
3261-
return `rows between ${p.value} and ${f.value}`
3261+
/ KW_ROWS __ op:KW_BETWEEN __ p:window_frame_preceding __ KW_AND __ f:window_frame_following {
3262+
const left = {
3263+
type: 'origin',
3264+
value: 'rows',
3265+
}
3266+
const right = {
3267+
type: 'expr_list',
3268+
value: [p, f]
3269+
}
3270+
return createBinaryExpr(op, left, right)
32623271
}
32633272

32643273
window_frame_following
@@ -3279,14 +3288,12 @@ window_frame_preceding
32793288

32803289
window_frame_current_row
32813290
= 'CURRENT'i __ 'ROW'i {
3282-
// => { type: 'single_quote_string'; value: string }
3283-
return { type: 'single_quote_string', value: 'current row' }
3291+
return { type: 'origin', value: 'current row' }
32843292
}
32853293

32863294
window_frame_value
32873295
= s:'UNBOUNDED'i {
3288-
// => literal_string
3289-
return { type: 'single_quote_string', value: s.toUpperCase() }
3296+
return { type: 'origin', value: s.toUpperCase() }
32903297
}
32913298
/ literal_numeric
32923299

0 commit comments

Comments
 (0)