Skip to content

Commit

Permalink
GH-41272: [Java] LargeListViewVector Implementation (#43516)
Browse files Browse the repository at this point in the history
### Rationale for this change

This PR includes the initial integration of `LargeListViewVector`. 

### What changes are included in this PR?

This PR includes the core functions associated with the `LargeListViewVector`. 

### Are these changes tested?

Yes.

### Are there any user-facing changes?

No

* GitHub Issue: #41272

Authored-by: Vibhatha Abeykoon <vibhatha@gmail.com>
Signed-off-by: David Li <li.davidm96@gmail.com>
  • Loading branch information
vibhatha authored Aug 9, 2024
1 parent 6f605ec commit b33f040
Show file tree
Hide file tree
Showing 18 changed files with 3,225 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -284,4 +284,9 @@ public ColumnBinder visit(ArrowType.Duration type) {
public ColumnBinder visit(ArrowType.ListView type) {
throw new UnsupportedOperationException("No column binder implemented for type " + type);
}

@Override
public ColumnBinder visit(ArrowType.LargeListView type) {
throw new UnsupportedOperationException("No column binder implemented for type " + type);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -403,4 +403,10 @@ public List<ArrowBuf> visit(ArrowType.ListView type) {
throw new UnsupportedOperationException(
"Importing buffers for view type: " + type + " not supported");
}

@Override
public List<ArrowBuf> visit(ArrowType.LargeListView type) {
throw new UnsupportedOperationException(
"Importing buffers for view type: " + type + " not supported");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -276,5 +276,10 @@ public Boolean visit(ArrowType.Duration type) {
public Boolean visit(ArrowType.ListView type) {
throw new UnsupportedOperationException("Binding is not yet supported for type " + type);
}

@Override
public Boolean visit(ArrowType.LargeListView type) {
throw new UnsupportedOperationException("Binding is not yet supported for type " + type);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -278,5 +278,11 @@ public AvaticaParameter visit(ArrowType.ListView type) {
throw new UnsupportedOperationException(
"AvaticaParameter not yet supported for type " + type);
}

@Override
public AvaticaParameter visit(ArrowType.LargeListView type) {
throw new UnsupportedOperationException(
"AvaticaParameter not yet supported for type " + type);
}
}
}
5 changes: 5 additions & 0 deletions java/vector/src/main/codegen/data/ArrowTypes.tdd
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@
name: "ListView",
fields: [],
complex: true
},
{
name: "LargeListView",
fields: [],
complex: true
}
]
}
1 change: 1 addition & 0 deletions java/vector/src/main/codegen/templates/ComplexCopier.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ private static void writeValue(FieldReader reader, FieldWriter writer) {
case LIST:
case LISTVIEW:
case LARGELIST:
case LARGELISTVIEW:
case FIXED_SIZE_LIST:
if (reader.isSet()) {
writer.startList();
Expand Down
13 changes: 12 additions & 1 deletion java/vector/src/main/codegen/templates/PromotableViewWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ public PromotableViewWriter(ValueVector v, ListViewVector listViewVector,
super(v, listViewVector, nullableStructWriterFactory);
}

public PromotableViewWriter(ValueVector v, LargeListViewVector largeListViewVector) {
super(v, largeListViewVector);
}

public PromotableViewWriter(ValueVector v, LargeListViewVector largeListViewVector,
NullableStructWriterFactory nullableStructWriterFactory) {
super(v, largeListViewVector, nullableStructWriterFactory);
}

public PromotableViewWriter(ValueVector v, AbstractStructVector parentContainer) {
super(v, parentContainer);
}
Expand Down Expand Up @@ -103,8 +112,10 @@ protected FieldWriter getWriter(MinorType type, ArrowType arrowType) {
v = fixedListVector.addOrGetVector(fieldType).getVector();
} else if (listViewVector != null) {
v = listViewVector.addOrGetVector(fieldType).getVector();
} else {
} else if (largeListVector != null) {
v = largeListVector.addOrGetVector(fieldType).getVector();
} else {
v = largeListViewVector.addOrGetVector(fieldType).getVector();
}
v.allocateNew();
setWriter(v);
Expand Down
47 changes: 47 additions & 0 deletions java/vector/src/main/codegen/templates/PromotableWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public class PromotableWriter extends AbstractPromotableFieldWriter {
protected final ListViewVector listViewVector;
protected final FixedSizeListVector fixedListVector;
protected final LargeListVector largeListVector;
protected final LargeListViewVector largeListViewVector;
protected final NullableStructWriterFactory nullableStructWriterFactory;
protected int position;
protected static final int MAX_DECIMAL_PRECISION = 38;
Expand Down Expand Up @@ -84,6 +85,7 @@ public PromotableWriter(
this.listViewVector = null;
this.fixedListVector = null;
this.largeListVector = null;
this.largeListViewVector = null;
this.nullableStructWriterFactory = nullableStructWriterFactory;
init(v);
}
Expand Down Expand Up @@ -118,6 +120,26 @@ public PromotableWriter(ValueVector v, LargeListVector largeListVector) {
this(v, largeListVector, NullableStructWriterFactory.getNullableStructWriterFactoryInstance());
}

/**
* Constructs a new instance.
*
* @param v The vector to initialize the writer with.
* @param listViewVector The vector that serves as a parent of v.
*/
public PromotableWriter(ValueVector v, ListViewVector listViewVector) {
this(v, listViewVector, NullableStructWriterFactory.getNullableStructWriterFactoryInstance());
}

/**
* Constructs a new instance.
*
* @param v The vector to initialize the writer with.
* @param largeListViewVector The vector that serves as a parent of v.
*/
public PromotableWriter(ValueVector v, LargeListViewVector largeListViewVector) {
this(v, largeListViewVector, NullableStructWriterFactory.getNullableStructWriterFactoryInstance());
}

/**
* Constructs a new instance.
*
Expand All @@ -134,6 +156,7 @@ public PromotableWriter(
this.parentContainer = null;
this.fixedListVector = null;
this.largeListVector = null;
this.largeListViewVector = null;
this.nullableStructWriterFactory = nullableStructWriterFactory;
init(v);
}
Expand All @@ -154,6 +177,7 @@ public PromotableWriter(
this.parentContainer = null;
this.fixedListVector = null;
this.largeListVector = null;
this.largeListViewVector = null;
this.nullableStructWriterFactory = nullableStructWriterFactory;
init(v);
}
Expand All @@ -174,6 +198,7 @@ public PromotableWriter(
this.listVector = null;
this.listViewVector = null;
this.largeListVector = null;
this.largeListViewVector = null;
this.nullableStructWriterFactory = nullableStructWriterFactory;
init(v);
}
Expand All @@ -194,6 +219,28 @@ public PromotableWriter(
this.parentContainer = null;
this.listVector = null;
this.listViewVector = null;
this.largeListViewVector = null;
this.nullableStructWriterFactory = nullableStructWriterFactory;
init(v);
}

/**
* Constructs a new instance.
*
* @param v The vector to initialize the writer with.
* @param largeListViewVector The vector that serves as a parent of v.
* @param nullableStructWriterFactory The factory to create the delegate writer.
*/
public PromotableWriter(
ValueVector v,
LargeListViewVector largeListViewVector,
NullableStructWriterFactory nullableStructWriterFactory) {
this.largeListViewVector = largeListViewVector;
this.fixedListVector = null;
this.parentContainer = null;
this.listVector = null;
this.listViewVector = null;
this.largeListVector = null;
this.nullableStructWriterFactory = nullableStructWriterFactory;
init(v);
}
Expand Down
48 changes: 44 additions & 4 deletions java/vector/src/main/codegen/templates/UnionListWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import java.math.BigDecimal;

<@pp.dropOutputFile />
<#list ["List", "ListView", "LargeList"] as listName>
<#list ["List", "ListView", "LargeList", "LargeListView"] as listName>
<@pp.changeOutputFile name="/org/apache/arrow/vector/complex/impl/Union${listName}Writer.java" />
Expand All @@ -53,23 +53,26 @@ public class Union${listName}Writer extends AbstractFieldWriter {
private boolean inStruct = false;
private boolean listStarted = false;
private String structName;
<#if listName == "LargeList">
<#if listName == "LargeList" || listName == "LargeListView">
private static final long OFFSET_WIDTH = 8;
<#else>
private static final int OFFSET_WIDTH = 4;
</#if>

<#if listName = "ListView">
<#if listName == "ListView">
private static final long SIZE_WIDTH = 4;
</#if>
<#if listName == "LargeListView">
private static final long SIZE_WIDTH = 8;
</#if>

public Union${listName}Writer(${listName}Vector vector) {
this(vector, NullableStructWriterFactory.getNullableStructWriterFactoryInstance());
}

public Union${listName}Writer(${listName}Vector vector, NullableStructWriterFactory nullableStructWriterFactory) {
this.vector = vector;
<#if listName = "ListView">
<#if listName = "ListView" || listName = "LargeListView">
this.writer = new PromotableViewWriter(vector.getDataVector(), vector, nullableStructWriterFactory);
<#else>
this.writer = new PromotableWriter(vector.getDataVector(), vector, nullableStructWriterFactory);
Expand Down Expand Up @@ -231,12 +234,49 @@ public void endList() {
listStarted = false;
}
@Override
public void startListView() {
vector.startNewValue(idx());
writer.setPosition(vector.getOffsetBuffer().getInt((idx()) * OFFSET_WIDTH));
listStarted = true;
}
@Override
public void endListView() {
int sizeUptoIdx = 0;
for (int i = 0; i < idx(); i++) {
sizeUptoIdx += vector.getSizeBuffer().getInt(i * SIZE_WIDTH);
}
vector.getSizeBuffer().setInt(idx() * SIZE_WIDTH, writer.idx() - sizeUptoIdx);
setPosition(idx() + 1);
listStarted = false;
}
<#elseif listName == "LargeListView">
@Override
public void startList() {
vector.startNewValue(idx());
writer.setPosition(vector.getOffsetBuffer().getInt((idx()) * OFFSET_WIDTH));
listStarted = true;
}
@Override
public void endList() {
int sizeUptoIdx = 0;
for (int i = 0; i < idx(); i++) {
sizeUptoIdx += vector.getSizeBuffer().getInt(i * SIZE_WIDTH);
}
vector.getSizeBuffer().setInt(idx() * SIZE_WIDTH, writer.idx() - sizeUptoIdx);
setPosition(idx() + 1);
listStarted = false;
}
@Override
public void startListView() {
vector.startNewValue(idx());
writer.setPosition(checkedCastToInt(vector.getOffsetBuffer().getInt((idx()) * OFFSET_WIDTH)));
listStarted = true;
}
@Override
public void endListView() {
int sizeUptoIdx = 0;
Expand Down
2 changes: 1 addition & 1 deletion java/vector/src/main/codegen/templates/UnionReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
@SuppressWarnings("unused")
public class UnionReader extends AbstractFieldReader {

private static final int NUM_SUPPORTED_TYPES = 49;
private static final int NUM_SUPPORTED_TYPES = 50;

private BaseReader[] readers = new BaseReader[NUM_SUPPORTED_TYPES];
public UnionVector data;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public String getName() {
private static final BufferLayout VALUES_32 = new BufferLayout(BufferType.DATA, 32);
private static final BufferLayout VALUES_16 = new BufferLayout(BufferType.DATA, 16);
private static final BufferLayout VALUES_8 = new BufferLayout(BufferType.DATA, 8);
private static final BufferLayout LARGE_SIZE_BUFFER = new BufferLayout(BufferType.SIZE, 64);
private static final BufferLayout SIZE_BUFFER = new BufferLayout(BufferType.SIZE, 32);
private static final BufferLayout VIEW_BUFFER = new BufferLayout(BufferType.VIEWS, 16);

Expand All @@ -80,6 +81,10 @@ public static BufferLayout sizeBuffer() {
return SIZE_BUFFER;
}

public static BufferLayout largeSizeBuffer() {
return LARGE_SIZE_BUFFER;
}

/**
* Returns a databuffer for the given bitwidth. Only supports powers of two between 8 and 128
* inclusive.
Expand Down
16 changes: 16 additions & 0 deletions java/vector/src/main/java/org/apache/arrow/vector/TypeLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,16 @@ public TypeLayout visit(ArrowType.ListView type) {
return new TypeLayout(vectors);
}

@Override
public TypeLayout visit(ArrowType.LargeListView type) {
List<BufferLayout> vectors =
asList(
BufferLayout.validityVector(),
BufferLayout.largeOffsetBuffer(),
BufferLayout.largeSizeBuffer());
return new TypeLayout(vectors);
}

@Override
public TypeLayout visit(ArrowType.LargeList type) {
List<BufferLayout> vectors =
Expand Down Expand Up @@ -340,6 +350,12 @@ public Integer visit(ArrowType.LargeList type) {
return 2;
}

@Override
public Integer visit(ArrowType.LargeListView type) {
// validity buffer + offset buffer + size buffer
return 3;
}

@Override
public Integer visit(FixedSizeList type) {
// validity buffer
Expand Down
Loading

0 comments on commit b33f040

Please sign in to comment.