Skip to content

Commit b824938

Browse files
committed
fix types; add licenses; more tests; more complex
1 parent 2fd3bc1 commit b824938

20 files changed

+369
-105
lines changed

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

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,11 @@
4242
import java.util.Iterator;
4343
import org.apache.arrow.vector.complex.impl.ComplexCopier;
4444
import org.apache.arrow.vector.util.CallBack;
45+
import org.apache.arrow.vector.schema.ArrowFieldNode;
4546

4647
import static org.apache.arrow.flatbuf.UnionMode.Sparse;
4748

49+
4850
/*
4951
* This class is generated using freemarker and the ${.template_name} template.
5052
*/
@@ -59,7 +61,7 @@
5961
* For performance reasons, UnionVector stores a cached reference to each subtype vector, to avoid having to do the map lookup
6062
* each time the vector is accessed.
6163
*/
62-
public class UnionVector implements ValueVector {
64+
public class UnionVector implements FieldVector {
6365

6466
private String name;
6567
private BufferAllocator allocator;
@@ -97,6 +99,28 @@ public MinorType getMinorType() {
9799
return MinorType.UNION;
98100
}
99101

102+
@Override
103+
public void initializeChildrenFromFields(List<Field> children) {
104+
getMap().initializeChildrenFromFields(children);
105+
}
106+
107+
@Override
108+
public List<FieldVector> getChildrenFromFields() {
109+
return getMap().getChildrenFromFields();
110+
}
111+
112+
@Override
113+
public void loadFieldBuffers(ArrowFieldNode fieldNode, List<ArrowBuf> ownBuffers) {
114+
// TODO
115+
throw new UnsupportedOperationException();
116+
}
117+
118+
@Override
119+
public List<ArrowBuf> getFieldBuffers() {
120+
// TODO
121+
throw new UnsupportedOperationException();
122+
}
123+
100124
public MapVector getMap() {
101125
if (mapVector == null) {
102126
int vectorCount = internalMap.size();
@@ -239,10 +263,10 @@ public void copyFromSafe(int inIndex, int outIndex, UnionVector from) {
239263
copyFrom(inIndex, outIndex, from);
240264
}
241265
242-
public ValueVector addVector(ValueVector v) {
266+
public FieldVector addVector(FieldVector v) {
243267
String name = v.getMinorType().name().toLowerCase();
244268
Preconditions.checkState(internalMap.getChild(name) == null, String.format("%s vector already exists", name));
245-
final ValueVector newVector = internalMap.addOrGet(name, v.getMinorType(), v.getClass());
269+
final FieldVector newVector = internalMap.addOrGet(name, v.getMinorType(), v.getClass());
246270
v.makeTransferPair(newVector).transfer();
247271
internalMap.putChild(name, newVector);
248272
if (callBack != null) {

java/vector/src/main/java/org/apache/arrow/vector/FieldVector.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
118
package org.apache.arrow.vector;
219

320
import java.util.List;

java/vector/src/main/java/org/apache/arrow/vector/ValueVector.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@
1919

2020
import java.io.Closeable;
2121

22-
import io.netty.buffer.ArrowBuf;
23-
2422
import org.apache.arrow.memory.BufferAllocator;
2523
import org.apache.arrow.memory.OutOfMemoryException;
2624
import org.apache.arrow.vector.complex.reader.FieldReader;
2725
import org.apache.arrow.vector.types.Types.MinorType;
28-
import org.apache.arrow.vector.util.TransferPair;
2926
import org.apache.arrow.vector.types.pojo.Field;
27+
import org.apache.arrow.vector.util.TransferPair;
28+
29+
import io.netty.buffer.ArrowBuf;
3030

3131
/**
3232
* An abstraction that is used to store a sequence of values in an individual column.

java/vector/src/main/java/org/apache/arrow/vector/VectorLoader.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
118
package org.apache.arrow.vector;
219

320
import static com.google.common.base.Preconditions.checkArgument;

java/vector/src/main/java/org/apache/arrow/vector/VectorUnloader.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
118
package org.apache.arrow.vector;
219

320
import java.util.ArrayList;

java/vector/src/main/java/org/apache/arrow/vector/ZeroVector.java

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,23 @@
1717
*/
1818
package org.apache.arrow.vector;
1919

20-
import com.google.flatbuffers.FlatBufferBuilder;
21-
import io.netty.buffer.ArrowBuf;
22-
2320
import java.util.Collections;
2421
import java.util.Iterator;
22+
import java.util.List;
2523

26-
import org.apache.arrow.flatbuf.Type;
2724
import org.apache.arrow.memory.BufferAllocator;
2825
import org.apache.arrow.memory.OutOfMemoryException;
2926
import org.apache.arrow.vector.complex.impl.NullReader;
3027
import org.apache.arrow.vector.complex.reader.FieldReader;
28+
import org.apache.arrow.vector.schema.ArrowFieldNode;
3129
import org.apache.arrow.vector.types.Types.MinorType;
3230
import org.apache.arrow.vector.types.pojo.ArrowType.Null;
3331
import org.apache.arrow.vector.types.pojo.Field;
3432
import org.apache.arrow.vector.util.TransferPair;
3533

36-
import com.google.common.collect.Iterators;
34+
import io.netty.buffer.ArrowBuf;
3735

38-
public class ZeroVector implements ValueVector {
36+
public class ZeroVector implements FieldVector {
3937
public final static ZeroVector INSTANCE = new ZeroVector();
4038

4139
private final String name = "[DEFAULT]";
@@ -175,4 +173,28 @@ public Mutator getMutator() {
175173
public FieldReader getReader() {
176174
return NullReader.INSTANCE;
177175
}
176+
177+
@Override
178+
public void initializeChildrenFromFields(List<Field> children) {
179+
if (!children.isEmpty()) {
180+
throw new IllegalArgumentException("Zero vector has no children");
181+
}
182+
}
183+
184+
@Override
185+
public List<FieldVector> getChildrenFromFields() {
186+
return Collections.emptyList();
187+
}
188+
189+
@Override
190+
public void loadFieldBuffers(ArrowFieldNode fieldNode, List<ArrowBuf> ownBuffers) {
191+
if (!ownBuffers.isEmpty()) {
192+
throw new IllegalArgumentException("Zero vector has no buffers");
193+
}
194+
}
195+
196+
@Override
197+
public List<ArrowBuf> getFieldBuffers() {
198+
return Collections.emptyList();
199+
}
178200
}

java/vector/src/main/java/org/apache/arrow/vector/complex/AbstractContainerVector.java

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

20-
import java.util.Collection;
21-
22-
import javax.annotation.Nullable;
23-
24-
import org.apache.arrow.flatbuf.Field;
2520
import org.apache.arrow.memory.BufferAllocator;
2621
import org.apache.arrow.memory.OutOfMemoryException;
22+
import org.apache.arrow.vector.FieldVector;
2723
import org.apache.arrow.vector.ValueVector;
2824
import org.apache.arrow.vector.types.Types.MinorType;
2925
import org.apache.arrow.vector.util.CallBack;
3026

31-
import com.google.common.base.Function;
32-
import com.google.common.base.Preconditions;
33-
import com.google.common.collect.Iterables;
34-
import com.google.common.collect.Sets;
35-
3627
/**
3728
* Base class for composite vectors.
3829
*
@@ -65,8 +56,8 @@ public BufferAllocator getAllocator() {
6556
/**
6657
* Returns a {@link org.apache.arrow.vector.ValueVector} corresponding to the given field name if exists or null.
6758
*/
68-
public ValueVector getChild(String name) {
69-
return getChild(name, ValueVector.class);
59+
public FieldVector getChild(String name) {
60+
return getChild(name, FieldVector.class);
7061
}
7162

7263
/**
@@ -81,7 +72,7 @@ public void close() {
8172

8273
protected <T extends ValueVector> T typeify(ValueVector v, Class<T> clazz) {
8374
if (clazz.isAssignableFrom(v.getClass())) {
84-
return (T) v;
75+
return clazz.cast(v);
8576
}
8677
throw new IllegalStateException(String.format("Vector requested [%s] was different than type stored [%s]. Arrow doesn't yet support hetergenous types.", clazz.getSimpleName(), v.getClass().getSimpleName()));
8778
}
@@ -94,10 +85,10 @@ protected boolean supportsDirectRead() {
9485
public abstract int size();
9586

9687
// add a new vector with the input MajorType or return the existing vector if we already added one with the same type
97-
public abstract <T extends ValueVector> T addOrGet(String name, MinorType minorType, Class<T> clazz, int... precisionScale);
88+
public abstract <T extends FieldVector> T addOrGet(String name, MinorType minorType, Class<T> clazz, int... precisionScale);
9889

9990
// return the child vector with the input name
100-
public abstract <T extends ValueVector> T getChild(String name, Class<T> clazz);
91+
public abstract <T extends FieldVector> T getChild(String name, Class<T> clazz);
10192

10293
// return the child vector's ordinal in the composite container
10394
public abstract VectorWithOrdinal getChildVectorWithOrdinal(String name);

java/vector/src/main/java/org/apache/arrow/vector/complex/AbstractMapVector.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@
1818
package org.apache.arrow.vector.complex;
1919

2020
import java.util.ArrayList;
21+
import java.util.Collections;
2122
import java.util.Iterator;
2223
import java.util.List;
2324

2425
import org.apache.arrow.memory.BufferAllocator;
26+
import org.apache.arrow.vector.FieldVector;
2527
import org.apache.arrow.vector.ValueVector;
2628
import org.apache.arrow.vector.types.Types.MinorType;
2729
import org.apache.arrow.vector.util.CallBack;
@@ -40,7 +42,7 @@ public abstract class AbstractMapVector extends AbstractContainerVector {
4042
private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(AbstractContainerVector.class);
4143

4244
// Maintains a map with key as field name and value is the vector itself
43-
private final MapWithOrdinal<String, ValueVector> vectors = new MapWithOrdinal<>();
45+
private final MapWithOrdinal<String, FieldVector> vectors = new MapWithOrdinal<>();
4446

4547
protected AbstractMapVector(String name, BufferAllocator allocator, CallBack callBack) {
4648
super(name, allocator, callBack);
@@ -108,7 +110,7 @@ public boolean allocateNewSafe() {
108110
* @return resultant {@link org.apache.arrow.vector.ValueVector}
109111
*/
110112
@Override
111-
public <T extends ValueVector> T addOrGet(String name, MinorType minorType, Class<T> clazz, int... precisionScale) {
113+
public <T extends FieldVector> T addOrGet(String name, MinorType minorType, Class<T> clazz, int... precisionScale) {
112114
final ValueVector existing = getChild(name);
113115
boolean create = false;
114116
if (existing == null) {
@@ -152,7 +154,7 @@ public ValueVector getChildByOrdinal(int id) {
152154
* field name if exists or null.
153155
*/
154156
@Override
155-
public <T extends ValueVector> T getChild(String name, Class<T> clazz) {
157+
public <T extends FieldVector> T getChild(String name, Class<T> clazz) {
156158
final ValueVector v = vectors.get(name.toLowerCase());
157159
if (v == null) {
158160
return null;
@@ -165,7 +167,7 @@ protected ValueVector add(String name, MinorType minorType, int... precisionScal
165167
if (existing != null) {
166168
throw new IllegalStateException(String.format("Vector already exists: Existing[%s], Requested[%s] ", existing.getClass().getSimpleName(), minorType));
167169
}
168-
ValueVector vector = minorType.getNewVector(name, allocator, callBack, precisionScale);
170+
FieldVector vector = minorType.getNewVector(name, allocator, callBack, precisionScale);
169171
putChild(name, vector);
170172
if (callBack!=null) {
171173
callBack.doWork();
@@ -178,7 +180,7 @@ protected ValueVector add(String name, MinorType minorType, int... precisionScal
178180
*
179181
* Note that this method does not enforce any vector type check nor throws a schema change exception.
180182
*/
181-
protected void putChild(String name, ValueVector vector) {
183+
protected void putChild(String name, FieldVector vector) {
182184
putVector(name, vector);
183185
}
184186

@@ -187,7 +189,7 @@ protected void putChild(String name, ValueVector vector) {
187189
* @param name field name
188190
* @param vector vector to be inserted
189191
*/
190-
protected void putVector(String name, ValueVector vector) {
192+
protected void putVector(String name, FieldVector vector) {
191193
final ValueVector old = vectors.put(
192194
Preconditions.checkNotNull(name, "field name cannot be null").toLowerCase(),
193195
Preconditions.checkNotNull(vector, "vector cannot be null")
@@ -201,9 +203,9 @@ protected void putVector(String name, ValueVector vector) {
201203
/**
202204
* Returns a sequence of underlying child vectors.
203205
*/
204-
protected List<ValueVector> getChildren() {
206+
protected List<FieldVector> getChildren() {
205207
int size = vectors.size();
206-
List<ValueVector> children = new ArrayList<>();
208+
List<FieldVector> children = new ArrayList<>();
207209
for (int i = 0; i < size; i++) {
208210
children.add(vectors.getByOrdinal(i));
209211
}
@@ -228,7 +230,7 @@ public int size() {
228230

229231
@Override
230232
public Iterator<ValueVector> iterator() {
231-
return vectors.values().iterator();
233+
return Collections.<ValueVector>unmodifiableCollection(vectors.values()).iterator();
232234
}
233235

234236
/**

0 commit comments

Comments
 (0)