makssent opened a new pull request, #40171:
URL: https://github.com/apache/shardingsphere/pull/40171

   Changes proposed in this pull request:
     - `FirebirdStatementVisitor.visitStringLiterals` takes the value of a 
string literal from its `STRING_` token. Before, it took the text of the whole 
`stringLiterals` rule with the character set introducer and `COLLATE`, and 
`StringLiteralValue` cut its first and last characters as quotes: `_UTF8 'abc'` 
got the value `UTF8'abc`, and `'abc' COLLATE UNICODE` got `abc'COLLATEUNICOD`.
     - The `HEX_DIGIT_` rule of the Firebird lexer (`Literals.g4`) accepts 
`x'...'` and `X'...'`, `0x` and `0X`, and an empty `x''`, as the Firebird 
server lexer does. Before, `x'4142'` was read as a string with the introducer 
`x` and got the value `'4142`.
     - `visitHexadecimalLiterals` keeps the original text of a hexadecimal 
literal with an introducer or `COLLATE` (`_OCTETS x'4546'`, `x'4748' COLLATE 
OCTETS`). Before, the tokens were glued together without spaces.
     - When the proxy rewrites an `INSERT` for a shard, it writes a string 
literal from this value, so the shard got a broken statement and the client got 
the error "Token unknown". Now these statements insert the same values as on 
the server. Without sharding the statement goes to the database as is, and the 
results were the same before the fix.
   
   Verification:
   The same queries were executed directly against a real database and through 
the proxy, and the results were compared.
   
   * Server: Firebird 5.0
   * Clients: Jaybird 5.0.13 and 6.0.6
   
     Through the proxy, table `T_PLAIN (ID INTEGER NOT NULL PRIMARY KEY, NAME 
VARCHAR(20))` is sharded across two data sources by `ID % 2` (`T_PLAIN_0` and 
`T_PLAIN_1`); on the server it is one table. Rows 5401 to 5406 are inserted 
with literals and read with `SELECT ID, NAME FROM T_PLAIN WHERE ID BETWEEN 5401 
AND 5404 ORDER BY ID`. Jaybird 5 and 6 give the same results.
   
     Before the fix:
   
     | Query | Proxy | Server | Match |
     |---|---|---|---|
     | `INSERT INTO T_PLAIN (ID, NAME) VALUES (5401, _UTF8 'abc')` | error 
335544382 "... SQL error code = -104; Token unknown - line 1, column 54; abc" | 
updated 1 | no |
     | `INSERT INTO T_PLAIN (ID, NAME) VALUES (5402, x'4142')` | error 
335544382 "... Token unknown - line 1, column 50; 4142" | updated 1 | no |
     | `INSERT INTO T_PLAIN (ID, NAME) VALUES (5403, 'abc' COLLATE UNICODE)` | 
error 335544382 "... Token unknown - line 1, column 53; COLLATEUNICOD" | 
updated 1 | no |
     | `INSERT INTO T_PLAIN (ID, NAME) VALUES (5404, X'4344')` | updated 1 | 
updated 1 | yes |
     | `INSERT INTO T_PLAIN (ID, NAME) VALUES (5405, _OCTETS x'4546')` | error 
335544569 "... You have an error in your SQL syntax ..." | updated 1 | no |
     | `INSERT INTO T_PLAIN (ID, NAME) VALUES (5406, x'4748' COLLATE OCTETS)` | 
error 335544382 "... Token unknown - line 1, column 50; 4748" | updated 1 | no |
     | `SELECT` of rows 5401 to 5406 | (5404, CD) | (5401, abc), (5402, AB), 
(5403, abc), (5404, CD), (5405, EF), (5406, GH) | no |
   
     After the fix:
   
     | Query | Proxy | Server | Match |
     |---|---|---|---|
     | `INSERT` of rows 5401 to 5406 with the same literals | updated 1 each | 
updated 1 each | yes |
     | `SELECT` of rows 5401 to 5406 | (5401, abc), (5402, AB), (5403, abc), 
(5404, CD), (5405, EF), (5406, GH) | the same | yes |
   
   ---
   
   Before committing this PR, I'm sure that I have checked the following 
options:
   - [x] My code follows the [code of 
conduct](https://shardingsphere.apache.org/community/en/involved/conduct/code/) 
of this project.
   - [x] I have self-reviewed the commit code.
   - [ ] I have (or in comment I request) added corresponding labels for the 
pull request.
   - [ ] I have passed maven check locally : `./mvnw clean install -B -T1C 
-Dmaven.javadoc.skip -Dmaven.jacoco.skip -e`.
   - [ ] I have made corresponding changes to the documentation.
   - [x] I have added corresponding unit tests for my changes.
   - [ ] I have updated the Release Notes of the current development version. 
For more details, see [Update Release 
Note](https://shardingsphere.apache.org/community/en/involved/contribute/contributor/)
   - [ ] I have specified the tool and the affected files or area for 
substantial AI assistance, as required by the [AI-assisted contribution policy].
   
   [AI-assisted contribution policy]: 
https://github.com/apache/shardingsphere/blob/master/AI_POLICY.md
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to