From a836c04bbe279b31c45245adee262432a5cceadb Mon Sep 17 00:00:00 2001 From: hao-xu5 Date: Mon, 5 Oct 2026 13:25:28 -0700 Subject: [PATCH] fix: Decode fixed_size_list as the matching Feast list value type `pa_to_feast_value_type` had no handling for `fixed_size_list`, so decoding an Arrow vector column raised `KeyError: 'fixed_size_list[8]'`. The variable-width spelling `list` already decoded to `FLOAT_LIST`, so only the fixed-width spelling was affected. That spelling is how Arrow-native stores represent an embedding, and it is the type `_validate_vector_field_lengths` reads a vector's width from, so schema inference failed on exactly the columns the vector support added in #6909 is meant to describe. A Feast value type carries no width -- `Field.vector_length` carries it -- so the fixed-width spelling is rewritten into the variable-width one and decodes identically, leaving the list handling single-sourced. Nesting is preserved, so a nested fixed-size list still decodes to `VALUE_LIST`. Signed-off-by: hao-xu5 --- sdk/python/feast/type_map.py | 14 +++++++ sdk/python/tests/unit/test_type_map.py | 57 ++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) diff --git a/sdk/python/feast/type_map.py b/sdk/python/feast/type_map.py index e86885f182f..16334e367c3 100644 --- a/sdk/python/feast/type_map.py +++ b/sdk/python/feast/type_map.py @@ -1595,8 +1595,22 @@ def _proto_value_to_value_type(proto_value: ProtoValue) -> ValueType: return PROTO_VALUE_TO_VALUE_TYPE_MAP[proto_str] +_FIXED_SIZE_LIST_PREFIX = "fixed_size_list ValueType: is_list = False + if pa_type_as_str.startswith(_FIXED_SIZE_LIST_PREFIX): + # A fixed-width vector is a list whose width happens to be fixed, and is + # how Arrow-native stores represent embeddings. Feast value types do not + # encode a width -- Field.vector_length carries it -- so this decodes to + # the same value type as the variable-width spelling, and is rewritten + # into that spelling so the list handling below stays single-sourced. + inner = pa_type_as_str[len(_FIXED_SIZE_LIST_PREFIX) :] + closing = inner.rfind(">") + if closing != -1: + pa_type_as_str = f"list" + if pa_type_as_str.startswith("list[8]") == ( + ValueType.FLOAT_LIST + ) + assert pa_to_feast_value_type("fixed_size_list[1536]") == ( + ValueType.DOUBLE_LIST + ) + assert pa_to_feast_value_type("fixed_size_list[4]") == ( + ValueType.INT64_LIST + ) + assert pa_to_feast_value_type("fixed_size_list[4]") == ( + ValueType.INT32_LIST + ) + assert pa_to_feast_value_type("fixed_size_list[2]") == ( + ValueType.STRING_LIST + ) + assert pa_to_feast_value_type("fixed_size_list[2]") == ( + ValueType.BOOL_LIST + ) + + +def test_pa_to_feast_value_type_fixed_size_list_matches_variable_width(): + for fixed, variable in [ + ("fixed_size_list[8]", "list"), + ("fixed_size_list[1536]", "list"), + ("fixed_size_list[4]", "list"), + ("fixed_size_list[2]", "list"), + ]: + assert pa_to_feast_value_type(fixed) == pa_to_feast_value_type(variable) + + +def test_pa_to_feast_value_type_nested_fixed_size_list(): + assert pa_to_feast_value_type("fixed_size_list>[8]") == ( + ValueType.VALUE_LIST + ) + + +def test_pa_to_feast_value_type_fixed_size_list_width_is_not_encoded(): + """The width is carried by Field.vector_length, not by the value type.""" + assert pa_to_feast_value_type("fixed_size_list[8]") == ( + pa_to_feast_value_type("fixed_size_list[1536]") + ) + + +def test_pa_to_feast_value_type_decodes_a_real_arrow_vector_type(): + """Guard the parser against the exact string PyArrow produces.""" + pa_type = pyarrow.list_(pyarrow.float32(), 8) + assert str(pa_type) == "fixed_size_list[8]" + assert pa_to_feast_value_type(str(pa_type)) == ValueType.FLOAT_LIST