Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
.classpath
.factorypath
.idea/
.vscode/
.cursor/
.project
.settings/
/*-build/
Expand Down
4 changes: 3 additions & 1 deletion vector/src/main/codegen/templates/DenseUnionWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ public DenseUnionWriter(DenseUnionVector vector, NullableStructWriterFactory nul
public void setPosition(int index) {
super.setPosition(index);
for (BaseWriter writer : writers) {
writer.setPosition(index);
if (writer != null) {
writer.setPosition(index);
}
}
}

Expand Down
Copy link
Member

Choose a reason for hiding this comment

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* 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.vector.complex.impl;

import static org.junit.jupiter.api.Assertions.assertEquals;

import java.util.List;
import org.apache.arrow.memory.BufferAllocator;
import org.apache.arrow.memory.RootAllocator;
import org.apache.arrow.vector.complex.ListVector;
import org.apache.arrow.vector.types.Types;
import org.apache.arrow.vector.types.pojo.FieldType;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class TestDenseUnionWriterNPE {
Copy link
Member

Choose a reason for hiding this comment

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

nit: JUnit 5 doesn't require declaring everything public


private BufferAllocator allocator;

@BeforeEach
public void init() {
allocator = new RootAllocator(Long.MAX_VALUE);
}

@AfterEach
public void terminate() {
allocator.close();
}

@Test
public void testListOfDenseUnionWriterNPE() {
Copy link
Member

Choose a reason for hiding this comment

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

Link back to the issue

Suggested change
public void testListOfDenseUnionWriterNPE() {
public void testListOfDenseUnionWriterNPE() {
// Regression test for ...

try (ListVector listVector = ListVector.empty("list", allocator)) {
listVector.addOrGetVector(FieldType.nullable(Types.MinorType.DENSEUNION.getType()));
UnionListWriter listWriter = listVector.getWriter();

listWriter.startList();
listWriter.endList();
}
}

@Test
public void testListOfDenseUnionWriterWithData() {
try (ListVector listVector = ListVector.empty("list", allocator)) {
listVector.addOrGetVector(FieldType.nullable(Types.MinorType.DENSEUNION.getType()));

UnionListWriter listWriter = listVector.getWriter();
listWriter.startList();
listWriter.writeInt(100);
listWriter.writeBigInt(200L);
listWriter.endList();

listWriter.startList();
listWriter.writeFloat4(3.14f);
listWriter.endList();

listVector.setValueCount(2);

assertEquals(2, listVector.getValueCount());

List<?> value0 = (List<?>) listVector.getObject(0);
List<?> value1 = (List<?>) listVector.getObject(1);

assertEquals(2, value0.size());
assertEquals(100, value0.get(0));
assertEquals(200L, value0.get(1));

assertEquals(1, value1.size());
assertEquals(3.14f, value1.get(0));
}
}
}
Loading