Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unary operator for identifier #5862

Merged
merged 2 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -422,9 +422,12 @@ public SQLExpr primary() {
sqlExpr = new OracleBinaryDoubleExpr(Double.parseDouble(lexer.numberString()) * -1);
lexer.nextToken();
break;
case IDENTIFIER:
sqlExpr = primary();
sqlExpr = new SQLUnaryExpr(SQLUnaryOperator.Negative, sqlExpr);
break;
case VARIANT:
case QUES:
case IDENTIFIER:
case LITERAL_ALIAS:
sqlExpr = expr();
sqlExpr = new SQLUnaryExpr(SQLUnaryOperator.Negative, sqlExpr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,21 @@ public void test_0() throws Exception {
// Assert.assertTrue(visitor.containsColumn("sup_task", "orgid"));
//
}

public void test_1() throws Exception {
String sql = "SELECT * FROM employees WHERE -salary < 0 ORDER BY employee_id";

OracleStatementParser parser = new OracleStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
SQLStatement statement = statementList.get(0);
print(statementList);

Assert.assertEquals(1, statementList.size());

OracleSchemaStatVisitor visitor = new OracleSchemaStatVisitor();
statement.accept(visitor);

Assert.assertEquals(1, visitor.getTables().size());
Assert.assertEquals(3, visitor.getColumns().size());
}
}