Skip to content

Commit 3634450

Browse files
Kikyou1997pull[bot]
authored andcommitted
[feature](Nereids) support Literal collate syntax (#23600)
Support such sql grammar, Just for compatibility ```sql select table_name from information_schema.tables where table_schema collate utf8_general_ci = 'information_schema' and table_name collate utf8_general_ci = 'parameters'; ```
1 parent 016b8fd commit 3634450

4 files changed

Lines changed: 40 additions & 0 deletions

File tree

‎fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,7 @@ primaryExpression
389389
| KEY (dbName=identifier DOT)? keyName=identifier #encryptKey
390390
| EXTRACT LEFT_PAREN field=identifier FROM (DATE | TIMESTAMP)?
391391
source=valueExpression RIGHT_PAREN #extract
392+
| primaryExpression COLLATE (identifier | STRING_LITERAL | DEFAULT) #collate
392393
;
393394

394395
functionIdentifier

‎fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.apache.doris.nereids.DorisParser.BooleanLiteralContext;
3434
import org.apache.doris.nereids.DorisParser.BracketJoinHintContext;
3535
import org.apache.doris.nereids.DorisParser.BracketRelationHintContext;
36+
import org.apache.doris.nereids.DorisParser.CollateContext;
3637
import org.apache.doris.nereids.DorisParser.ColumnReferenceContext;
3738
import org.apache.doris.nereids.DorisParser.CommentJoinHintContext;
3839
import org.apache.doris.nereids.DorisParser.CommentRelationHintContext;
@@ -2054,4 +2055,9 @@ private String parseConstant(ConstantContext context) {
20542055
}
20552056
return context.getText();
20562057
}
2058+
2059+
@Override
2060+
public Object visitCollate(CollateContext ctx) {
2061+
return visit(ctx.primaryExpression());
2062+
}
20572063
}

‎fe/fe-core/src/test/java/org/apache/doris/nereids/parser/NereidsParserTest.java‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,7 @@ public void testParseCast() {
348348
}
349349

350350
@Test
351+
351352
void testParseExprDepthWidth() {
352353
String sql = "SELECT 1+2 = 3 from t";
353354
NereidsParser nereidsParser = new NereidsParser();
@@ -357,4 +358,11 @@ void testParseExprDepthWidth() {
357358
Assertions.assertEquals(4, logicalPlan.getExpressions().get(0).getDepth());
358359
Assertions.assertEquals(3, logicalPlan.getExpressions().get(0).getWidth());
359360
}
361+
362+
@Test
363+
public void testParseCollate() {
364+
String sql = "SELECT * FROM t1 WHERE col COLLATE utf8 = 'test'";
365+
NereidsParser nereidsParser = new NereidsParser();
366+
nereidsParser.parseSingle(sql);
367+
}
360368
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
suite("collate_grammar_test") {
19+
sql "set enable_nereids_planner=true;"
20+
sql "set enable_fallback_to_original_planner=false;"
21+
sql """
22+
select table_name from information_schema.tables where table_schema collate utf8_general_ci = 'information_schema' and table_name collate utf8_general_ci = 'parameters';
23+
"""
24+
25+
}

0 commit comments

Comments
 (0)