Skip to content

Commit 53b2c99

Browse files
committed
fix: over partition and extract in athena
1 parent d2f34ba commit 53b2c99

13 files changed

+182
-17
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"scripts": {
88
"start": "webpack --config webpack.config.js",
99
"build": "npm run lint && npm run compile && webpack --config webpack.config.js --mode production",
10-
"test": "npm run lint && mochapack \"test/**/*.spec.js\"",
10+
"test": "npm run lint && mochapack --reporter-option maxDiffSize=1000000 \"test/**/*.spec.js\"",
1111
"lint": "eslint src",
1212
"compile": "babel src -d lib",
1313
"coverLocal": "cross-env NODE_ENV=coverage nyc --reporter=lcov --reporter=text npm run test",

pegjs/athena.pegjs

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@
9797
'PERSIST_ONLY': true,
9898
};
9999

100+
function getLocationObject() {
101+
return options.includeLocations ? {loc: location()} : {}
102+
}
103+
100104
function createUnaryExpr(op, e) {
101105
return {
102106
type: 'unary_expr',
@@ -1911,13 +1915,15 @@ aggr_func
19111915
/ aggr_fun_smma
19121916

19131917
aggr_fun_smma
1914-
= name:KW_SUM_MAX_MIN_AVG __ LPAREN __ e:additive_expr __ RPAREN {
1918+
= name:KW_SUM_MAX_MIN_AVG __ LPAREN __ e:additive_expr __ RPAREN __ bc:over_partition? {
19151919
return {
19161920
type: 'aggr_func',
19171921
name: name,
19181922
args: {
19191923
expr: e
1920-
}
1924+
},
1925+
over: bc,
1926+
...getLocationObject(),
19211927
};
19221928
}
19231929

@@ -1994,6 +2000,7 @@ func_call
19942000
over: bc
19952001
};
19962002
}
2003+
/ extract_func
19972004
/ f:scalar_time_func __ up:on_update_current_timestamp? {
19982005
return {
19992006
type: 'function',
@@ -2020,6 +2027,33 @@ func_call
20202027
over: bc
20212028
};
20222029
}
2030+
extract_filed
2031+
= f:('CENTURY'i / 'DAY'i / 'DATE'i / 'DECADE'i / 'DOW'i / 'DOY'i / 'EPOCH'i / 'HOUR'i / 'ISODOW'i / 'ISOYEAR'i / 'MICROSECONDS'i / 'MILLENNIUM'i / 'MILLISECONDS'i / 'MINUTE'i / 'MONTH'i / 'QUARTER'i / 'SECOND'i / 'TIMEZONE'i / 'TIMEZONE_HOUR'i / 'TIMEZONE_MINUTE'i / 'WEEK'i / 'YEAR'i) {
2032+
// => 'string'
2033+
return f
2034+
}
2035+
extract_func
2036+
= kw:KW_EXTRACT __ LPAREN __ f:extract_filed __ KW_FROM __ t:(KW_TIMESTAMP / KW_INTERVAL / KW_TIME / KW_DATE)? __ s:expr __ RPAREN {
2037+
// => { type: 'extract'; args: { field: extract_filed; cast_type: 'TIMESTAMP' | 'INTERVAL' | 'TIME'; source: expr; }}
2038+
return {
2039+
type: kw.toLowerCase(),
2040+
args: {
2041+
field: f,
2042+
cast_type: t,
2043+
source: s,
2044+
}
2045+
}
2046+
}
2047+
/ kw:KW_EXTRACT __ LPAREN __ f:extract_filed __ KW_FROM __ s:expr __ RPAREN {
2048+
// => { type: 'extract'; args: { field: extract_filed; source: expr; }}
2049+
return {
2050+
type: kw.toLowerCase(),
2051+
args: {
2052+
field: f,
2053+
source: s,
2054+
}
2055+
}
2056+
}
20232057
scalar_time_func
20242058
= KW_CURRENT_DATE
20252059
/ KW_CURRENT_TIME
@@ -2315,6 +2349,7 @@ KW_MIN = "MIN"i !ident_start { return 'MIN'; }
23152349
KW_SUM = "SUM"i !ident_start { return 'SUM'; }
23162350
KW_AVG = "AVG"i !ident_start { return 'AVG'; }
23172351

2352+
KW_EXTRACT = "EXTRACT"i !ident_start { return 'EXTRACT'; }
23182353
KW_CALL = "CALL"i !ident_start { return 'CALL'; }
23192354

23202355
KW_CASE = "CASE"i !ident_start

pegjs/db2.pegjs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1933,13 +1933,15 @@ aggr_func
19331933
/ aggr_fun_smma
19341934

19351935
aggr_fun_smma
1936-
= name:KW_SUM_MAX_MIN_AVG __ LPAREN __ e:additive_expr __ RPAREN {
1936+
= name:KW_SUM_MAX_MIN_AVG __ LPAREN __ e:additive_expr __ RPAREN __ bc:over_partition? {
19371937
return {
19381938
type: 'aggr_func',
19391939
name: name,
19401940
args: {
19411941
expr: e
1942-
}
1942+
},
1943+
over: bc,
1944+
...getLocationObject(),
19431945
};
19441946
}
19451947

pegjs/hive.pegjs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1913,13 +1913,15 @@ aggr_func
19131913
/ aggr_fun_smma
19141914

19151915
aggr_fun_smma
1916-
= name:KW_SUM_MAX_MIN_AVG __ LPAREN __ e:additive_expr __ RPAREN {
1916+
= name:KW_SUM_MAX_MIN_AVG __ LPAREN __ e:additive_expr __ RPAREN __ bc:over_partition? {
19171917
return {
19181918
type: 'aggr_func',
19191919
name: name,
19201920
args: {
19211921
expr: e
1922-
}
1922+
},
1923+
over: bc,
1924+
...getLocationObject(),
19231925
};
19241926
}
19251927

pegjs/mariadb.pegjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2914,6 +2914,7 @@ aggr_fun_smma
29142914
expr: e
29152915
},
29162916
over: bc,
2917+
...getLocationObject(),
29172918
};
29182919
}
29192920

pegjs/noql.pegjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4245,7 +4245,8 @@ aggr_fun_smma
42454245
args: {
42464246
expr: e
42474247
},
4248-
over: bc
4248+
over: bc,
4249+
...getLocationObject(),
42494250
};
42504251
}
42514252

pegjs/postgresql.pegjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4455,7 +4455,8 @@ aggr_fun_smma
44554455
args: {
44564456
expr: e
44574457
},
4458-
over: bc
4458+
over: bc,
4459+
...getLocationObject(),
44594460
};
44604461
}
44614462

pegjs/redshift.pegjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4309,7 +4309,8 @@ aggr_fun_smma
43094309
args: {
43104310
expr: e
43114311
},
4312-
over: bc
4312+
over: bc,
4313+
...getLocationObject(),
43134314
};
43144315
}
43154316

pegjs/snowflake.pegjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3646,7 +3646,8 @@ aggr_fun_smma
36463646
args: {
36473647
expr: e
36483648
},
3649-
over: bc
3649+
over: bc,
3650+
...getLocationObject(),
36503651
};
36513652
}
36523653

pegjs/sqlite.pegjs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2102,13 +2102,15 @@ aggr_func
21022102
/ aggr_fun_smma
21032103

21042104
aggr_fun_smma
2105-
= name:KW_SUM_MAX_MIN_AVG __ LPAREN __ e:additive_expr __ RPAREN {
2105+
= name:KW_SUM_MAX_MIN_AVG __ LPAREN __ e:additive_expr __ RPAREN __ bc:over_partition? {
21062106
return {
21072107
type: 'aggr_func',
21082108
name: name,
21092109
args: {
21102110
expr: e
2111-
}
2111+
},
2112+
over: bc,
2113+
...getLocationObject(),
21122114
};
21132115
}
21142116

0 commit comments

Comments
 (0)