-
Notifications
You must be signed in to change notification settings - Fork 122
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 5 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,35 @@ public interface MapWriter extends ListWriter { | |||||
| MapWriter value(); | ||||||
| } | ||||||
|
|
||||||
| public interface ExtensionWriter extends BaseWriter { | ||||||
|
|
||||||
| /** | ||||||
| * Writes a null value. | ||||||
| */ | ||||||
| void writeNull(); | ||||||
|
|
||||||
| /** | ||||||
| * Writes vlaue from the given extension holder. | ||||||
| * | ||||||
| * @param holder the extension holder to write | ||||||
| */ | ||||||
| void write(ExtensionHolder holder); | ||||||
|
|
||||||
| /** | ||||||
| * Writes the given extension type value. | ||||||
| * | ||||||
| * @param value the extension type value to write | ||||||
| */ | ||||||
| void writeExtensionType(Object value); | ||||||
|
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. This is a nit but now I'm thinking it should be just |
||||||
|
|
||||||
| /** | ||||||
| * Adds the given extension type factory. This factory allows configuring writer implementations for specific ExtensionTypeVector. | ||||||
| * | ||||||
| * @param factory the extension type factory to add | ||||||
| */ | ||||||
| void addExtensionTypeFactory(ExtensionTypeWriterFactory factory); | ||||||
|
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.
Suggested change
for consistency as well |
||||||
| } | ||||||
|
|
||||||
| 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,38 @@ | ||
| /* | ||
| * 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.complex.writer.FieldWriter; | ||
|
|
||
| /** | ||
| * A factory interface for creating instances of {@link ExtensionTypeWriter}. This factory allows | ||
| * configuring writer implementations for specific {@link ExtensionTypeVector}. | ||
| * | ||
| * @param <T> the type of writer implementation for a specific {@link ExtensionTypeVector}. | ||
| */ | ||
| public interface ExtensionTypeWriterFactory<T extends FieldWriter> { | ||
|
|
||
| /** | ||
| * Returns an instance of the writer implementation for the given {@link ExtensionTypeVector}. | ||
| * | ||
| * @param vector the {@link ExtensionTypeVector} for which the writer implementation is to be | ||
| * returned. | ||
| * @return an instance of the writer implementation for the given {@link ExtensionTypeVector}. | ||
| */ | ||
| 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.