Exemple #1
0
    def _analyze_explores(self,
                          model=None,
                          explore=None,
                          sortkey=None,
                          limit=None,
                          min_queries=0,
                          timeframe=90):
        explores = fetcher.get_explores(self,
                                        model=model,
                                        explore=explore,
                                        verbose=1)
        explores_usage = {}
        info = []
        for e in explores:
            # in case explore does not exist (bug - #32748)
            if e is None:
                pass
            else:
                _used_fields = fetcher.get_used_explore_fields(
                    self, e['model_name'], e['scopes'], timeframe, min_queries)
                used_fields = list(_used_fields.keys())
                exposed_fields = fetcher.get_explore_fields(self,
                                                            explore=e,
                                                            scoped_names=1)
                unused_fields = set(exposed_fields) - set(used_fields)
                field_count = len(exposed_fields)
                query_count = fetcher.get_used_explores(self,
                                                        model=e['model_name'],
                                                        explore=e['name'])

                all_joins = set(e['scopes'])
                all_joins.remove(e['name'])
                used_joins = set([i.split('.')[2] for i in used_fields])
                unused_joins = len(list(all_joins - used_joins))

                has_description = 'Yes' if e['description'] else 'No'

                if query_count.get(e['name']):
                    query_count = query_count[e['name']]
                else:
                    query_count = 0
                info.append({
                    'model': e['model_name'],
                    'explore': e['name'],
                    'is_hidden': e['hidden'],
                    'has_description': has_description,
                    'join_count': len(all_joins),
                    'unused_joins': unused_joins,
                    'field_count': field_count,
                    'unused_fields': len(unused_fields),
                    'query_count': query_count
                })

        if not info:
            self.analyze_logger.error('No matching explores found')
            raise Exception('No matching explores found')
        valid_values = list(info[0].keys())
        info = dc.sort(info, valid_values, sortkey)
        info = dc.limit(info, limit=limit)
        return info
Exemple #2
0
def test_get_used_explores(fc: fetcher.Fetcher, test_model, test_used_explore_names):
    """fetcher.get_used_explores() should return all used explores."""
    used_explores = fc.get_used_explores(model=test_model["name"])
    assert isinstance(used_explores, dict)
    assert all(e in test_used_explore_names for e in used_explores)