Skip to content

[spark][flink] Fix vector-field column conversion in catalogs - #9014

Open
jackylee-ch wants to merge 1 commit into
apache:masterfrom
jackylee-ch:spark-vector-field-conversion
Open

[spark][flink] Fix vector-field column conversion in catalogs#9014
jackylee-ch wants to merge 1 commit into
apache:masterfrom
jackylee-ch:spark-vector-field-conversion

Conversation

@jackylee-ch

@jackylee-ch jackylee-ch commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Purpose

SparkCatalog.toInitialSchema converts a column listed in vector-field into a Paimon VECTOR. Problems on that path:

  • The array check reports The type of blob field must be array — copied from the BLOB branch above it, naming the wrong option.
  • checkArgument is given a template with %s but no varargs, so the user is told to set the literal key field.%s.vector-dim. Flink's LogicalTypeConversion.toVectorType has the same defect.
  • Integer.parseInt(properties.get(dimKey)) is unguarded, so a non-integer dimension surfaces as a raw NumberFormatException. Flink already guards this.
  • DataTypes.VECTOR(length, element) forces isNullable = true, so NOT NULL was silently dropped. The BLOB branch in the same method and ColumnDirectiveUtils.convertType both preserve it.

Extracts the conversion into SparkCatalog#toVectorType, mirroring the existing toBlobType. No storage format or option semantics change.

Tests

DDLTestBase, LogicalTypeConversionTest.

### Purpose

`SparkCatalog.toInitialSchema` converts a column listed in the `vector-field`
option into a Paimon `VECTOR`. Three problems on that path:

1. The array check reports `"The type of blob field must be array"` — the
   message was copied from the BLOB branch above it and names the wrong option.
2. `checkArgument` is called with a template containing `%s` but no varargs, so
   `Preconditions` leaves the placeholders unsubstituted and the user is told to
   set the literal key `field.%s.vector-dim`. `LogicalTypeConversion.toVectorType`
   on the Flink side has the same defect.
3. `Integer.parseInt(properties.get(dimKey))` is unguarded, so a non-integer
   dimension surfaces as a raw `NumberFormatException: For input string: "abc"`
   from inside the catalog. Flink already guards this; Spark did not.

`DataTypes.VECTOR(length, element)` also forces `isNullable = true`, so a
`NOT NULL` array column declared in Spark silently lost its nullability. The
BLOB branch in the same method and the `__VECTOR_FIELD` comment-directive path in
`ColumnDirectiveUtils.convertType` both preserve it.

### Changes

- Extract the vector conversion into `SparkCatalog#toVectorType`, mirroring the
  existing `toBlobType`: name the option correctly, pass the `checkArgument`
  arguments, reject blank/non-integer dimensions with the option key in the
  message, and build `VectorType` with the declared nullability.
- Align the two `checkArgument` messages in Flink's `toVectorType` and reuse
  `StringUtils.isNullOrWhitespaceOnly` so a whitespace-only dimension is rejected
  the same way in both engines.

No storage format or option semantics change; only validation messages and the
nullability carried into the schema.

### Tests

- Added `Paimon DDL: create table with vector-field` and `Paimon DDL: create
  table with invalid vector-field` to `DDLTestBase`, covering the round-trip
  (length, element type, `NOT NULL`) and all four rejection paths. These run for
  every Spark version via the per-module `DDLTest` subclasses.
- `mvn -pl paimon-spark/paimon-spark-3.5 -am -Pfast-build,spark3 -DfailIfNoTests=false -DwildcardSuites=org.apache.paimon.spark.sql.DDLTest -Dtest=none test`
  → 35 succeeded, 0 failed (33 on master before this change).
- `mvn -pl paimon-flink/paimon-flink-common -Pfast-build -Dtest=LogicalTypeConversionTest test`
  → 6 succeeded, 0 failed.
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.

1 participant