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 #4094 https://github.com/alibaba/druid/issues/4094 #4102

Merged
merged 1 commit into from
Dec 22, 2020
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ public boolean visit(OracleAnalyticWindowing x) {
SQLBetweenExpr betweenExpr = (SQLBetweenExpr) expr;
SQLOver.WindowingBound beginBound = over.getWindowingBetweenBeginBound();
if (beginBound != null) {
print0(ucase ? " BETWEEN " : " between ");
betweenExpr.getBeginExpr().accept(this);
print(' ');
print0(ucase ? beginBound.name : beginBound.name_lower);
Expand Down
44 changes: 44 additions & 0 deletions src/test/java/com/alibaba/druid/bvt/bug/Issue_4094.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright 1999-2018 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.druid.bvt.bug;

import com.alibaba.druid.DbType;
import com.alibaba.druid.sql.SQLUtils;
import com.alibaba.druid.wall.WallConfig;
import com.alibaba.druid.wall.WallUtils;

import junit.framework.TestCase;
import org.junit.Assert;

/**
* https://github.com/alibaba/druid/issues/4094
*/
public class Issue_4094 extends TestCase {

public void test_betweent_lost(){
// 此sql可以正常执行
String sql ="SELECT B.CUSTOMER_ID customerId,B.CN_NAME NAME,OPENING_DATE,CLOSING_DATE,count(A.OPENING_DATE) over (partition BY B.CUSTOMER_ID ORDER BY trunc(A.OPENING_DATE,'mm') RANGE BETWEEN interval '3' month (4) preceding AND CURRENT ROW) AS createCount,count(A.CLOSING_DATE) over (partition BY B.CUSTOMER_ID ORDER BY trunc(NVL(A.CLOSING_DATE,SYSDATE),'mm') RANGE BETWEEN interval '3' month (4) preceding AND CURRENT ROW) AS cancelCount,row_number () over (partition BY B.CUSTOMER_ID ORDER BY trunc(A.OPENING_DATE) DESC) AS row_flg FROM account_info A,CUSTOMER_INFO B WHERE A.CUSTOMER_ID=B.CUSTOMER_ID";
String format = SQLUtils.format(sql, DbType.oracle);
assertEquals("SELECT B.CUSTOMER_ID AS customerId, B.CN_NAME AS NAME, OPENING_DATE, CLOSING_DATE\n"
+ "\t, count(A.OPENING_DATE) OVER (PARTITION BY B.CUSTOMER_ID ORDER BY trunc(A.OPENING_DATE, 'mm') RANGE "
+ "BETWEEN INTERVAL '3' MONTH(4) PRECEDING AND CURRENT ROW) AS createCount\n"
+ "\t, count(A.CLOSING_DATE) OVER (PARTITION BY B.CUSTOMER_ID ORDER BY trunc(NVL(A.CLOSING_DATE, SYSDATE),"
+ " 'mm') RANGE BETWEEN INTERVAL '3' MONTH(4) PRECEDING AND CURRENT ROW) AS cancelCount\n"
+ "\t, row_number() OVER (PARTITION BY B.CUSTOMER_ID ORDER BY trunc(A.OPENING_DATE) DESC) AS row_flg\n"
+ "FROM account_info A, CUSTOMER_INFO B\n"
+ "WHERE A.CUSTOMER_ID = B.CUSTOMER_ID", format);
}
}