Skip to content

Commit a5df965

Browse files
siddharthteotiakou
authored andcommitted
ARROW-1373: Implement getBuffer() methods for ValueVector
cc @jacques-n , @StevenMPhillips Patch Summary: As part of ARROW-801, we recently added getValidityBufferAddress(), getOffsetBufferAddress(), getDataBufferAddress() interfaces to get the virtual address of the ArrowBuf. We now have the following new interfaces to get the corresponding ArrowBuf: getValidityBuffer() getDataBuffer() getOffsetBuffer() Background: Currently we have getBuffer() method implemented as part of BaseDataValueVector abstract class. As part of patch for ARROW-276, NullableValueVectors no longer extends BaseDataValueVector -- they don't have to since they don't need the underlying data buffer (ArrowBuf data field) of BaseDataValueVector. The call to getBuffer() on NullableValueVectors simply delegates the operation to getBuffer() of underlying data/value vector. Problem: If a piece of code is working with ValueVector abstraction and the expected runtime type is Nullable<something>Vector, the compiler obviously complains about doing (v of type ValueVector).getBuffer(). Until now this worked as we kept the compiler happy by casting the ValueVector to BaseDataValueVector and then do ((BaseDataValueVector)(v of type ValueVector)).getBuffer(). This code broke since NullableValueVectors are no longer a subtype of BaseDataValueVector -- the inheritance hierarchy was changed as part of ARROW-276. Solution: Similar to what was done in ARROW-801, we have new methods at ValueVector interface to get the underlying buffer. ValueVector has always had the methods getBuffers(), getBufferSizeFor(), getBufferSize(), so it makes sense to augment the ValueVector interface with new APIs. It looks like new unit tests are not needed since the unit tests added for ARROW-801 test the new APIs as well --> getDataBufferAddress() underneath invokes getDataBuffer() to get the memory address of ArrowBuf so we are good. Author: siddharth <siddharth@dremio.com> Closes apache#976 from siddharthteotia/ARROW-1373 and squashes the following commits: 1ef2022 [siddharth] Fixed failures and added javadocs e5ff023 [siddharth] ARROW-1373: Implement getBuffer() methods for ValueVector
1 parent 7518c81 commit a5df965

11 files changed

Lines changed: 192 additions & 8 deletions

File tree

vector/src/main/codegen/templates/FixedValueVectors.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,24 @@ public int getBufferSizeFor(final int valueCount) {
9696
return valueCount * ${type.width};
9797
}
9898

99+
@Override
100+
public ArrowBuf getValidityBuffer() {
101+
/* this operation is not supported for non-nullable vectors */
102+
throw new UnsupportedOperationException();
103+
}
104+
105+
@Override
106+
public ArrowBuf getDataBuffer() {
107+
/* we are not throwing away getBuffer() of BaseDataValueVector so use it wherever applicable */
108+
return getBuffer();
109+
}
110+
111+
@Override
112+
public ArrowBuf getOffsetBuffer() {
113+
/* this operation is not supported for fixed-width vectors */
114+
throw new UnsupportedOperationException();
115+
}
116+
99117
@Override
100118
public int getValueCapacity(){
101119
return (int) (data.capacity() *1.0 / ${type.width});

vector/src/main/codegen/templates/NullableValueVectors.java

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ public int getBufferSizeFor(final int valueCount) {
219219
}
220220

221221
public ArrowBuf getBuffer() {
222-
return values.getBuffer();
222+
return values.getDataBuffer();
223223
}
224224

225225
@Override
@@ -437,23 +437,50 @@ public void copyFromSafe(int fromIndex, int thisIndex, ${className} from){
437437

438438
@Override
439439
public long getValidityBufferAddress() {
440-
return (bits.getBuffer().memoryAddress());
440+
/* address of the databuffer associated with the bitVector */
441+
return (bits.getDataBuffer().memoryAddress());
441442
}
442443

443444
@Override
444445
public long getDataBufferAddress() {
445-
return (values.getBuffer().memoryAddress());
446+
/* address of the dataBuffer associated with the valueVector */
447+
return (values.getDataBuffer().memoryAddress());
446448
}
447449

448450
@Override
449451
public long getOffsetBufferAddress() {
452+
/* address of the dataBuffer associated with the offsetVector
453+
* this operation is not supported for fixed-width vector types.
454+
*/
450455
<#if type.major != "VarLen">
451456
throw new UnsupportedOperationException();
452457
<#else>
453458
return (values.getOffsetAddr());
454459
</#if>
455460
}
456461

462+
@Override
463+
public ArrowBuf getValidityBuffer() {
464+
/* dataBuffer associated with the bitVector */
465+
return (bits.getDataBuffer());
466+
}
467+
468+
@Override
469+
public ArrowBuf getDataBuffer() {
470+
/* dataBuffer associated with the valueVector */
471+
return (values.getDataBuffer());
472+
}
473+
474+
@Override
475+
public ArrowBuf getOffsetBuffer() {
476+
/* dataBuffer associated with the offsetVector of the valueVector */
477+
<#if type.major != "VarLen">
478+
throw new UnsupportedOperationException();
479+
<#else>
480+
return (values.getOffsetBuffer());
481+
</#if>
482+
}
483+
457484
public final class Accessor extends BaseDataValueVector.BaseAccessor <#if type.major = "VarLen">implements VariableWidthVector.VariableWidthAccessor</#if> {
458485
final BitVector.Accessor bAccessor = bits.getAccessor();
459486
final ${valuesName}.Accessor vAccessor = values.getAccessor();

vector/src/main/codegen/templates/UnionVector.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ private <T extends FieldVector> T addOrGet(MinorType minorType, Class<T> c) {
134134

135135
@Override
136136
public long getValidityBufferAddress() {
137-
return typeVector.getBuffer().memoryAddress();
137+
return typeVector.getDataBuffer().memoryAddress();
138138
}
139139

140140
@Override
@@ -147,6 +147,15 @@ public long getOffsetBufferAddress() {
147147
throw new UnsupportedOperationException();
148148
}
149149

150+
@Override
151+
public ArrowBuf getValidityBuffer() { return typeVector.getDataBuffer(); }
152+
153+
@Override
154+
public ArrowBuf getDataBuffer() { throw new UnsupportedOperationException(); }
155+
156+
@Override
157+
public ArrowBuf getOffsetBuffer() { throw new UnsupportedOperationException(); }
158+
150159
public NullableMapVector getMap() {
151160
if (mapVector == null) {
152161
int vectorCount = internalMap.size();

vector/src/main/codegen/templates/VariableLengthVectors.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,24 @@ public int getBufferSizeFor(final int valueCount) {
123123
return offsetVector.getBufferSizeFor(valueCount + 1) + idx;
124124
}
125125

126+
@Override
127+
public ArrowBuf getValidityBuffer() {
128+
/* this operation is not supported for non-nullable vectors */
129+
throw new UnsupportedOperationException();
130+
}
131+
132+
@Override
133+
public ArrowBuf getDataBuffer() {
134+
/* we are not throwing away getBuffer() of BaseDataValueVector so use it wherever applicable */
135+
return getBuffer();
136+
}
137+
138+
@Override
139+
public ArrowBuf getOffsetBuffer() {
140+
/* dataBuffer associated with the underlying offsetVector */
141+
return offsetVector.getDataBuffer();
142+
}
143+
126144
@Override
127145
public int getValueCapacity(){
128146
return Math.max(offsetVector.getValueCapacity() - 1, 0);
@@ -170,7 +188,7 @@ public ArrowBuf[] getBuffers(boolean clear) {
170188
}
171189

172190
public long getOffsetAddr(){
173-
return offsetVector.getBuffer().memoryAddress();
191+
return offsetVector.getDataBuffer().memoryAddress();
174192
}
175193

176194
public UInt${type.width}Vector getOffsetVector(){

vector/src/main/java/org/apache/arrow/vector/BitVector.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,24 @@ public int getBufferSizeFor(final int valueCount) {
110110
return getSizeFromCount(valueCount);
111111
}
112112

113+
@Override
114+
public ArrowBuf getValidityBuffer() {
115+
/* this operation is not supported for non-nullable vectors */
116+
throw new UnsupportedOperationException();
117+
}
118+
119+
@Override
120+
public ArrowBuf getDataBuffer() {
121+
/* we are not throwing away getBuffer() of BaseDataValueVector so use it wherever applicable */
122+
return getBuffer();
123+
}
124+
125+
@Override
126+
public ArrowBuf getOffsetBuffer() {
127+
/* this operation is not supported for fixed-width vectors */
128+
throw new UnsupportedOperationException();
129+
}
130+
113131
int getSizeFromCount(int valueCount) {
114132
return (int) Math.ceil(valueCount / 8.0);
115133
}

vector/src/main/java/org/apache/arrow/vector/ValueVector.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,4 +234,25 @@ interface Mutator {
234234
@Deprecated
235235
void generateTestData(int values);
236236
}
237+
238+
/**
239+
* Gets the underlying buffer associated with validity vector
240+
*
241+
* @return buffer
242+
*/
243+
public ArrowBuf getValidityBuffer();
244+
245+
/**
246+
* Gets the underlying buffer associated with data vector
247+
*
248+
* @return buffer
249+
*/
250+
public ArrowBuf getDataBuffer();
251+
252+
/**
253+
* Gets the underlying buffer associated with offset vector
254+
*
255+
* @return buffer
256+
*/
257+
public ArrowBuf getOffsetBuffer();
237258
}

vector/src/main/java/org/apache/arrow/vector/ZeroVector.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,4 +244,19 @@ public long getDataBufferAddress() {
244244
public long getOffsetBufferAddress() {
245245
throw new UnsupportedOperationException();
246246
}
247+
248+
@Override
249+
public ArrowBuf getValidityBuffer() {
250+
throw new UnsupportedOperationException();
251+
}
252+
253+
@Override
254+
public ArrowBuf getDataBuffer() {
255+
throw new UnsupportedOperationException();
256+
}
257+
258+
@Override
259+
public ArrowBuf getOffsetBuffer() {
260+
throw new UnsupportedOperationException();
261+
}
247262
}

vector/src/main/java/org/apache/arrow/vector/complex/FixedSizeListVector.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ public UnionVector promoteToUnion() {
295295

296296
@Override
297297
public long getValidityBufferAddress() {
298-
return (bits.getBuffer().memoryAddress());
298+
return (bits.getDataBuffer().memoryAddress());
299299
}
300300

301301
@Override
@@ -308,6 +308,21 @@ public long getOffsetBufferAddress() {
308308
throw new UnsupportedOperationException();
309309
}
310310

311+
@Override
312+
public ArrowBuf getValidityBuffer() {
313+
return (bits.getDataBuffer());
314+
}
315+
316+
@Override
317+
public ArrowBuf getDataBuffer() {
318+
throw new UnsupportedOperationException();
319+
}
320+
321+
@Override
322+
public ArrowBuf getOffsetBuffer() {
323+
throw new UnsupportedOperationException();
324+
}
325+
311326
public class Accessor extends BaseValueVector.BaseAccessor {
312327

313328
@Override

vector/src/main/java/org/apache/arrow/vector/complex/ListVector.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ public TransferPair makeTransferPair(ValueVector target) {
180180

181181
@Override
182182
public long getValidityBufferAddress() {
183-
return (bits.getBuffer().memoryAddress());
183+
return (bits.getDataBuffer().memoryAddress());
184184
}
185185

186186
@Override
@@ -190,9 +190,20 @@ public long getDataBufferAddress() {
190190

191191
@Override
192192
public long getOffsetBufferAddress() {
193-
return (offsets.getBuffer().memoryAddress());
193+
return (offsets.getDataBuffer().memoryAddress());
194194
}
195195

196+
@Override
197+
public ArrowBuf getValidityBuffer() { return bits.getDataBuffer(); }
198+
199+
@Override
200+
public ArrowBuf getDataBuffer() {
201+
throw new UnsupportedOperationException();
202+
}
203+
204+
@Override
205+
public ArrowBuf getOffsetBuffer() { return offsets.getDataBuffer(); }
206+
196207
private class TransferImpl implements TransferPair {
197208

198209
ListVector to;

vector/src/main/java/org/apache/arrow/vector/complex/MapVector.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
import com.google.common.collect.Ordering;
3333
import com.google.common.primitives.Ints;
3434

35+
import io.netty.buffer.ArrowBuf;
36+
3537
import org.apache.arrow.memory.BufferAllocator;
3638
import org.apache.arrow.vector.BaseValueVector;
3739
import org.apache.arrow.vector.FieldVector;
@@ -129,6 +131,21 @@ public int getBufferSizeFor(final int valueCount) {
129131
return (int) bufferSize;
130132
}
131133

134+
@Override
135+
public ArrowBuf getValidityBuffer() {
136+
throw new UnsupportedOperationException();
137+
}
138+
139+
@Override
140+
public ArrowBuf getDataBuffer() {
141+
throw new UnsupportedOperationException();
142+
}
143+
144+
@Override
145+
public ArrowBuf getOffsetBuffer() {
146+
throw new UnsupportedOperationException();
147+
}
148+
132149
@Override
133150
public TransferPair getTransferPair(BufferAllocator allocator) {
134151
return getTransferPair(name, allocator, null);

0 commit comments

Comments
 (0)