-
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 1 commit
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,23 @@ | ||
| /* | ||
| * 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; | ||
|
|
||
| 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.
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| /* | ||
| * 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.holders.ExtensionHolder; | ||
| import org.apache.arrow.vector.types.pojo.Field; | ||
|
|
||
| public class UnionExtensionWriter extends AbstractFieldWriter { | ||
| protected ExtensionTypeVector vector; | ||
| protected AbstractFieldWriter writer; | ||
|
|
||
| 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(); | ||
| } | ||
|
|
||
| @Override | ||
| public void writeExtensionType(Object var1) { | ||
| this.writer.writeExtensionType(var1); | ||
| } | ||
|
|
||
| @Override | ||
| public <S extends ExtensionTypeWriterFactory> void addExtensionTypeFactory(S var1) { | ||
| this.writer = var1.getWriterImpl(vector); | ||
| this.writer.setPosition(idx()); | ||
| } | ||
|
|
||
| public <T extends ExtensionHolder> void write(T var1) { | ||
| this.writer.write(var1); | ||
| } | ||
|
|
||
| @Override | ||
| public void setPosition(int index) { | ||
| super.setPosition(index); | ||
| if (this.writer != null) { | ||
| this.writer.setPosition(index); | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| /* | ||
| * 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.holders; | ||
|
|
||
| public abstract class ExtensionHolder implements ValueHolder { | ||
|
lidavidm marked this conversation as resolved.
|
||
| public int isSet; | ||
| } | ||
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