Skip to content

[common][spark] Fix ClassCastException when reading a VECTOR column as ARRAY#8830

Merged
JingsongLi merged 3 commits into
apache:masterfrom
XiaoHongbo-Hope:fix_vector_read_as_array
Jul 23, 2026
Merged

[common][spark] Fix ClassCastException when reading a VECTOR column as ARRAY#8830
JingsongLi merged 3 commits into
apache:masterfrom
XiaoHongbo-Hope:fix_vector_read_as_array

Conversation

@XiaoHongbo-Hope

@XiaoHongbo-Hope XiaoHongbo-Hope commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Purpose

Reading a VECTOR column through Flink throws:

java.lang.ClassCastException: ...CastedVectorColumnVector cannot be cast to ...ArrayColumnVector
    at ...VectorizedColumnBatch.getArray(VectorizedColumnBatch.java:125)
    at ...ColumnarRow.getArray(ColumnarRow.java:169)
    at ...FlinkRowData.getArray(FlinkRowData.java:137)

Flink has no vector type, so DataTypeToLogicalType maps a Paimon VectorType to a Flink ArrayType, and Flink's generated code reads the column via getArray. However the columnar read produces a VecColumnVector (e.g. CastedVectorColumnVector / ReadableVectorColumnVector), and VectorizedColumnBatch.getArray unconditionally cast it to ArrayColumnVector, causing the ClassCastException.

(Spark is not affected: it keeps the Paimon VectorType and reads a VECTOR column via getVector, see AbstractSparkInternalRow. Only the Flink path, which flattens VECTOR to ARRAY and calls getArray, hits this.)

Since a vector is an array (InternalVector extends InternalArray), read a VecColumnVector column through getVector. This mirrors the ARRAY-vs-VECTOR branching that ColumnarArray and RowToColumnConverter already do, and makes getArray robust for any caller that reads a VECTOR column as an array.

Tests

ColumnarRowWithVectorTest#testVectorReadAsArray — reads a VECTOR column via getArray; fails with ClassCastException before the fix, passes after.

A VECTOR column is exposed as ARRAY at the engine boundary (e.g. Flink maps
VECTOR to ARRAY), so it is read through VectorizedColumnBatch.getArray. But the
columnar read produces a VecColumnVector (e.g. CastedVectorColumnVector), and
getArray blindly cast it to ArrayColumnVector, throwing ClassCastException.

Since a vector is an array (InternalVector extends InternalArray), read a
VecColumnVector column via getVector, mirroring what ColumnarArray and
RowToColumnConverter already do for the ARRAY-vs-VECTOR split.
For ARRAY<VECTOR<..>> / MAP<.., VECTOR<..>>, the element column is a
VecColumnVector read through ColumnarArray.getArray, which had the same blind
cast to ArrayColumnVector and threw ClassCastException. Apply the same branch,
and add a nested regression test.

@yunfengzhou-hub yunfengzhou-hub left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

+1

For ARRAY<VECTOR<..>> / MAP<.., VECTOR<..>>, a Spark array element's type is a
VectorType (VECTOR is exposed as a Spark array), but SparkArrayData.getArray
cast the element type to ArrayType unconditionally, throwing ClassCastException.
Branch on VectorType vs ArrayType, mirroring AbstractSparkInternalRow.getArray.
@XiaoHongbo-Hope XiaoHongbo-Hope changed the title [common] Fix ClassCastException when reading a VECTOR column as ARRAY [common][spark] Fix ClassCastException when reading a VECTOR column as ARRAY Jul 23, 2026

@JingsongLi JingsongLi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

+1

@JingsongLi
JingsongLi merged commit 5df8b98 into apache:master Jul 23, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants