generator.explores.metric_definitions_explore

Metric Hub metrics explore type.

 1"""Metric Hub metrics explore type."""
 2
 3from __future__ import annotations
 4
 5from pathlib import Path
 6from typing import Any, Dict, Iterator, List, Optional
 7
 8from ..views import View
 9from . import Explore
10
11
12class MetricDefinitionsExplore(Explore):
13    """Metric Hub Metrics Explore."""
14
15    type: str = "metric_definitions_explore"
16
17    def __init__(
18        self,
19        name: str,
20        views: Dict[str, str],
21        views_path: Optional[Path] = None,
22        defn: Optional[Dict[str, Any]] = None,
23    ):
24        """Initialize MetricDefinitionsExplore."""
25        super().__init__(name, views, views_path)
26
27    @staticmethod
28    def from_views(views: List[View]) -> Iterator[Explore]:
29        """Generate an Operational Monitoring explore for this namespace."""
30        for view in views:
31            if view.view_type == "metric_definitions_view":
32                yield MetricDefinitionsExplore("metric_definitions", {})
33
34    @staticmethod
35    def from_dict(name: str, defn: dict, views_path: Path) -> MetricDefinitionsExplore:
36        """Get an instance of this explore from a dictionary definition."""
37        return MetricDefinitionsExplore(name, defn["views"], views_path, defn)
38
39    def _to_lookml(
40        self,
41        _v1_name: Optional[str],
42    ) -> List[Dict[str, Any]]:
43        exposed_fields = ["ALL_FIELDS*"]
44
45        explore_lookml: Dict[str, Any] = {
46            "name": self.name,
47            "always_filter": {
48                "filters": [{"submission_date": "7 days"}, {"sampling": "1"}]
49            },
50            # The base view is the only view that exposes the date and client_id fields.
51            # All other views only expose the metric definitions.
52            "fields": exposed_fields,
53        }
54
55        return [explore_lookml]
56
57    def get_view_time_partitioning_group(self, view: str) -> Optional[str]:
58        """Override time partitioning."""
59        return None
class MetricDefinitionsExplore(generator.explores.explore.Explore):
13class MetricDefinitionsExplore(Explore):
14    """Metric Hub Metrics Explore."""
15
16    type: str = "metric_definitions_explore"
17
18    def __init__(
19        self,
20        name: str,
21        views: Dict[str, str],
22        views_path: Optional[Path] = None,
23        defn: Optional[Dict[str, Any]] = None,
24    ):
25        """Initialize MetricDefinitionsExplore."""
26        super().__init__(name, views, views_path)
27
28    @staticmethod
29    def from_views(views: List[View]) -> Iterator[Explore]:
30        """Generate an Operational Monitoring explore for this namespace."""
31        for view in views:
32            if view.view_type == "metric_definitions_view":
33                yield MetricDefinitionsExplore("metric_definitions", {})
34
35    @staticmethod
36    def from_dict(name: str, defn: dict, views_path: Path) -> MetricDefinitionsExplore:
37        """Get an instance of this explore from a dictionary definition."""
38        return MetricDefinitionsExplore(name, defn["views"], views_path, defn)
39
40    def _to_lookml(
41        self,
42        _v1_name: Optional[str],
43    ) -> List[Dict[str, Any]]:
44        exposed_fields = ["ALL_FIELDS*"]
45
46        explore_lookml: Dict[str, Any] = {
47            "name": self.name,
48            "always_filter": {
49                "filters": [{"submission_date": "7 days"}, {"sampling": "1"}]
50            },
51            # The base view is the only view that exposes the date and client_id fields.
52            # All other views only expose the metric definitions.
53            "fields": exposed_fields,
54        }
55
56        return [explore_lookml]
57
58    def get_view_time_partitioning_group(self, view: str) -> Optional[str]:
59        """Override time partitioning."""
60        return None

Metric Hub Metrics Explore.

MetricDefinitionsExplore( name: str, views: Dict[str, str], views_path: Optional[pathlib.Path] = None, defn: Optional[Dict[str, Any]] = None)
18    def __init__(
19        self,
20        name: str,
21        views: Dict[str, str],
22        views_path: Optional[Path] = None,
23        defn: Optional[Dict[str, Any]] = None,
24    ):
25        """Initialize MetricDefinitionsExplore."""
26        super().__init__(name, views, views_path)

Initialize MetricDefinitionsExplore.

type: str = 'metric_definitions_explore'
@staticmethod
def from_views( views: List[generator.views.view.View]) -> Iterator[generator.explores.explore.Explore]:
28    @staticmethod
29    def from_views(views: List[View]) -> Iterator[Explore]:
30        """Generate an Operational Monitoring explore for this namespace."""
31        for view in views:
32            if view.view_type == "metric_definitions_view":
33                yield MetricDefinitionsExplore("metric_definitions", {})

Generate an Operational Monitoring explore for this namespace.

@staticmethod
def from_dict( name: str, defn: dict, views_path: pathlib.Path) -> MetricDefinitionsExplore:
35    @staticmethod
36    def from_dict(name: str, defn: dict, views_path: Path) -> MetricDefinitionsExplore:
37        """Get an instance of this explore from a dictionary definition."""
38        return MetricDefinitionsExplore(name, defn["views"], views_path, defn)

Get an instance of this explore from a dictionary definition.

def get_view_time_partitioning_group(self, view: str) -> Optional[str]:
58    def get_view_time_partitioning_group(self, view: str) -> Optional[str]:
59        """Override time partitioning."""
60        return None

Override time partitioning.