Skip to content
Closed
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 @@ -18,6 +18,7 @@
package org.apache.spark.sql.execution.datasources.orc;

import org.apache.hadoop.hive.ql.exec.vector.ColumnVector;
import org.apache.hadoop.hive.ql.exec.vector.ListColumnVector;

import org.apache.spark.sql.types.ArrayType;
import org.apache.spark.sql.types.DataType;
Expand All @@ -31,26 +32,22 @@
*/
public class OrcArrayColumnVector extends OrcColumnVector {
private final OrcColumnVector data;
private final long[] offsets;
private final long[] lengths;

OrcArrayColumnVector(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we don't need to store another copy of vector here. We can change OrcColumnVector.baseData from private to protected, and just use baseData to get offset and length. So how about defining the constructor like below:

OrcArrayColumnVector(
    DataType type,
    ListColumnVector vector,
    OrcColumnVector data) {

  super(type, vector);

  this.data = data;
}

DataType type,
ColumnVector vector,
OrcColumnVector data,
long[] offsets,
long[] lengths) {
OrcColumnVector data) {

super(type, vector);

this.data = data;
this.offsets = offsets;
this.lengths = lengths;
}

@Override
public ColumnarArray getArray(int rowId) {
return new ColumnarArray(data, (int) offsets[rowId], (int) lengths[rowId]);
int offsets = (int) ((ListColumnVector) baseData).offsets[rowId];
int lengths = (int) ((ListColumnVector) baseData).lengths[rowId];
return new ColumnarArray(data, offsets, lengths);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
* this column vector is used to adapt Hive ColumnVector with Spark ColumnarVector.
*/
public abstract class OrcColumnVector extends org.apache.spark.sql.vectorized.ColumnVector {
private final ColumnVector baseData;
protected final ColumnVector baseData;
private int batchSize;

OrcColumnVector(DataType type, ColumnVector vector) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,13 @@ static OrcColumnVector toOrcColumnVector(DataType type, ColumnVector vector) {
ListColumnVector listVector = (ListColumnVector) vector;
OrcColumnVector dataVector = toOrcColumnVector(
((ArrayType) type).elementType(), listVector.child);
return new OrcArrayColumnVector(
type, vector, dataVector, listVector.offsets, listVector.lengths);
return new OrcArrayColumnVector(type, vector, dataVector);
} else if (vector instanceof MapColumnVector) {
MapColumnVector mapVector = (MapColumnVector) vector;
MapType mapType = (MapType) type;
OrcColumnVector keysVector = toOrcColumnVector(mapType.keyType(), mapVector.keys);
OrcColumnVector valuesVector = toOrcColumnVector(mapType.valueType(), mapVector.values);
return new OrcMapColumnVector(
type, vector, keysVector, valuesVector, mapVector.offsets, mapVector.lengths);
return new OrcMapColumnVector(type, vector, keysVector, valuesVector);
} else {
throw new IllegalArgumentException(
String.format("OrcColumnVectorUtils.toOrcColumnVector should not take %s as type " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.apache.spark.sql.execution.datasources.orc;

import org.apache.hadoop.hive.ql.exec.vector.ColumnVector;
import org.apache.hadoop.hive.ql.exec.vector.MapColumnVector;

import org.apache.spark.sql.types.DataType;
import org.apache.spark.sql.types.Decimal;
Expand All @@ -32,28 +33,24 @@
public class OrcMapColumnVector extends OrcColumnVector {
private final OrcColumnVector keys;
private final OrcColumnVector values;
private final long[] offsets;
private final long[] lengths;

OrcMapColumnVector(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly we can define OrcMapColumnVector constructor as below:

OrcMapColumnVector(
    DataType type,
    MapColumnVector vector,
    OrcColumnVector keys,
    OrcColumnVector values) {

  super(type, vector);

  this.keys = keys;
  this.values = values;
}

DataType type,
ColumnVector vector,
OrcColumnVector keys,
OrcColumnVector values,
long[] offsets,
long[] lengths) {
OrcColumnVector values) {

super(type, vector);

this.keys = keys;
this.values = values;
this.offsets = offsets;
this.lengths = lengths;
}

@Override
public ColumnarMap getMap(int ordinal) {
return new ColumnarMap(keys, values, (int) offsets[ordinal], (int) lengths[ordinal]);
int offsets = (int) ((MapColumnVector) baseData).offsets[ordinal];
int lengths = (int) ((MapColumnVector) baseData).lengths[ordinal];
return new ColumnarMap(keys, values, offsets, lengths);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,28 @@ abstract class OrcQuerySuite extends OrcQueryTest with SharedSparkSession {
}
}

test("SPARK-37728: Reading nested columns with ORC vectorized reader should not " +
"cause ArrayIndexOutOfBoundsException") {
withTempPath { dir =>
val path = dir.getCanonicalPath
val df = spark.range(100).map { _ =>
val arrayColumn = (0 until 50).map(_ => (0 until 1000).map(k => k.toString))
arrayColumn
}.toDF("record").repartition(1)
df.write.format("orc").save(path)

withSQLConf(SQLConf.ORC_VECTORIZED_READER_NESTED_COLUMN_ENABLED.key -> "true") {
val readDf = spark.read.orc(path)
val vectorizationEnabled = readDf.queryExecution.executedPlan.find {
case scan @ (_: FileSourceScanExec | _: BatchScanExec) => scan.supportsColumnar
case _ => false
}.isDefined
assert(vectorizationEnabled)
checkAnswer(readDf, df)
}
}
}

test("SPARK-36594: ORC vectorized reader should properly check maximal number of fields") {
withTempPath { dir =>
val path = dir.getCanonicalPath
Expand Down