Skip to content

Inconsistent behaviour when combining dimensions and measures with a top level and filterΒ #10117

@dablak

Description

@dablak

Problem

When combining a dimension and a measure within an and filter, Cube.js raises the following error:

You cannot use dimension and measure in same condition

Example (failing query)

{
    "dimensions":
    [
        "customers.id"
    ],
    "filters":
    [
        {
            "and":
            [
                {
                    "member": "items.quantity",
                    "operator": "gt",
                    "values":
                    [
                        "1"
                    ]
                },
                {
                    "member": "item.id",
                    "operator": "equals",
                    "values":
                    [
                        "1234"
                    ]
                }
            ]
        }
    ]
}

If the same filters are moved to the top level (without the and wrapper), the query runs successfully:

{
    "dimensions":
    [
        "customers.id"
    ],
    "filters":
    [
        {
            "member": "items.quantity",
            "operator": "gt",
            "values":
            [
                "1"
            ]
        },
        {
            "member": "item.id",
            "operator": "equals",
            "values":
            [
                "1234"
            ]
        }
    ]
}

Both versions should be equivalent. Logically they produce the same SQL, differing only in an extra set of parentheses around the WHERE clause:

-- With `and` filter
WHERE ((filter1) AND (filter2))

-- Without `and` filter
WHERE (filter1) AND (filter2)

Question: Is the current behaviour expected, or should Cube.js handle both forms equivalently?
If not, should the non-and version also raise the same validation error for consistency?

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionThe issue is a question. Please use Stack Overflow for questions.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions