Skip to content

Data, Spark: Fix FIXED type conversion in format model TCK - #17482

Open
joyhaldar wants to merge 1 commit into
apache:mainfrom
joyhaldar:spark-fixed-type-converter
Open

Data, Spark: Fix FIXED type conversion in format model TCK#17482
joyhaldar wants to merge 1 commit into
apache:mainfrom
joyhaldar:spark-fixed-type-converter

Conversation

@joyhaldar

@joyhaldar joyhaldar commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

InternalRowConverter cast both FIXED and BINARY to ByteBuffer, but Iceberg's generic model represents fixed as byte[], leading to ClassCastException. FIXED was excluded from the Spark TCK as a result.

  1. toByteArray handles both, delegating to ByteBuffers.toByteArray for the buffer case.
  2. Removes FIXED from unsupportedTypeIds() in Spark 3.5/4.0/4.1.
  3. Adds fixed_with_default to DataGenerators.PrimitiveDefaults, exercising both branches alongside binary_with_default.

Refs: GenericDataUtil.internalToGeneric, RandomGenericData.

@joyhaldar
joyhaldar marked this pull request as ready for review August 3, 2026 03:30
@joyhaldar
joyhaldar force-pushed the spark-fixed-type-converter branch from 71520b3 to f19ea71 Compare August 3, 2026 03:30
@joyhaldar joyhaldar changed the title Spark: Fix FIXED type conversion in format model TCK Data, Spark: Fix FIXED type conversion in format model TCK Aug 3, 2026

@Guosmilesmile Guosmilesmile 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.

Thank you very much for your PR. Overall, LGTM!

if (value instanceof byte[]) {
return (byte[]) value;
}
return ByteBuffers.toByteArray((ByteBuffer) value);

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.

nit: newline

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

if (value instanceof byte[]) {
return (byte[]) value;
}
return ByteBuffers.toByteArray((ByteBuffer) value);

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.

nit:newline.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

if (value instanceof byte[]) {
return (byte[]) value;
}
return ByteBuffers.toByteArray((ByteBuffer) value);

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.

nit:newline.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

@joyhaldar
joyhaldar force-pushed the spark-fixed-type-converter branch from f19ea71 to 5dca7d0 Compare August 3, 2026 03:46
@joyhaldar

Copy link
Copy Markdown
Contributor Author

Thank you very much for your PR. Overall, LGTM!

Addressed the nits, thank you very much for the review!

Comment on lines +111 to +115
if (value instanceof byte[]) {
return (byte[]) value;
}

return ByteBuffers.toByteArray((ByteBuffer) value);

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.

Maybe:

Suggested change
if (value instanceof byte[]) {
return (byte[]) value;
}
return ByteBuffers.toByteArray((ByteBuffer) value);
return value instanceof byte[] bytes ? bytes : ByteBuffers.toByteArray((ByteBuffer) value);

or

Suggested change
if (value instanceof byte[]) {
return (byte[]) value;
}
return ByteBuffers.toByteArray((ByteBuffer) value);
if (value instanceof byte[] bytes) {
return bytes;
} else if (value instanceof ByteBuffer buffer) {
return ByteBuffers.toByteArray(buffer);
}
throw new UnsupportedOperationException(
"Unsupported binary value class: " + value.getClass().getName());

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thank you for your review @pvary. Went with the second option. Updated across all three Spark versions.

Co-authored-by: Joy Haldar <joy.haldar@target.com>
@joyhaldar
joyhaldar force-pushed the spark-fixed-type-converter branch from 5dca7d0 to c435fd9 Compare August 3, 2026 13:23
@pvary
pvary requested a review from huaxingao August 3, 2026 14:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants