Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ParseException due to ARRAY_AGG() and SAFE_CAST() #1622

Closed
Tianqi1006 opened this issue Aug 24, 2022 · 8 comments
Closed

ParseException due to ARRAY_AGG() and SAFE_CAST() #1622

Tianqi1006 opened this issue Aug 24, 2022 · 8 comments

Comments

@Tianqi1006
Copy link

Hi,

We recently found this ParseException due to the use of ARRAY_AGG() and SAFE_CAST() from the built-in functions provided by Google BigQuery. However, when I tried to validate the SQL syntax, I got this error:

ParseException: Cannot parse statement: Encountered unexpected token: "(" "(" at line 1, column 17.

Was expecting one of:

"&"
"::"
";"
"<<"
">>"
"ACTION"
"ACTIVE"
"ALGORITHM"
"ARCHIVE"
"ARRAY"
"AS"
"AT"
"BYTE"
"CASCADE"
"CASE"
"CAST"
"CHANGE"
"CHAR"
"CHARACTER"
"CHECKPOINT"
"COLLATE"
"COLUMN"
"COLUMNS"
"COMMENT"
"COMMIT"
"CONNECT"
"COSTS"
"CYCLE"
"DBA_RECYCLEBIN"
"DEFAULT"
"DESC"
"DESCRIBE"
"DISABLE"
"DISCONNECT"
"DIV"
"DO"
"DUMP"
"DUPLICATE"
"EMIT"
"ENABLE"
"END"
"EXCLUDE"
"EXTRACT"
"FALSE"
"FILTER"
"FIRST"
"FLUSH"
"FN"
"FOLLOWING"
"FORMAT"
"FULLTEXT"
"GROUP"
"HAVING"
"HISTORY"
"INDEX"
"INSERT"
"INTERVAL"
"INTO"
"ISNULL"
"JSON"
"KEY"
"LAST"
"LEADING"
"LINK"
"LOCAL"
"LOG"
"MATERIALIZED"
"NO"
"NOLOCK"
"NULLS"
"OF"
"OPEN"
"OVER"
"PARALLEL"
"PARTITION"
"PATH"
"PERCENT"
"PRECISION"
"PRIMARY"
"PRIOR"
"QUERY"
"QUIESCE"
"RANGE"
"READ"
"RECYCLEBIN"
"REGISTER"
"REPLACE"
"RESTRICTED"
"RESUME"
"ROW"
"ROWS"
"SCHEMA"
"SEPARATOR"
"SEQUENCE"
"SESSION"
"SHUTDOWN"
"SIBLINGS"
"SIGNED"
"SIZE"
"SKIP"
"START"
"SUSPEND"
"SWITCH"
"SYNONYM"
"SYSTEM"
"TABLE"
"TABLESPACE"
"TEMP"
"TEMPORARY"
"TIMEOUT"
"TO"
"TOP"
"TRUE"
"TRUNCATE"
"TRY_CAST"
"TYPE"
"UNQIESCE"
"UNSIGNED"
"USER"
"VALIDATE"
"VALUE"
"VALUES"
"VIEW"
"WINDOW"
"XML"
"ZONE"
"["
"^"
"|"
<EOF>
<K_DATETIMELITERAL>
<K_DATE_LITERAL>
<K_NEXTVAL>
<K_STRING_FUNCTION_NAME>
<S_CHAR_LITERAL>
<S_IDENTIFIER>
<S_QUOTED_IDENTIFIER>

The SQL statement looks like this:
select array_agg(safe_cast(n as Float64)) as temp from UNNEST(SPLIT("0,0,0,0,0",",")) as n

We are wondering is there a way to allow ARRAY_AGG() and SAFE_CAST() without throwing exceptions?

Thank you very much in advance,
Tianqi

@Tianqi1006 Tianqi1006 changed the title ParseException due to ARRAY_AGG() and SAFE_CAST ParseException due to ARRAY_AGG() and SAFE_CAST() Aug 24, 2022
@manticore-projects
Copy link
Contributor

Greetings,

The problem is about SAFE_CAST(x AS y), which is not a regular function but a special expression.
We will need to extend the CAST() expression accordingly.

@Tianqi1006
Copy link
Author

Greetings,

Thanks a lot for quickly identifying the root cause of the problem. Just would like to follow up with you and see when approximately will this change be applied / released? Any details would be greatly appreciated.

Best regards,
Tianqi

@dequn
Copy link
Contributor

dequn commented Sep 19, 2022

Hi @manticore-projects , not only SAFE_CAST, but also ARRAY_AGG can not be fully correctly parsed.
failed cases:

  1. ARRAY_AGG(x LMIT 10)
  2. ARRAY_AGG( x IGNORE NULLS ORDER BY x)
  3. ARRAY_AGG( DISTINCT x)
    Google ARRAY_AGG references: https://cloud.google.com/bigquery/docs/reference/standard-sql/aggregate_functions#array_agg
    JsqlParser Version: 4.5

@manticore-projects
Copy link
Contributor

1. `ARRAY_AGG(x LMIT 10)`
2. `ARRAY_AGG( x IGNORE NULLS ORDER BY x)`
3. `ARRAY_AGG( DISTINCT x)`
   Google ARRAY_AGG references: https://cloud.google.com/bigquery/docs/reference/standard-sql/aggregate_functions#array_agg

Certainly, because all of those are mot standard compliant, but Google BigQuery specific.
You will need to sponsor or provide an implementation for such special function parameters.

dequn pushed a commit to dequn/JSqlParser that referenced this issue Sep 19, 2022
@dequn
Copy link
Contributor

dequn commented Sep 19, 2022

@manticore-projects Thanks, I add SAFE_CAST support and create a PR.

wumpz pushed a commit that referenced this issue Sep 20, 2022
Co-authored-by: Zhang, Dequn <deqzhang@paypal.com>
@wumpz
Copy link
Member

wumpz commented Sep 20, 2022

Do I get this right, that this issue is not yet complete by the PR?

@dequn
Copy link
Contributor

dequn commented Sep 21, 2022

@wumpz Yes, It only solves SAFE_CAST related problem, ARRAY_AGG is not included in this PR.

@manticore-projects
Copy link
Contributor

Continued as Feature request under #1856

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants