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-41569: [Java] ListViewVector Implementation for UnionListViewReader #43077

Merged
merged 37 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
fa7bbf4
fix: upgrade to junit5
vibhatha Jun 6, 2024
815de1e
feat: initial partial commit
vibhatha Jun 7, 2024
96f82f8
feat: adding rest of the test cases: snapshot 1: requires transferPai…
vibhatha Jun 7, 2024
3ff5a85
fix: adding intermediate transferPair function
vibhatha Jun 11, 2024
1c73d48
fix: refactor utils
vibhatha Jun 11, 2024
681ee28
fix: addressing split and transfer initial release
vibhatha Jun 11, 2024
260cf5d
fix: refactor util locations
vibhatha Jun 28, 2024
c5daa57
fix: rebase
vibhatha Jul 2, 2024
a63728b
temp
vibhatha Jul 3, 2024
33222bd
fix: revert ListViewWriter to ListWriter
vibhatha Jul 3, 2024
42763ed
fix: temp view fix testing
vibhatha Jul 4, 2024
c023634
fix: adding minor changes to the interfaces
vibhatha Jul 4, 2024
e60caa8
fix: bug in promotion logic
vibhatha Jul 8, 2024
2edffda
fix: adding startListView and endListView usage
vibhatha Jul 9, 2024
a3b93d7
fix: updating test cases for new interface
vibhatha Jul 9, 2024
a43d8fc
fix: updating test cases
vibhatha Jul 9, 2024
692675e
fix: adding json reader/writer
vibhatha Jul 10, 2024
00efc88
fix: adding test cases
vibhatha Jul 10, 2024
febd540
fix: adding c data component v1 WIP
vibhatha Jul 11, 2024
e181e6a
feat: adding rountrip tests for c data interface
vibhatha Jul 22, 2024
df778a2
feat: adding java/python integration tests v1
vibhatha Jul 22, 2024
3e8815a
fix: minor typo
vibhatha Jul 22, 2024
059a2a8
feat: adding listview integration tests
vibhatha Jul 22, 2024
2d8b412
fix: adding range equal visitor test cases
vibhatha Jul 22, 2024
e6da575
fix: adding type equal visitor tests
vibhatha Jul 22, 2024
69b5742
fix: review
vibhatha Jul 23, 2024
9f4c9ff
fix: minor test option
vibhatha Jul 23, 2024
05b0998
fix: add new line
vibhatha Jul 23, 2024
dbfd228
fix: removing C Data interface components
vibhatha Jul 24, 2024
cf5ebcc
fix: addressing reviews v1
vibhatha Jul 24, 2024
e7daa32
fix: addressing reviews v2
vibhatha Jul 24, 2024
0561213
fix: removing visitor related component
vibhatha Jul 25, 2024
7603db6
fix: remove setters and inline
vibhatha Jul 29, 2024
3fe3f3f
fix: removing size=0 case for listview
vibhatha Jul 29, 2024
25c01a5
fix: revert moving logic to sub-class
vibhatha Jul 30, 2024
32dd3fc
fix: addressing reviews v3
vibhatha Aug 1, 2024
3cc972e
fix: format
vibhatha Aug 1, 2024
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
22 changes: 22 additions & 0 deletions java/vector/src/main/codegen/templates/AbstractFieldWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@ public void endList() {
throw new IllegalStateException(String.format("You tried to end a list when you are using a ValueWriter of type %s.", this.getClass().getSimpleName()));
}

@Override
public void startListView() {
throw new IllegalStateException(String.format("You tried to start a list view when you are using a ValueWriter of type %s.", this.getClass().getSimpleName()));
}

@Override
public void endListView() {
throw new IllegalStateException(String.format("You tried to end a list view when you are using a ValueWriter of type %s.", this.getClass().getSimpleName()));
}

@Override
public void startMap() {
throw new IllegalStateException(String.format("You tried to start a map when you are using a ValueWriter of type %s.", this.getClass().getSimpleName()));
Expand Down Expand Up @@ -184,6 +194,12 @@ public ListWriter list() {
return null;
}

@Override
public ListWriter listView() {
fail("ListView");
return null;
}

@Override
public MapWriter map() {
fail("Map");
Expand All @@ -202,6 +218,12 @@ public ListWriter list(String name) {
return null;
}

@Override
public ListWriter listView(String name) {
fail("ListView");
return null;
}

@Override
public MapWriter map(String name) {
fail("Map");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,17 @@ public void endList() {
setPosition(idx() + 1);
}

@Override
public void startListView() {
getWriter(MinorType.LISTVIEW).startListView();
}

@Override
public void endListView() {
getWriter(MinorType.LISTVIEW).endListView();
setPosition(idx() + 1);
}

@Override
public void startMap() {
getWriter(MinorType.MAP).startMap();
Expand Down Expand Up @@ -267,6 +278,11 @@ public ListWriter list() {
return getWriter(MinorType.LIST).list();
}

@Override
public ListWriter listView() {
return getWriter(MinorType.LISTVIEW).listView();
}

@Override
public MapWriter map() {
return getWriter(MinorType.LIST).map();
Expand All @@ -287,6 +303,11 @@ public ListWriter list(String name) {
return getWriter(MinorType.STRUCT).list(name);
}

@Override
public ListWriter listView(String name) {
return getWriter(MinorType.STRUCT).listView(name);
lidavidm marked this conversation as resolved.
Show resolved Hide resolved
}

@Override
public MapWriter map(String name) {
return getWriter(MinorType.STRUCT).map(name);
Expand All @@ -296,6 +317,7 @@ public MapWriter map(String name) {
public MapWriter map(String name, boolean keysSorted) {
return getWriter(MinorType.STRUCT).map(name, keysSorted);
}

<#list vv.types as type><#list type.minor as minor>
<#assign lowerName = minor.class?uncap_first />
<#if lowerName == "int" ><#assign lowerName = "integer" /></#if>
Expand Down
5 changes: 5 additions & 0 deletions java/vector/src/main/codegen/templates/BaseWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public interface StructWriter extends BaseWriter {
void copyReaderToField(String name, FieldReader reader);
StructWriter struct(String name);
ListWriter list(String name);
ListWriter listView(String name);
MapWriter map(String name);
MapWriter map(String name, boolean keysSorted);
void start();
Expand All @@ -71,8 +72,11 @@ public interface StructWriter extends BaseWriter {
public interface ListWriter extends BaseWriter {
void startList();
void endList();
void startListView();
void endListView();
StructWriter struct();
ListWriter list();
ListWriter listView();
MapWriter map();
MapWriter map(boolean keysSorted);
void copyReader(FieldReader reader);
Expand Down Expand Up @@ -106,6 +110,7 @@ public interface ComplexWriter {
void copyReader(FieldReader reader);
StructWriter rootAsStruct();
ListWriter rootAsList();
ListWriter rootAsListView();
MapWriter rootAsMap(boolean keysSorted);

void setPosition(int index);
Expand Down
7 changes: 7 additions & 0 deletions java/vector/src/main/codegen/templates/ComplexCopier.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ private static void writeValue(FieldReader reader, FieldWriter writer) {
switch (mt) {

case LIST:
case LISTVIEW:
case LARGELIST:
case FIXED_SIZE_LIST:
if (reader.isSet()) {
Expand Down Expand Up @@ -158,6 +159,8 @@ private static FieldWriter getStructWriterForReader(FieldReader reader, StructWr
return (FieldWriter) writer.list(name);
case MAP:
return (FieldWriter) writer.map(name);
case LISTVIEW:
return (FieldWriter) writer.listView(name);
default:
throw new UnsupportedOperationException(reader.getMinorType().toString());
}
Expand All @@ -180,6 +183,8 @@ private static FieldWriter getListWriterForReader(FieldReader reader, ListWriter
case MAP:
case NULL:
return (FieldWriter) writer.list();
case LISTVIEW:
return (FieldWriter) writer.listView();
default:
throw new UnsupportedOperationException(reader.getMinorType().toString());
}
Expand All @@ -201,6 +206,8 @@ private static FieldWriter getMapWriterForReader(FieldReader reader, MapWriter w
case LIST:
case NULL:
return (FieldWriter) writer.list();
case LISTVIEW:
return (FieldWriter) writer.listView();
case MAP:
return (FieldWriter) writer.map(false);
default:
Expand Down
21 changes: 21 additions & 0 deletions java/vector/src/main/codegen/templates/DenseUnionWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,18 @@ public void endList() {
getListWriter(typeId).endList();
}

@Override
public void startListView() {
byte typeId = data.getTypeId(idx());
getListViewWriter(typeId).startList();
}

@Override
public void endListView() {
byte typeId = data.getTypeId(idx());
getListViewWriter(typeId).endList();
}

private StructWriter getStructWriter(byte typeId) {
StructWriter structWriter = (StructWriter) writers[typeId];
if (structWriter == null) {
Expand All @@ -106,6 +118,15 @@ private ListWriter getListWriter(byte typeId) {
return listWriter;
}

private ListWriter getListViewWriter(byte typeId) {
ListWriter listWriter = (ListWriter) writers[typeId];
if (listWriter == null) {
listWriter = new UnionListViewWriter((ListViewVector) data.getVectorByType(typeId), nullableStructWriterFactory);
writers[typeId] = listWriter;
}
return listWriter;
}

public ListWriter asList(byte typeId) {
data.setTypeId(idx(), typeId);
return getListWriter(typeId);
Expand Down
167 changes: 167 additions & 0 deletions java/vector/src/main/codegen/templates/PromotableViewWriter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

<@pp.dropOutputFile />
<@pp.changeOutputFile name="/org/apache/arrow/vector/complex/impl/PromotableViewWriter.java" />

<#include "/@includes/license.ftl" />

package org.apache.arrow.vector.complex.impl;

import java.util.Locale;
<#include "/@includes/vv_imports.ftl" />

/**
* This FieldWriter implementation delegates all FieldWriter API calls to an inner FieldWriter. This
* inner field writer can start as a specific type, and this class will promote the writer to a
* UnionWriter if a call is made that the specifically typed writer cannot handle. A new UnionVector
* is created, wrapping the original vector, and replaces the original vector in the parent vector,
* which can be either an AbstractStructVector or a ListViewVector.
*
* <p>The writer used can either be for single elements (struct) or lists.
*/
public class PromotableViewWriter extends PromotableWriter {

public PromotableViewWriter(ValueVector v, FixedSizeListVector fixedListVector) {
super(v, fixedListVector);
}

public PromotableViewWriter(ValueVector v, FixedSizeListVector fixedListVector,
NullableStructWriterFactory nullableStructWriterFactory) {
super(v, fixedListVector, nullableStructWriterFactory);
}

public PromotableViewWriter(ValueVector v, LargeListVector largeListVector) {
super(v, largeListVector);
}

public PromotableViewWriter(ValueVector v, LargeListVector largeListVector,
NullableStructWriterFactory nullableStructWriterFactory) {
super(v, largeListVector, nullableStructWriterFactory);
}

public PromotableViewWriter(ValueVector v, ListVector listVector) {
super(v, listVector);
}

public PromotableViewWriter(ValueVector v, ListVector listVector,
NullableStructWriterFactory nullableStructWriterFactory) {
super(v, listVector, nullableStructWriterFactory);
}

public PromotableViewWriter(ValueVector v, ListViewVector listViewVector,
NullableStructWriterFactory nullableStructWriterFactory) {
super(v, listViewVector, nullableStructWriterFactory);
}

public PromotableViewWriter(ValueVector v, AbstractStructVector parentContainer) {
super(v, parentContainer);
}

public PromotableViewWriter(ValueVector v, AbstractStructVector parentContainer,
NullableStructWriterFactory nullableStructWriterFactory) {
super(v, parentContainer, nullableStructWriterFactory);
}

@Override
protected FieldWriter getWriter(MinorType type, ArrowType arrowType) {
if (state == State.UNION) {
if (requiresArrowType(type)) {
writer = ((UnionWriter) writer).toViewWriter();
((UnionViewWriter) writer).getWriter(type, arrowType);
} else {
writer = ((UnionWriter) writer).toViewWriter();
((UnionViewWriter) writer).getWriter(type);
}
} else if (state == State.UNTYPED) {
if (type == null) {
// ???
return null;
}
if (arrowType == null) {
arrowType = type.getType();
}
FieldType fieldType = new FieldType(addVectorAsNullable, arrowType, null, null);
ValueVector v;
if (listVector != null) {
v = listVector.addOrGetVector(fieldType).getVector();
} else if (fixedListVector != null) {
v = fixedListVector.addOrGetVector(fieldType).getVector();
} else if (listViewVector != null) {
v = listViewVector.addOrGetVector(fieldType).getVector();
} else {
v = largeListVector.addOrGetVector(fieldType).getVector();
}
v.allocateNew();
setWriter(v);
writer.setPosition(position);
} else if (type != this.type) {
promoteToUnion();
if (requiresArrowType(type)) {
writer = ((UnionWriter) writer).toViewWriter();
((UnionViewWriter) writer).getWriter(type, arrowType);
} else {
writer = ((UnionWriter) writer).toViewWriter();
((UnionViewWriter) writer).getWriter(type);
}
}
return writer;
}

@Override
public StructWriter struct() {
return getWriter(MinorType.LISTVIEW).struct();
}

<#list vv.types as type><#list type.minor as minor>
<#assign lowerName = minor.class?uncap_first />
<#if lowerName == "int" ><#assign lowerName = "integer" /></#if>
<#assign upperName = minor.class?upper_case />
<#assign capName = minor.class?cap_first />

@Override
public ${capName}Writer ${lowerName}() {
return getWriter(MinorType.LISTVIEW).${lowerName}();
}

</#list></#list>

@Override
public void allocate() {
getWriter().allocate();
}

@Override
public void clear() {
getWriter().clear();
}

@Override
public Field getField() {
return getWriter().getField();
}

@Override
public int getValueCapacity() {
return getWriter().getValueCapacity();
}

@Override
public void close() throws Exception {
getWriter().close();
}
}
Loading
Loading