Skip to content

IS NULL doesn't type-check its input #20201

@neilconway

Description

@neilconway

Describe the bug

The input expression to IS NULL isn't type-checked, unless for other constructs (IS TRUE, binary operators, etc.)

To Reproduce

CREATE TABLE tt();
SELECT * FROM tt WHERE ((STARTS_WITH()) IS NULL);

Yields:

thread 'main' (41425691) panicked at datafusion/functions/src/string/starts_with.rs:168:54:
index out of bounds: the len is 0 but the index is 1
stack backtrace:
   0: __rustc::rust_begin_unwind
             at /rustc/ded5c06cf21d2b93bffd5d884aa6e96934ee4234/library/std/src/panicking.rs:698:5
   1: core::panicking::panic_fmt
             at /rustc/ded5c06cf21d2b93bffd5d884aa6e96934ee4234/library/core/src/panicking.rs:80:14
   2: core::panicking::panic_bounds_check
             at /rustc/ded5c06cf21d2b93bffd5d884aa6e96934ee4234/library/core/src/panicking.rs:276:5
   3: <usize as core::slice::index::SliceIndex<[T]>>::index
             at /Users/neilconway/.rustup/toolchains/1.92.0-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/slice/index.rs:267:10
   4: core::slice::index::<impl core::ops::index::Index<I> for [T]>::index
             at /Users/neilconway/.rustup/toolchains/1.92.0-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/slice/index.rs:18:15
   5: <alloc::vec::Vec<T,A> as core::ops::index::Index<I>>::index
             at /Users/neilconway/.rustup/toolchains/1.92.0-aarch64-apple-darwin/lib/rustlib/src/rust/library/alloc/src/vec/mod.rs:3628:9
   6: <datafusion_functions::string::starts_with::StartsWithFunc as datafusion_expr::udf::ScalarUDFImpl>::simplify
             at ./datafusion/functions/src/string/starts_with.rs:168:54

Expected behavior

The expected behavior is that STARTS_WITH() should be rejected at planning time because of a type mismatch -- which is what happens for other variants like STARTS_WITH() IS TRUE.

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions