SELECT CURRENT_TIMESTAMP

Is a synactically and semantically valid query (because CURRENT_TIMESTAMP 
happens to be a built-in function that doesn’t take parentheses or arguments). 
On the other hand

  SELECT x

Is syntactically valid but semantically invalid (because there is no ‘x’ in 
global scope).  Lastly,

  SELECT language

Is syntactically invalid (and gives a different error to ’SELECT x’). The 
following patch demonstrates:

diff --git 
a/testkit/src/main/java/org/apache/calcite/sql/parser/SqlParserTest.java 
b/testkit/src/main/java/org/apache/calcite/sql/parser/SqlParserTest.java
index 0dd79138ea..e45809105a 100644
--- a/testkit/src/main/java/org/apache/calcite/sql/parser/SqlParserTest.java
+++ b/testkit/src/main/java/org/apache/calcite/sql/parser/SqlParserTest.java
@@ -8769,6 +8769,14 @@ private static Consumer<List<? extends Throwable>> 
checkWarnings(
     sql(sql).ok(expected);
   }
 
+  @Test void testLanguage() {
+    final String sql = "select x";
+    sql(sql).ok("SELECT `X`");
+
+    final String sql2 = "select language";
+    sql(sql2).ok("SELECT `X`");
+  }
+
   @Test void testMatchRecognizePatternSkip5() {
     final String sql = "select *\n"
         + "  from t match_recognize\n"




> On Mar 23, 2022, at 11:20 AM, Michael Mior <[email protected]> wrote:
> 
> I was hinting that there might be a syntax issue caused by a missing part
> of the query. I would not have assumed "SELECT foobar" is a valid query
> both in syntax and semantics.
> --
> Michael Mior
> [email protected]
> 
> 
> Le mer. 23 mars 2022 à 14:12, Julian Hyde <[email protected]> a écrit :
> 
>> If there’s nowhere for LANGUAGE to come from that would make it
>> semantically invalid but wouldn’t affect the syntactic validity. (In other
>> words, you’d get an error from SqlValidator but not from SqlParser.)
>> 
>> In this case, the problem is that LANGUAGE is a reserved keyword in both
>> standard SQL and Calcite.
>> 
>> Julian
>> 
>> 
>>> On Mar 23, 2022, at 11:05 AM, Michael Mior <[email protected]> wrote:
>>> 
>>> What would you expect this query to return? You haven't specified a FROM
>>> clause, so there's no indication where "language" should come from.
>>> 
>>> --
>>> Michael Mior
>>> [email protected]
>>> 
>>> 
>>> Le mer. 23 mars 2022 à 14:02, Adolfo Ochagavía <[email protected]> a
>>> écrit :
>>> 
>>>> Hi there,
>>>> 
>>>> I am trying to find my way using Calcite to parse SQL queries, and was
>>>> surprised to find out that parsing the query "SELECT language" fails
>> with
>>>> an exception.
>>>> 
>>>> This is the code:
>>>>> var config = SqlParser.Config.DEFAULT.withLex(Lex.MYSQL);
>>>>> var parser = SqlParser.create("SELECT language", config);
>>>>> var parsed = parser.parseQuery();
>>>> 
>>>> This is the exception:
>>>>> org.apache.calcite.sql.parser.SqlParseException: Encountered ".
>>>> language" at line 1, column 18.
>>>>> Was expecting one of:
>>>>>   <EOF>
>>>>>   "AS" ...
>>>>>   [the rest is omitted for brevity, but about 60 more lines follow]
>>>> 
>>>> Am I missing something or is this a bug? Note that the query is a
>>>> simplified excerpt of an autoconfiguration query issued by MySQL's JDBC
>>>> driver and seems to be handled well by MySQL servers. Below I am pasting
>>>> the full query, in case someone would like to see the original:
>>>>> /* mysql-connector-java-8.0.19 (Revision:
>>>> a0ca826f5cdf51a98356fdfb1bf251eb042f80bf) */SELECT
>>>> @@session.auto_increment_increment AS auto_increment_increment,
>>>> @@character_set_client AS character_set_client,
>>>> @@character_set_connection AS character_set_connection,
>>>> @@character_set_results AS character_set_results,
>>>> @@character_set_server AS character_set_server, @@collation_server AS
>>>> collation_server, @@collation_connection AS collation_connection,
>>>> @@init_connect AS init_connect, @@interactive_timeout AS
>>>> interactive_timeout, @@language AS language, @@license AS license,
>>>> @@lower_case_table_names AS lower_case_table_names,
>>>> @@max_allowed_packet AS max_allowed_packet, @@net_write_timeout AS
>>>> net_write_timeout, @@performance_schema AS performance_schema,
>>>> @@query_cache_size AS query_cache_size, @@query_cache_type AS
>>>> query_cache_type, @@sql_mode AS sql_mode, @@system_time_zone AS
>>>> system_time_zone, @@time_zone AS time_zone, @@tx_isolation AS
>>>> transaction_isolation, @@wait_timeout AS wait_timeout
>>>> 
>>>> Thanks for helping out ;)
>>>> Adolfo
>> 
>> 

Reply via email to