Skip to content

Commit 4ab857c

Browse files
committed
GH-87: fixed comments
1 parent fc08192 commit 4ab857c

File tree

16 files changed

+355
-208
lines changed

16 files changed

+355
-208
lines changed

vector/src/main/codegen/templates/AbstractFieldWriter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,13 @@ public void endEntry() {
107107
throw new IllegalStateException(String.format("You tried to end a map entry when you are using a ValueWriter of type %s.", this.getClass().getSimpleName()));
108108
}
109109

110-
public <T extends ExtensionHolder> void write(T var1) {
110+
public void write(ExtensionHolder var1) {
111111
this.fail("ExtensionType");
112112
}
113113
public void writeExtensionType(Object var1) {
114114
this.fail("ExtensionType");
115115
}
116-
public <T extends ExtensionTypeWriterFactory> void addExtensionTypeFactory(T var1) {
116+
public void addExtensionTypeFactory(ExtensionTypeWriterFactory var1) {
117117
this.fail("ExtensionType");
118118
}
119119

vector/src/main/codegen/templates/BaseWriter.java

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,32 @@ public interface MapWriter extends ListWriter {
104104
}
105105

106106
public interface ExtensionWriter extends BaseWriter {
107+
108+
/**
109+
* Writes a null value.
110+
*/
107111
void writeNull();
108-
<T extends ExtensionHolder> void write(T var1);
109-
void writeExtensionType(Object var1);
110-
<T extends ExtensionTypeWriterFactory> void addExtensionTypeFactory(T var1);
112+
113+
/**
114+
* Writes vlaue from the given extension holder.
115+
*
116+
* @param holder the extension holder to write
117+
*/
118+
void write(ExtensionHolder holder);
119+
120+
/**
121+
* Writes the given extension type value.
122+
*
123+
* @param value the extension type value to write
124+
*/
125+
void writeExtensionType(Object value);
126+
127+
/**
128+
* Adds the given extension type factory. This factory allows configuring writer implementations for specific ExtensionTypeVector.
129+
*
130+
* @param factory the extension type factory to add
131+
*/
132+
void addExtensionTypeFactory(ExtensionTypeWriterFactory factory);
111133
}
112134

113135
public interface ScalarWriter extends

vector/src/main/codegen/templates/PromotableWriter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -546,8 +546,8 @@ public void writeExtensionType(Object value) {
546546
}
547547

548548
@Override
549-
public <T extends ExtensionTypeWriterFactory> void addExtensionTypeFactory(T var1) {
550-
getWriter(MinorType.EXTENSIONTYPE).addExtensionTypeFactory(var1);
549+
public void addExtensionTypeFactory(ExtensionTypeWriterFactory factory) {
550+
getWriter(MinorType.EXTENSIONTYPE).addExtensionTypeFactory(factory);
551551
}
552552

553553
@Override

vector/src/main/codegen/templates/UnionListWriter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,10 +339,10 @@ public void writeExtensionType(Object value) {
339339
writer.writeExtensionType(value);
340340
}
341341
@Override
342-
public <T extends ExtensionTypeWriterFactory> void addExtensionTypeFactory(T var1) {
342+
public void addExtensionTypeFactory(ExtensionTypeWriterFactory var1) {
343343
writer.addExtensionTypeFactory(var1);
344344
}
345-
public <T extends ExtensionHolder> void write(T var1) {
345+
public void write(ExtensionHolder var1) {
346346
writer.write(var1);
347347
}
348348

vector/src/main/java/org/apache/arrow/vector/complex/impl/ExtensionTypeWriterFactory.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,22 @@
1717
package org.apache.arrow.vector.complex.impl;
1818

1919
import org.apache.arrow.vector.ExtensionTypeVector;
20+
import org.apache.arrow.vector.complex.writer.FieldWriter;
2021

2122
/**
22-
* A factory for {@link ExtensionTypeWriter} instances. The factory allow to configure writer
23-
* implementation for specific ExtensionTypeVector.
23+
* A factory interface for creating instances of {@link ExtensionTypeWriter}. This factory allows
24+
* configuring writer implementations for specific {@link ExtensionTypeVector}.
2425
*
25-
* @param <T> writer implementation for specific {@link ExtensionTypeVector}.
26+
* @param <T> the type of writer implementation for a specific {@link ExtensionTypeVector}.
2627
*/
27-
public interface ExtensionTypeWriterFactory<T extends AbstractFieldWriter> {
28+
public interface ExtensionTypeWriterFactory<T extends FieldWriter> {
29+
30+
/**
31+
* Returns an instance of the writer implementation for the given {@link ExtensionTypeVector}.
32+
*
33+
* @param vector the {@link ExtensionTypeVector} for which the writer implementation is to be
34+
* returned.
35+
* @return an instance of the writer implementation for the given {@link ExtensionTypeVector}.
36+
*/
2837
T getWriterImpl(ExtensionTypeVector vector);
2938
}

vector/src/main/java/org/apache/arrow/vector/complex/impl/UnionExtensionWriter.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@
1717
package org.apache.arrow.vector.complex.impl;
1818

1919
import org.apache.arrow.vector.ExtensionTypeVector;
20+
import org.apache.arrow.vector.complex.writer.FieldWriter;
2021
import org.apache.arrow.vector.holders.ExtensionHolder;
2122
import org.apache.arrow.vector.types.pojo.Field;
2223

2324
public class UnionExtensionWriter extends AbstractFieldWriter {
2425
protected ExtensionTypeVector vector;
25-
protected AbstractFieldWriter writer;
26+
protected FieldWriter writer;
2627

2728
public UnionExtensionWriter(ExtensionTypeVector vector) {
2829
this.vector = vector;
@@ -59,13 +60,13 @@ public void writeExtensionType(Object var1) {
5960
}
6061

6162
@Override
62-
public <S extends ExtensionTypeWriterFactory> void addExtensionTypeFactory(S var1) {
63-
this.writer = var1.getWriterImpl(vector);
63+
public void addExtensionTypeFactory(ExtensionTypeWriterFactory factory) {
64+
this.writer = factory.getWriterImpl(vector);
6465
this.writer.setPosition(idx());
6566
}
6667

67-
public <T extends ExtensionHolder> void write(T var1) {
68-
this.writer.write(var1);
68+
public void write(ExtensionHolder holder) {
69+
this.writer.write(holder);
6970
}
7071

7172
@Override

vector/src/test/java/org/apache/arrow/vector/TestStructVector.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
import org.apache.arrow.vector.types.pojo.ArrowType.Struct;
4343
import org.apache.arrow.vector.types.pojo.Field;
4444
import org.apache.arrow.vector.types.pojo.FieldType;
45-
import org.apache.arrow.vector.types.pojo.TestUuidVector;
45+
import org.apache.arrow.vector.types.pojo.UuidType;
4646
import org.apache.arrow.vector.util.TransferPair;
4747
import org.junit.jupiter.api.AfterEach;
4848
import org.junit.jupiter.api.BeforeEach;
@@ -341,7 +341,7 @@ public void testGetTransferPairWithFieldAndCallBack() {
341341

342342
@Test
343343
public void testStructVectorWithExtensionTypes() {
344-
TestUuidVector.UuidType uuidType = new TestUuidVector.UuidType();
344+
UuidType uuidType = new UuidType();
345345
Field uuidField = new Field("struct_child", FieldType.nullable(uuidType), null);
346346
Field structField =
347347
new Field("struct", FieldType.nullable(new ArrowType.Struct()), List.of(uuidField));
@@ -353,14 +353,14 @@ public void testStructVectorWithExtensionTypes() {
353353

354354
@Test
355355
public void testStructVectorTransferPairWithExtensionType() {
356-
TestUuidVector.UuidType uuidType = new TestUuidVector.UuidType();
356+
UuidType uuidType = new UuidType();
357357
Field uuidField = new Field("uuid_child", FieldType.nullable(uuidType), null);
358358
Field structField =
359359
new Field("struct", FieldType.nullable(new ArrowType.Struct()), List.of(uuidField));
360360

361361
StructVector s1 = (StructVector) structField.createVector(allocator);
362-
TestUuidVector.UuidVector uuidVector =
363-
s1.addOrGet("uuid_child", FieldType.nullable(uuidType), TestUuidVector.UuidVector.class);
362+
UuidVector uuidVector =
363+
s1.addOrGet("uuid_child", FieldType.nullable(uuidType), UuidVector.class);
364364
s1.setValueCount(1);
365365
uuidVector.set(0, new UUID(1, 2));
366366
s1.setIndexDefined(0);
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.arrow.vector;
18+
19+
import java.nio.ByteBuffer;
20+
import java.util.UUID;
21+
import org.apache.arrow.memory.BufferAllocator;
22+
import org.apache.arrow.memory.util.hash.ArrowBufHasher;
23+
import org.apache.arrow.vector.types.pojo.Field;
24+
import org.apache.arrow.vector.types.pojo.FieldType;
25+
import org.apache.arrow.vector.types.pojo.UuidType;
26+
import org.apache.arrow.vector.util.TransferPair;
27+
28+
public class UuidVector extends ExtensionTypeVector<FixedSizeBinaryVector>
29+
implements ValueIterableVector<UUID> {
30+
private final Field field;
31+
32+
public UuidVector(
33+
String name, BufferAllocator allocator, FixedSizeBinaryVector underlyingVector) {
34+
super(name, allocator, underlyingVector);
35+
this.field = new Field(name, FieldType.nullable(new UuidType()), null);
36+
}
37+
38+
public UuidVector(String name, BufferAllocator allocator) {
39+
super(name, allocator, new FixedSizeBinaryVector(name, allocator, 16));
40+
this.field = new Field(name, FieldType.nullable(new UuidType()), null);
41+
}
42+
43+
@Override
44+
public UUID getObject(int index) {
45+
final ByteBuffer bb = ByteBuffer.wrap(getUnderlyingVector().getObject(index));
46+
return new UUID(bb.getLong(), bb.getLong());
47+
}
48+
49+
@Override
50+
public int hashCode(int index) {
51+
return hashCode(index, null);
52+
}
53+
54+
@Override
55+
public int hashCode(int index, ArrowBufHasher hasher) {
56+
return getUnderlyingVector().hashCode(index, hasher);
57+
}
58+
59+
public void set(int index, UUID uuid) {
60+
ByteBuffer bb = ByteBuffer.allocate(16);
61+
bb.putLong(uuid.getMostSignificantBits());
62+
bb.putLong(uuid.getLeastSignificantBits());
63+
getUnderlyingVector().set(index, bb.array());
64+
}
65+
66+
@Override
67+
public void copyFromSafe(int fromIndex, int thisIndex, ValueVector from) {
68+
getUnderlyingVector()
69+
.copyFromSafe(fromIndex, thisIndex, ((UuidVector) from).getUnderlyingVector());
70+
}
71+
72+
@Override
73+
public Field getField() {
74+
return field;
75+
}
76+
77+
@Override
78+
public TransferPair makeTransferPair(ValueVector to) {
79+
return new TransferImpl((UuidVector) to);
80+
}
81+
82+
public void setSafe(int index, byte[] value) {
83+
getUnderlyingVector().setIndexDefined(index);
84+
getUnderlyingVector().setSafe(index, value);
85+
}
86+
87+
public class TransferImpl implements TransferPair {
88+
UuidVector to;
89+
ValueVector targetUnderlyingVector;
90+
TransferPair tp;
91+
92+
public TransferImpl(UuidVector to) {
93+
this.to = to;
94+
targetUnderlyingVector = this.to.getUnderlyingVector();
95+
tp = getUnderlyingVector().makeTransferPair(targetUnderlyingVector);
96+
}
97+
98+
public UuidVector getTo() {
99+
return this.to;
100+
}
101+
102+
public void transfer() {
103+
tp.transfer();
104+
}
105+
106+
public void splitAndTransfer(int startIndex, int length) {
107+
tp.splitAndTransfer(startIndex, length);
108+
}
109+
110+
public void copyValueSafe(int fromIndex, int toIndex) {
111+
tp.copyValueSafe(fromIndex, toIndex);
112+
}
113+
}
114+
}

vector/src/test/java/org/apache/arrow/vector/complex/impl/TestPromotableWriter.java

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@
3131
import org.apache.arrow.memory.BufferAllocator;
3232
import org.apache.arrow.vector.DecimalVector;
3333
import org.apache.arrow.vector.DirtyRootAllocator;
34-
import org.apache.arrow.vector.ExtensionTypeVector;
3534
import org.apache.arrow.vector.LargeVarBinaryVector;
3635
import org.apache.arrow.vector.LargeVarCharVector;
36+
import org.apache.arrow.vector.UuidVector;
3737
import org.apache.arrow.vector.VarBinaryVector;
3838
import org.apache.arrow.vector.VarCharVector;
3939
import org.apache.arrow.vector.complex.ListVector;
@@ -54,8 +54,7 @@
5454
import org.apache.arrow.vector.types.pojo.ArrowType.ArrowTypeID;
5555
import org.apache.arrow.vector.types.pojo.Field;
5656
import org.apache.arrow.vector.types.pojo.FieldType;
57-
import org.apache.arrow.vector.types.pojo.TestUuidVector.UuidType;
58-
import org.apache.arrow.vector.types.pojo.TestUuidVector.UuidVector;
57+
import org.apache.arrow.vector.types.pojo.UuidType;
5958
import org.apache.arrow.vector.util.DecimalUtility;
6059
import org.apache.arrow.vector.util.Text;
6160
import org.junit.jupiter.api.AfterEach;
@@ -806,32 +805,4 @@ public void testExtensionType() throws Exception {
806805
assertEquals(u2, uuidVector.getObject(1));
807806
}
808807
}
809-
810-
public class UuidWriterFactory implements ExtensionTypeWriterFactory {
811-
812-
@Override
813-
public AbstractFieldWriter getWriterImpl(ExtensionTypeVector extensionTypeVector) {
814-
if (extensionTypeVector instanceof UuidVector) {
815-
return new UuidWriterImpl((UuidVector) extensionTypeVector);
816-
}
817-
return null;
818-
}
819-
}
820-
821-
public class UuidWriterImpl extends AbstractExtensionTypeWriter {
822-
823-
public UuidWriterImpl(UuidVector vector) {
824-
super(vector);
825-
}
826-
827-
@Override
828-
public void writeExtensionType(Object var1) {
829-
UUID uuid = (UUID) var1;
830-
ByteBuffer bb = ByteBuffer.allocate(16);
831-
bb.putLong(uuid.getMostSignificantBits());
832-
bb.putLong(uuid.getLeastSignificantBits());
833-
((UuidVector) this.vector).setSafe(this.idx(), bb.array());
834-
this.vector.setValueCount(this.idx() + 1);
835-
}
836-
}
837808
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.arrow.vector.complex.impl;
18+
19+
import org.apache.arrow.vector.ExtensionTypeVector;
20+
import org.apache.arrow.vector.UuidVector;
21+
22+
public class UuidWriterFactory implements ExtensionTypeWriterFactory {
23+
24+
@Override
25+
public AbstractFieldWriter getWriterImpl(ExtensionTypeVector extensionTypeVector) {
26+
if (extensionTypeVector instanceof UuidVector) {
27+
return new UuidWriterImpl((UuidVector) extensionTypeVector);
28+
}
29+
return null;
30+
}
31+
}

0 commit comments

Comments
 (0)