Skip to content

Conversation

@parthchandra
Copy link
Contributor

Which issue does this PR close?

Rationale for this change

reduce code duplication in Datafusion Comet.

What changes are included in this PR?

Makes the method public

Are these changes tested?

Existing tests

Are there any user-facing changes?

No

Copy link
Contributor

@comphead comphead left a comment

Choose a reason for hiding this comment

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

Thanks @parthchandra please check if proposed method description is accurate enough

@parthchandra
Copy link
Contributor Author

Thanks @parthchandra please check if proposed method description is accurate enough

Shouldn't that be -

/// # Input
/// ["alice", "bob", "alice", null, "carol"]
/// 
/// # Output
/// DictionaryArray<Int32>
/// {
///   keys:   [0, 1, 0, null, 2],
///   values: ["alice", "bob", "carol"]
/// }

@comphead
Copy link
Contributor

comphead commented Sep 3, 2025

Thanks @parthchandra please check if proposed method description is accurate enough

Shouldn't that be -

/// # Input
/// ["alice", "bob", "alice", null, "carol"]
/// 
/// # Output
/// DictionaryArray<Int32>
/// {
///   keys:   [0, 1, 0, null, 2],
///   values: ["alice", "bob", "carol"]
/// }

I dont think so, as there is no dict conversions, just a loop, but I ran a test

    #[test]
    fn test_dict_from_values_with_strings() {
        let values = Arc::new(StringArray::from(vec!["a", "b", "a", "c"])) as ArrayRef;
        let dict = dict_from_values::<Int32Type>(values).unwrap();
        dbg!(&dict);
    }

[datafusion/common/src/scalar/mod.rs:7650:9] &dict = DictionaryArray {keys: PrimitiveArray<Int32>
[
  0,
  1,
  2,
  3,
] values: StringArray
[
  "a",
  "b",
  "a",
  "c",
]}

Co-authored-by: Oleks V <comphead@users.noreply.github.com>
@parthchandra
Copy link
Contributor Author

I dont think so, as there is no dict conversions, just a loop, but I ran a test
Ah, I see now that there is no de-duping. I've applied the comment change.

@comphead
Copy link
Contributor

comphead commented Sep 4, 2025

Thanks @parthchandra

@comphead comphead merged commit d83a290 into apache:main Sep 4, 2025
28 checks passed
destrex271 pushed a commit to destrex271/datafusion that referenced this pull request Sep 5, 2025
* minor: make dict_from_values public

* Update datafusion/common/src/scalar/mod.rs

Co-authored-by: Oleks V <comphead@users.noreply.github.com>

* fix format

* one more format

---------

Co-authored-by: Oleks V <comphead@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

common Related to common crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

make dict_from_values public

2 participants