[ 
https://issues.apache.org/jira/browse/CALCITE-5677?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17716984#comment-17716984
 ] 

Dmitry Sysolyatin edited comment on CALCITE-5677 at 4/27/23 5:46 AM:
---------------------------------------------------------------------

Is there any database that does not support {{SUBSTRING(value, position [, 
length])}} ?
I checked PostgreSQL, MySQL, MSSQL, BigQuery, Spark. All of them support 
{{SUBSTRING(value, position [, length])}}

Instead of changing the BigQuery dialect, perhaps it is better to unparse 
{{SqlSubstringFunction}} to {{SUBSTRING(value, position [, length])}} ? MSSQL, 
Spark do not support {{SUBSTRING(value FROM position[ FOR length])}} syntax 
either [1][2].

[1] 
[https://learn.microsoft.com/en-us/sql/t-sql/functions/substring-transact-sql?view=sql-server-ver16]
[2] [https://spark.apache.org/docs/2.3.0/api/sql/index.html#substring]


was (Author: dmsysolyatin):
Is there any database that does not support {{SUBSTRING(value, position [, 
length])}} ?
I checked PostgreSQL, MySQL, MSSQL, BigQuery, Spark. All of them support 
{{SUBSTRING(value, position [, length])}}

Instead of changing the BigQuery dialect, perhaps it is better to unparse 
{{SqlSubstringFunction}} to {{SUBSTRING(value, position [, length])}} instead 
of {{SUBSTRING(value FROM position[ FOR length])}} ? MSSQL, Spark do not 
support {{SUBSTRING(value FROM position[ FOR length])}} syntax either [1][2].

[1] 
[https://learn.microsoft.com/en-us/sql/t-sql/functions/substring-transact-sql?view=sql-server-ver16]
[2] [https://spark.apache.org/docs/2.3.0/api/sql/index.html#substring]

> Fix unparsing for BigQuery SUBSTR
> ---------------------------------
>
>                 Key: CALCITE-5677
>                 URL: https://issues.apache.org/jira/browse/CALCITE-5677
>             Project: Calcite
>          Issue Type: Bug
>            Reporter: Tanner Clary
>            Assignee: Tanner Clary
>            Priority: Major
>              Labels: pull-request-available
>
> BigQuery's {{SUBSTR(value, position[, length])}} function currently gets 
> translated to the standard {{SUBSTRING(value FROM position[ FOR length])]}. 
> BigQuery expects the arguments to be comma-separated rather than the use of 
> the {{FROM}} and {{FOR}} keywords. 
> EXAMPLE: {{SUBSTR('hello', 2)}} would get translated to {{SUBSTRING('hello' 
> FROM 2)}} which BigQuery does not recognize.
> Hive addresses this issue by adding onto {{HiveSqlDialect#unparseCall}} 
> method. I believe BigQuery should do something similar to avoid this 
> incorrect translation. The docs for the {{SUBSTR}} (and alias {{SUBSTRING}}) 
> function may be found 
> [here|https://cloud.google.com/bigquery/docs/reference/standard-sql/string_functions#substr].
> I will open a PR shortly that implements my suggestion and adds a couple of 
> tests as well.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to