Skip to content

Conversation

@kumarUjjawal
Copy link
Contributor

Which issue does this PR close?

Rationale for this change

  • dict_id is intentionally not preserved protobuf (it’s deprecated in Arrow schema metadata), but Arrow IPC still requires dict IDs for dictionary encoding/decoding.

What changes are included in this PR?

  • Fix protobuf serde for nested ScalarValue (list/struct/map) containing dictionary arrays by using Arrow IPC’s dictionary handling correctly.
  • Seed DictionaryTracker by encoding the schema before encoding the nested scalar batch.
  • On decode, reconstruct an IPC schema from the protobuf schema and use arrow_ipc::reader::read_dictionary to build dict_by_id before reading the record batch.

Are these changes tested?

Yes added a test for this

Are there any user-facing changes?

No

@github-actions github-actions bot added the proto Related to proto crate label Jan 29, 2026
@kumarUjjawal kumarUjjawal force-pushed the fix/dict_id_regression branch from af1a108 to e0a0061 Compare January 29, 2026 15:09
Copy link
Contributor

@brancz brancz left a comment

Choose a reason for hiding this comment

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

lgtm, thank you for fixing this!

@kumarUjjawal
Copy link
Contributor Author

lgtm, thank you for fixing this!

Thanks for the review!

Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

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

Thank you @kumarUjjawal

FYI @dispanser

@dispanser
Copy link

thanks @kumarUjjawal , appreciated!

root_as_message(encoded_schema.ipc_message.as_slice()).map_err(
|e| {
Error::General(format!(
"Error IPC schema message while deserializing ScalarValue::List: {e}"
Copy link
Member

Choose a reason for hiding this comment

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

Why the error messages say ScalarValue::List ? (List)
Isn't this used for any nested type ? List, Map, Struct, ...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch! I will update.

dispanser added a commit to coralogix/arrow-datafusion that referenced this pull request Feb 3, 2026
…f-45

Undoing [apache#14227](apache#14227) which
introduces a bug in protobuf deserialization by passing a wrong schema
to record batch construction of the IPC message containing the
dictionary.

The associated test and a fix will probably be merged into datafusion as
apache#20063 but the test fails in
main for completely different reason so the patch cannot be backported
and doesn't make sense in the context of df46.
Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

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

Thank you @kumarUjjawal and @brancz

I feel intuitively something could be made much simpler here, but given this fixes the bug and i don't have any specific ideas of how to improve the PR, let's go with this one

));
};

// IPC dictionary batch IDs are assigned when encoding the schema, but our protobuf
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel like somehow I missing something key -- this seems like a pretty massive overhead to create / decode a single value here.

That being said, it seems like the existing code is also doing the overhead, so maybe it is fine for now 🤔

I wonder if we could pull this logic for creating the schema into its own function to try and reduce the size of the overall method / make it easier to understand

Ok(())
}

#[test]
Copy link
Contributor

Choose a reason for hiding this comment

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

With the code change reverted, this test fails like

---- cases::roundtrip_physical_plan::roundtrip_call_null_scalar_struct_dict stdout ----
Error: Plan("General error: Error encoding ScalarValue::List as IPC: Ipc error: no dict id for field item")

@alamb
Copy link
Contributor

alamb commented Feb 3, 2026

Screenshot 2026-02-03 at 4 30 18 PM

I merged up to resolve a conflict

@kumarUjjawal
Copy link
Contributor Author

Thank you @alamb. I will look into your suggestions.

@alamb
Copy link
Contributor

alamb commented Feb 4, 2026

Thank you @alamb. I will look into your suggestions.

Thanks -- let's do it as a follow on PR

@alamb alamb added this pull request to the merge queue Feb 4, 2026
Merged via the queue into apache:main with commit 8ba3d26 Feb 4, 2026
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

proto Related to proto crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Physical plan proto roundtrip for null-valued scalar of a Struct(Dict) data type

5 participants