Repository navigation
fix: Keep the Arrow type of an all-missing feature in OnlineResponse.to_arrow - #7249
mansur-akhmadi wants to merge 2 commits into
Conversation
…to_arrow to_arrow() infers column types from the returned values, so a feature that no requested entity has came back as an Arrow null column, while the same feature with a value present is int64, double, string and so on. Build such columns with the type inferred for present values of the feature's value type, so the schema no longer depends on the batch. Signed-off-by: Mansur Akhmadi <10739460+mansur-akhmadi@users.noreply.github.com>
There was a problem hiding this comment.
Devin Review found 3 potential issues.
2 flags not posted on this PR by your GitHub settings — view them in Devin Review. (Configure)
| if arrow_type is not None and all(v is None for v in values): | ||
| result[name] = pa.nulls(len(values), type=arrow_type) |
There was a problem hiding this comment.
🔴 Missing numeric inputs bypass Pandas defaults
For an all-missing numeric input, to_arrow now feeds NaN instead of None to Pandas transformations. Transforms that check for None skip their missing-value fallback and return the wrong feature.
Learn more
An on-demand feature view runs a user-defined function during an online read. OnlineStore passes feature types into the on-demand serving path, which calls to_arrow before running the function. PandasTransformation converts an untyped null column to Python None values, but it converts an all-null Arrow integer or float column to floating-point NaN. The function sees that change even when the caller never requests Arrow output.
Example: A Pandas feature sets is_new_driver with inputs["trips"].map(lambda value: value is None). For a request containing only an unmaterialized driver, the old path returns True; the new path returns False.
Recommended fix: Keep the existing all-missing representation on the internal Pandas transformation path, for example by sharing an Arrow conversion helper with an explicit option to preserve legacy null inference. Keep typed nulls for public Arrow responses and add an online serving regression test that checks the value produced by a Pandas fallback.
Was this helpful? React with 👍 or 👎 to provide feedback.
There was a problem hiding this comment.
Fixed in 212e697. The on demand path now reads the untyped table (OnlineResponse._to_arrow(), what to_arrow() returned before this PR), so a pandas UDF still gets None for a feature no requested entity has; the public to_arrow() keeps the typed column. Added test_pandas_odfv_sees_none_for_feature_missing_for_every_entity with your is None example, which fails if the on demand path reads the typed table.
| for name, values in result.items(): | ||
| arrow_type = _ALL_MISSING_ARROW_TYPES.get(self._feature_types.get(name)) | ||
| if arrow_type is not None and all(v is None for v in values): | ||
| result[name] = pa.nulls(len(values), type=arrow_type) |
There was a problem hiding this comment.
🟡 On-demand output inherits the wrong type
When an all-missing on-demand output reuses a source feature’s short name, to_arrow assigns it the source’s type. The response type map only describes stored features, so the output gets the wrong Arrow type when those types differ.
Learn more
The default online response uses short feature names. _group_feature_refs includes stored dependencies even when only their on-demand output was requested. OnlineStore builds its type map from stored features before computing on-demand outputs. The transform response builder appends those outputs after the source columns. If a short name is reused, to_dict keeps the later output values under that name, but the Arrow conversion still looks up the source type.
Example: An on-demand view converts stored integer trips into a string bucket also named trips. Requesting only the on-demand output returns Arrow string for populated rows, but an all-missing batch reports int64 instead of an untyped null column or a string column.
Recommended fix: When building the final response, resolve the type from the same feature that supplied each output column. For computed outputs, use their declared type or omit the hint if they remain out of scope. Preserve the source type map for transformation inputs.
Was this helpful? React with 👍 or 👎 to provide feedback.
There was a problem hiding this comment.
Leaving this one as is. ODFV outputs aren't in feature_types; your case needs an ODFV output that reuses the short name of a stored feature in the same response. With that collision to_dict() already deserializes the output's values with the stored feature's type, on master too, since the type map is keyed by name. The fix for that belongs in how OnlineStore builds feature_types (skip names an ODFV output takes over), which is outside this PR.
| ValueType.STRING: pa.string(), | ||
| ValueType.BYTES: pa.binary(), | ||
| ValueType.BOOL: pa.bool_(), |
There was a problem hiding this comment.
🟡 Missing PDF and image features lose their type
_ALL_MISSING_ARROW_TYPES leaves PDF and image features as Arrow null when every entity lacks them. Both serialize as bytes, so populated batches use binary and the schema still changes between batches.
Learn more
Feast gives PDF and image features distinct schema types, but its protobuf serializer stores both as ordinary byte values. OnlineStore passes the distinct declared types to OnlineResponse, so a lookup for ordinary BYTES does not cover either alias.
Example: A request for an ImageBytes feature returns Arrow binary for a known item and Arrow null for a batch containing only unmaterialized items.
Recommended fix: Map both aliases to pa.binary() and add one Value(bytes_val=...) case for each alias to the parameterized Arrow test matrix.
| ValueType.STRING: pa.string(), | |
| ValueType.BYTES: pa.binary(), | |
| ValueType.BOOL: pa.bool_(), | |
| ValueType.STRING: pa.string(), | |
| ValueType.BYTES: pa.binary(), | |
| ValueType.PDF_BYTES: pa.binary(), | |
| ValueType.IMAGE_BYTES: pa.binary(), | |
| ValueType.BOOL: pa.bool_(), |
Was this helpful? React with 👍 or 👎 to provide feedback.
There was a problem hiding this comment.
Fixed in 212e697: PdfBytes and ImageBytes map to binary, with a case for each in the parametrized test.
…issing for every entity Pandas reads a typed all-null Arrow column as NaN or NaT, so a UDF that checks for None stopped seeing the missing value. The on demand path keeps the previous null column; to_arrow() still types it. PDF and image bytes map to binary like bytes, and UNIX_TIMESTAMP is typed now that on demand transformations no longer read the typed table. Signed-off-by: Mansur Akhmadi <10739460+mansur-akhmadi@users.noreply.github.com>
What this PR does / why we need it:
OnlineResponse.to_arrow()infers column types from the returned values, so a feature that is missing for every requested entity (or a zero-row request) came back as an Arrownullcolumn, while the same feature with any value present isint64/double/string/... The schema of a serving batch depended on its data.When every value of a column is missing and the feature's value type is known (
feature_types, whichOnlineStore.get_online_featuresalready passes), the column is now built withpa.nulls(n, type=...), using the type thatto_arrow()infers for that value type when values are present (Int32/Int64->int64,Float32/Float64->double,String/UUIDs ->string,Bytes/PdfBytes/ImageBytes->binary,Bool,UnixTimestamp->timestamp[us, tz=UTC], and the list types likewise, includingArray(UnixTimestamp)->list<timestamp[us, tz=UTC]>). Columns with at least one value go throughfrom_pydictexactly as before, so existing schemas do not change.Left as is:
Map,Struct,Json,Decimal, sets, nested lists) keepnullwhen all values are missing.OnlineResponse._to_arrow(), same as before this PR): pandas turns a typed all-null column intoNaN/NaT, so a UDF that checks forNonewould change behavior, and a passed-throughNaTwould become aunix_timestamp_valof int64 min.feature_types(only feature view features are), so an all-missing ODFV output is stillnull.Which issue(s) this PR fixes:
Fixes #7248
Checks
git commit -s)Testing Strategy
Misc
How it was verified:
pytest sdk/python/tests/unit/test_online_response.py: the new tests fail on master (22 failed: every mapped value type givesnull, also with afv__featurename and with zero rows) and pass with the change (27 passed). Each mapped type is checked against the typeto_arrow()produces for the same feature with a value present, and a test keeps the cases in sync with the map; also covered: a partially missing column is unchanged, an unknown type staysnull.test_on_demand_pandas_transformation.py::test_pandas_odfv_sees_none_for_feature_missing_for_every_entity: a pandas UDF still getsNonefor a feature no requested entity has, whileto_arrow()of the same response types that columnint64; fails if the on demand path reads the typed table.feast initdemo repo with the SQLite online store:to_arrow()for an entity that is not materialized now givesavg_daily_trips: int64, conv_rate: double, same as for a materialized one.pytest -n 8overtest_online_response.py,test_unit_feature_store.py,online_store/, the ODFV pandas/python transformation tests,test_feature_server.py,test_precomputed_feature_vectors.py,local_feast_tests/: 243 passed; 3 failures are environment-only and fail the same on master (no Java for the Spark stream feature view tests, Milvus Lite worker crash on macOS).test_online_response.py, the ODFV pandas/aggregation/input-schema/feature view tests andtest_utils.py: 96 passed, 4 skipped (the twoto_tensortests need torch, not installed here).ruff check,ruff format --check,mypy feast/online_response.py feast/utils.py: clean.