Skip to content

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

@tfzrch

Description

@tfzrch

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

Metadata

Metadata

Assignees

Labels

api:sqlIssues related to SQL APIbugLEGACY. Use the Bug issue type instead

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions