Skip to content

Commit baa99db

Browse files
committed
Fix Window Functions
1 parent 7082929 commit baa99db

File tree

5 files changed

+75
-61
lines changed

5 files changed

+75
-61
lines changed

src/backend/parser/ag_scanner.l

+51-49
Original file line numberDiff line numberDiff line change
@@ -224,32 +224,6 @@ digitseq {digit}+
224224
hexint 0[Xx]{hexdigit}+
225225
hexintfail 0[Xx]
226226

227-
228-
/*
229-
* decimal pattern covers RegularDecimalReal rule in Cypher and also accepts
230-
* "{digitseq}\." pattern (e.g. "1.") which RegularDecimalReal rule doesn't.
231-
* Decimal in JSON is represented in "(0|[1-9][0-9]*)\.[0-9]+" pattern that is
232-
* covered by decimal pattern.
233-
*
234-
* decimalfail pattern is for ranges (e.g. "0..1"). The action for the pattern
235-
* consumes digitseq and returns dot_dot back to the input stream so that
236-
* dot_dot can be matched next.
237-
*/
238-
decimal {digitseq}\.{digit}*|\.{digitseq}
239-
decimalfail {digitseq}\.\.
240-
241-
/*
242-
* decimalsci pattern covers ExponentDecimalReal rule in Cypher. It also
243-
* accepts coefficients in "{digitseq}\." pattern and explicit positive
244-
* exponents ("+") which ExponentDecimalReal rule doesn't.
245-
* Scientific notation in JSON is represented in
246-
* "(0|[1-9][0-9]*)(\.[0-9]+)?[Ee][+-]?[0-9]+" pattern that is covered by
247-
* decimalsci pattern.
248-
*/
249-
decimalsci ({digitseq}|{decimal})[Ee][+-]?{digitseq}
250-
decimalscifail1 ({digitseq}|{decimal})[Ee]
251-
decimalscifail2 ({digitseq}|{decimal})[Ee][+-]
252-
253227
/*
254228
* These patterns cover StringLiteral rule in Cypher and JSON strings.
255229
* The escape sequence "\/" has been added for JSON strings.
@@ -300,10 +274,8 @@ dolqdelim \$({dolq_start}{dolq_cont}*)?\$
300274
dolqfailed \${dolq_start}{dolq_cont}*
301275
dolqinside [^$]+
302276

303-
304-
305277
sqchars [^'\\]+
306-
esascii \\["'/\\bfnrtdw1]
278+
esascii \\[^0-7]
307279
esasciifail \\[^Uu]?
308280
esunicode \\(U{hexdigit}{8}|u{hexdigit}{4})
309281
esunicodefail \\(U{hexdigit}{0,7}|u{hexdigit}{0,3})
@@ -325,32 +297,57 @@ bquote `
325297
bqchars [^`]+
326298
esbquote {bquote}{bquote}
327299

328-
/*
329-
* Parameter rule in Cypher is "$" followed by SymbolicName or DecimalInteger
330-
* rule. However, according to "Cypher Query Language Reference",
331-
*
332-
* Parameters may consist of letters and numbers, and any combination of
333-
* these, but cannot start with a number or a currency symbol.
334-
*
335-
* So, a modified version of Parameter rule that follows the above explanation
336-
* has been used.
337-
*/
338-
param (\${id})|(\${digitseq})
339-
300+
dot_dot ".."
301+
typecast "::"
302+
colon_equals ":="
340303
/*
341304
* These are tokens that are used as operators and language constructs in
342305
* Cypher, and some of them are structural characters in JSON.
343306
*/
344307
lt_gt "<>"|"!="
345308
lt_eq "<="
346309
gt_eq ">="
347-
dot_dot ".."
348310
plus_eq "+="
349-
typecast "::"
311+
350312
self [?&!@#%()*+,\-.~/:;<=>[\]^{|}]
351313
operator [\~\!\|\-\<\>\=\#\%\~\!\@\^\&\`\?\+\*\/]+
352314

315+
/*
316+
* decimal pattern covers RegularDecimalReal rule in Cypher and also accepts
317+
* "{digitseq}\." pattern (e.g. "1.") which RegularDecimalReal rule doesn't.
318+
* Decimal in JSON is represented in "(0|[1-9][0-9]*)\.[0-9]+" pattern that is
319+
* covered by decimal pattern.
320+
*
321+
* decimalfail pattern is for ranges (e.g. "0..1"). The action for the pattern
322+
* consumes digitseq and returns dot_dot back to the input stream so that
323+
* dot_dot can be matched next.
324+
*/
325+
decimal {digitseq}\.{digit}*|\.{digitseq}
326+
decimalfail {digitseq}\.\.
353327

328+
/*
329+
* real pattern covers ExponentDecimalReal rule in Cypher. It also
330+
* accepts coefficients in "{digitseq}\." pattern and explicit positive
331+
* exponents ("+") which ExponentDecimalReal rule doesn't.
332+
* Scientific notation in JSON is represented in
333+
* "(0|[1-9][0-9]*)(\.[0-9]+)?[Ee][+-]?[0-9]+" pattern that is covered by
334+
* real pattern.
335+
*/
336+
real ({digitseq}|{decimal})[Ee][+-]?{digitseq}
337+
realfail1 ({digitseq}|{decimal})[Ee]
338+
realfail2 ({digitseq}|{decimal})[Ee][+-]
339+
340+
/*
341+
* Parameter rule in Cypher is "$" followed by SymbolicName or DecimalInteger
342+
* rule. However, according to "Cypher Query Language Reference",
343+
*
344+
* Parameters may consist of letters and numbers, and any combination of
345+
* these, but cannot start with a number or a currency symbol.
346+
*
347+
* So, a modified version of Parameter rule that follows the above explanation
348+
* has been used.
349+
*/
350+
param (\${id})|(\${digitseq})
354351

355352
other .
356353

@@ -363,9 +360,6 @@ typedef struct strbuf
363360
int length;
364361
} strbuf;
365362

366-
367-
368-
369363
static void strbuf_trunc_buf(strbuf *sb, const int len);
370364
static void strbuf_init(strbuf *sb, int capacity);
371365
static void strbuf_cleanup(strbuf *sb);
@@ -525,7 +519,7 @@ ag_token token;
525519
}
526520

527521
{decimal} |
528-
{decimalsci} {
522+
{real} {
529523
update_location();
530524
token.type = AG_TOKEN_DECIMAL;
531525
token.value.s = yytext;
@@ -546,8 +540,8 @@ ag_token token;
546540
}
547541

548542

549-
{decimalscifail1} |
550-
{decimalscifail2} {
543+
{realfail1} |
544+
{realfail2} {
551545
update_location();
552546
ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR),
553547
scan_errmsg("invalid scientific notation literal"),
@@ -1354,6 +1348,14 @@ ag_token token;
13541348
return token;
13551349
}
13561350

1351+
{colon_equals} {
1352+
update_location();
1353+
token.type = AG_TOKEN_COLON_EQUALS;
1354+
token.value.s = yytext;
1355+
token.location = get_location();
1356+
return token;
1357+
}
1358+
13571359
{plus_eq} {
13581360
update_location();
13591361
token.type = AG_TOKEN_PLUS_EQ;

src/backend/parser/cypher_gram.y

+19-12
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
199199
%token <string> XCONST BCONST
200200

201201
/* operators that have more than 1 character */
202-
%token NOT_EQ LT_EQ GT_EQ DOT_DOT TYPECAST PLUS_EQ
202+
%token NOT_EQ LT_EQ GT_EQ DOT_DOT TYPECAST PLUS_EQ COLON_EQUALS
203203

204204
/* keywords in alphabetical order */
205205
%token <keyword> ABORT_P ACCESS ACTION ADD_P ADMIN AFTER AGGREGATE ALL ALSO ALTER AND ANY ALWAYS ARRAY
@@ -218,7 +218,7 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
218218
DO DOMAIN_P DOCUMENT_P DOUBLE_P DROP DISABLE_P DAY_P DICTIONARY DEPENDS DISCARD DEALLOCATE DECLARE
219219

220220
EACH ENCODING ENCRYPTED ELSE END_P ENDS ESCAPE EXCEPT EXCLUDE EXCLUDING EXISTS EXTENSION EXTRACT EXTERNAL
221-
EVENT EXECUTE ENABLE_P EXPLAIN EXPRESSION EXCLUSIVE ENUM_P
221+
EVENT EXECUTE ENABLE_P EXPLAIN EXPRESSION EXCLUSIVE ENUM_P
222222

223223
GENERATED GLOBAL GRANT GRANTED GRAPH GREATEST GROUP GROUPS GROUPING
224224

@@ -741,18 +741,25 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
741741
%left AND
742742
%left XOR
743743
%right NOT
744-
%left '=' NOT_EQ '<' LT_EQ '>' GT_EQ '~' '!'
745-
%left OPERATOR RIGHT_ARROW
744+
%nonassoc IN IS
745+
%nonassoc '=' NOT_EQ '<' LT_EQ '>' GT_EQ '~' '!'
746+
%nonassoc CONTAINS ENDS EQ_TILDE STARTS LIKE ILIKE SIMILAR
747+
%nonassoc ESCAPE
748+
%nonassoc UNBOUNDED /* ideally would have same precedence as IDENT */
749+
%nonassoc IDENTIFIER PARTITION RANGE ROWS GROUPS PRECEDING FOLLOWING CUBE ROLLUP
750+
751+
%left OPERATOR RIGHT_ARROW COLON_EQUALS
746752
%left '+' '-'
747753
%left '*' '/' '%'
748754
%left '^' '&' '|'
749-
%nonassoc IN IS
755+
750756
%right UNARY_MINUS
751-
%nonassoc CONTAINS ENDS EQ_TILDE STARTS LIKE ILIKE SIMILAR
752-
%nonassoc ESCAPE
753-
%left '[' ']' '(' ')'
754-
%left '.'
757+
%left '[' ']'
758+
%left '(' ')'
755759
%left TYPECAST
760+
%left '.'
761+
762+
%left JOIN CROSS LEFT FULL RIGHT INNER_P NATURAL
756763

757764
%{
758765
// logical operators
@@ -14655,11 +14662,11 @@ func_arg_expr: a_expr
1465514662
{
1465614663
$$ = $1;
1465714664
}
14658-
| param_name ':' '=' a_expr
14665+
| param_name COLON_EQUALS a_expr
1465914666
{
1466014667
NamedArgExpr *na = makeNode(NamedArgExpr);
1466114668
na->name = $1;
14662-
na->arg = (Expr *) $4;
14669+
na->arg = (Expr *) $3;
1466314670
na->argnumber = -1; /* until determined */
1466414671
na->location = @1;
1466514672
$$ = (Node *) na;
@@ -17395,7 +17402,7 @@ window_definition:
1739517402
;
1739617403
over_clause:
1739717404
OVER window_specification { $$ = $2; }
17398-
| OVER symbolic_name
17405+
| OVER ColId
1739917406
{
1740017407
WindowDef *n = makeNode(WindowDef);
1740117408
n->name = $2;

src/backend/parser/cypher_parser.c

+2
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ int cypher_yylex(YYSTYPE *lvalp, YYLTYPE *llocp, ag_scanner_t scanner)
4848
GT_EQ,
4949
DOT_DOT,
5050
TYPECAST,
51+
COLON_EQUALS,
5152
OPERATOR,
5253
RIGHT_ARROW,
5354
PLUS_EQ,
@@ -108,6 +109,7 @@ int cypher_yylex(YYSTYPE *lvalp, YYLTYPE *llocp, ag_scanner_t scanner)
108109
case AG_TOKEN_GT_EQ:
109110
case AG_TOKEN_DOT_DOT:
110111
case AG_TOKEN_PLUS_EQ:
112+
case AG_TOKEN_COLON_EQUALS:
111113
break;
112114
case AG_TOKEN_TYPECAST:
113115
break;

src/include/parser/ag_scanner.h

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ typedef enum ag_token_type
4242
AG_TOKEN_GT_EQ,
4343
AG_TOKEN_DOT_DOT,
4444
AG_TOKEN_TYPECAST,
45+
AG_TOKEN_COLON_EQUALS,
4546
AG_TOKEN_OPERATOR,
4647
AG_TOKEN_RIGHT_ARROW,
4748
AG_TOKEN_PLUS_EQ,

src/include/parser/cypher_kwlist.h

+2
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ PG_KEYWORD("enum", ENUM_P, RESERVED_KEYWORD)
130130
PG_KEYWORD("escape", ESCAPE, RESERVED_KEYWORD)
131131
PG_KEYWORD("event", EVENT, RESERVED_KEYWORD)
132132
PG_KEYWORD("except", EXCEPT, RESERVED_KEYWORD)
133+
PG_KEYWORD("exclude", EXCLUDE, RESERVED_KEYWORD)
133134
PG_KEYWORD("excluding", EXCLUDING, RESERVED_KEYWORD)
134135
PG_KEYWORD("exclusive", EXCLUSIVE, RESERVED_KEYWORD)
135136
PG_KEYWORD("execute", EXECUTE, RESERVED_KEYWORD)
@@ -395,6 +396,7 @@ PG_KEYWORD("template", TEMPLATE, RESERVED_KEYWORD)
395396
PG_KEYWORD("temporary", TEMPORARY, RESERVED_KEYWORD)
396397
PG_KEYWORD("text", TEXT_P, RESERVED_KEYWORD)
397398
PG_KEYWORD("then", THEN, RESERVED_KEYWORD)
399+
PG_KEYWORD("ties", TIES, RESERVED_KEYWORD)
398400
PG_KEYWORD("time", TIME, RESERVED_KEYWORD)
399401
PG_KEYWORD("timestamp", TIMESTAMP, RESERVED_KEYWORD)
400402
PG_KEYWORD("to", TO, RESERVED_KEYWORD)

0 commit comments

Comments
 (0)