fix load data report 'unsupported cast from json to JSON'#23825
fix load data report 'unsupported cast from json to JSON'#23825mergify[bot] merged 3 commits intomatrixorigin:mainfrom
Conversation
|
|
ⓘ You are approaching your monthly quota for Qodo. Upgrade your plan Review Summary by QodoFix JSON to JSON cast in parallel LOAD DATA operations
WalkthroughsDescription• Add identity cast path for JSON to JSON conversion • Prevent parallel LOAD DATA failures on tables with JSON columns • Use safe value copying via GetStrValue()/AppendBytes() methods • Add regression test for JSON to JSON cast operation Diagramflowchart LR
A["LOAD DATA PARALLEL on JSON column"] -->|encounters irregular index| B["Legacy load path with cast layer"]
B -->|JSON to JSON cast| C["jsonToOthers function"]
C -->|before fix| D["❌ unsupported cast error"]
C -->|after fix| E["✓ Identity cast with safe copy"]
E --> F["Parallel load succeeds"]
File Changes1. pkg/sql/plan/function/func_cast.go
|
Code Review by Qodo
1. Planner rejects JSON→JSON
|
Merge Queue Status
This pull request spent 5 seconds in the queue, with no time running CI. ReasonThe pull request can't be updated
HintYou should update or rebase your pull request manually. If you do, this pull request will automatically be requeued once the queue conditions match again. |
Merge Queue Status
This pull request spent 11 seconds in the queue, with no time running CI. Required conditions to merge
|
What type of PR is this?
Which issue(s) this PR fixes:
issue #23822
What this PR does / why we need it:
Fix LOAD DATA ... PARALLEL 'TRUE' failure on tables with JSON columns and irregular indexes (for example IVFFLAT).
This change adds a safe identity cast path for JSON -> JSON, which prevents parallel load from failing with:
internal error: unsupported cast from json to JSON
Root Cause
For LOAD DATA on tables with irregular indexes, the planner may fall back to the legacy load path.
In the parallel branch, that path introduces an extra cast layer. For JSON columns, execution could reach the generic jsonToOthers() cast path.
Before this change, jsonToOthers() did not handle JSON -> JSON, so parallel load could fail even though the source and target types were both JSON.
Fix
Add an explicit identity cast branch for JSON -> JSON in pkg/sql/plan/function/func_cast.go
Copy JSON values safely via GetStrValue()/AppendBytes() instead of using a generic fixed-type duplication path
Add a regression unit test for JSON -> JSON cast in pkg/sql/plan/function/func_cast_test.go
Impact
This fixes parallel LOAD DATA for scenarios like:
JSON column present
IVFFLAT index present
LOAD DATA URL S3OPTION ... PARALLEL 'TRUE'
The fix is intentionally minimal and does not change the broader legacy load path behavior.
Files Changed
pkg/sql/plan/function/func_cast.go
pkg/sql/plan/function/func_cast_test.go
Validation
Unit Test
go test ./pkg/sql/plan/function -run 'TestCastJsonTo(Json|Numeric)' -count=1
Build
make build
Runtime Verification
Verified with a real LOAD DATA URL S3OPTION ... PARALLEL 'TRUE' flow against local MinIO.
Scenario:
table with JSON column
VECF64 column
IVFFLAT index
large CSV file (parallel path actually triggered)
Result:
before fix: internal error: unsupported cast from json to JSON
after fix: parallel load succeeded
Notes
This PR is a minimal functional fix to unblock the reported issue.
If needed, the legacy parallel LOAD DATA cast path can be further cleaned up in a follow-up change.