diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index 193d52a59483e..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 diff --git a/RELEASE-NOTES_ZH.md b/RELEASE-NOTES_ZH.md index 873d14ebd6a19..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`解析异常 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)); } diff --git a/sharding-core/src/test/resources/parser/select_pagination.xml b/sharding-core/src/test/resources/parser/select_pagination.xml index 7cc2618728c88..6e50d9484859a 100644 --- a/sharding-core/src/test/resources/parser/select_pagination.xml +++ b/sharding-core/src/test/resources/parser/select_pagination.xml @@ -329,4 +329,19 @@ + + + + + + + + + + + + + + + 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 @@ + + + + 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..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,4 +11,5 @@ +