Skip to content

Commit

Permalink
GH-38511: [Java] Add getTransferPair(Field, BufferAllocator, CallBack…
Browse files Browse the repository at this point in the history
…) for StructVector and MapVector (#38512)

### Rationale for this change
Missed impl of getTransferPair(Field, BufferAllocator, CallBack) for StructVector and MapVector

### What changes are included in this PR?

### Are these changes tested?
yes, added unit test.

### Are there any user-facing changes?

* Closes: #38511

Authored-by: Ivan Chesnov <ivan.chesnov@dremio.com>
Signed-off-by: David Li <li.davidm96@gmail.com>
  • Loading branch information
xxlaykxx authored Nov 1, 2023
1 parent 5d6192c commit 87a1852
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@ public TransferPair getTransferPair(String ref, BufferAllocator allocator, CallB
return new TransferImpl(ref, allocator, callBack);
}

@Override
public TransferPair getTransferPair(Field field, BufferAllocator allocator, CallBack callBack) {
return new TransferImpl(field, allocator, callBack);
}

@Override
public TransferPair makeTransferPair(ValueVector target) {
return new MapVector.TransferImpl((MapVector) target);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,15 @@ public TransferPair getTransferPair(Field field, BufferAllocator allocator) {
allowConflictPolicyChanges), false);
}

@Override
public TransferPair getTransferPair(Field field, BufferAllocator allocator, CallBack callBack) {
return new NullableStructTransferPair(this, new StructVector(field,
allocator,
callBack,
getConflictPolicy(),
allowConflictPolicyChanges), false);
}

/**
* {@link TransferPair} for this (nullable) {@link StructVector}.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1155,4 +1155,27 @@ public void testGetTransferPairWithField() {
toVector.clear();
}
}

@Test
public void testGetTransferPairWithFieldAndCallBack() {
SchemaChangeCallBack callBack = new SchemaChangeCallBack();
try (MapVector mapVector = MapVector.empty("mapVector", allocator, false)) {

FieldType type = new FieldType(false, ArrowType.Struct.INSTANCE, null, null);
AddOrGetResult<StructVector> addResult = mapVector.addOrGetVector(type);
FieldType keyType = new FieldType(false, MinorType.BIGINT.getType(), null, null);
FieldType valueType = FieldType.nullable(MinorType.FLOAT8.getType());
addResult.getVector().addOrGet(MapVector.KEY_NAME, keyType, BigIntVector.class);
addResult.getVector().addOrGet(MapVector.VALUE_NAME, valueType, Float8Vector.class);
mapVector.allocateNew();
mapVector.setValueCount(0);

assertEquals(-1, mapVector.getLastSet());
TransferPair tp = mapVector.getTransferPair(mapVector.getField(), allocator, callBack);
tp.transfer();
MapVector toVector = (MapVector) tp.getTo();
assertSame(toVector.getField(), mapVector.getField());
toVector.clear();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,18 @@ public void testGetTransferPair() {
}
}

@Test
public void testGetTransferPairWithFieldAndCallBack() {
SchemaChangeCallBack callBack = new SchemaChangeCallBack();
try (final StructVector fromVector = simpleStructVector("s1", allocator)) {
TransferPair tp = fromVector.getTransferPair(fromVector.getField(), allocator, callBack);
final StructVector toVector = (StructVector) tp.getTo();
// Field inside a new vector created by reusing a field should be the same in memory as the original field.
assertSame(toVector.getField(), fromVector.getField());
toVector.clear();
}
}

private StructVector simpleStructVector(String name, BufferAllocator allocator) {
final String INT_COL = "struct_int_child";
final String FLT_COL = "struct_flt_child";
Expand Down

0 comments on commit 87a1852

Please sign in to comment.