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

优化SQLBinaryOpExpr的括号解析逻辑 #5847 #5855

Merged
merged 20 commits into from
May 3, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
优化逻辑,调整单测断言
优化逻辑,调整单测断言
  • Loading branch information
lizongbo committed Apr 17, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 18c57cca367b4afefd33c2487e452254adcd9d1f
Original file line number Diff line number Diff line change
@@ -433,9 +433,7 @@ public boolean visit(PGTypeCastExpr x) {

if (expr != null) {
if (expr instanceof SQLBinaryOpExpr) {
print('(');
expr.accept(this);
print(')');
} else if (expr instanceof PGTypeCastExpr && dataType.getArguments().isEmpty()) {
dataType.accept(this);
print('(');
Original file line number Diff line number Diff line change
@@ -5456,9 +5456,9 @@ public boolean visit(SQLColumnCheck x) {
name.accept(this);
print(' ');
}
print0(ucase ? "CHECK (" : "check (");
print0(ucase ? "CHECK " : "check ");
x.getExpr().accept(this);
print(')');
print("");

Boolean enable = x.getEnable();
if (enable != null) {
3 changes: 3 additions & 0 deletions core/src/test/java/com/alibaba/druid/bvt/bug/Issue5847.java
Original file line number Diff line number Diff line change
@@ -24,6 +24,9 @@ public void test_for_issue() throws Exception {

sql="select a.*, (a.swanav-lead(a.swanav,1,null::numeric) over w)/lead(a.swanav,1,null::numeric) over w as roe_lag\n";
sql="select a.*, ((a.swanav-lead(a.swanav,1,null::numeric) over w)/lead(a.swanav,1,null::numeric) over w) as roe_lag\n";
sql="select * from aaa "

+ "group by to_char((CreateDate || ' ' || cast(HourArgment as VARCHAR) || ':00:00')::TIMESTAMP, 'YYYY-MM-DD HH24')";

for (DbType dbType : new DbType[]{
//DbType.db2,
Original file line number Diff line number Diff line change
@@ -68,18 +68,18 @@ public void test_0() throws Exception {
"\tSELECT M.*, A.*\n" +
"\tFROM T_EW_MERCHANT M\n" +
"\t\tLEFT JOIN LP_ADDRESS A ON M.ADDRESS_KEY = A.KEY\n" +
"\tWHERE M.MERCHANT_CODE LIKE ('%' || ? || '%')\n" +
"\t\tOR M.MERCHANT_NAME LIKE ('%' || ? || '%')\n" +
"\t\tOR M.MERCHANT_NAME LIKE ('%' || ? || '%')\n" +
"\t\tOR M.CERTIFICATE LIKE ('%' || ? || '%')\n" +
"\t\tOR M.OWNER LIKE ('%' || ? || '%')\n" +
"\t\tOR A.COUNTRY LIKE ('%' || ? || '%')\n" +
"\t\tOR A.PROVINCE LIKE ('%' || ? || '%')\n" +
"\t\tOR A.CITY LIKE ('%' || ? || '%')\n" +
"\t\tOR A.COUNTY LIKE ('%' || ? || '%')\n" +
"\t\tOR A.STREET_AREA LIKE ('%' || ? || '%')\n" +
"\t\tOR A.DETAILE LIKE ('%' || ? || '%')\n" +
"\t\tOR A.ZIPCODE LIKE ('%' || ? || '%')\n" +
"\tWHERE M.MERCHANT_CODE LIKE '%' || ? || '%'\n" +
"\t\tOR M.MERCHANT_NAME LIKE '%' || ? || '%'\n" +
"\t\tOR M.MERCHANT_NAME LIKE '%' || ? || '%'\n" +
"\t\tOR M.CERTIFICATE LIKE '%' || ? || '%'\n" +
"\t\tOR M.OWNER LIKE '%' || ? || '%'\n" +
"\t\tOR A.COUNTRY LIKE '%' || ? || '%'\n" +
"\t\tOR A.PROVINCE LIKE '%' || ? || '%'\n" +
"\t\tOR A.CITY LIKE '%' || ? || '%'\n" +
"\t\tOR A.COUNTY LIKE '%' || ? || '%'\n" +
"\t\tOR A.STREET_AREA LIKE '%' || ? || '%'\n" +
"\t\tOR A.DETAILE LIKE '%' || ? || '%'\n" +
"\t\tOR A.ZIPCODE LIKE '%' || ? || '%'\n" +
") TMP_PAGE\n" +
"WHERE ROWNUM <= 10", SQLUtils.toPGString(stmt));

@@ -88,18 +88,18 @@ public void test_0() throws Exception {
"\tselect M.*, A.*\n" +
"\tfrom T_EW_MERCHANT M\n" +
"\t\tleft join LP_ADDRESS A on M.ADDRESS_KEY = A.KEY\n" +
"\twhere M.MERCHANT_CODE like ('%' || ? || '%')\n" +
"\t\tor M.MERCHANT_NAME like ('%' || ? || '%')\n" +
"\t\tor M.MERCHANT_NAME like ('%' || ? || '%')\n" +
"\t\tor M.CERTIFICATE like ('%' || ? || '%')\n" +
"\t\tor M.OWNER like ('%' || ? || '%')\n" +
"\t\tor A.COUNTRY like ('%' || ? || '%')\n" +
"\t\tor A.PROVINCE like ('%' || ? || '%')\n" +
"\t\tor A.CITY like ('%' || ? || '%')\n" +
"\t\tor A.COUNTY like ('%' || ? || '%')\n" +
"\t\tor A.STREET_AREA like ('%' || ? || '%')\n" +
"\t\tor A.DETAILE like ('%' || ? || '%')\n" +
"\t\tor A.ZIPCODE like ('%' || ? || '%')\n" +
"\twhere M.MERCHANT_CODE like '%' || ? || '%'\n" +
"\t\tor M.MERCHANT_NAME like '%' || ? || '%'\n" +
"\t\tor M.MERCHANT_NAME like '%' || ? || '%'\n" +
"\t\tor M.CERTIFICATE like '%' || ? || '%'\n" +
"\t\tor M.OWNER like '%' || ? || '%'\n" +
"\t\tor A.COUNTRY like '%' || ? || '%'\n" +
"\t\tor A.PROVINCE like '%' || ? || '%'\n" +
"\t\tor A.CITY like '%' || ? || '%'\n" +
"\t\tor A.COUNTY like '%' || ? || '%'\n" +
"\t\tor A.STREET_AREA like '%' || ? || '%'\n" +
"\t\tor A.DETAILE like '%' || ? || '%'\n" +
"\t\tor A.ZIPCODE like '%' || ? || '%'\n" +
") TMP_PAGE\n" +
"where ROWNUM <= 10", SQLUtils.toPGString(stmt, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION));