cube-js / cube

📊 Cube — The Semantic Layer for Building Data Applications
https://cube.dev
Other
17.49k stars 1.74k forks source link

FILTER_PARAMS with views #7062

Open danielli-ziprecruiter opened 10 months ago

danielli-ziprecruiter commented 10 months ago

Problem Is this the intended behavior when applying FILTER_PARAMS with views? If I use FILTER_PARAMS in a measure:

cubes:
  - name: my_cube
    measures: 
      - name: my_measure
        type: count
        filters:
          - sql: {FILTER_PARAMS.my_cube.my_dimension.filter(filter)}

with a view that uses the cube:

views:
  - name: my_view
    cubes:
      - join_path: my_cube
        includes: "*"

The FILTER_PARAMS doesn't apply if I query the view with the SQL API:

SELECT count(my_measure)
FROM my_view
WHERE my_dimension = x

since this references my_view.my_dimension, not my_cube.my_dimension.

Is this the intended behavior? There are some workarounds like adding the view's dimension as a FILTER_PARAM:

sql: {FILTER_PARAMS.my_cube.my_dimension.filter(filter)} 
  and {FILTER_PARAMS.my_view.my_dimension.filter(filter)}

Or joining with the cube so the cube's dimension can be referenced:

SELECT count(my_measure)
FROM my_view CROSS JOIN my_cube
WHERE my_cube.my_dimension = x

But these seem like hacky solutions.

paveltiunov commented 10 months ago

@danielli-ziprecruiter That's a good one! So it's actually right behavior by design, but I agree it might be suboptimal in some cases. The obvious intuition is to always use leaf members for FILTER_PARAMS but it'll most likely break existing calculated members. So we'd need to think about trade-offs here.