cube-js / cube

📊 Cube — Universal semantic layer platform for AI, BI, spreadsheets, and embedded analytics
https://cube.dev
Other
17.97k stars 1.78k forks source link

Parent timeDimensions not automatically propagating to drillDown #1737

Closed john-nexkey closed 3 years ago

john-nexkey commented 3 years ago

Describe the bug resultSet.drillDown method does not automatically apply timeDimensions from the parent query to the drill down query

To Reproduce Steps to reproduce the behavior: Exactly the same issue as what we saw in (https://github.com/cube-js/cube.js/issues/1138) but in this case timeDimensions.

Expected behavior resultSet.drillDown method applies the timeDimensions from the parent query to the drill down query as well.

vasilev-alex commented 3 years ago

hi @john-nexkey! Could you please post the parent query and the param values you're passing in to the drillDown method?

MattGson commented 3 years ago

Same issue here:

This is roughly what the code looks like.

query: {
    measures: ['Groups.count'],
    timeDimensions: [
        {
            dimension: 'Groups.createdAt',
            dateRange: 'This month',
            granularity: 'month',
        },
    ],
    order: {
        'Groups.count': 'desc',
    },
    dimensions: ['Org.name'],
},
resultSet.drillDown({
    xValues: ['GroupA'],
});

I have been manually applying the time dimensions to get around this.

vasilev-alex commented 3 years ago

@MattGson thanks for the details. Looks like you're passing the wrong params. Actually, you shouldn't create the xValues/yValues manually but rather take them from the pivot (or chartPivot) result as the values you're passing are later mapped to the pivotConfig.

The default pivotConfig in your case would be

{
  x: ['Groups.createdAt.month'],
  y: ['Org.name', 'measures']
}

As you can see the drill down params can't be properly mapped in your case.

You can find a comprehensive example here https://cube.dev/blog/introducing-a-drill-down-table-api-in-cubejs/

john-nexkey commented 3 years ago

Hi @vasilev-alex. In my case, my query is designed with the intent output to a pie chart, so I am not grouping in my timeDimensions

query: {
    measures: ['Groups.count'],
    timeDimensions: [
        {
            dimension: 'Groups.createdAt',
            dateRange: 'Last 7 days',
        },
    ],
    order: {
        'Groups.count': 'desc',
    },
    dimensions: ['Org.name'],
},

As a result I have been unable to use a technique similar to what's used in the drill down example. Is there another approach I might consider to this? I would prefer to use timeDimensions to define time here as opposed to a time filter in order to be able to leverage relative time values.

vasilev-alex commented 3 years ago

@john-nexkey thanks! That makes sense.

vasilev-alex commented 3 years ago

... I would prefer to use timeDimensions to define time here as opposed to a time filter in order to be able to leverage relative time values.

Looks like a feature request. I think we can support relative time values for time filters. Could you post another issue, please?