Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions java/vector/src/main/codegen/templates/NullableValueVectors.java
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,25 @@ public void copyFromSafe(int fromIndex, int thisIndex, ${className} from){
<#if type.major == "VarLen">mutator.lastSet = thisIndex;</#if>
}

@Override
public long getValidityBufferAddress() {
return (bits.getBuffer().memoryAddress());
}

@Override
public long getDataBufferAddress() {
return (values.getBuffer().memoryAddress());
}

@Override
public long getOffsetBufferAddress() {
<#if type.major != "VarLen">
throw new UnsupportedOperationException();
<#else>
return (values.getOffsetAddr());
</#if>
}

public final class Accessor extends BaseDataValueVector.BaseAccessor <#if type.major = "VarLen">implements VariableWidthVector.VariableWidthAccessor</#if> {
final BitVector.Accessor bAccessor = bits.getAccessor();
final ${valuesName}.Accessor vAccessor = values.getAccessor();
Expand Down
15 changes: 15 additions & 0 deletions java/vector/src/main/codegen/templates/UnionVector.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,21 @@ private <T extends FieldVector> T addOrGet(MinorType minorType, Class<T> c) {
return internalMap.addOrGet(fieldName(minorType), fieldType(minorType), c);
}

@Override
public long getValidityBufferAddress() {
return typeVector.getBuffer().memoryAddress();
}

@Override
public long getDataBufferAddress() {
throw new UnsupportedOperationException();
}

@Override
public long getOffsetBufferAddress() {
throw new UnsupportedOperationException();
}

public NullableMapVector getMap() {
if (mapVector == null) {
int vectorCount = internalMap.size();
Expand Down
21 changes: 21 additions & 0 deletions java/vector/src/main/java/org/apache/arrow/vector/FieldVector.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,25 @@ public interface FieldVector extends ValueVector {
* @return the inner vectors for this field as defined by the TypeLayout
*/
List<BufferBacked> getFieldInnerVectors();

/**
* Gets the starting address of the underlying buffer associated with validity vector
*
* @return buffer address
*/
public long getValidityBufferAddress();

/**
* Gets the starting address of the underlying buffer associated with data vector
*
* @return buffer address
*/
public long getDataBufferAddress();

/**
* Gets the starting address of the underlying buffer associated with offset vector
*
* @return buffer address
*/
public long getOffsetBufferAddress();
}
15 changes: 15 additions & 0 deletions java/vector/src/main/java/org/apache/arrow/vector/ZeroVector.java
Original file line number Diff line number Diff line change
Expand Up @@ -229,4 +229,19 @@ public List<ArrowBuf> getFieldBuffers() {
public List<BufferBacked> getFieldInnerVectors() {
return Collections.emptyList();
}

@Override
public long getValidityBufferAddress() {
throw new UnsupportedOperationException();
}

@Override
public long getDataBufferAddress() {
throw new UnsupportedOperationException();
}

@Override
public long getOffsetBufferAddress() {
throw new UnsupportedOperationException();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,21 @@ public UnionVector promoteToUnion() {
return vector;
}

@Override
public long getValidityBufferAddress() {
return (bits.getBuffer().memoryAddress());
}

@Override
public long getDataBufferAddress() {
throw new UnsupportedOperationException();
}

@Override
public long getOffsetBufferAddress() {
throw new UnsupportedOperationException();
}

public class Accessor extends BaseValueVector.BaseAccessor {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,21 @@ public TransferPair makeTransferPair(ValueVector target) {
return new TransferImpl((ListVector) target);
}

@Override
public long getValidityBufferAddress() {
return (bits.getBuffer().memoryAddress());
}

@Override
public long getDataBufferAddress() {
throw new UnsupportedOperationException();
}

@Override
public long getOffsetBufferAddress() {
return (offsets.getBuffer().memoryAddress());
}

private class TransferImpl implements TransferPair {

ListVector to;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,21 @@ public void reAlloc() {
super.reAlloc();
}

@Override
public long getValidityBufferAddress() {
return bits.getBuffer().memoryAddress();
}

@Override
public long getDataBufferAddress() {
throw new UnsupportedOperationException();
}

@Override
public long getOffsetBufferAddress() {
throw new UnsupportedOperationException();
}

public final class Accessor extends MapVector.Accessor {
final BitVector.Accessor bAccessor = bits.getAccessor();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
import java.util.ArrayList;
import java.util.List;

import io.netty.buffer.ArrowBuf;


public class TestListVector {

Expand Down Expand Up @@ -436,14 +438,14 @@ public void testSplitAndTransfer() throws Exception {
dataLength2 = offsetAccessor1.get(i + 1) - offsetAccessor1.get(i);

assertEquals("Different data lengths at index: " + i + " and start: " + start,
dataLength1, dataLength2);
dataLength1, dataLength2);

offset1 = offsetAccessor.get(start + i);
offset2 = offsetAccessor1.get(i);

for (int j = 0; j < dataLength1; j++) {
assertEquals("Different data at indexes: " + offset1 + " and " + offset2,
valueAccessor.getObject(offset1), valueAccessor1.getObject(offset2));
valueAccessor.getObject(offset1), valueAccessor1.getObject(offset2));

offset1++;
offset2++;
Expand Down Expand Up @@ -569,4 +571,61 @@ public void testNestedListVector() throws Exception {
assertEquals(5, offsetAccessor.get(2));
}
}

@Test
public void testGetBufferAddress() throws Exception {
try (ListVector listVector = ListVector.empty("vector", allocator)) {

UnionListWriter listWriter = listVector.getWriter();
boolean error = false;

listWriter.allocate();

listWriter.setPosition(0);
listWriter.startList();
listWriter.bigInt().writeBigInt(50);
listWriter.bigInt().writeBigInt(100);
listWriter.bigInt().writeBigInt(200);
listWriter.endList();

listWriter.setPosition(1);
listWriter.startList();
listWriter.bigInt().writeBigInt(250);
listWriter.bigInt().writeBigInt(300);
listWriter.endList();

final ListVector.Accessor accessor = listVector.getAccessor();

/* check listVector contents */
Object result = accessor.getObject(0);
ArrayList<Long> resultSet = (ArrayList<Long>) result;
assertEquals(3, resultSet.size());
assertEquals(new Long(50), resultSet.get(0));
assertEquals(new Long(100), resultSet.get(1));
assertEquals(new Long(200), resultSet.get(2));

result = accessor.getObject(1);
resultSet = (ArrayList<Long>) result;
assertEquals(2, resultSet.size());
assertEquals(new Long(250), resultSet.get(0));
assertEquals(new Long(300), resultSet.get(1));

List<ArrowBuf> buffers = listVector.getFieldBuffers();

long bitAddress = listVector.getValidityBufferAddress();
long offsetAddress = listVector.getOffsetBufferAddress();

try {
long dataAddress = listVector.getDataBufferAddress();
} catch (UnsupportedOperationException ue) {
error = true;
} finally {
assertTrue(error);
}

assertEquals(2, buffers.size());
assertEquals(bitAddress, buffers.get(0).memoryAddress());
assertEquals(offsetAddress, buffers.get(1).memoryAddress());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
package org.apache.arrow.vector;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import java.util.List;

import org.apache.arrow.memory.BufferAllocator;
import org.apache.arrow.vector.complex.UnionVector;
Expand All @@ -33,6 +36,8 @@
import org.junit.Before;
import org.junit.Test;

import io.netty.buffer.ArrowBuf;

public class TestUnionVector {
private final static String EMPTY_SCHEMA_PATH = "";

Expand Down Expand Up @@ -292,6 +297,71 @@ public void testSplitAndTransferWithMixedVectors() throws Exception {
}
}

@Test
public void testGetBufferAddress() throws Exception {
try (UnionVector vector = new UnionVector(EMPTY_SCHEMA_PATH, allocator, null)) {
final UnionVector.Mutator mutator = vector.getMutator();
final UnionVector.Accessor accessor = vector.getAccessor();
boolean error = false;

vector.allocateNew();

/* populate the UnionVector */
mutator.setType(0, MinorType.INT);
mutator.setSafe(0, newIntHolder(5));

mutator.setType(1, MinorType.FLOAT4);
mutator.setSafe(1, newFloat4Holder(5.5f));

mutator.setType(2, MinorType.INT);
mutator.setSafe(2, newIntHolder(10));

mutator.setType(3, MinorType.FLOAT4);
mutator.setSafe(3, newFloat4Holder(10.5f));

mutator.setValueCount(10);

/* check the vector output */
assertEquals(10, accessor.getValueCount());
assertEquals(false, accessor.isNull(0));
assertEquals(5, accessor.getObject(0));
assertEquals(false, accessor.isNull(1));
assertEquals(5.5f, accessor.getObject(1));
assertEquals(false, accessor.isNull(2));
assertEquals(10, accessor.getObject(2));
assertEquals(false, accessor.isNull(3));
assertEquals(10.5f, accessor.getObject(3));

List<ArrowBuf> buffers = vector.getFieldBuffers();

long bitAddress = vector.getValidityBufferAddress();

try {
long offsetAddress = vector.getOffsetBufferAddress();
}
catch (UnsupportedOperationException ue) {
error = true;
}
finally {
assertTrue(error);
error = false;
}

try {
long dataAddress = vector.getDataBufferAddress();
}
catch (UnsupportedOperationException ue) {
error = true;
}
finally {
assertTrue(error);
}

assertEquals(1, buffers.size());
assertEquals(bitAddress, buffers.get(0).memoryAddress());
}
}

private static NullableIntHolder newIntHolder(int value) {
final NullableIntHolder holder = new NullableIntHolder();
holder.isSet = 1;
Expand Down
Loading