Skip to content

feat(parquet): support FINITE_VECTOR in Arrow Go - #1605

Draft
MashrafeeAryan wants to merge 6 commits into
apache:mainfrom
MashrafeeAryan:parquet-finite-vector
Draft

MashrafeeAryan wants to merge 6 commits into
apache:mainfrom
MashrafeeAryan:parquet-finite-vector

Conversation

@MashrafeeAryan

@MashrafeeAryan MashrafeeAryan commented Nov 18, 2026 •

Copy link
Copy Markdown

Rationale for this change

Arrow Go can already save a fixed-size list as a Parquet LIST. It needs a saved Arrow schema to recover the list size when reading. With FINITE_VECTOR(3) in the Parquet schema, Arrow Go can read the column as a fixed-size list of length 3 even when the file has no saved Arrow schema.

What changes are included in this PR?

  • Read and write the FINITE_VECTOR logical type.
  • Add the experimental pqarrow.WithFiniteVectorLogicalType() option. It writes fixed-size lists as vectors when their size is positive and their elements are booleans, integers, floats, or decimals. Other fixed-size lists are written as plain LIST.
  • Reject null elements, NaN, and infinity when writing a present vector. A whole vector can still be null if the column allows it.
  • Fix reading a required fixed-size list under a nullable struct when the list is stored as a plain Parquet LIST with a saved Arrow schema.
  • Restore saved element metadata for regular, large, and fixed-size lists.
  • Regenerate the Go Thrift bindings with Thrift 0.22.0 from apache/parquet-format at ec90dd4. This also includes the upstream FILE field in the generated bindings.

References: Parquet spec, Arrow C++ PR, and Parquet Java PR.

Are these changes tested?

Yes. go test ./parquet/... -count=1 passed on Windows. The new cases cover eligible element types, nested and sliced vectors, invalid values and schema shapes, LIST fallback, and the two fixes for ordinary lists.

Are there any user-facing changes?

Arrow Go can read the list size directly from FINITE_VECTOR. Writing it requires opting in with pqarrow.WithFiniteVectorLogicalType(). The option is off by default. Older Arrow Go versions without FINITE_VECTOR support cannot open files that use the annotation and may panic while reading the schema.

Codex and Gemini assisted with reviewing it. Codex also helped address the review feedback.

Read and save the size stored in FINITE_VECTOR. Check the list shape before linking its children so a bad schema leaves the original nodes alone.
Use the size in the Parquet label to rebuild each list. Keep missing rows missing and reject lists with the wrong number of values.
Add an opt-in setting to save the size in Parquet. Keep using normal list storage and reject missing or non-finite values inside a present vector.
Use the same schema checks whether the caller passes a finite vector type directly or by pointer. Reject a nil pointer before reading the type.
Stop the direct writer from saving a finite vector whose dictionary hides a NaN or other invalid value. Ordinary list writes still support dictionaries.
@MashrafeeAryan

Copy link
Copy Markdown
Author

Hi @rok, I opened this PR for the FINITE_VECTOR implementation. Whenver you have time, would you please review it? Thank you so much!

@rok rok left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you for working on this @MashrafeeAryan !
I posted some 🤖 assisted comments, please take a look.

validityIO := file.ValidityBitmapInputOutput{ReadUpperBound: lenBound}
if lr.field.Nullable {
// Required fixed-size lists can still be absent under a null struct.
if lr.field.Nullable || lr.field.Type.ID() == arrow.FIXED_SIZE_LIST {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This fixes a bug that exists independently of FINITE_VECTOR. On main, a non-nullable fixed_size_list under a nullable struct, written as a plain LIST with WithStoreSchema(), fails to read back:

expected all lists to be of size=3, but index 1 had size=0

With this change it round-trips. TestFiniteVectorUnderNullStruct only exercises it together with WithFiniteVectorLogicalType(), so could you add a case that uses WithStoreSchema() without the new option? That pins the fix for ordinary lists too. It also deserves a line in the PR description.

Comment thread parquet/pqarrow/schema.go

modified = origin.Type.ID() != inferred.Field.Type.ID()
childModified, err := applyOriginalMetadata(arrow.Field{Type: origin.Type.(arrow.ListLikeType).Elem()}, &inferred.Children[0])
originalElement := origin.Type.(arrow.ListLikeType).ElemField()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Switching from Elem() to ElemField() changes what applyOriginalMetadata sees for every list-like type, not only for fixed-size lists inferred from FINITE_VECTOR. The element field's metadata from ARROW:schema is now merged back for list, large_list and fixed_size_list; on main it is dropped. I checked with a list<item: int32> whose item field carries {"k": "v"}.

I think the new behaviour is the right one, and it matches C++, which passes the full child field. It is a user-visible change outside the scope of this PR though, so please add a small test for it and mention it in the description.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I have added a test for it as well.

Comment thread parquet/pqarrow/properties.go Outdated
Comment on lines +117 to +119
// WithFiniteVectorLogicalType writes eligible fixed-size lists as FINITE_VECTOR.
// This is off by default. A present vector cannot contain nulls, NaN or infinity.
// Readers must support FINITE_VECTOR to preserve the size without an Arrow schema.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

A few things for this doc comment:

  • The effect on older readers is stronger than losing the size. arrow-go without this PR panics with invalid logical type in schema.getLogicalType when it opens a file written with this option (I read such a file from this PR's merge base), because unknown LogicalType union members are not tolerated. That is a pre-existing problem and not for this PR to fix, but the comment should warn that older arrow-go versions cannot open these files at all.
  • FINITE_VECTOR is merged in parquet-format but not in a release yet, and the C++ and Java implementations are still in review. Could we mark the option as experimental, like the C++ PR does?
  • It would help to say what "eligible" means (size > 0 and a bool, integer, float or decimal element type) and that everything else is still written as a plain LIST.

VARIANT *VariantType `thrift:"VARIANT,16" db:"VARIANT" json:"VARIANT,omitempty"`
GEOMETRY *GeometryType `thrift:"GEOMETRY,17" db:"GEOMETRY" json:"GEOMETRY,omitempty"`
GEOGRAPHY *GeographyType `thrift:"GEOGRAPHY,18" db:"GEOGRAPHY" json:"GEOGRAPHY,omitempty"`
// unused field # 19

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

How was this file regenerated? Upstream parquet.thrift (and the copy in the C++ PR) has 19: FileType FILE in the LogicalType union, and generating from upstream master produces a FileType struct. Here field 19 is skipped, while the FILE - undefined line in the ColumnOrder comment did come along, so it looks like the thrift file was trimmed before generating.

I would prefer a plain regeneration from a pinned parquet-format commit, with the commit noted in the PR description, so the next regeneration does not produce unrelated diffs.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I have regenrated it from ec90dd4 and linked in the PR description

Comment thread parquet/pqarrow/encode_arrow.go Outdated
// Using an arrow column writer is a convenience to avoid having to process the arrow array yourself
// and determine the correct definition and repetition levels manually.
func newArrowColumnWriter(data *arrow.Chunked, offset, size int64, manifest *SchemaManifest, rgw file.RowGroupWriter, leafColIdx int) (arrowColumnWriter, error) {
func newArrowColumnWriter(data *arrow.Chunked, offset, size int64, manifest *SchemaManifest, rgw file.RowGroupWriter, leafColIdx int, writeFiniteVector bool) (arrowColumnWriter, error) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: writeFiniteVector looks redundant. The Parquet schema is built from the same ArrowWriterProperties, so isFiniteVectorLeaf on the column descriptors already says which leaves are vector elements, and WriteArrowToColumn relies on exactly that. Dropping the parameter also removes the possibility of the flag and the schema disagreeing, in which case the level builder would treat a required element as nullable.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I agree with you Rok! I have removed the redundant flag

ctx := context.Background()
mem := memory.NewCheckedAllocator(memory.DefaultAllocator)
defer mem.AssertSize(t, 0)
typ := arrow.FixedSizeListOf(3, arrow.PrimitiveTypes.Float32)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The write tests only cover float32. Could you make this table-driven over the eligible element types (bool, signed and unsigned ints, float16, float64, decimal128, decimal256)? The Float16 and Float64 branches of checkFiniteVectorValues are currently not executed by any test.

A few more cases that pass when I run them locally and are worth pinning:

  • a vector nested in list<...> and as a map value
  • a sliced input array
  • a null vector whose child slots hold nulls, which must be accepted

For the fallback, an assertion on the written Parquet schema is enough: a plain LIST for ineligible element types (string, date32, dictionary) and for list size 0. Please don't round-trip the size-0 case, it has an unrelated problem that predates this PR.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I didn't think of those cases. Thank you so much! I have added tests for all the necessary types.

list, err := NewGroupNode("list", parquet.Repetitions.Repeated, FieldList{element}, -1)
require.NoError(t, err)

for _, annotation := range []LogicalType{logical, &logical} {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could you also cover the other rejections in validateFiniteVector? For example an element not named element, an optional element, a two-level list without the list group, an unsupported element type such as BYTE_ARRAY, and FINITE_VECTOR on a primitive node. A table like TestFiniteVectorLogicalType.InvalidStructure in the C++ PR would do.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Added the tests for the cases you mentioned

@MashrafeeAryan

Copy link
Copy Markdown
Author

Thank you for working on this @MashrafeeAryan !
I posted some 🤖 assisted comments, please take a look.

Thank you so much Rok! I will look more into it!

@MashrafeeAryan

MashrafeeAryan commented Dec 3, 2026 •

Copy link
Copy Markdown
Author

Hi @rok, I have pushed some commits addressing the review comments. Thank you so much for the review!

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.

2 participants