This is an automated email from the ASF dual-hosted git repository.

morningman pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/master by this push:
     new 3d59f24403b [fix](compatibility) add some keywords (#29251)
3d59f24403b is described below

commit 3d59f24403b76d80e917ee18eb35eb7fa0deecde
Author: Mingyu Chen <[email protected]>
AuthorDate: Mon Jan 1 17:20:45 2024 +0800

    [fix](compatibility) add some keywords (#29251)
    
    1. Add `BINARY` keywords
        `BINARY` is used for tell MySQL to treat a String(or String column) as 
case sensitive.
         eg: `"abc" = "ABC"` is true, but `BINARY "abc" = "ABC"` is false.
    
        But in Doris, `"abc" = "ABC"` is false by default.
    
         I add this `BINARY` keyword just for compatibility, it will take no 
effect.
    
    2. Add `PARTITIONS` and `AUTO_INCREMENT` as reserved words.
    
        `PARTITIONS` is the table name in `information_schema` database.
        `AUTO_INCREMENT` is a column name of a table in `information_schema`
---
 .../main/antlr4/org/apache/doris/nereids/DorisLexer.g4    |  1 +
 .../main/antlr4/org/apache/doris/nereids/DorisParser.g4   |  6 ++++--
 fe/fe-core/src/main/cup/sql_parser.cup                    |  4 ++++
 .../apache/doris/nereids/parser/NereidsParserTest.java    | 15 +++++++++++++++
 4 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisLexer.g4 
b/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisLexer.g4
index c7e823ac65d..a1eea971611 100644
--- a/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisLexer.g4
+++ b/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisLexer.g4
@@ -121,6 +121,7 @@ BEGIN: 'BEGIN';
 BETWEEN: 'BETWEEN';
 BIGINT: 'BIGINT';
 BIN: 'BIN';
+BINARY: 'BINARY';
 BINLOG: 'BINLOG';
 BITAND: 'BITAND';
 BITMAP: 'BITMAP';
diff --git a/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4 
b/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4
index 880986a6cec..a91f207e47c 100644
--- a/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4
+++ b/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4
@@ -678,7 +678,7 @@ primaryExpression
     | LEFT_PAREN query RIGHT_PAREN                                             
                #subqueryExpression
     | ATSIGN identifierOrText                                                  
                #userVariable
     | DOUBLEATSIGN (kind=(GLOBAL | SESSION) DOT)? identifier                   
                #systemVariable
-    | identifier                                                               
                #columnReference
+    | BINARY? identifier                                                       
                #columnReference
     | base=primaryExpression DOT fieldName=identifier                          
                #dereference
     | LEFT_PAREN expression RIGHT_PAREN                                        
                #parenthesizedExpression
     | KEY (dbName=identifier DOT)? keyName=identifier                          
                #encryptKey
@@ -760,7 +760,7 @@ constant
     | type=(DATE | DATEV1 | DATEV2 | TIMESTAMP) STRING_LITERAL                 
                #typeConstructor
     | number                                                                   
                #numericLiteral
     | booleanValue                                                             
                #booleanLiteral
-    | STRING_LITERAL                                                           
                #stringLiteral
+    | BINARY? STRING_LITERAL                                                   
                #stringLiteral
     | LEFT_BRACKET (items+=constant)? (COMMA items+=constant)* RIGHT_BRACKET   
                #arrayLiteral
     | LEFT_BRACE (items+=constant COLON items+=constant)?
        (COMMA items+=constant COLON items+=constant)* RIGHT_BRACE              
                #mapLiteral
@@ -898,6 +898,7 @@ nonReserved
     | ARRAY
     | AT
     | AUTHORS
+    | AUTO_INCREMENT
     | BACKENDS
     | BACKUP
     | BEGIN
@@ -1067,6 +1068,7 @@ nonReserved
     | PASSWORD_HISTORY
     | PASSWORD_LOCK_TIME
     | PASSWORD_REUSE
+    | PARTITIONS
     | PATH
     | PAUSE
     | PERCENT
diff --git a/fe/fe-core/src/main/cup/sql_parser.cup 
b/fe/fe-core/src/main/cup/sql_parser.cup
index 26b221c128c..976ad030dfa 100644
--- a/fe/fe-core/src/main/cup/sql_parser.cup
+++ b/fe/fe-core/src/main/cup/sql_parser.cup
@@ -7557,6 +7557,8 @@ keyword ::=
     {: RESULT = id; :}
     | KW_ARRAY:id
     {: RESULT = id; :}
+    | KW_AUTO_INCREMENT:id
+    {: RESULT = id; :}
     | KW_BACKUP:id
     {: RESULT = id; :}
     | KW_BEGIN:id
@@ -7783,6 +7785,8 @@ keyword ::=
     {: RESULT = id; :}
     | KW_PARAMETER:id
     {: RESULT = id; :}
+    | KW_PARTITIONS:id
+    {: RESULT = id; :}
     | KW_PASSWORD:id
     {: RESULT = id; :}
     | KW_PASSWORD_EXPIRE:id
diff --git 
a/fe/fe-core/src/test/java/org/apache/doris/nereids/parser/NereidsParserTest.java
 
b/fe/fe-core/src/test/java/org/apache/doris/nereids/parser/NereidsParserTest.java
index dc7e336433f..6dbcacee40f 100644
--- 
a/fe/fe-core/src/test/java/org/apache/doris/nereids/parser/NereidsParserTest.java
+++ 
b/fe/fe-core/src/test/java/org/apache/doris/nereids/parser/NereidsParserTest.java
@@ -457,4 +457,19 @@ public class NereidsParserTest extends ParserTestBase {
         NereidsParser nereidsParser = new NereidsParser();
         nereidsParser.parseSingle(sql);
     }
+
+    @Test
+    public void testParseBinaryKeyword() {
+        String sql = "SELECT BINARY 'abc' FROM t";
+        NereidsParser nereidsParser = new NereidsParser();
+        nereidsParser.parseSingle(sql);
+    }
+
+    @Test
+    public void testParseReserveKeyword() {
+        // partitions and auto_increment are reserve keywords
+        String sql = "SELECT BINARY 'abc' FROM information_schema.partitions 
order by AUTO_INCREMENT";
+        NereidsParser nereidsParser = new NereidsParser();
+        nereidsParser.parseSingle(sql);
+    }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to