Skip to content

fix: Keep the Arrow type of an all-missing feature in OnlineResponse.to_arrow - #7249

Open
mansur-akhmadi wants to merge 2 commits into
feast-dev:masterfrom
mansur-akhmadi:fix/online-to-arrow-missing-types
Open

mansur-akhmadi wants to merge 2 commits into
feast-dev:masterfrom
mansur-akhmadi:fix/online-to-arrow-missing-types

Conversation

@mansur-akhmadi

@mansur-akhmadi mansur-akhmadi commented Nov 26, 2026 •

Copy link
Copy Markdown

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 Arrow null column, while the same feature with any value present is int64/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, which OnlineStore.get_online_features already passes), the column is now built with pa.nulls(n, type=...), using the type that to_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, including Array(UnixTimestamp) -> list<timestamp[us, tz=UTC]>). Columns with at least one value go through from_pydict exactly as before, so existing schemas do not change.

Left as is:

  • Value types whose inferred Arrow type depends on the data (Map, Struct, Json, Decimal, sets, nested lists) keep null when all values are missing.
  • On demand transformations keep reading the untyped table (OnlineResponse._to_arrow(), same as before this PR): pandas turns a typed all-null column into NaN/NaT, so a UDF that checks for None would change behavior, and a passed-through NaT would become a unix_timestamp_val of int64 min.
  • On demand feature view outputs are not in feature_types (only feature view features are), so an all-missing ODFV output is still null.

Which issue(s) this PR fixes:

Fixes #7248

Checks

  • I've made sure the tests are passing.
  • My commits are signed off (git commit -s)
  • My PR title follows conventional commits format

Testing Strategy

  • Unit tests
  • Integration tests
  • Manual tests
  • Testing is not required for this change

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 gives null, also with a fv__feature name and with zero rows) and pass with the change (27 passed). Each mapped type is checked against the type to_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 stays null.
  • test_on_demand_pandas_transformation.py::test_pandas_odfv_sees_none_for_feature_missing_for_every_entity: a pandas UDF still gets None for a feature no requested entity has, while to_arrow() of the same response types that column int64; fails if the on demand path reads the typed table.
  • feast init demo repo with the SQLite online store: to_arrow() for an entity that is not materialized now gives avg_daily_trips: int64, conv_rate: double, same as for a materialized one.
  • pytest -n 8 over test_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).
  • After the review round: test_online_response.py, the ODFV pandas/aggregation/input-schema/feature view tests and test_utils.py: 96 passed, 4 skipped (the two to_tensor tests need torch, not installed here).
  • ruff check, ruff format --check, mypy feast/online_response.py feast/utils.py: clean.

Devin Review

…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>
@mansur-akhmadi
mansur-akhmadi requested a review from a team as a code owner November 26, 2026 17:10

@devin-ai-integration devin-ai-integration Bot 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.

Devin Review found 3 potential issues.

2 flags not posted on this PR by your GitHub settings — view them in Devin Review. (Configure)

Devin Review

Comment thread sdk/python/feast/online_response.py Outdated
Comment on lines +135 to +136
if arrow_type is not None and all(v is None for v in values):
result[name] = pa.nulls(len(values), type=arrow_type)

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.

🔴 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.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

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.

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.

Comment thread sdk/python/feast/online_response.py Outdated
Comment on lines +133 to +136
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)

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.

🟡 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.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

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.

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.

Comment on lines +43 to +45
ValueType.STRING: pa.string(),
ValueType.BYTES: pa.binary(),
ValueType.BOOL: pa.bool_(),

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.

🟡 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.

Suggested change
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_(),

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

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.

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>

This branch has not been deployed

No deployments
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.

OnlineResponse.to_arrow() returns a null-typed column when a feature is missing for every requested entity

1 participant