Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -432,36 +432,42 @@ public ColumnVector getChild(int ordinal) {
}

private static class UnionConverter implements Converter {
private final Types.StructType structType;
private final Type type;
private final List<Converter> optionConverters;

private UnionConverter(Type type, List<Converter> optionConverters) {
this.structType = type.asStructType();
this.type = type;
this.optionConverters = optionConverters;
}

@Override
public ColumnVector convert(org.apache.orc.storage.ql.exec.vector.ColumnVector vector, int batchSize,
long batchOffsetInFile) {
UnionColumnVector unionColumnVector = (UnionColumnVector) vector;
List<Types.NestedField> fields = structType.fields();
List<ColumnVector> fieldVectors = Lists.newArrayListWithExpectedSize(fields.size());

LongColumnVector longColumnVector = new LongColumnVector();
longColumnVector.vector = Arrays.stream(unionColumnVector.tags).asLongStream().toArray();
if (optionConverters.size() > 1) {
// the case of complex union with multiple types
List<Types.NestedField> fields = type.asStructType().fields();
List<ColumnVector> fieldVectors = Lists.newArrayListWithExpectedSize(fields.size());

LongColumnVector longColumnVector = new LongColumnVector();
longColumnVector.vector = Arrays.stream(unionColumnVector.tags).asLongStream().toArray();

fieldVectors.add(new PrimitiveOrcColumnVector(Types.IntegerType.get(), batchSize, longColumnVector,
OrcValueReaders.ints(), batchOffsetInFile));
for (int i = 0; i < fields.size() - 1; i += 1) {
fieldVectors.add(optionConverters.get(i).convert(unionColumnVector.fields[i], batchSize, batchOffsetInFile));
}

fieldVectors.add(new PrimitiveOrcColumnVector(Types.IntegerType.get(), batchSize, longColumnVector,
OrcValueReaders.ints(), batchOffsetInFile));
for (int i = 0; i < fields.size() - 1; i += 1) {
fieldVectors.add(optionConverters.get(i).convert(unionColumnVector.fields[i], batchSize, batchOffsetInFile));
return new BaseOrcColumnVector(type.asStructType(), batchSize, vector) {
@Override
public ColumnVector getChild(int ordinal) {
return fieldVectors.get(ordinal);
}
};
} else {
// the case of single type union
return optionConverters.get(0).convert(unionColumnVector.fields[0], batchSize, batchOffsetInFile);
}

return new BaseOrcColumnVector(structType, batchSize, vector) {
@Override
public ColumnVector getChild(int ordinal) {
return fieldVectors.get(ordinal);
}
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,6 @@ public void testSingleTypeUnion() throws IOException {
}

// Test vectorized reader
/*
try (CloseableIterable<ColumnarBatch> reader = ORC.read(Files.localInput(orcFile))
.project(expectedSchema)
.createBatchedReaderFunc(readOrcSchema ->
Expand All @@ -304,7 +303,6 @@ public void testSingleTypeUnion() throws IOException {
assertEquals(expectedSchema, expectedFirstRow, actualRowsIt.next());
assertEquals(expectedSchema, expectedSecondRow, actualRowsIt.next());
}
*/
}

@Test
Expand Down Expand Up @@ -366,7 +364,6 @@ public void testSingleTypeUnionOfStruct() throws IOException {
}

// Test vectorized reader
/*
try (CloseableIterable<ColumnarBatch> reader = ORC.read(Files.localInput(orcFile))
.project(expectedSchema)
.createBatchedReaderFunc(readOrcSchema ->
Expand All @@ -377,7 +374,6 @@ public void testSingleTypeUnionOfStruct() throws IOException {
assertEquals(expectedSchema, expectedFirstRow, actualRowsIt.next());
assertEquals(expectedSchema, expectedSecondRow, actualRowsIt.next());
}
*/
}

@Test
Expand Down Expand Up @@ -441,7 +437,6 @@ public void testDeepNestedSingleTypeUnion() throws IOException {
}

// Test vectorized reader
/*
try (CloseableIterable<ColumnarBatch> reader = ORC.read(Files.localInput(orcFile))
.project(expectedSchema)
.createBatchedReaderFunc(readOrcSchema ->
Expand All @@ -452,7 +447,6 @@ public void testDeepNestedSingleTypeUnion() throws IOException {
assertEquals(expectedSchema, expectedFirstRow, actualRowsIt.next());
assertEquals(expectedSchema, expectedSecondRow, actualRowsIt.next());
}
*/
}

private Iterator<InternalRow> batchesToRows(Iterator<ColumnarBatch> batches) {
Expand Down