Skip to content

Make DuckString::new() public #484

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
yutannihilation opened this issue Apr 6, 2025 · 4 comments
Closed

Make DuckString::new() public #484

yutannihilation opened this issue Apr 6, 2025 · 4 comments

Comments

@yutannihilation
Copy link
Contributor

I want to add an option to a scalar function, but I can't find a way to get the user-provided parameters as String. Do you have a plan to implement some mechanism like BindInfo of VTab? If not, I think I need DuckString::new() to extract the string. However, new() is pub(crate).

Currently, I had to do this:

let input_vec = input.flat_vector(0);
let mut option_raw = input_vec.as_slice_with_len::<duckdb_string_t>(input.len())[0];

// TODO: duckdb-rs doesn't prvide a way to get string from a FlatVector.
// (DuckString::new() is pub(crate) so unavailable).
let option = unsafe {
    let len = duckdb_string_t_length(option_raw);
    let c_ptr = duckdb_string_t_data(&mut option_raw);
    let string = String::from_utf8_lossy(std::slice::from_raw_parts(
        c_ptr as *const u8,
        len as usize,
    ));

    // This is very important. Cow refers to DuckDB's memory, which
    // might can be erased. So, it needs to be copied into Rust.
    string.to_string()
};
@benjamintli
Copy link
Contributor

I have the same issue, I created a PR to address this

@yutannihilation
Copy link
Contributor Author

Thanks! I was also wondering if this means the API needs overhauled rather than exposing the implementation detail...

@benjamintli
Copy link
Contributor

I think we can close this now that my change has been merged

@yutannihilation
Copy link
Contributor Author

I'm still wondering if this is the right solution to the problem. But, I agree this issue itself should be closed. Thanks for addressing this!

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

No branches or pull requests

2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy