DaZuiZui opened a new pull request, #18977:
URL: https://github.com/apache/iotdb/pull/18977

   ## Problem
   
   `IoTDBTablePreparedStatement.processQueryResult()` built its result set with 
the 14-argument `IoTDBJDBCResultSet` constructor. That constructor hard-codes 
`tableModel=false` and substitutes `IntStream.range(0, columnNameList.size())` 
for the server-provided `columnIndex2TsBlockColumnIndexList`. It also never 
assigns `charset`, so the field keeps its `TSFileConfig.STRING_CHARSET` 
initializer.
   
   Consequences for table-model prepared statements:
   
   - **Reordered projections** (`SELECT b, a FROM t WHERE a > ?`) silently 
return values in physical order instead of the projection order.
   - **Repeated projections / aliases** (`SELECT a AS x, a AS y ...`) map the 
second logical column to a physical index that does not exist, raising 
`ArrayIndexOutOfBoundsException`.
   - `getBytes(...)` ignores the connection charset.
   
   `IoTDBStatement` already uses the full constructor and forwards all three, 
so the same response gave different results on the two paths.
   
   Notably, `DatasetHeader.setTableColumnToTsBlockIndexMap` builds the mapping 
from each output symbol's position in the child output symbol list, so 
non-identity mappings and duplicate entries are both reachable from the server, 
not only from synthetic fixtures.
   
   ## Fix
   
   In `IoTDBTablePreparedStatement.processQueryResult()`, call the full 
`IoTDBJDBCResultSet` constructor and forward:
   
   - `charset` (inherited from `IoTDBStatement`, assigned by this class's 
constructor),
   - `resp.isSetTableModel() && resp.isTableModel()` (never hard-coded),
   - a **null-safe defensive copy** of 
`resp.getColumnIndex2TsBlockColumnIndexList()`.
   
   The copy is required because `IoTDBRpcDataSet` prepends the tree-model time 
column in place at index 0, and the Thrift getter returns the response's 
internal list. It is null-safe so that a response without a mapping still falls 
back to the existing derivation instead of throwing.
   
   The 14-argument constructor is left in place; it still has callers in the 
metadata classes.
   
   ## Tests
   
   **Mocked-RPC unit tests** (`IoTDBTablePreparedStatementTest`) assert both 
`getInt(int)` and `getInt(String)` plus the actual values:
   
   | columns | mapping | physical | expected |
   | --- | --- | --- | --- |
   | `["b","a"]` | `[1,0]` | `[10,20]` | `[20,10]`, `b=20`, `a=10` |
   | `["x","y"]` | `[0,0]` | `[10]` | `[10,10]`, `x=10`, `y=10` (no exception) |
   | `["a","b"]` | `[0,1]` | `[10,20]` | `[10,20]` (identity control) |
   | `["a","b"]` | absent | `[10,20]` | `[10,20]` (fallback regression) |
   
   **Real-server ITs:**
   
   - `IoTDBTablePreparedStatementJDBCIT`: reordered projection, repeated 
projection/aliases, identity control, and TIMESTAMP projection (TIMESTAMP is a 
valid table-model field type and is covered as a mapped value column).
   - `IoTDBTablePreparedStatementIT`: the `PREPARE`/`EXECUTE` path with 
reordered and repeated projections.
   
   Results on this branch (TableSimpleIT, 1 ConfigNode + 1 DataNode):
   
   - `IoTDBTablePreparedStatementTest`: 12/12 pass
   - `IoTDBTablePreparedStatementJDBCIT`: 21/21 pass
   - `IoTDBTablePreparedStatementIT`: 14/14 pass
   
   Out-of-range ordinals / unknown column names returning `SQLException` is a 
separate JDBC-conformance concern and is not gated on by this fix.
   
   Closes #18846
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


-- 
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