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

array_to_string panic on dictionary values #10862

Closed
appletreeisyellow opened this issue Jun 10, 2024 · 2 comments · Fixed by #10908
Closed

array_to_string panic on dictionary values #10862

appletreeisyellow opened this issue Jun 10, 2024 · 2 comments · Fixed by #10908
Assignees
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@appletreeisyellow
Copy link
Contributor

Describe the bug

array_to_string function panic's when running a query on data that has dictionary data type. To fix the panic, array_to_string needs to support dictionary type

To Reproduce

  1. Use DataFusion CLI:
# in dir datafusion/datafusion-cli
$ cargo build
$ ./target/debug/datafusion-cli
  1. Write sample data
CREATE TABLE table1 AS VALUES (1, arrow_cast('foo', 'Dictionary(Int32, Utf8)')), (2, arrow_cast('bar', 'Dictionary(Int32, Utf8)'));
  1. Run query
> SELECT array_to_string(array_agg(column2),',') FROM (SELECT column2 FROM table1);
thread 'main' panicked at .../datafusion/datafusion/functions-array/src/string.rs:298:17:
internal error: entered unreachable code
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Expected behavior

> SELECT array_to_string(array_agg(column2),',') FROM (SELECT column2 FROM table1);
+------------------------------------------------------+
| array_to_string(ARRAY_AGG(table2.column2),Utf8(",")) |
+------------------------------------------------------+
| foo,bar                                              |
+------------------------------------------------------+

Additional context

  1. Here are the data types that array_to_string currently supports:

    macro_rules! call_array_function {
    ($DATATYPE:expr, false) => {
    match $DATATYPE {
    DataType::Utf8 => array_function!(StringArray),
    DataType::LargeUtf8 => array_function!(LargeStringArray),
    DataType::Boolean => array_function!(BooleanArray),
    DataType::Float32 => array_function!(Float32Array),
    DataType::Float64 => array_function!(Float64Array),
    DataType::Int8 => array_function!(Int8Array),
    DataType::Int16 => array_function!(Int16Array),
    DataType::Int32 => array_function!(Int32Array),
    DataType::Int64 => array_function!(Int64Array),
    DataType::UInt8 => array_function!(UInt8Array),
    DataType::UInt16 => array_function!(UInt16Array),
    DataType::UInt32 => array_function!(UInt32Array),
    DataType::UInt64 => array_function!(UInt64Array),
    _ => unreachable!(),
    }
    };
    ($DATATYPE:expr, $INCLUDE_LIST:expr) => {{
    match $DATATYPE {
    DataType::List(_) => array_function!(ListArray),
    DataType::Utf8 => array_function!(StringArray),
    DataType::LargeUtf8 => array_function!(LargeStringArray),
    DataType::Boolean => array_function!(BooleanArray),
    DataType::Float32 => array_function!(Float32Array),
    DataType::Float64 => array_function!(Float64Array),
    DataType::Int8 => array_function!(Int8Array),
    DataType::Int16 => array_function!(Int16Array),
    DataType::Int32 => array_function!(Int32Array),
    DataType::Int64 => array_function!(Int64Array),
    DataType::UInt8 => array_function!(UInt8Array),
    DataType::UInt16 => array_function!(UInt16Array),
    DataType::UInt32 => array_function!(UInt32Array),
    DataType::UInt64 => array_function!(UInt64Array),
    _ => unreachable!(),
    }
    }};
    }

  2. instead of panic, it would be better to throw an error

@appletreeisyellow appletreeisyellow added the bug Something isn't working label Jun 10, 2024
@alamb alamb added the good first issue Good for newcomers label Jun 10, 2024
@alamb
Copy link
Contributor

alamb commented Jun 10, 2024

I think this is a good first issue as it is well documented , has a test case and the desired behavior is well understood

@evegaval evegaval removed their assignment Jun 11, 2024
@EduardoVega
Copy link
Contributor

take

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants