generator.explores.table_explore

Table explore type.

 1"""Table explore type."""
 2
 3from __future__ import annotations
 4
 5from pathlib import Path
 6from typing import Any, Dict, Iterator, List, Optional
 7
 8from ..views import TableView, View
 9from . import Explore
10
11ALLOWED_VIEWS = {"events_stream_table"}
12
13
14class TableExplore(Explore):
15    """A table explore."""
16
17    type: str = "table_explore"
18
19    def _to_lookml(self, v1_name: Optional[str]) -> List[Dict[str, Any]]:
20        """Generate LookML to represent this explore."""
21        explore_lookml: Dict[str, Any] = {
22            "name": self.name,
23            "view_name": self.views["base_view"],
24            "joins": self.get_unnested_fields_joins_lookml(),
25        }
26        if required_filters := self.get_required_filters("base_view"):
27            explore_lookml["always_filter"] = {
28                "filters": required_filters,
29            }
30
31        if datagroup := self.get_datagroup():
32            explore_lookml["persist_with"] = datagroup
33
34        return [explore_lookml]
35
36    @staticmethod
37    def from_views(views: List[View]) -> Iterator[TableExplore]:
38        """Don't generate all possible TableExplores from the views, only generate for ALLOWED_VIEWS."""
39        for view in views:
40            if view.view_type == TableView.type:
41                if view.name in ALLOWED_VIEWS:
42                    yield TableExplore(view.name, {"base_view": view.name})
43
44    @staticmethod
45    def from_dict(name: str, defn: dict, views_path: Path) -> TableExplore:
46        """Get an instance of this explore from a name and dictionary definition."""
47        return TableExplore(name, defn["views"], views_path)
48
49    def get_datagroup(self) -> Optional[str]:
50        """
51        Return the name of the associated datagroup.
52
53        Return `None` if there is no datagroup for this explore.
54        """
55        if self.views_path and (self.views_path.parent / "datagroups").exists():
56            datagroups_path = self.views_path.parent / "datagroups"
57            datagroup_file = (
58                datagroups_path
59                / f'{self.views["base_view"]}_last_updated.datagroup.lkml'
60            )
61            if datagroup_file.exists():
62                return f'{self.views["base_view"]}_last_updated'
63        return None
ALLOWED_VIEWS = {'events_stream_table'}
class TableExplore(generator.explores.explore.Explore):
15class TableExplore(Explore):
16    """A table explore."""
17
18    type: str = "table_explore"
19
20    def _to_lookml(self, v1_name: Optional[str]) -> List[Dict[str, Any]]:
21        """Generate LookML to represent this explore."""
22        explore_lookml: Dict[str, Any] = {
23            "name": self.name,
24            "view_name": self.views["base_view"],
25            "joins": self.get_unnested_fields_joins_lookml(),
26        }
27        if required_filters := self.get_required_filters("base_view"):
28            explore_lookml["always_filter"] = {
29                "filters": required_filters,
30            }
31
32        if datagroup := self.get_datagroup():
33            explore_lookml["persist_with"] = datagroup
34
35        return [explore_lookml]
36
37    @staticmethod
38    def from_views(views: List[View]) -> Iterator[TableExplore]:
39        """Don't generate all possible TableExplores from the views, only generate for ALLOWED_VIEWS."""
40        for view in views:
41            if view.view_type == TableView.type:
42                if view.name in ALLOWED_VIEWS:
43                    yield TableExplore(view.name, {"base_view": view.name})
44
45    @staticmethod
46    def from_dict(name: str, defn: dict, views_path: Path) -> TableExplore:
47        """Get an instance of this explore from a name and dictionary definition."""
48        return TableExplore(name, defn["views"], views_path)
49
50    def get_datagroup(self) -> Optional[str]:
51        """
52        Return the name of the associated datagroup.
53
54        Return `None` if there is no datagroup for this explore.
55        """
56        if self.views_path and (self.views_path.parent / "datagroups").exists():
57            datagroups_path = self.views_path.parent / "datagroups"
58            datagroup_file = (
59                datagroups_path
60                / f'{self.views["base_view"]}_last_updated.datagroup.lkml'
61            )
62            if datagroup_file.exists():
63                return f'{self.views["base_view"]}_last_updated'
64        return None

A table explore.

type: str = 'table_explore'
@staticmethod
def from_views( views: List[generator.views.view.View]) -> Iterator[TableExplore]:
37    @staticmethod
38    def from_views(views: List[View]) -> Iterator[TableExplore]:
39        """Don't generate all possible TableExplores from the views, only generate for ALLOWED_VIEWS."""
40        for view in views:
41            if view.view_type == TableView.type:
42                if view.name in ALLOWED_VIEWS:
43                    yield TableExplore(view.name, {"base_view": view.name})

Don't generate all possible TableExplores from the views, only generate for ALLOWED_VIEWS.

@staticmethod
def from_dict( name: str, defn: dict, views_path: pathlib.Path) -> TableExplore:
45    @staticmethod
46    def from_dict(name: str, defn: dict, views_path: Path) -> TableExplore:
47        """Get an instance of this explore from a name and dictionary definition."""
48        return TableExplore(name, defn["views"], views_path)

Get an instance of this explore from a name and dictionary definition.

def get_datagroup(self) -> Optional[str]:
50    def get_datagroup(self) -> Optional[str]:
51        """
52        Return the name of the associated datagroup.
53
54        Return `None` if there is no datagroup for this explore.
55        """
56        if self.views_path and (self.views_path.parent / "datagroups").exists():
57            datagroups_path = self.views_path.parent / "datagroups"
58            datagroup_file = (
59                datagroups_path
60                / f'{self.views["base_view"]}_last_updated.datagroup.lkml'
61            )
62            if datagroup_file.exists():
63                return f'{self.views["base_view"]}_last_updated'
64        return None

Return the name of the associated datagroup.

Return None if there is no datagroup for this explore.