Skip to content

Commit 0e5506e

Browse files
committed
avoid changing literalExpression for performance reason
Signed-off-by: Murphy <mofei@starrocks.com>
1 parent b855d6b commit 0e5506e

4 files changed

Lines changed: 50 additions & 30 deletions

File tree

fe/fe-core/src/main/java/com/starrocks/sql/parser/AstBuilder.java

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6243,8 +6243,9 @@ public ParseNode visitJoinRelation(com.starrocks.sql.parser.StarRocksParser.Join
62436243
if (context.bracketHint().primaryExpression() != null) {
62446244
joinRelation.setSkewColumn((Expr) visit(context.bracketHint().primaryExpression()));
62456245
}
6246-
if (context.bracketHint().literalExpressionList() != null) {
6247-
joinRelation.setSkewValues(visit(context.bracketHint().literalExpressionList().literalExpression(),
6246+
if (context.bracketHint().generalLiteralExpressionList() != null) {
6247+
joinRelation.setSkewValues(
6248+
visit(context.bracketHint().generalLiteralExpressionList().generalLiteralExpression(),
62486249
Expr.class));
62496250
}
62506251
}
@@ -8032,27 +8033,40 @@ public ParseNode visitBooleanLiteral(com.starrocks.sql.parser.StarRocksParser.Bo
80328033

80338034
@Override
80348035
public ParseNode visitNumericLiteral(com.starrocks.sql.parser.StarRocksParser.NumericLiteralContext context) {
8035-
ParseNode node = visit(context.number());
8036-
if (context.MINUS_SYMBOL() != null) {
8037-
if (node instanceof IntLiteral) {
8038-
return new IntLiteral(-((IntLiteral) node).getLongValue(), node.getPos());
8039-
} else if (node instanceof LargeIntLiteral) {
8040-
BigInteger val = ((LargeIntLiteral) node).getValue();
8041-
val = val.negate();
8042-
if (val.compareTo(BigInteger.valueOf(Long.MIN_VALUE)) >= 0 &&
8043-
val.compareTo(BigInteger.valueOf(Long.MAX_VALUE)) <= 0) {
8044-
return new IntLiteral(val.longValue(), node.getPos());
8036+
return visit(context.number());
8037+
}
8038+
8039+
@Override
8040+
public ParseNode visitGeneralLiteralExpression(
8041+
com.starrocks.sql.parser.StarRocksParser.GeneralLiteralExpressionContext context) {
8042+
if (context.literalExpression() != null) {
8043+
return visit(context.literalExpression());
8044+
} else {
8045+
ParseNode node = visit(context.number());
8046+
if (context.MINUS_SYMBOL() != null) {
8047+
if (node instanceof IntLiteral) {
8048+
return new IntLiteral(-((IntLiteral) node).getLongValue(), node.getPos());
8049+
} else if (node instanceof LargeIntLiteral) {
8050+
BigInteger val = ((LargeIntLiteral) node).getValue();
8051+
val = val.negate();
8052+
if (val.compareTo(BigInteger.valueOf(Long.MIN_VALUE)) >= 0 &&
8053+
val.compareTo(BigInteger.valueOf(Long.MAX_VALUE)) <= 0) {
8054+
return new IntLiteral(val.longValue(), node.getPos());
8055+
}
8056+
return new LargeIntLiteral(val.toString(), node.getPos());
8057+
} else if (node instanceof DecimalLiteral) {
8058+
BigDecimal val = ((DecimalLiteral) node).getValue();
8059+
return new DecimalLiteral(val.negate(), node.getPos());
8060+
} else if (node instanceof FloatLiteral) {
8061+
double val = ((FloatLiteral) node).getDoubleValue();
8062+
return new FloatLiteral(-val, node.getPos());
8063+
} else {
8064+
throw new ParsingException(PARSER_ERROR_MSG.invalidNumFormat(context.getText()), node.getPos());
80458065
}
8046-
return new LargeIntLiteral(val.toString(), node.getPos());
8047-
} else if (node instanceof DecimalLiteral) {
8048-
BigDecimal val = ((DecimalLiteral) node).getValue();
8049-
return new DecimalLiteral(val.negate(), node.getPos());
8050-
} else if (node instanceof FloatLiteral) {
8051-
double val = ((FloatLiteral) node).getDoubleValue();
8052-
return new FloatLiteral(-val, node.getPos());
8066+
} else {
8067+
return node;
80538068
}
80548069
}
8055-
return node;
80568070
}
80578071

80588072
@Override

fe/fe-core/src/test/java/com/starrocks/sql/parser/InPredicateParserBench.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,13 @@ public void setup() {
6161
sql = generateSQL();
6262
}
6363

64-
@Param({"5000", "50000"})
64+
@Param({"5000", "50000", "200000"})
6565
public int count;
6666

67-
@Param({"true", "false"})
67+
@Param({"false", "true"})
6868
public boolean positive;
6969

70-
public final int baseNumber = 1_000_000;
70+
public final int baseNumber = 10_000_000;
7171

7272
@Benchmark
7373
public void parseInPredicate() {

fe/fe-core/src/test/java/com/starrocks/sql/parser/ParserTest.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -707,11 +707,7 @@ void testSkewHintWithNegativeValues() {
707707
};
708708
SessionVariable sessionVariable = new SessionVariable();
709709
for (String sql : sqls) {
710-
try {
711-
SqlParser.parse(sql, sessionVariable);
712-
} catch (Exception e) {
713-
fail("sql should parse successfully: " + sql + ", error: " + e.getMessage());
714-
}
710+
SqlParser.parse(sql, sessionVariable);
715711
}
716712
}
717713

fe/fe-grammar/src/main/antlr/com/starrocks/grammar/StarRocks.g4

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2497,7 +2497,7 @@ outerAndSemiJoinType
24972497

24982498
bracketHint
24992499
: '[' identifier (',' identifier)* ']'
2500-
| '[' identifier '|' primaryExpression literalExpressionList']'
2500+
| '[' identifier '|' primaryExpression generalLiteralExpressionList']'
25012501
;
25022502

25032503
hintMap
@@ -2678,7 +2678,7 @@ primaryExpression
26782678
;
26792679

26802680
literalExpression
2681-
: MINUS_SYMBOL? number #numericLiteral
2681+
: number #numericLiteral
26822682
| NULL #nullLiteral
26832683
| booleanValue #booleanLiteral
26842684
| (DATE | DATETIME) string #dateLiteral
@@ -2689,6 +2689,12 @@ literalExpression
26892689
| PARAMETER #Parameter
26902690
;
26912691

2692+
// can represents negative number long with other literal expression
2693+
generalLiteralExpression
2694+
: literalExpression
2695+
| MINUS_SYMBOL number
2696+
;
2697+
26922698
functionCall
26932699
: EXTRACT '(' identifier FROM valueExpression ')' #extract
26942700
| GROUPING '(' (expression (',' expression)*)? ')' #groupingOperation
@@ -2900,6 +2906,10 @@ literalExpressionList
29002906
: '(' literalExpression (',' literalExpression)* ')'
29012907
;
29022908

2909+
generalLiteralExpressionList
2910+
: '(' generalLiteralExpression (',' generalLiteralExpression)* ')'
2911+
;
2912+
29032913
rangePartitionDesc
29042914
: singleRangePartition
29052915
| multiRangePartition

0 commit comments

Comments
 (0)