spark-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Chin Han Yu (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (SPARK-21674) Support double/single-quoted strings for alias names in SQL
Date Mon, 21 Aug 2017 04:03:01 GMT

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

Chin Han Yu commented on SPARK-21674:
-------------------------------------

Found that back quote is working fine for alias names. 
Do we also need to support single/double quotes? 

{code:java}
scala> spark.sql("""SELECT 1 as `NAME` from people""").show()
+----+
|NAME|
+----+
|   1|
|   1|
|   1|
+----+
{code}


> Support double/single-quoted strings for alias names in SQL
> -----------------------------------------------------------
>
>                 Key: SPARK-21674
>                 URL: https://issues.apache.org/jira/browse/SPARK-21674
>             Project: Spark
>          Issue Type: Improvement
>          Components: SQL
>    Affects Versions: 2.2.0
>            Reporter: Takeshi Yamamuro
>            Priority: Trivial
>              Labels: starter
>
> In the master, users can't use single/double-quoted strings for alias names in SQL;
> {code}
> scala> sql("""SELECT 1 AS "NAME" """)
> org.apache.spark.sql.catalyst.parser.ParseException:
> extraneous input '"NAME"' expecting {<EOF>, ',', 'FROM', 'WHERE', 'GROUP', 'ORDER',
'HAVING', 'LIMIT', 'LATERAL', 'WINDOW', 'UNION', 'EXCEPT', 'MINUS', 'INTERSECT', 'SORT', 'CLUSTER',
'DISTRIBUTE'}(line 1, pos 12)
> == SQL ==
> SELECT 1 AS "NAME"
> ------------^^^
>   at org.apache.spark.sql.catalyst.parser.ParseException.withCommand(ParseDriver.scala:217)
>   at org.apache.spark.sql.catalyst.parser.AbstractSqlParser.parse(ParseDriver.scala:114)
> ...
> {code}
> PostgreSQL and MySQL support this;
> {code}
> ~:$psql -d postgres
> psql (9.5beta1)
> Type "help" for help.
> postgres=# select 1 AS "NAME";
>  NAME 
> ------
>     1
> (1 row)
> mysql> select 1 AS "NAME";
> +------+
> | NAME |
> +------+
> |    1 |
> +------+
> 1 row in set (0.00 sec)
> {code}
> Hive does not;
> {code}
> hive> select 1 AS "NAME";
> NoViableAltException(352@[87:7: ( ( ( KW_AS )? identifier ) | ( KW_AS LPAREN identifier
( COMMA identifier )* RPAREN ) )?])
> 	at org.antlr.runtime.DFA.noViableAlt(DFA.java:158)
> 	at org.antlr.runtime.DFA.predict(DFA.java:116)
> {code}
> Trivial though, it might some help for PostgreSQL/MySQL users.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@spark.apache.org
For additional commands, e-mail: issues-help@spark.apache.org


Mime
View raw message