Repository navigation
Conversation
terrymanu
left a comment
There was a problem hiding this comment.
Summary
This PR adds JDBC PreparedStatement parameter capture for setNString, removes the unsupported-operation exception, and updates the circuit-breaker implementation and tests. However, parameters are still replayed through untyped setObject calls, losing national-character type information. Consequently, the configuration required by the linked issue can still lose Chinese characters.
Result
Review Result: Not Mergeable
Feedback Mode: Change Request
Review Status: Not Converged
Confirmed Blocking Issues: 1
The following is a confirmed subset of findings. Review-record validation could not be completed, so this report does not claim an exhaustive finding set.
Blocking Issues
-
[P1] Preserve national-character binding semantics for
setNString- Evidence:
AbstractPreparedStatementAdapter.java:101–104stores only a plain String. Parameter replay always callssetObject(index, value). Ordinary execution, cached-statement reuse, and batch execution all use this path. Microsoft’s documentation distinguishes ordinary string binding from national-character setters, which always send Unicode. - Impact: When
sendStringParametersAsUnicode=falseand the database collation cannot encode the supplied characters,setNString(1, "中文")can still silently write question marks or fail to match NVARCHAR data. This is precisely the scenario described in #32314. The default configuration can mask the problem, and disclosing this limitation in the PR does not satisfy the method’s JDBC contract. - Required Change: Preserve national-character binding intent through native execution, including ordinary execution, statement reuse, and batches. Add regression coverage that distinguishes national-character binding from merely capturing a String value.
- Evidence:
Coverage
- Public candidate:
fe8b4808cb4d08f60f700642cb0afec973d1f679. Two independent assessments covered all five changed files and the affected execution paths. - Checkstyle and Spotless passed for all five files. Production and test compilation passed. Focused tests timed out twice with exit code 124; no passing test result was obtained.
- The public commit’s Git object was unavailable locally, preventing ledger initialization and review-record validation. No live SQL Server reproduction was performed. This assessment covers code correctness only; CI was not reviewed.
Thanks for the review — updated in e4f28d1.
Latest head verification: full |
Bind setNString parameters through PreparedStatement#setNString instead of untyped setObject, covering regular execution, cached statement reuse, batch execution and SQL federation scans.
terrymanu
left a comment
There was a problem hiding this comment.
Summary
This PR enables JDBC setNString for the SQL Server scenario in #32314. It preserves native setter intent using NationalCharacterString and shared replay dispatch. However, that wrapper also reaches logical sharding values and breaks existing string-routing behavior.
Result
Review Result: Not Mergeable
Feedback Mode: Change Request
Review Status: Not Converged
Confirmed Blocking Issues: 5
These findings are a confirmed subset. Formal review-record validation could not complete.
Blocking Issues
-
[P1] Preserve logical String semantics during routing
- Evidence: Parameter capture stores the wrapper directly. Condition merging then treats it as the logical value. Focused reproductions confirm mixed-type conversion failures and incorrect case-insensitive intersections.
- Impact: For
WHERE k = ? AND k = ?, mixingsetStringandsetNStringcan throw before execution. Two national-string values"foo"and"FOO"on a case-insensitive key can produce a false empty intersection, triggering unicast routing and potentially missing matching data on other shards. - Required Change: Preserve logical String semantics while retaining native binding intent. Add regression coverage for mixed setters, literal/parameter ranges, and case-insensitive keys.
-
[P2] Exercise replay through public APIs
- Evidence: The new replay tests directly invoke protected
replaySetParameter. - Impact: This violates the explicit public-API testing rule.
- Required Change: Verify adapter replay through public execution APIs without widening production visibility.
- Evidence: The new replay tests directly invoke protected
-
[P2] Use equivalent Lombok constructor generation
- Evidence: The new constructor only assigns its final field.
- Impact: It violates the boilerplate constructor rule; no manual-constructor exception applies.
- Required Change: Use
@RequiredArgsConstructor, which preserves the current signature and behavior.
-
[P2] Document the nullable binding value
- Evidence: The public binding method accepts SQL NULL through normal replay but does not document that meaning.
- Impact: Its contract violates the nullable-parameter documentation rule.
- Required Change: Document SQL NULL in
@param valueor apply the appropriate nullable annotation.
-
[P2] Mark the new high-frequency parameter paths
- Evidence: The new
setNStringand shared binder repeat with normal query throughput and lack@HighFrequencyInvocation. - Impact: They do not satisfy the required annotation rule. This is a policy finding, not a measured performance regression.
- Required Change: Apply the annotation at the smallest accurate declaration scope.
- Evidence: The new
Coverage
- Public head:
d081bbfb2467ea1abf30b86dbfaed5fa5b51817c. Two independent assessments covered all eight changed files and affected consumers. - Checkstyle and Spotless passed for all eight Java files, exit 0. Focused source reproductions confirmed the routing failures.
- The public-head Git object was unavailable locally, preventing canonical ledger/session validation; source and style verification used a hash-verified snapshot. Full module tests and live SQL Server execution were not run. This is a code-scope review; CI was not reviewed.
Unwrap NationalCharacterString at every routing parameter read so sharding condition merging and assignment routing see logical Strings while replay still binds through PreparedStatement#setNString. - Unwrap in ConditionValue, InsertClauseShardingConditionEngine and ShardingRouteContextCheckUtils - Drive replay tests through public executeQuery APIs - Use @requiredargsconstructor, document SQL NULL and mark high-frequency parameter paths - Cover mixed setters, literal/parameter ranges, case-insensitive keys and INSERT/SET assignment values
All five findings are addressed in 979e49d:
Focused suites pass (condition engines, adapter, federation scan, parameter type); Spotless/Checkstyle clean on all 15 files; RAT clean. Live SQL Server execution and full-module suites were not run. |
What
Implement
PreparedStatement#setNStringin ShardingSphere JDBC:AbstractPreparedStatementAdapterexactly likesetStringsetNStringthrow fromAbstractUnsupportedOperationPreparedStatementCircuitBreakerPreparedStatementWhy
Fixes #32314.
setNStringcurrently throwsSQLFeatureNotSupportedException.Behavior
setNStringbinds throughPreparedStatement#setNStringon every replay path (regular execution, cached statement reuse, batches and SQL federation scans), preserving SQL Server national-character semantics even whensendStringParametersUnicode=false.Testing
mvn -pl jdbc -Dtest=PreparedStatementAdapterTest,UnsupportedOperationPreparedStatementTest testjdbcmodule tests: 1425 passed-Pcheck): cleanAI assistance
Prepared with Qoder (AI coding agent) under human review; affected files are the five files listed above. The contributor reviewed and verified every change.