From b3bf0590a0eaa2229a87b014d3c1e0c45e2b91dd Mon Sep 17 00:00:00 2001 From: tuohai666 Date: Wed, 22 Aug 2018 14:15:57 +0800 Subject: [PATCH 01/11] #569, fix RowCountToken beginPosition --- .../core/parsing/parser/clause/WhereClauseParser.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/clause/WhereClauseParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/clause/WhereClauseParser.java index 550dacb89f3be..51145f47aa5a4 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/clause/WhereClauseParser.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/clause/WhereClauseParser.java @@ -260,6 +260,7 @@ private boolean isRowNumberCondition(final List items, final SQLExpr protected abstract boolean isRowNumberCondition(List items, String columnLabel); private void parseRowCountCondition(final SelectStatement selectStatement, final boolean includeRowCount) { + int endPosition = lexerEngine.getCurrentToken().getEndPosition(); SQLExpression sqlExpression = basicExpressionParser.parse(selectStatement); if (null == selectStatement.getLimit()) { selectStatement.setLimit(new Limit(databaseType)); @@ -267,8 +268,7 @@ private void parseRowCountCondition(final SelectStatement selectStatement, final if (sqlExpression instanceof SQLNumberExpression) { int rowCount = ((SQLNumberExpression) sqlExpression).getNumber().intValue(); selectStatement.getLimit().setRowCount(new LimitValue(rowCount, -1, includeRowCount)); - selectStatement.getSqlTokens().add(new RowCountToken( - lexerEngine.getCurrentToken().getEndPosition() - String.valueOf(rowCount).length() - lexerEngine.getCurrentToken().getLiterals().length(), rowCount)); + selectStatement.getSqlTokens().add(new RowCountToken(endPosition - String.valueOf(rowCount).length(), rowCount)); } else if (sqlExpression instanceof SQLPlaceholderExpression) { selectStatement.getLimit().setRowCount(new LimitValue(-1, ((SQLPlaceholderExpression) sqlExpression).getIndex(), includeRowCount)); } From c390bbbdd2d0cdb5269aea0d4bee3b5e05c527fd Mon Sep 17 00:00:00 2001 From: tuohai666 Date: Wed, 22 Aug 2018 18:48:02 +0800 Subject: [PATCH 02/11] #569, add parser test case --- .../src/test/resources/parser/select.xml | 18 ++++++++++++++++++ .../src/main/resources/sql/dql/select.xml | 1 + 2 files changed, 19 insertions(+) diff --git a/sharding-core/src/test/resources/parser/select.xml b/sharding-core/src/test/resources/parser/select.xml index 929b6e1d9e9d1..2761a23612857 100644 --- a/sharding-core/src/test/resources/parser/select.xml +++ b/sharding-core/src/test/resources/parser/select.xml @@ -452,4 +452,22 @@ + + + + + + + + + + + + + + + + + + diff --git a/sharding-sql-test/src/main/resources/sql/dql/select.xml b/sharding-sql-test/src/main/resources/sql/dql/select.xml index 62c1d0e92f803..5c45f1a815904 100644 --- a/sharding-sql-test/src/main/resources/sql/dql/select.xml +++ b/sharding-sql-test/src/main/resources/sql/dql/select.xml @@ -24,4 +24,5 @@ + From f502348d1a393c7e38fa5b5b16867eabe951f279 Mon Sep 17 00:00:00 2001 From: tuohai666 Date: Wed, 22 Aug 2018 20:58:10 +0800 Subject: [PATCH 03/11] #569, update parser test case --- .../src/test/resources/parser/select.xml | 18 ------------------ .../resources/parser/select_pagination.xml | 19 +++++++++++++++++++ .../src/main/resources/sql/dql/select.xml | 1 - .../resources/sql/dql/select_pagination.xml | 1 + 4 files changed, 20 insertions(+), 19 deletions(-) diff --git a/sharding-core/src/test/resources/parser/select.xml b/sharding-core/src/test/resources/parser/select.xml index 2761a23612857..929b6e1d9e9d1 100644 --- a/sharding-core/src/test/resources/parser/select.xml +++ b/sharding-core/src/test/resources/parser/select.xml @@ -452,22 +452,4 @@ - - -
- - - - - - - - - - - - - - - diff --git a/sharding-core/src/test/resources/parser/select_pagination.xml b/sharding-core/src/test/resources/parser/select_pagination.xml index 7cc2618728c88..a99ac64522445 100644 --- a/sharding-core/src/test/resources/parser/select_pagination.xml +++ b/sharding-core/src/test/resources/parser/select_pagination.xml @@ -329,4 +329,23 @@ + + + +
+ + + + + + + + + + + + + + + diff --git a/sharding-sql-test/src/main/resources/sql/dql/select.xml b/sharding-sql-test/src/main/resources/sql/dql/select.xml index 5c45f1a815904..62c1d0e92f803 100644 --- a/sharding-sql-test/src/main/resources/sql/dql/select.xml +++ b/sharding-sql-test/src/main/resources/sql/dql/select.xml @@ -24,5 +24,4 @@ - diff --git a/sharding-sql-test/src/main/resources/sql/dql/select_pagination.xml b/sharding-sql-test/src/main/resources/sql/dql/select_pagination.xml index 0f100be22cbb9..46a0295ae88e6 100644 --- a/sharding-sql-test/src/main/resources/sql/dql/select_pagination.xml +++ b/sharding-sql-test/src/main/resources/sql/dql/select_pagination.xml @@ -11,4 +11,5 @@ + From 7981a7bf288e95b576311d1ee7e1b86f9bf291e8 Mon Sep 17 00:00:00 2001 From: tuohai666 Date: Wed, 22 Aug 2018 21:04:00 +0800 Subject: [PATCH 04/11] #569, update parser test case --- .../src/test/resources/parser/select_pagination.xml | 6 +++--- .../src/main/resources/sql/dql/select_pagination.xml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/sharding-core/src/test/resources/parser/select_pagination.xml b/sharding-core/src/test/resources/parser/select_pagination.xml index a99ac64522445..2c73cc68b33d1 100644 --- a/sharding-core/src/test/resources/parser/select_pagination.xml +++ b/sharding-core/src/test/resources/parser/select_pagination.xml @@ -330,7 +330,7 @@ - +
@@ -341,11 +341,11 @@ - + - + diff --git a/sharding-sql-test/src/main/resources/sql/dql/select_pagination.xml b/sharding-sql-test/src/main/resources/sql/dql/select_pagination.xml index 46a0295ae88e6..799f79868975a 100644 --- a/sharding-sql-test/src/main/resources/sql/dql/select_pagination.xml +++ b/sharding-sql-test/src/main/resources/sql/dql/select_pagination.xml @@ -11,5 +11,5 @@ - + From 95ff7a0072fbed08e4c6b9782e4564fd94eefb92 Mon Sep 17 00:00:00 2001 From: tuohai666 Date: Thu, 23 Aug 2018 10:18:35 +0800 Subject: [PATCH 05/11] #569, update parser test case --- .../src/test/resources/parser/select_pagination.xml | 12 ++++-------- .../src/main/resources/sql/dql/select_pagination.xml | 2 +- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/sharding-core/src/test/resources/parser/select_pagination.xml b/sharding-core/src/test/resources/parser/select_pagination.xml index 2c73cc68b33d1..9717b1b4d0643 100644 --- a/sharding-core/src/test/resources/parser/select_pagination.xml +++ b/sharding-core/src/test/resources/parser/select_pagination.xml @@ -330,7 +330,7 @@ - +
@@ -338,13 +338,9 @@ - - - - - - - + + + diff --git a/sharding-sql-test/src/main/resources/sql/dql/select_pagination.xml b/sharding-sql-test/src/main/resources/sql/dql/select_pagination.xml index 799f79868975a..74df16b3b1521 100644 --- a/sharding-sql-test/src/main/resources/sql/dql/select_pagination.xml +++ b/sharding-sql-test/src/main/resources/sql/dql/select_pagination.xml @@ -11,5 +11,5 @@ - + From b5d45fee2a9195e83d281d55c2d7709ea86a2290 Mon Sep 17 00:00:00 2001 From: tuohai666 Date: Thu, 23 Aug 2018 10:21:46 +0800 Subject: [PATCH 06/11] #569, update parser test case --- sharding-core/src/test/resources/parser/select_pagination.xml | 2 +- .../src/main/resources/sql/dql/select_pagination.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sharding-core/src/test/resources/parser/select_pagination.xml b/sharding-core/src/test/resources/parser/select_pagination.xml index 9717b1b4d0643..6e50d9484859a 100644 --- a/sharding-core/src/test/resources/parser/select_pagination.xml +++ b/sharding-core/src/test/resources/parser/select_pagination.xml @@ -330,7 +330,7 @@ - +
diff --git a/sharding-sql-test/src/main/resources/sql/dql/select_pagination.xml b/sharding-sql-test/src/main/resources/sql/dql/select_pagination.xml index 74df16b3b1521..12729f6b1f65b 100644 --- a/sharding-sql-test/src/main/resources/sql/dql/select_pagination.xml +++ b/sharding-sql-test/src/main/resources/sql/dql/select_pagination.xml @@ -11,5 +11,5 @@ - + From c9eafb313765fba8c9bd5501b732a5405f4f0a36 Mon Sep 17 00:00:00 2001 From: tuohai666 Date: Thu, 23 Aug 2018 10:49:17 +0800 Subject: [PATCH 07/11] #569, add integrate test case --- ..._pagination_with_row_number_not_at_end.xml | 27 +++++++++++++++++++ ..._pagination_with_row_number_not_at_end.xml | 27 +++++++++++++++++++ ..._pagination_with_row_number_not_at_end.xml | 27 +++++++++++++++++++ ..._pagination_with_row_number_not_at_end.xml | 27 +++++++++++++++++++ .../cases/dql/dql-integrate-test-cases.xml | 4 +++ 5 files changed, 112 insertions(+) create mode 100644 sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_pagination_with_row_number_not_at_end.xml create mode 100644 sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_pagination_with_row_number_not_at_end.xml create mode 100644 sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_pagination_with_row_number_not_at_end.xml create mode 100644 sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_pagination_with_row_number_not_at_end.xml diff --git a/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_pagination_with_row_number_not_at_end.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_pagination_with_row_number_not_at_end.xml new file mode 100644 index 0000000000000..30d34512f9b0d --- /dev/null +++ b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_pagination_with_row_number_not_at_end.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_pagination_with_row_number_not_at_end.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_pagination_with_row_number_not_at_end.xml new file mode 100644 index 0000000000000..b74861ec6db41 --- /dev/null +++ b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_pagination_with_row_number_not_at_end.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_pagination_with_row_number_not_at_end.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_pagination_with_row_number_not_at_end.xml new file mode 100644 index 0000000000000..7e1790572ec3f --- /dev/null +++ b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_pagination_with_row_number_not_at_end.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_pagination_with_row_number_not_at_end.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_pagination_with_row_number_not_at_end.xml new file mode 100644 index 0000000000000..54e9910ed9c23 --- /dev/null +++ b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_pagination_with_row_number_not_at_end.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sharding-jdbc/src/test/resources/integrate/cases/dql/dql-integrate-test-cases.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dql-integrate-test-cases.xml index 5e547f170f16f..ff876fcb84be9 100644 --- a/sharding-jdbc/src/test/resources/integrate/cases/dql/dql-integrate-test-cases.xml +++ b/sharding-jdbc/src/test/resources/integrate/cases/dql/dql-integrate-test-cases.xml @@ -321,6 +321,10 @@ + + + + From 72d9c0318482e0454fac98c46a67f058b0790982 Mon Sep 17 00:00:00 2001 From: tuohai666 Date: Thu, 23 Aug 2018 12:46:31 +0800 Subject: [PATCH 08/11] #569, for comments --- .../src/main/resources/sql/dql/select_pagination.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sharding-sql-test/src/main/resources/sql/dql/select_pagination.xml b/sharding-sql-test/src/main/resources/sql/dql/select_pagination.xml index 12729f6b1f65b..1f50de24f52a0 100644 --- a/sharding-sql-test/src/main/resources/sql/dql/select_pagination.xml +++ b/sharding-sql-test/src/main/resources/sql/dql/select_pagination.xml @@ -11,5 +11,5 @@ - + From ab94f389193c56e7e1afd8420199ad19168c87d8 Mon Sep 17 00:00:00 2001 From: tuohai666 Date: Thu, 23 Aug 2018 12:55:17 +0800 Subject: [PATCH 09/11] #569, add to release notes --- RELEASE-NOTES.md | 1 + RELEASE-NOTES_ZH.md | 1 + 2 files changed, 2 insertions(+) diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index 193d52a59483e..ed1eddaaf940b 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -47,6 +47,7 @@ 1. [ISSUE #919](https://github.com/sharding-sphere/sharding-sphere/issues/919) Inline expression with groovy may cause memory leak 1. [ISSUE #993](https://github.com/sharding-sphere/sharding-sphere/issues/993) Fail to parsing PostgreSQL due to the quotation 1. [ISSUE #1015](https://github.com/sharding-sphere/sharding-sphere/issues/1015) Support SQL like `SELECT id, COUNT(*) FROM table GROUP BY 1,2` +1. [ISSUE #569](https://github.com/sharding-sphere/sharding-sphere/issues/569) Failed to parse SQL for Oracle when ROWNUM is not at end. #### Sharding-JDBC diff --git a/RELEASE-NOTES_ZH.md b/RELEASE-NOTES_ZH.md index 873d14ebd6a19..d097f984ee6e0 100644 --- a/RELEASE-NOTES_ZH.md +++ b/RELEASE-NOTES_ZH.md @@ -48,6 +48,7 @@ 1. [ISSUE #919](https://github.com/sharding-sphere/sharding-sphere/issues/919) 使用Groovy解析行表达式可能导致内存泄漏 1. [ISSUE #993](https://github.com/sharding-sphere/sharding-sphere/issues/993) 无法解析PostgreSQL的双引号占位符 1. [ISSUE #1015](https://github.com/sharding-sphere/sharding-sphere/issues/1015) 支持SQL `SELECT id, COUNT(*) FROM table GROUP BY 1,2` +1. [ISSUE #569](https://github.com/sharding-sphere/sharding-sphere/issues/569) 当Oracle的SQL中ROWNUM不在语句尾部时,解析错误。 #### Sharding-JDBC From c2e4f33def655627108e2ca9bdf510b91e5f57ff Mon Sep 17 00:00:00 2001 From: tuohai666 Date: Thu, 23 Aug 2018 12:57:24 +0800 Subject: [PATCH 10/11] #569, add to release notes --- RELEASE-NOTES.md | 2 +- RELEASE-NOTES_ZH.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index ed1eddaaf940b..717aeeb46c733 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -47,7 +47,7 @@ 1. [ISSUE #919](https://github.com/sharding-sphere/sharding-sphere/issues/919) Inline expression with groovy may cause memory leak 1. [ISSUE #993](https://github.com/sharding-sphere/sharding-sphere/issues/993) Fail to parsing PostgreSQL due to the quotation 1. [ISSUE #1015](https://github.com/sharding-sphere/sharding-sphere/issues/1015) Support SQL like `SELECT id, COUNT(*) FROM table GROUP BY 1,2` -1. [ISSUE #569](https://github.com/sharding-sphere/sharding-sphere/issues/569) Failed to parse SQL for Oracle when ROWNUM is not at end. +1. [ISSUE #569](https://github.com/sharding-sphere/sharding-sphere/issues/569) Failed to parse SQL for Oracle when ROWNUM is not at end #### Sharding-JDBC diff --git a/RELEASE-NOTES_ZH.md b/RELEASE-NOTES_ZH.md index d097f984ee6e0..0b4aa5051c0ee 100644 --- a/RELEASE-NOTES_ZH.md +++ b/RELEASE-NOTES_ZH.md @@ -48,7 +48,7 @@ 1. [ISSUE #919](https://github.com/sharding-sphere/sharding-sphere/issues/919) 使用Groovy解析行表达式可能导致内存泄漏 1. [ISSUE #993](https://github.com/sharding-sphere/sharding-sphere/issues/993) 无法解析PostgreSQL的双引号占位符 1. [ISSUE #1015](https://github.com/sharding-sphere/sharding-sphere/issues/1015) 支持SQL `SELECT id, COUNT(*) FROM table GROUP BY 1,2` -1. [ISSUE #569](https://github.com/sharding-sphere/sharding-sphere/issues/569) 当Oracle的SQL中ROWNUM不在语句尾部时,解析错误。 +1. [ISSUE #569](https://github.com/sharding-sphere/sharding-sphere/issues/569) 当Oracle的SQL中ROWNUM不在语句尾部时,解析错误 #### Sharding-JDBC From 3e4e4e1cc83d5fb57c6ea67c7648d1c3a35f93af Mon Sep 17 00:00:00 2001 From: tuohai666 Date: Thu, 23 Aug 2018 14:15:25 +0800 Subject: [PATCH 11/11] #569, for comments --- RELEASE-NOTES.md | 2 +- RELEASE-NOTES_ZH.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index 717aeeb46c733..be4aede47e9e0 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -40,6 +40,7 @@ #### Core +1. [ISSUE #569](https://github.com/sharding-sphere/sharding-sphere/issues/569) Failed to parse SQL for Oracle when ROWNUM is not at end 1. [ISSUE #628](https://github.com/sharding-sphere/sharding-sphere/issues/628) Support data type jsonb for PostgreSQL 1. [ISSUE #646](https://github.com/sharding-sphere/sharding-sphere/issues/646) When aliases in `SELECT ITEMS` correspond to the real column names of `GROUP BY` or `ORDER BY`, there is no need to generate derived columns 1. [ISSUE #806](https://github.com/sharding-sphere/sharding-sphere/issues/806) `NOT IN` parse exception @@ -47,7 +48,6 @@ 1. [ISSUE #919](https://github.com/sharding-sphere/sharding-sphere/issues/919) Inline expression with groovy may cause memory leak 1. [ISSUE #993](https://github.com/sharding-sphere/sharding-sphere/issues/993) Fail to parsing PostgreSQL due to the quotation 1. [ISSUE #1015](https://github.com/sharding-sphere/sharding-sphere/issues/1015) Support SQL like `SELECT id, COUNT(*) FROM table GROUP BY 1,2` -1. [ISSUE #569](https://github.com/sharding-sphere/sharding-sphere/issues/569) Failed to parse SQL for Oracle when ROWNUM is not at end #### Sharding-JDBC diff --git a/RELEASE-NOTES_ZH.md b/RELEASE-NOTES_ZH.md index 0b4aa5051c0ee..4b0464e827915 100644 --- a/RELEASE-NOTES_ZH.md +++ b/RELEASE-NOTES_ZH.md @@ -41,6 +41,7 @@ #### 内核 +1. [ISSUE #569](https://github.com/sharding-sphere/sharding-sphere/issues/569) 当Oracle的SQL中ROWNUM不在语句尾部时解析错误 1. [ISSUE #628](https://github.com/sharding-sphere/sharding-sphere/issues/628) 支持PostgreSQL的数据类型jsonb 1. [ISSUE #646](https://github.com/sharding-sphere/sharding-sphere/issues/646) 当SELECT ITEMS中的别名与GROUP BY或ORDER BY的真实列名对应时无需补列 1. [ISSUE #806](https://github.com/sharding-sphere/sharding-sphere/issues/806) `NOT IN`解析异常 @@ -48,7 +49,6 @@ 1. [ISSUE #919](https://github.com/sharding-sphere/sharding-sphere/issues/919) 使用Groovy解析行表达式可能导致内存泄漏 1. [ISSUE #993](https://github.com/sharding-sphere/sharding-sphere/issues/993) 无法解析PostgreSQL的双引号占位符 1. [ISSUE #1015](https://github.com/sharding-sphere/sharding-sphere/issues/1015) 支持SQL `SELECT id, COUNT(*) FROM table GROUP BY 1,2` -1. [ISSUE #569](https://github.com/sharding-sphere/sharding-sphere/issues/569) 当Oracle的SQL中ROWNUM不在语句尾部时,解析错误 #### Sharding-JDBC