-
Notifications
You must be signed in to change notification settings - Fork 4k
GH-41728:[Java][Vector] Add ExtensionWriter and fix StructVector construction with ExtensionTypes #41731
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-41728:[Java][Vector] Add ExtensionWriter and fix StructVector construction with ExtensionTypes #41731
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| /* | ||
| * 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 org.apache.arrow.vector.ExtensionTypeVector; | ||
| import org.apache.arrow.vector.types.pojo.Field; | ||
|
|
||
| public class UnionExtensionWriter extends AbstractFieldWriter { | ||
|
||
| protected ExtensionTypeVector vector; | ||
|
|
||
| public UnionExtensionWriter(ExtensionTypeVector vector) { | ||
| this.vector = vector; | ||
| } | ||
|
|
||
| @Override | ||
| public void allocate() { | ||
| vector.allocateNew(); | ||
| } | ||
|
|
||
| @Override | ||
| public void clear() { | ||
| vector.clear(); | ||
| } | ||
|
|
||
| @Override | ||
| public int getValueCapacity() { | ||
| return vector.getValueCapacity(); | ||
| } | ||
|
|
||
| @Override | ||
| public Field getField() { | ||
| return vector.getField(); | ||
| } | ||
|
|
||
| @Override | ||
| public void close() throws Exception { | ||
| vector.close(); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,12 +17,17 @@ | |
|
|
||
| package org.apache.arrow.vector; | ||
|
|
||
| import static org.junit.Assert.*; | ||
| import static org.junit.Assert.assertEquals; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could we use JUnit5? |
||
| import static org.junit.Assert.assertNotEquals; | ||
| import static org.junit.Assert.assertNotNull; | ||
| import static org.junit.Assert.assertNull; | ||
| import static org.junit.Assert.assertSame; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.HashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.UUID; | ||
|
|
||
| import org.apache.arrow.memory.BufferAllocator; | ||
| import org.apache.arrow.vector.complex.AbstractStructVector; | ||
|
|
@@ -35,9 +40,11 @@ | |
| import org.apache.arrow.vector.holders.ComplexHolder; | ||
| import org.apache.arrow.vector.types.Types; | ||
| import org.apache.arrow.vector.types.Types.MinorType; | ||
| import org.apache.arrow.vector.types.pojo.ArrowType; | ||
| import org.apache.arrow.vector.types.pojo.ArrowType.Struct; | ||
| import org.apache.arrow.vector.types.pojo.Field; | ||
| import org.apache.arrow.vector.types.pojo.FieldType; | ||
| import org.apache.arrow.vector.types.pojo.TestExtensionType; | ||
| import org.apache.arrow.vector.util.TransferPair; | ||
| import org.junit.After; | ||
| import org.junit.Assert; | ||
|
|
@@ -82,6 +89,44 @@ public void testMakeTransferPair() { | |
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void testStructVectorWithExtensionTypes() { | ||
| TestExtensionType.UuidType uuidType = new TestExtensionType.UuidType(); | ||
| Field uuidField = new Field("struct_child", FieldType.nullable(uuidType), null); | ||
| Field structField = new Field("struct", FieldType.nullable(new ArrowType.Struct()), List.of(uuidField)); | ||
| StructVector s1 = new StructVector(structField, allocator, null); | ||
| StructVector s2 = (StructVector) structField.createVector(allocator); | ||
| s1.close(); | ||
| s2.close(); | ||
| } | ||
|
|
||
| @Test | ||
| public void testStructVectorTransferPairWithExtensionType() { | ||
| TestExtensionType.UuidType uuidType = new TestExtensionType.UuidType(); | ||
| Field uuidField = new Field("uuid_child", FieldType.nullable(uuidType), null); | ||
| Field structField = new Field("struct", FieldType.nullable(new ArrowType.Struct()), List.of(uuidField)); | ||
|
|
||
| StructVector s1 = (StructVector) structField.createVector(allocator); | ||
| TestExtensionType.UuidVector uuidVector = | ||
| s1.addOrGet("uuid_child", FieldType.nullable(uuidType), TestExtensionType.UuidVector.class); | ||
| s1.setValueCount(1); | ||
| uuidVector.set(0, new UUID(1, 2)); | ||
| s1.setIndexDefined(0); | ||
|
|
||
| TransferPair tp = s1.getTransferPair(structField, allocator); | ||
| final StructVector toVector = (StructVector) tp.getTo(); | ||
| assertEquals(s1.getField(), toVector.getField()); | ||
| assertEquals(s1.getField().getChildren().get(0), toVector.getField().getChildren().get(0)); | ||
| // also fails but probably another issue | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I also debugged the code. It seems the copy didn't work properly. I guess you're still not finished with this work, right? |
||
| // assertEquals(s1.getValueCount(), toVector.getValueCount()); | ||
| // assertEquals(s1, toVector); | ||
|
|
||
| s1.close(); | ||
| toVector.close(); | ||
| } | ||
|
|
||
|
|
||
|
|
||
| @Test | ||
| public void testAllocateAfterReAlloc() throws Exception { | ||
| Map<String, String> metadata = new HashMap<>(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is where some design decisions have to be made of how to actually expose the
ExtensionWriterto the user and how the user should actually extend someExtensionWriter.As mentioned above I would make this one interface
BaswWriterexposing all the possible writers and leaving them abstract in the concrete implementations.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This sounds reasonable to me.