Skip to content

Commit

Permalink
[2/n][dagster-tableau] Scaffold DagsterTableauTranslator class (#24190)
Browse files Browse the repository at this point in the history
## Summary & Motivation

Builds out a very barebones translator class to build specs for Tableau
assets.

The structure of the `DagsterTableauTranslator` is based on the
`DagsterPowerBITranslator` introduced in #23245.

## How I Tested These Changes

Tests will be added in subsequent PRs.

## Changelog [New | Bug | Docs]

> Replace this message with a changelog entry, or `NOCHANGELOG`
  • Loading branch information
maximearmstrong authored Sep 12, 2024
1 parent 122885e commit 9773296
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 0 deletions.
1 change: 1 addition & 0 deletions pyright/master/requirements-pinned.txt
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ daff==1.3.46
-e docs/sphinx/_ext/dagster-sphinx
-e python_modules/libraries/dagster-ssh
-e python_modules/dagster-test
-e python_modules/libraries/dagster-tableau
-e python_modules/libraries/dagster-twilio
-e docs/dagster-ui-screenshot
-e python_modules/libraries/dagster-wandb
Expand Down
1 change: 1 addition & 0 deletions pyright/master/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
-e python_modules/libraries/dagster-snowflake-pyspark/
-e python_modules/libraries/dagster-spark/
-e python_modules/libraries/dagster-ssh/
-e python_modules/libraries/dagster-tableau
-e python_modules/libraries/dagster-twilio/
-e python_modules/libraries/dagster-wandb[dev]
-e python_modules/libraries/dagstermill/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from dagster._core.libraries import DagsterLibraryRegistry

from dagster_tableau.translator import DagsterTableauTranslator as DagsterTableauTranslator

# Move back to version.py and edit setup.py once we are ready to publish.
__version__ = "1!0+dev"

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
from enum import Enum
from typing import Any, Mapping

from dagster import _check as check
from dagster._core.definitions.asset_key import AssetKey
from dagster._core.definitions.asset_spec import AssetSpec
from dagster._record import record


class TableauContentType(Enum):
"""Enum representing each object in Tableau's ontology."""

WORKBOOK = "workbook"
VIEW = "view"
DATA_SOURCE = "data_source"


@record
class TableauContentData:
"""A record representing a piece of content in Tableau.
Includes the content's type and data as returned from the API.
"""

content_type: TableauContentType
properties: Mapping[str, Any]


@record
class TableauWorkspaceData:
"""A record representing all content in a Tableau workspace.
Provided as context for the translator so that it can resolve dependencies between content.
"""

site_name: str
workbooks_by_id: Mapping[str, TableauContentData]
views_by_id: Mapping[str, TableauContentData]
data_sources_by_id: Mapping[str, TableauContentData]


class DagsterTableauTranslator:
"""Translator class which converts raw response data from the Tableau API into AssetSpecs.
Subclass this class to implement custom logic for each type of Tableau content.
"""

def __init__(self, context: TableauWorkspaceData):
self._context = context

@property
def workspace_data(self) -> TableauWorkspaceData:
return self._context

def get_asset_spec(self, data: TableauContentData) -> AssetSpec:
if data.content_type == TableauContentType.VIEW:
return self.get_view_spec(data)
elif data.content_type == TableauContentType.DATA_SOURCE:
return self.get_data_source_spec(data)
else:
check.assert_never(data.content_type)

def get_view_asset_key(self, data: TableauContentData) -> AssetKey: ...
def get_view_spec(self, data: TableauContentData) -> AssetSpec: ...

def get_data_source_asset_key(self, data: TableauContentData) -> AssetKey: ...
def get_data_source_spec(self, data: TableauContentData) -> AssetSpec: ...

0 comments on commit 9773296

Please sign in to comment.