Skip to content

Commit

Permalink
Merge pull request #1903 from taozhi8833998/fix-over-partition-extrac…
Browse files Browse the repository at this point in the history
…t-athena

fix: over partition and extract in athena
  • Loading branch information
taozhi8833998 authored May 13, 2024
2 parents ef6b73c + 53b2c99 commit 252c21e
Show file tree
Hide file tree
Showing 13 changed files with 182 additions and 17 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"scripts": {
"start": "webpack --config webpack.config.js",
"build": "npm run lint && npm run compile && webpack --config webpack.config.js --mode production",
"test": "npm run lint && mochapack \"test/**/*.spec.js\"",
"test": "npm run lint && mochapack --reporter-option maxDiffSize=1000000 \"test/**/*.spec.js\"",
"lint": "eslint src",
"compile": "babel src -d lib",
"coverLocal": "cross-env NODE_ENV=coverage nyc --reporter=lcov --reporter=text npm run test",
Expand Down
39 changes: 37 additions & 2 deletions pegjs/athena.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@
'PERSIST_ONLY': true,
};

function getLocationObject() {
return options.includeLocations ? {loc: location()} : {}
}

function createUnaryExpr(op, e) {
return {
type: 'unary_expr',
Expand Down Expand Up @@ -1911,13 +1915,15 @@ aggr_func
/ aggr_fun_smma

aggr_fun_smma
= name:KW_SUM_MAX_MIN_AVG __ LPAREN __ e:additive_expr __ RPAREN {
= name:KW_SUM_MAX_MIN_AVG __ LPAREN __ e:additive_expr __ RPAREN __ bc:over_partition? {
return {
type: 'aggr_func',
name: name,
args: {
expr: e
}
},
over: bc,
...getLocationObject(),
};
}

Expand Down Expand Up @@ -1994,6 +2000,7 @@ func_call
over: bc
};
}
/ extract_func
/ f:scalar_time_func __ up:on_update_current_timestamp? {
return {
type: 'function',
Expand All @@ -2020,6 +2027,33 @@ func_call
over: bc
};
}
extract_filed
= 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) {
// => 'string'
return f
}
extract_func
= kw:KW_EXTRACT __ LPAREN __ f:extract_filed __ KW_FROM __ t:(KW_TIMESTAMP / KW_INTERVAL / KW_TIME / KW_DATE)? __ s:expr __ RPAREN {
// => { type: 'extract'; args: { field: extract_filed; cast_type: 'TIMESTAMP' | 'INTERVAL' | 'TIME'; source: expr; }}
return {
type: kw.toLowerCase(),
args: {
field: f,
cast_type: t,
source: s,
}
}
}
/ kw:KW_EXTRACT __ LPAREN __ f:extract_filed __ KW_FROM __ s:expr __ RPAREN {
// => { type: 'extract'; args: { field: extract_filed; source: expr; }}
return {
type: kw.toLowerCase(),
args: {
field: f,
source: s,
}
}
}
scalar_time_func
= KW_CURRENT_DATE
/ KW_CURRENT_TIME
Expand Down Expand Up @@ -2315,6 +2349,7 @@ KW_MIN = "MIN"i !ident_start { return 'MIN'; }
KW_SUM = "SUM"i !ident_start { return 'SUM'; }
KW_AVG = "AVG"i !ident_start { return 'AVG'; }

KW_EXTRACT = "EXTRACT"i !ident_start { return 'EXTRACT'; }
KW_CALL = "CALL"i !ident_start { return 'CALL'; }

KW_CASE = "CASE"i !ident_start
Expand Down
6 changes: 4 additions & 2 deletions pegjs/db2.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -1933,13 +1933,15 @@ aggr_func
/ aggr_fun_smma

aggr_fun_smma
= name:KW_SUM_MAX_MIN_AVG __ LPAREN __ e:additive_expr __ RPAREN {
= name:KW_SUM_MAX_MIN_AVG __ LPAREN __ e:additive_expr __ RPAREN __ bc:over_partition? {
return {
type: 'aggr_func',
name: name,
args: {
expr: e
}
},
over: bc,
...getLocationObject(),
};
}

Expand Down
6 changes: 4 additions & 2 deletions pegjs/hive.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -1913,13 +1913,15 @@ aggr_func
/ aggr_fun_smma

aggr_fun_smma
= name:KW_SUM_MAX_MIN_AVG __ LPAREN __ e:additive_expr __ RPAREN {
= name:KW_SUM_MAX_MIN_AVG __ LPAREN __ e:additive_expr __ RPAREN __ bc:over_partition? {
return {
type: 'aggr_func',
name: name,
args: {
expr: e
}
},
over: bc,
...getLocationObject(),
};
}

Expand Down
1 change: 1 addition & 0 deletions pegjs/mariadb.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -2914,6 +2914,7 @@ aggr_fun_smma
expr: e
},
over: bc,
...getLocationObject(),
};
}

Expand Down
3 changes: 2 additions & 1 deletion pegjs/noql.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -4245,7 +4245,8 @@ aggr_fun_smma
args: {
expr: e
},
over: bc
over: bc,
...getLocationObject(),
};
}

Expand Down
3 changes: 2 additions & 1 deletion pegjs/postgresql.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -4455,7 +4455,8 @@ aggr_fun_smma
args: {
expr: e
},
over: bc
over: bc,
...getLocationObject(),
};
}

Expand Down
3 changes: 2 additions & 1 deletion pegjs/redshift.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -4309,7 +4309,8 @@ aggr_fun_smma
args: {
expr: e
},
over: bc
over: bc,
...getLocationObject(),
};
}

Expand Down
3 changes: 2 additions & 1 deletion pegjs/snowflake.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -3646,7 +3646,8 @@ aggr_fun_smma
args: {
expr: e
},
over: bc
over: bc,
...getLocationObject(),
};
}

Expand Down
6 changes: 4 additions & 2 deletions pegjs/sqlite.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -2102,13 +2102,15 @@ aggr_func
/ aggr_fun_smma

aggr_fun_smma
= name:KW_SUM_MAX_MIN_AVG __ LPAREN __ e:additive_expr __ RPAREN {
= name:KW_SUM_MAX_MIN_AVG __ LPAREN __ e:additive_expr __ RPAREN __ bc:over_partition? {
return {
type: 'aggr_func',
name: name,
args: {
expr: e
}
},
over: bc,
...getLocationObject(),
};
}

Expand Down
3 changes: 2 additions & 1 deletion pegjs/transactsql.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -2506,7 +2506,8 @@ aggr_fun_smma
args: {
expr: e
},
over: bc
over: bc,
...getLocationObject(),
};
}

Expand Down
3 changes: 2 additions & 1 deletion pegjs/trino.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -3705,7 +3705,8 @@ aggr_fun_smma
args: {
expr: e
},
over: bc
over: bc,
...getLocationObject(),
};
}

Expand Down
121 changes: 119 additions & 2 deletions test/athena.spec.js

Large diffs are not rendered by default.

0 comments on commit 252c21e

Please sign in to comment.