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-40289: [Java] Proposal for ListViewVector implementation #40290

Closed
wants to merge 7 commits into from
Closed
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import org.apache.arrow.vector.VarBinaryVector;
import org.apache.arrow.vector.VarCharVector;
import org.apache.arrow.vector.complex.ListVector;
import org.apache.arrow.vector.complex.ListViewVector;
import org.apache.arrow.vector.complex.MapVector;
import org.apache.arrow.vector.types.pojo.ArrowType;

Expand Down Expand Up @@ -83,6 +84,11 @@ public ColumnBinder visit(ArrowType.List type) {
return new ListBinder((ListVector) vector);
}

@Override
public ColumnBinder visit(ArrowType.ListView type) {
return new ListBinder((ListViewVector) vector);
}

@Override
public ColumnBinder visit(ArrowType.LargeList type) {
throw new UnsupportedOperationException("No column binder implemented for type " + type);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* 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.
*/

package org.apache.arrow.driver.jdbc.converter.impl;

import java.util.List;

import org.apache.arrow.driver.jdbc.utils.AvaticaParameterBinder;
import org.apache.arrow.vector.FieldVector;
import org.apache.arrow.vector.complex.ListViewVector;
import org.apache.arrow.vector.types.pojo.ArrowType;
import org.apache.arrow.vector.types.pojo.Field;
import org.apache.calcite.avatica.AvaticaParameter;
import org.apache.calcite.avatica.remote.TypedValue;

/**
* AvaticaParameterConverter for List Arrow types.
*/
public class ListViewAvaticaParameterConverter extends BaseAvaticaParameterConverter {

public ListViewAvaticaParameterConverter(ArrowType.ListView type) {
}

//FIXME! Add unit test to validate this bindParameter
@Override
public boolean bindParameter(FieldVector vector, TypedValue typedValue, int index) {
final List<?> values = (List<?>) typedValue.value;

if (vector instanceof ListViewVector) {
ListViewVector listViewVector = ((ListViewVector) vector);
FieldVector childVector = listViewVector.getDataVector();

int startPos = listViewVector.startNewValue(index);
for (int i = 0; i < values.size(); i++) {
Object val = values.get(i);
int childIndex = startPos + i;
if (val == null) {
if (childVector.getField().isNullable()) {
childVector.setNull(childIndex);
} else {
throw new UnsupportedOperationException("Can't set null on non-nullable child list");
}
} else {
childVector.getField().getType().accept(
new AvaticaParameterBinder.BinderVisitor(
childVector, TypedValue.ofSerial(typedValue.componentType, val), childIndex));
}
}
listViewVector.endValue(index, values.size());
listViewVector.setValueCount(index + 1);
return true;
}
return false;
}

@Override
public AvaticaParameter createParameter(Field field) {
return createParameter(field, false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.apache.arrow.driver.jdbc.converter.impl.LargeListAvaticaParameterConverter;
import org.apache.arrow.driver.jdbc.converter.impl.LargeUtf8AvaticaParameterConverter;
import org.apache.arrow.driver.jdbc.converter.impl.ListAvaticaParameterConverter;
import org.apache.arrow.driver.jdbc.converter.impl.ListViewAvaticaParameterConverter;
import org.apache.arrow.driver.jdbc.converter.impl.MapAvaticaParameterConverter;
import org.apache.arrow.driver.jdbc.converter.impl.NullAvaticaParameterConverter;
import org.apache.arrow.driver.jdbc.converter.impl.StructAvaticaParameterConverter;
Expand Down Expand Up @@ -155,6 +156,11 @@ public Boolean visit(ArrowType.List type) {
return new ListAvaticaParameterConverter(type).bindParameter(vector, typedValue, index);
}

@Override
public Boolean visit(ArrowType.ListView type) {
return new ListViewAvaticaParameterConverter(type).bindParameter(vector, typedValue, index);
}

@Override
public Boolean visit(ArrowType.LargeList type) {
return new LargeListAvaticaParameterConverter(type).bindParameter(vector, typedValue, index);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.apache.arrow.driver.jdbc.converter.impl.LargeListAvaticaParameterConverter;
import org.apache.arrow.driver.jdbc.converter.impl.LargeUtf8AvaticaParameterConverter;
import org.apache.arrow.driver.jdbc.converter.impl.ListAvaticaParameterConverter;
import org.apache.arrow.driver.jdbc.converter.impl.ListViewAvaticaParameterConverter;
import org.apache.arrow.driver.jdbc.converter.impl.MapAvaticaParameterConverter;
import org.apache.arrow.driver.jdbc.converter.impl.NullAvaticaParameterConverter;
import org.apache.arrow.driver.jdbc.converter.impl.StructAvaticaParameterConverter;
Expand Down Expand Up @@ -170,6 +171,12 @@ public AvaticaParameter visit(ArrowType.List type) {

}

@Override
public AvaticaParameter visit(ArrowType.ListView type) {
return new ListViewAvaticaParameterConverter(type).createParameter(field);

}

@Override
public AvaticaParameter visit(ArrowType.LargeList type) {
return new LargeListAvaticaParameterConverter(type).createParameter(field);
Expand Down
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 @@ -119,6 +119,11 @@
name: "Duration",
fields: [{name: "unit", type: short, valueType: TimeUnit}],
complex: false
},
{
name: "ListView",
fields: [],
complex: true
}
]
}
58 changes: 58 additions & 0 deletions java/vector/src/main/codegen/templates/UnionListViewWriter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* 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.
*/

import org.apache.arrow.vector.complex.ListViewVector;
import org.apache.arrow.vector.complex.impl.UnionListWriter;

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


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

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

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

/*
* This class is generated using freemarker and the ${.template_name} template.
*/

/**
* <p>Writer for ListViewVector. This extends UnionListWriter to simplify writing listview entries to a list
* </p>
*/
@SuppressWarnings("unused")
public class UnionListViewWriter extends UnionListWriter {
public UnionListViewWriter(ListViewVector vector) {
super(vector);
}

public void startList(int offset) {
((ListViewVector) vector).startNewValue(idx(), offset);
writer.setPosition(((ListViewVector) vector).getOffsetBuffer().getInt((idx()) * 4));
}

public void endList(int size) {
((ListViewVector) vector).endValue(idx(), size);
setPosition(idx() + 1);
}

public void setValueCount(int count) {
((ListViewVector) vector).setValueCount(count);
}
}
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 = 46;
private static final int NUM_SUPPORTED_TYPES = 47;

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 @@ -108,6 +108,15 @@ public TypeLayout visit(org.apache.arrow.vector.types.pojo.ArrowType.List type)
return new TypeLayout(vectors);
}

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

@Override
public TypeLayout visit(ArrowType.LargeList type) {
List<BufferLayout> vectors = asList(
Expand Down Expand Up @@ -304,6 +313,12 @@ public Integer visit(org.apache.arrow.vector.types.pojo.ArrowType.List type) {
return 2;
}

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

@Override
public Integer visit(ArrowType.LargeList type) {
// validity buffer + offset buffer
Expand Down
Loading
Loading