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

panic when executing sql expression with invalid column #19426

Open
2 tasks done
ZemanOndrej opened this issue Oct 24, 2024 · 2 comments
Open
2 tasks done

panic when executing sql expression with invalid column #19426

ZemanOndrej opened this issue Oct 24, 2024 · 2 comments
Labels
bug Something isn't working needs triage Awaiting prioritization by a maintainer rust Related to Rust Polars

Comments

@ZemanOndrej
Copy link

Checks

  • I have checked that this issue has not already been reported.
  • I have confirmed this bug exists on the latest version of Polars.

Reproducible example

    #[test]
    fn polars_panic() {
        let mut ctx = SQLContext::new();
        let df = df! {
            "col_1"=> ["1", "2", "3"],
        }
        .unwrap();
        ctx.register("df1", df.lazy());

        let res = ctx.execute("select * from df1 where nonexistent_col = 2"); // this is fine and returns Ok(Err(...))
        assert!(res.unwrap().collect().is_err());
        let res = ctx.execute("select * from df1 where nonexistent_col = '2'"); // this panics
        assert!(res.unwrap().collect().is_err());
    }

Log output

thread 'builtin::tests::polars_panic' panicked at /home/ubuntu/.cargo/registry/src/index.crates.io-6f17d22bba15001f/polars-sql-0.43.1/src/sql_expr.rs:389:88:
called `Option::unwrap()` on a `None` value
stack backtrace:
   0: rust_begin_unwind
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/panicking.rs:665:5
   1: core::panicking::panic_fmt
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/panicking.rs:74:14
   2: core::panicking::panic
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/panicking.rs:148:5
   3: core::option::unwrap_failed
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/option.rs:2020:5
   4: core::option::Option<T>::unwrap
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/option.rs:970:21
   5: polars_sql::sql_expr::SQLExprVisitor::convert_temporal_strings::{{closure}}
             at /home/ubuntu/.cargo/registry/src/index.crates.io-6f17d22bba15001f/polars-sql-0.43.1/src/sql_expr.rs:389:40
   6: core::option::Option<T>::unwrap_or_else
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/option.rs:1015:21
   7: polars_sql::sql_expr::SQLExprVisitor::convert_temporal_strings
             at /home/ubuntu/.cargo/registry/src/index.crates.io-6f17d22bba15001f/polars-sql-0.43.1/src/sql_expr.rs:388:34
   8: polars_sql::sql_expr::SQLExprVisitor::visit_binary_op
             at /home/ubuntu/.cargo/registry/src/index.crates.io-6f17d22bba15001f/polars-sql-0.43.1/src/sql_expr.rs:469:15
   9: polars_sql::sql_expr::SQLExprVisitor::visit_expr
             at /home/ubuntu/.cargo/registry/src/index.crates.io-6f17d22bba15001f/polars-sql-0.43.1/src/sql_expr.rs:104:54
  10: polars_sql::sql_expr::parse_sql_expr
             at /home/ubuntu/.cargo/registry/src/index.crates.io-6f17d22bba15001f/polars-sql-0.43.1/src/sql_expr.rs:1020:5
  11: polars_sql::context::SQLContext::process_where
             at /home/ubuntu/.cargo/registry/src/index.crates.io-6f17d22bba15001f/polars-sql-0.43.1/src/context.rs:871:41
  12: polars_sql::context::SQLContext::execute_select
             at /home/ubuntu/.cargo/registry/src/index.crates.io-6f17d22bba15001f/polars-sql-0.43.1/src/context.rs:645:14
  13: polars_sql::context::SQLContext::process_query
             at /home/ubuntu/.cargo/registry/src/index.crates.io-6f17d22bba15001f/polars-sql-0.43.1/src/context.rs:313:45
  14: polars_sql::context::SQLContext::execute_query_no_ctes
             at /home/ubuntu/.cargo/registry/src/index.crates.io-6f17d22bba15001f/polars-sql-0.43.1/src/context.rs:217:18
  15: polars_sql::context::SQLContext::execute_query
             at /home/ubuntu/.cargo/registry/src/index.crates.io-6f17d22bba15001f/polars-sql-0.43.1/src/context.rs:213:9
  16: polars_sql::context::SQLContext::execute_statement
             at /home/ubuntu/.cargo/registry/src/index.crates.io-6f17d22bba15001f/polars-sql-0.43.1/src/context.rs:196:40
  17: polars_sql::context::SQLContext::execute
             at /home/ubuntu/.cargo/registry/src/index.crates.io-6f17d22bba15001f/polars-sql-0.43.1/src/context.rs:158:19
  18: polars_poc::builtin::tests::polars_panic
             at ./src/builtin.rs:67:19
  19: polars_poc::builtin::tests::polars_panic::{{closure}}
             at ./src/builtin.rs:57:22
  20: core::ops::function::FnOnce::call_once
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/ops/function.rs:250:5
  21: core::ops::function::FnOnce::call_once
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/ops/function.rs:250:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

Issue description

running that execute panics in /polars-sql-0.43.1/src/sql_expr.rs on line 389 when you try to unwrap None value

Expected behavior

the expected result of the execute function should be something like
Err(Context { error: Context { error: ColumnNotFound(ErrString("unable to find column \"nonexistent_col\"; valid columns: [\"col_1\"]")), msg: ErrString("'filter' failed") }, msg: ErrString("'select' input failed to resolve") })

Installed versions

polars = { version = "0.43.1", default-features = false, optional = false, features = [
"ipc_streaming",
"lazy",
"fmt",
"parquet",
"sql",
] }

@ZemanOndrej ZemanOndrej added bug Something isn't working needs triage Awaiting prioritization by a maintainer rust Related to Rust Polars labels Oct 24, 2024
@cmdlineluser
Copy link
Contributor

Python repro.

pl.DataFrame({"a": [1]}).sql("select * from self where b = '2'")
# thread '<unnamed>' panicked at crates/polars-sql/src/sql_expr.rs:389:88:
# called `Option::unwrap()` on a `None` value

@ritchie46
Copy link
Member

@alexander-beedie can you take a look?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs triage Awaiting prioritization by a maintainer rust Related to Rust Polars
Projects
None yet
Development

No branches or pull requests

3 participants