2023-06-05 18:59:20 +03:00
|
|
|
"""Table explore type."""
|
2024-03-20 01:43:59 +03:00
|
|
|
|
2023-06-05 18:59:20 +03:00
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
from pathlib import Path
|
|
|
|
from typing import Any, Dict, Iterator, List, Optional
|
|
|
|
|
2024-02-12 22:31:15 +03:00
|
|
|
from ..views import TableView, View
|
2023-06-05 18:59:20 +03:00
|
|
|
from . import Explore
|
|
|
|
|
2024-02-12 22:31:15 +03:00
|
|
|
ALLOWED_VIEWS = {"events_stream_table"}
|
|
|
|
|
2023-06-05 18:59:20 +03:00
|
|
|
|
|
|
|
class TableExplore(Explore):
|
|
|
|
"""A table explore."""
|
|
|
|
|
|
|
|
type: str = "table_explore"
|
|
|
|
|
2024-07-29 19:24:50 +03:00
|
|
|
def _to_lookml(self, v1_name: Optional[str]) -> List[Dict[str, Any]]:
|
2023-06-05 18:59:20 +03:00
|
|
|
"""Generate LookML to represent this explore."""
|
|
|
|
explore_lookml: Dict[str, Any] = {
|
|
|
|
"name": self.name,
|
|
|
|
"view_name": self.views["base_view"],
|
|
|
|
"joins": self.get_unnested_fields_joins_lookml(),
|
|
|
|
}
|
|
|
|
if required_filters := self.get_required_filters("base_view"):
|
|
|
|
explore_lookml["always_filter"] = {
|
|
|
|
"filters": required_filters,
|
|
|
|
}
|
|
|
|
return [explore_lookml]
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def from_views(views: List[View]) -> Iterator[TableExplore]:
|
2024-02-12 22:31:15 +03:00
|
|
|
"""Don't generate all possible TableExplores from the views, only generate for ALLOWED_VIEWS."""
|
|
|
|
for view in views:
|
|
|
|
if view.view_type == TableView.type:
|
|
|
|
if view.name in ALLOWED_VIEWS:
|
|
|
|
yield TableExplore(view.name, {"base_view": view.name})
|
2023-06-05 18:59:20 +03:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def from_dict(name: str, defn: dict, views_path: Path) -> TableExplore:
|
|
|
|
"""Get an instance of this explore from a name and dictionary definition."""
|
|
|
|
return TableExplore(name, defn["views"], views_path)
|