|
26 | 26 | import org.apache.arrow.driver.jdbc.utils.SqlTypes; |
27 | 27 | import org.apache.arrow.memory.util.LargeMemoryUtil; |
28 | 28 | import org.apache.arrow.vector.FieldVector; |
| 29 | +import org.apache.arrow.vector.IntVector; |
29 | 30 | import org.apache.arrow.vector.ValueVector; |
30 | 31 | import org.apache.arrow.vector.VectorSchemaRoot; |
31 | 32 | import org.apache.arrow.vector.types.pojo.ArrowType; |
@@ -135,12 +136,22 @@ public ResultSet getResultSet(long index, int count) throws SQLException { |
135 | 136 |
|
136 | 137 | private static ResultSet getResultSetNoBoundariesCheck( |
137 | 138 | ValueVector dataVector, long start, long count) throws SQLException { |
| 139 | + int intStart = LargeMemoryUtil.checkedCastToInt(start); |
| 140 | + int intCount = LargeMemoryUtil.checkedCastToInt(count); |
| 141 | + |
| 142 | + // Create an index vector with 1-based indices (per JDBC spec) to return with value vector |
| 143 | + IntVector indexVector = new IntVector("INDEX", dataVector.getAllocator()); |
| 144 | + indexVector.allocateNew(intCount); |
| 145 | + for (int i = 0; i < intCount; i++) { |
| 146 | + indexVector.set(i, i + 1); |
| 147 | + } |
| 148 | + indexVector.setValueCount(intCount); |
| 149 | + |
138 | 150 | TransferPair transferPair = dataVector.getTransferPair(dataVector.getAllocator()); |
139 | | - transferPair.splitAndTransfer( |
140 | | - LargeMemoryUtil.checkedCastToInt(start), LargeMemoryUtil.checkedCastToInt(count)); |
141 | | - FieldVector vectorSlice = (FieldVector) transferPair.getTo(); |
| 151 | + transferPair.splitAndTransfer(intStart, intCount); |
| 152 | + FieldVector valueVector = (FieldVector) transferPair.getTo(); |
142 | 153 |
|
143 | | - VectorSchemaRoot vectorSchemaRoot = VectorSchemaRoot.of(vectorSlice); |
| 154 | + VectorSchemaRoot vectorSchemaRoot = VectorSchemaRoot.of(indexVector, valueVector); |
144 | 155 | return ArrowFlightJdbcVectorSchemaRootResultSet.fromVectorSchemaRoot(vectorSchemaRoot); |
145 | 156 | } |
146 | 157 |
|
|
0 commit comments