Skip to content
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

[Question] how to convert UBIGINT[] to Vec<u64> #254

Closed
oliverdding opened this issue Jan 12, 2024 · 2 comments
Closed

[Question] how to convert UBIGINT[] to Vec<u64> #254

oliverdding opened this issue Jan 12, 2024 · 2 comments

Comments

@oliverdding
Copy link

oliverdding commented Jan 12, 2024

I'm writting a little demo with a UBIGINT[] type column in my table.

While trying to query the table, the rustc told me that the trait bound `Vec<u64>: FromSql` is not satisfied:

  let mut stmt = conn
        .prepare("SELECT * FROM users WHERE id = ?")
        .map_err(internal_error)?;

    stmt.query_row(params![id.0], |row| {
        Ok(Response::User(UserResponse {
            arr: row.get(1)?,
        }))
    })
    .map_err(|err| match err {
        duckdb::Error::QueryReturnedNoRows => (
            StatusCode::NOT_FOUND,
            ErrorResponse {
                code: -1,
                reason: "User not found".to_string(),
            },
        ),
        _ => internal_error(err),
    })

Here is UserResponse definition:

#[derive(Debug, Serialize, Deserialize)]
pub struct UserResponse {
    pub arr: Vec<u64>,
}

Here is my table DDL:

    CREATE SEQUENCE IF NOT EXISTS seq_user_id START 0;
    
    CREATE TABLE IF NOT EXISTS users (
        id UBIGINT PRIMARY KEY DEFAULT nextval('seq_user_id'),
        arr UBIGINT[]
    );

After browsing the source code, I found that only Vec<u8> type are implementated with FromSql trait

image

Any advice are appreciated!

@dvic
Copy link

dvic commented Jan 18, 2024

If I'm not mistaken, it's not yet implemented:

duckdb-rs/src/row.rs

Lines 545 to 580 in 9af377a

// TODO: support more data types
// DataType::Interval(unit) => match unit {
// IntervalUnit::DayTime => {
// make_string_interval_day_time!(column, row)
// }
// IntervalUnit::YearMonth => {
// make_string_interval_year_month!(column, row)
// }
// },
// DataType::List(_) => make_string_from_list!(column, row),
// DataType::Dictionary(index_type, _value_type) => match **index_type {
// DataType::Int8 => dict_array_value_to_string::<Int8Type>(column, row),
// DataType::Int16 => dict_array_value_to_string::<Int16Type>(column, row),
// DataType::Int32 => dict_array_value_to_string::<Int32Type>(column, row),
// DataType::Int64 => dict_array_value_to_string::<Int64Type>(column, row),
// DataType::UInt8 => dict_array_value_to_string::<UInt8Type>(column, row),
// DataType::UInt16 => dict_array_value_to_string::<UInt16Type>(column, row),
// DataType::UInt32 => dict_array_value_to_string::<UInt32Type>(column, row),
// DataType::UInt64 => dict_array_value_to_string::<UInt64Type>(column, row),
// _ => Err(ArrowError::InvalidArgumentError(format!(
// "Pretty printing not supported for {:?} due to index type",
// column.data_type()
// ))),
// },
// NOTE: DataTypes not supported by duckdb
// DataType::Date64 => make_string_date!(array::Date64Array, column, row),
// DataType::Time32(unit) if *unit == TimeUnit::Second => {
// make_string_time!(array::Time32SecondArray, column, row)
// }
// DataType::Time32(unit) if *unit == TimeUnit::Millisecond => {
// make_string_time!(array::Time32MillisecondArray, column, row)
// }
// DataType::Time64(unit) if *unit == TimeUnit::Nanosecond => {
// make_string_time!(array::Time64NanosecondArray, column, row)
// }

@oliverdding
Copy link
Author

Hi @dvic , thanks for your reference. I would close this issue and keep an eye on 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