Skip to content

Commit b943199

Browse files
authored
[opt](Nereids) support no-key hint parameter (#37720) (#37989)
pick from master #37720 support hint use parameter without key, like: ```sql SELECT /*+ query_timeout(3000) */ * FROM t; ```
1 parent 79b4154 commit b943199

File tree

3 files changed

+43
-11
lines changed

3 files changed

+43
-11
lines changed

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
@@ -197,6 +197,7 @@ hintStatement
197197

198198
hintAssignment
199199
: key=identifierOrText (EQ (constantValue=constant | identifierValue=identifier))?
200+
| constant
200201
;
201202

202203
updateAssignment

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

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1796,24 +1796,28 @@ private LogicalPlan withSelectHint(LogicalPlan logicalPlan, SelectHintContext hi
17961796
case "set_var":
17971797
Map<String, Optional<String>> parameters = Maps.newLinkedHashMap();
17981798
for (HintAssignmentContext kv : hintStatement.parameters) {
1799-
String parameterName = visitIdentifierOrText(kv.key);
1800-
Optional<String> value = Optional.empty();
1801-
if (kv.constantValue != null) {
1802-
Literal literal = (Literal) visit(kv.constantValue);
1803-
value = Optional.ofNullable(literal.toLegacyLiteral().getStringValue());
1804-
} else if (kv.identifierValue != null) {
1805-
// maybe we should throw exception when the identifierValue is quoted identifier
1806-
value = Optional.ofNullable(kv.identifierValue.getText());
1799+
if (kv.key != null) {
1800+
String parameterName = visitIdentifierOrText(kv.key);
1801+
Optional<String> value = Optional.empty();
1802+
if (kv.constantValue != null) {
1803+
Literal literal = (Literal) visit(kv.constantValue);
1804+
value = Optional.ofNullable(literal.toLegacyLiteral().getStringValue());
1805+
} else if (kv.identifierValue != null) {
1806+
// maybe we should throw exception when the identifierValue is quoted identifier
1807+
value = Optional.ofNullable(kv.identifierValue.getText());
1808+
}
1809+
parameters.put(parameterName, value);
18071810
}
1808-
parameters.put(parameterName, value);
18091811
}
18101812
hints.put(hintName, new SelectHintSetVar(hintName, parameters));
18111813
break;
18121814
case "leading":
18131815
List<String> leadingParameters = new ArrayList<String>();
18141816
for (HintAssignmentContext kv : hintStatement.parameters) {
1815-
String parameterName = visitIdentifierOrText(kv.key);
1816-
leadingParameters.add(parameterName);
1817+
if (kv.key != null) {
1818+
String parameterName = visitIdentifierOrText(kv.key);
1819+
leadingParameters.add(parameterName);
1820+
}
18171821
}
18181822
hints.put(hintName, new SelectHintLeading(hintName, leadingParameters));
18191823
break;
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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("hint") {
19+
sql """select /*+ func(k=v) */ 1"""
20+
sql """select /*+ func('k'=v) */ 1"""
21+
sql """select /*+ func("k"=v) */ 1"""
22+
sql """select /*+ func(k) */ 1"""
23+
sql """select /*+ func('k') */ 1"""
24+
sql """select /*+ func("k") */ 1"""
25+
sql """select /*+ func(1) */ 1"""
26+
}
27+

0 commit comments

Comments
 (0)