Repository navigation
Conversation
…aba#6735) Since alibaba#6474, SQLExprParser.orderBy() keeps parsing order-by items without a comma whenever the previous item is a SQLVariantRefExpr and the next token is an IDENTIFIER. This was intended for template parameters such as ${...}, but it also matched @@Version and @var. In SQL Server OFFSET is an IDENTIFIER, so "ORDER BY @@Version OFFSET 0 ROWS FETCH ..." (the pagination SQL generated by Hibernate 6) treated OFFSET as another order-by item and then failed on the row count. Only continue without a comma when the previous item is a template parameter, consistent with how SQLSelectParser handles select items.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #6735
Problem
Since 1.2.26, the SQL Server parser fails on an
ORDER BYwhose last item is a variable when it is followed byOFFSET ... FETCH:Hibernate 6 (
SQLServer2012LimitHandler) generates exactly this SQL for every paginated query that has no explicitORDER BY. SoStatFilter.mergeSqllogs an error for each such query, andWallFiltercannot parse it either.Cause
#6474 changed
SQLExprParser.orderBy()to keep parsing order-by items without a comma whenever the previous item is aSQLVariantRefExprand the next token is anIDENTIFIER. This is meant for template parameters (${...}), which may already contain the separating comma. However, the check also matches regular variables such as@@versionand@var. The SQL Server lexer returnsOFFSETas anIDENTIFIER, soOFFSETwas parsed as a second order-by item and the row count that follows failed to parse.Fix
Only continue without a comma when the previous item is a template parameter (
SQLVariantRefExpr.isTemplateParameter()). This matches howSQLSelectParseralready handles template parameters in the select list.Tests
Added
Issue6735, which covers:@@versionfollowed byOFFSETwith a literal row count and with a?placeholder@v DESCas the last order-by itemParameterizedOutputVisitorUtils.parameterizepath used byStatFilterAll 4 tests fail without the fix and pass with it.
mvn -pl core test -Dtest='com/alibaba/druid/bvt/sql/**/*'passes: 2678 tests, 0 failures, checkstyle OK. This includes the ClickHouse template-parameter tests from Implement template parser. #6474 (CKResourceTest).