vvaezian / metabase_api_python

A python wrapper for Metabase API
MIT License
136 stars 40 forks source link

Missing step in the clone_card function #33

Closed kienli closed 2 years ago

kienli commented 2 years ago

Hello,

I found that the function clone_card doesn't change the column_id to target_col_id for 'aggregation' part of the query here

My card_info has the following part

'dataset_query': {'database': 5,
                   'query': {'aggregation': [['distinct',
                                              ['field', 577, None]]],
                             'filter': ['and',
                                        ['=', ['field', 576, None], 'type'],
                                        ['=',
                                         ['field', 567, None],
                                         'approved']],
                             'source-table': 103},
                   'type': 'query'},

I assume that we have to iterate over aggregation part as well.

Metabase v0.43.0

kienli commented 2 years ago

And it does not iterate over 'breakout' section.

'dataset_query': {'database': 5,
                   'query': {'aggregation': [['distinct',
                                              ['field', 419, None]]],
                             'breakout': [['field',
                                           414,
                                           {'temporal-unit': 'day'}]],
                             'filter': ['not-null', ['field', 439, None]],
                             'source-table': 95},
                   'type': 'query'},
vvaezian commented 2 years ago

Hi @kienli, thanks for the feedback. I'll work on this on the weekend.

kienli commented 2 years ago

I found that aggregation can be quite tricky because of the custom aggregations:

Example 1

 'dataset_query': {'database': 5,
                   'query': {'aggregation': [['aggregation-options',
                                              ['/',
                                               ['avg', ['field', 566, None]],
                                               60],
                                              {'display-name': 'tat1',
                                               'name': 'tat1'}]],
                             'filter': ['and',
                                        ['=', ['field', 576, None], 'type'],
                                        ['not-null', ['field', 566, None]]],
                             'source-table': 103},
                   'type': 'query'},

Example 2

 'dataset_query': {'database': 5,
                   'query': {'aggregation': [['aggregation-options',
                                              ['/',
                                               ['avg', ['field', 472, None]],
                                               60],
                                              {'display-name': 'tat1',
                                               'name': 'tat1'}],
                                             ['aggregation-options',
                                              ['/',
                                               ['avg', ['field', 470, None]],
                                               60],
                                              {'display-name': 'tat2',
                                               'name': 'tat2'}],
                                             ['aggregation-options',
                                              ['/',
                                               ['avg', ['field', 471, None]],
                                               60],
                                              {'display-name': 'tat3',
                                               'name': 'tat3'}]],
                             'breakout': [['field',
                                           473,
                                           {'temporal-unit': 'day'}]],
                             'filter': ['and',
                                        ['=',
                                         ['field', 418, None],
                                         'NY'],
                                        ['=', ['field', 560, None], 'type']],
                             'source-table': 95},
                   'type': 'query'},
vvaezian commented 2 years ago

Fixed in version 0.2.15