Skip to content

Commit 2fe79c3

Browse files
Merge pull request taozhi8833998#1345 from poulinjulien/feat-flink-overlay
feat: support overlay in flink
2 parents e428e22 + c0d2255 commit 2fe79c3

2 files changed

Lines changed: 41 additions & 1 deletion

File tree

pegjs/flinksql.pegjs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@
241241
'OUTER': true,
242242
'OVER': true,
243243
'OVERLAPS': true,
244-
'OVERLAPS': true,
244+
'OVERLAY': true,
245245

246246
'PARAMETER': true,
247247
'PARTITION': true,
@@ -2866,6 +2866,31 @@ trim_func_clause
28662866
};
28672867
}
28682868

2869+
overlay_func_args
2870+
= s1:expr __ 'placing'i __ s2:expr __ KW_FROM __ start:literal_numeric length:(__ 'for'i __ literal_numeric)? {
2871+
// => expr_list
2872+
let value = [s1, { type: 'origin', value: 'placing' }, s2, { type: 'origin', value: 'from' }, start]
2873+
if (length) {
2874+
value.push({ type: 'origin', value: 'for' })
2875+
value.push(length[3])
2876+
}
2877+
return {
2878+
type: 'expr_list',
2879+
value,
2880+
}
2881+
}
2882+
2883+
overlay_func_clause
2884+
= 'overlay'i __ LPAREN __ args:overlay_func_args __ RPAREN {
2885+
// => { type: 'function'; name: string; args: expr_list; }
2886+
return {
2887+
type: 'function',
2888+
name: 'OVERLAY',
2889+
separator: ' ',
2890+
args,
2891+
};
2892+
}
2893+
28692894
substring_func_args
28702895
= e:expr __ KW_FROM __ start:literal_numeric length:(__ 'for'i __ literal_numeric)? {
28712896
// => expr_list
@@ -2895,6 +2920,7 @@ func_call
28952920
= position_func_clause
28962921
/ trim_func_clause
28972922
/ substring_func_clause
2923+
/ overlay_func_clause
28982924
/ name:proc_func_name __ LPAREN __ l:or_and_where_expr? __ RPAREN __ bc:over_partition? {
28992925
// => { type: 'function'; name: string; args: expr_list; }
29002926
if (l && l.type !== 'expr_list') l = { type: 'expr_list', value: [l] }

test/flink.spec.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,20 @@ describe('Flink', () => {
259259
"SELECT SHA512(TRY_CAST(CONCAT(`a`, `b`, `c`) AS VARCHAR)) AS `Hashed` FROM `v`",
260260
],
261261
},
262+
{
263+
title: "OVERLAY",
264+
sql: [
265+
`SELECT OVERLAY(a PLACING 'a' FROM 3) FROM users`,
266+
"SELECT OVERLAY(`a` PLACING 'a' FROM 3) FROM `users`",
267+
],
268+
},
269+
{
270+
title: "OVERLAY with length",
271+
sql: [
272+
`SELECT * FROM users WHERE OVERLAY(a PLACING 'abc' FROM 3 FOR 2) = 'abcde'`,
273+
"SELECT * FROM `users` WHERE OVERLAY(`a` PLACING 'abc' FROM 3 FOR 2) = 'abcde'",
274+
],
275+
},
262276
];
263277

264278
SQL_LIST.forEach(sqlInfo => {

0 commit comments

Comments
 (0)