diff --git a/fe/fe-core/src/main/java/com/starrocks/sql/parser/AstBuilder.java b/fe/fe-core/src/main/java/com/starrocks/sql/parser/AstBuilder.java index 7111757039bbe6..dd149111151c91 100644 --- a/fe/fe-core/src/main/java/com/starrocks/sql/parser/AstBuilder.java +++ b/fe/fe-core/src/main/java/com/starrocks/sql/parser/AstBuilder.java @@ -5177,6 +5177,7 @@ private static ArithmeticExpr.Operator getArithmeticBinaryOperator(Token operato case StarRocksLexer.SLASH_SYMBOL: return ArithmeticExpr.Operator.DIVIDE; case StarRocksLexer.PERCENT_SYMBOL: + case StarRocksLexer.MOD: return ArithmeticExpr.Operator.MOD; case StarRocksLexer.INT_DIV: return ArithmeticExpr.Operator.INT_DIVIDE; @@ -5190,8 +5191,10 @@ private static ArithmeticExpr.Operator getArithmeticBinaryOperator(Token operato return ArithmeticExpr.Operator.BIT_SHIFT_LEFT; case StarRocksLexer.BIT_SHIFT_RIGHT: return ArithmeticExpr.Operator.BIT_SHIFT_RIGHT; - default: + case StarRocksLexer.BIT_SHIFT_RIGHT_LOGICAL: return ArithmeticExpr.Operator.BIT_SHIFT_RIGHT_LOGICAL; + default: + throw new ParsingException(PARSER_ERROR_MSG.wrongTypeOfArgs(operator.getText()), new NodePosition(operator)); } } diff --git a/fe/fe-core/src/test/java/com/starrocks/sql/parser/ParserTest.java b/fe/fe-core/src/test/java/com/starrocks/sql/parser/ParserTest.java index 0b7c5c40faf8d7..a60f5b3c0f352f 100644 --- a/fe/fe-core/src/test/java/com/starrocks/sql/parser/ParserTest.java +++ b/fe/fe-core/src/test/java/com/starrocks/sql/parser/ParserTest.java @@ -29,10 +29,12 @@ import com.starrocks.qe.SqlModeHelper; import com.starrocks.qe.VariableMgr; import com.starrocks.sql.analyzer.Analyzer; +import com.starrocks.sql.analyzer.AstToSQLBuilder; import com.starrocks.sql.ast.JoinRelation; import com.starrocks.sql.ast.QueryStatement; import com.starrocks.sql.ast.SelectList; import com.starrocks.sql.ast.SelectRelation; +import com.starrocks.sql.ast.StatementBase; import com.starrocks.utframe.UtFrameUtils; import org.antlr.v4.runtime.BaseErrorListener; import org.antlr.v4.runtime.CharStreams; @@ -49,6 +51,7 @@ import java.util.stream.Stream; import static com.starrocks.sql.plan.PlanTestBase.assertContains; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; class ParserTest { @@ -403,6 +406,14 @@ void testWrongVariableName() { assertContains(res, "{'disable_join_reorder', 'disable_colocate_join', 'enable_predicate_reorder'}"); } + @Test + void testModOperator() { + String sql = "select 100 MOD 2"; + List stmts = SqlParser.parse(sql, new SessionVariable()); + String newSql = AstToSQLBuilder.toSQL(stmts.get(0)); + assertEquals("SELECT 100 % 2", newSql); + } + private static Stream keyWordSqls() { List sqls = Lists.newArrayList(); sqls.add("select current_role()");