Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH-41272: [Java] LargeListViewVector Implementation #43516

Merged
merged 14 commits into from
Aug 9, 2024
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
}
]
}
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:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ListView is also referenced on lines 163, 187, 210. Do we need to add LargeListView there, too?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, good point. Arrow Java legacy implementation doesn't seem to support 64-bit cases.The places where I dropped it are similar in that regard. But in case I have really missed, please correct me 😌

case FIXED_SIZE_LIST:
if (reader.isSet()) {
writer.startList();
Expand Down
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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ListView is also referenced on lines 279, 344, 389, 575. Do we need to add LargeListView, too?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as the above point.

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;
}

vibhatha marked this conversation as resolved.
Show resolved Hide resolved
@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
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
Loading