Skip to content

Commit

Permalink
Fix parse empty assign item issue. (#6272)
Browse files Browse the repository at this point in the history
* Fix parse empty assign item issue.

* Set PPROX_QUANTILES as agg function.

* Set PPROX_QUANTILES as agg function.

* Fix.

---------

Co-authored-by: Shaojin Wen <shaojin.wensj@alibaba-inc.com>
  • Loading branch information
lingo-xp and wenshao authored Dec 6, 2024
1 parent f869c9f commit 1ce01d7
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 8 deletions.
18 changes: 10 additions & 8 deletions core/src/main/java/com/alibaba/druid/sql/parser/SQLExprParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -5178,15 +5178,17 @@ public SQLUnique parseUnique() {

public void parseAssignItem(List<SQLAssignItem> outList, SQLObject parent) {
accept(Token.LPAREN);
for (; ; ) {
SQLAssignItem item = this.parseAssignItem(true, parent);
item.setParent(parent);
outList.add(item);
if (lexer.token() == Token.COMMA) {
lexer.nextToken();
continue;
if (lexer.token() != Token.RPAREN) {
for (; ; ) {
SQLAssignItem item = this.parseAssignItem(true, parent);
item.setParent(parent);
outList.add(item);
if (lexer.token() == Token.COMMA) {
lexer.nextToken();
continue;
}
break;
}
break;
}
accept(Token.RPAREN);
}
Expand Down
59 changes: 59 additions & 0 deletions core/src/test/resources/bvt/parser/bigquery/0.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,62 @@
create temporary function poly(polygon string)
returns string language js as """
var res = JSON.parse(polygon);
var l = res.length;
var i;
for (i=0; i<l; i++) {
temp = res[i][0]
res[i][0] = res[i][1]
res[i][1] = temp
};
var last = [res[0][0],res[0][1]];
res.push(last);
var geojson = {"type": "Polygon", "coordinates" : [res]}
return JSON.stringify(geojson);
"""
OPTIONS();
--------------------
CREATE TEMPORARY FUNCTION poly (
polygon string
)
RETURNS string
LANGUAGE js
AS """
var res = JSON.parse(polygon);
var l = res.length;
var i;
for (i=0; i<l; i++) {
temp = res[i][0]
res[i][0] = res[i][1]
res[i][1] = temp
};
var last = [res[0][0],res[0][1]];
res.push(last);
var geojson = {"type": "Polygon", "coordinates" : [res]}
return JSON.stringify(geojson);
""";
------------------------------------------------------------------------------------------------------------------------
CREATE TEMP FUNCTION myFunc(a FLOAT64, b STRING)
RETURNS STRING
LANGUAGE js
AS r"""
// Assumes 'doInterestingStuff' is defined in one of the library files.
return doInterestingStuff(a, b);
"""
OPTIONS (
library=['gs://my-bucket/path/to/lib1.js', 'gs://my-bucket/path/to/lib2.js']);
--------------------
CREATE TEMPORARY FUNCTION myFunc (
a FLOAT64,
b STRING
)
RETURNS STRING
LANGUAGE js
OPTIONS (library = ['gs://my-bucket/path/to/lib1.js', 'gs://my-bucket/path/to/lib2.js'])
AS """
// Assumes 'doInterestingStuff' is defined in one of the library files.
return doInterestingStuff(a, b);
""";
------------------------------------------------------------------------------------------------------------------------
SELECT DATE(verify_timestamp, 'Asia/Jakarta') AS jakarta_data_date, app_version, device_platform as device_platform_name,
BU as business_unit_name, verification_method as verification_type,
CAST(APPROX_QUANTILES(time_diff, 100 IGNORE NULLS)[OFFSET(50)] AS NUMERIC) AS p50_granted_time_in_second,
Expand Down

0 comments on commit 1ce01d7

Please sign in to comment.