-
Notifications
You must be signed in to change notification settings - Fork 121
GH-87: [Vector] Add ExtensionWriter #697
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
Changes from 4 commits
fc7d55d
9f96325
867c797
fc08192
4ab857c
3e88e76
4df283a
9c8a022
f8799ea
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 |
|---|---|---|
|
|
@@ -61,6 +61,7 @@ public interface StructWriter extends BaseWriter { | |
|
|
||
| void copyReaderToField(String name, FieldReader reader); | ||
| StructWriter struct(String name); | ||
| ExtensionWriter extension(String name, ArrowType arrowType); | ||
| ListWriter list(String name); | ||
| ListWriter listView(String name); | ||
| MapWriter map(String name); | ||
|
|
@@ -79,6 +80,7 @@ public interface ListWriter extends BaseWriter { | |
| ListWriter listView(); | ||
| MapWriter map(); | ||
| MapWriter map(boolean keysSorted); | ||
| ExtensionWriter extension(ArrowType arrowType); | ||
| void copyReader(FieldReader reader); | ||
|
|
||
| <#list vv.types as type><#list type.minor as minor> | ||
|
|
@@ -101,6 +103,13 @@ public interface MapWriter extends ListWriter { | |
| MapWriter value(); | ||
| } | ||
|
|
||
| public interface ExtensionWriter extends BaseWriter { | ||
| void writeNull(); | ||
| <T extends ExtensionHolder> void write(T var1); | ||
| void writeExtensionType(Object var1); | ||
| <T extends ExtensionTypeWriterFactory> void addExtensionTypeFactory(T var1); | ||
|
Member
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. While the existing code is short on docstrings, can we add docstrings for new code going forward? In particular it's not clear what
Member
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. Are the generic bounds actually useful here? Why can't it just be
Member
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. Can we replace |
||
| } | ||
|
|
||
| public interface ScalarWriter extends | ||
| <#list vv.types as type><#list type.minor as minor><#assign name = minor.class?cap_first /> ${name}Writer, </#list></#list> BaseWriter {} | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| /* | ||
| * 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; | ||
|
|
||
| /** | ||
| * Base {@link AbstractFieldWriter} class for an {@link | ||
| * org.apache.arrow.vector.ExtensionTypeVector}. | ||
| * | ||
| * @param <T> a specific {@link ExtensionTypeVector}. | ||
| */ | ||
| public class AbstractExtensionTypeWriter<T extends ExtensionTypeVector> | ||
| extends AbstractFieldWriter { | ||
| protected final T vector; | ||
|
|
||
| public AbstractExtensionTypeWriter(T vector) { | ||
| this.vector = vector; | ||
| } | ||
|
|
||
| @Override | ||
| public Field getField() { | ||
| return this.vector.getField(); | ||
| } | ||
|
|
||
| @Override | ||
| public int getValueCapacity() { | ||
| return this.vector.getValueCapacity(); | ||
| } | ||
|
|
||
| @Override | ||
| public void allocate() { | ||
| this.vector.allocateNew(); | ||
| } | ||
|
|
||
| @Override | ||
| public void close() { | ||
| this.vector.close(); | ||
| } | ||
|
|
||
| @Override | ||
| public void clear() { | ||
| this.vector.clear(); | ||
| } | ||
|
|
||
| @Override | ||
| protected int idx() { | ||
| return super.idx(); | ||
|
Member
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. Hmm, is the only reason we override here to make it
Contributor
Author
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. yep, makes sense - logic with idx() method added for all other writers. |
||
| } | ||
|
|
||
| @Override | ||
| public void writeNull() { | ||
| this.vector.setNull(this.idx()); | ||
| this.vector.setValueCount(this.idx() + 1); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| /* | ||
| * 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; | ||
|
|
||
| /** | ||
| * A factory for {@link ExtensionTypeWriter} instances. The factory allow to configure writer | ||
| * implementation for specific ExtensionTypeVector. | ||
| * | ||
| * @param <T> writer implementation for specific {@link ExtensionTypeVector}. | ||
| */ | ||
| public interface ExtensionTypeWriterFactory<T extends AbstractFieldWriter> { | ||
|
Member
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. Can we document this?
Member
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. Does the type bound need to be
Contributor
Author
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. I chose AbstractFieldWriter just to make sure that the user will use some specific implementation of writer, but in general yes - it could be FieldWriter
Member
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. IMO abstract implementation classes should not go in generic bounds - it should be the interface type |
||
| T getWriterImpl(ExtensionTypeVector vector); | ||
|
lidavidm marked this conversation as resolved.
|
||
| } | ||
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.
Same here - why not just
void write(ExtensionHolder value)?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.
fixed