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

SQL API query with where column in (null) causes unexpected panic during rewrite #9164

Closed
tfzrch opened this issue Jan 31, 2025 · 2 comments
Closed
Assignees
Labels
api:sql Issues related to SQL API bug Something isn't working

Comments

@tfzrch
Copy link

tfzrch commented Jan 31, 2025

Describe the bug
SQL API is unable to handle where clauses including the condition column in (null). Instead it throws an "Unexpected panic" error.

To Reproduce

Using SQL API, query a column from any Cube using where (<column> is null or <column> in (null) and (1<>1)) as a filter. Should see an error (details below).

Alternatively, a minimal reprex with a fresh installation of Postgres and Cube:

  1. Create a fresh Postgres and Cube setup with Docker
  2. Add a table to Postgres and insert some data
CREATE TABLE tbl (
  id serial PRIMARY KEY,
  label text
);

INSERT INTO tbl(label) VALUES ('one'), ('two'), (NULL), ('four');
  1. Query the database directly: select * from tbl where (label is null or label in (null) and (1<>1)). Should get row 3 returned without error.
  2. Create a Cube data model for tbl (schema below)
  3. Query the cube using the same SQL syntax
  4. See error
Error during rewrite: Unexpected panic. Reason: Unsupported filter scalar: NULL. Please check logs for additional information.
  1. Logs show
thread 'tokio-runtime-worker' panicked at /__w/cube/cube/rust/cubesql/cubesql/src/compile/rewrite/rules/filters.rs:3573:18:
Unsupported filter scalar: NULL
SQL API Error: c4df0a8c-46b8-470c-a92f-9c78328ebeca-span-1 (6ms)
--
{
  "sql": "select * from tbl where (label is null or label in (null) and (1<>1))"
}
--
{
  "securityContext": {},
  "appName": "NULL",
  "protocol": "postgres",
  "apiType": "sql"
} 
Error during rewrite: Unexpected panic. Reason: Unsupported filter scalar: NULL. Please check logs for additional information.
Cube SQL Error: undefined 
--
"SELECT * FROM tbl WHERE (label IS NULL OR label IN (NULL) AND (1 <> 1))"
--
{
  "protocol": "postgres",
  "apiType": "sql",
  "appName": "NULL",
  "sanitizedQuery": "SELECT * FROM tbl WHERE (label IS NULL OR label IN (NULL) AND (1 <> 1))"
} 
Error during rewrite: Unexpected panic. Reason: Unsupported filter scalar: NULL. Please check logs for additional information.

Expected behavior
Cube SQL API query should return the same result as direct query to Postgres

Minimally reproducible Cube Schema

cubes:
  - name: tbl
    sql_table: public.tbl
    data_source: default
    dimensions:
      - name: id
        sql: id
        type: number
        primary_key: true

      - name: label
        sql: label
        type: string

Version:
Cube: 1.1.18
Postgres: 16

Additional Context

  • Superset native filters generate this SQL when attempting to filter for a null value
  • As it's generated I'm not able to use where label is null without the or label in (null) and (1<>1) as a workaround
@mcheshkov
Copy link
Member

@tfzrch Can you check it on 1.2.0 or newer?

@tfzrch
Copy link
Author

tfzrch commented Feb 7, 2025

Tested on 1.2.0; it works! Many thanks!

@igorlukanin igorlukanin added bug Something isn't working api:sql Issues related to SQL API labels Feb 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api:sql Issues related to SQL API bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants