Skip to content

Server

koheesio.integrations.spark.tableau.server.TableauHyperPublishMode #

Publishing modes for the TableauHyperPublisher.

APPEND class-attribute instance-attribute #

APPEND = Append

OVERWRITE class-attribute instance-attribute #

OVERWRITE = Overwrite

koheesio.integrations.spark.tableau.server.TableauHyperPublisher #

TableauHyperPublisher(**data)

Publish the given Hyper file to the Tableau server. Hyper file will be treated by Tableau server as a datasource.

Source code in src/koheesio/integrations/spark/tableau/server.py
def __init__(self, **data):
    super().__init__(**data)
    self.server = None

datasource_name class-attribute instance-attribute #

datasource_name: str = Field(
    default=...,
    description="Name of the datasource to publish",
)

hyper_path class-attribute instance-attribute #

hyper_path: PurePath = Field(
    default=..., description="Path to Hyper file"
)

publish_mode class-attribute instance-attribute #

publish_mode: TableauHyperPublishMode = Field(
    default=OVERWRITE,
    description="Publish mode for the Hyper file",
)

Output #

Output class for TableauHyperPublisher

datasource_item class-attribute instance-attribute #

datasource_item: DatasourceItem = Field(
    default=...,
    description="DatasourceItem object representing the published datasource",
)

execute #

execute()
Source code in src/koheesio/integrations/spark/tableau/server.py
def execute(self):
    # Ensure that the Hyper File exists
    if not os.path.isfile(self.hyper_path):
        raise FileNotFoundError(f"Hyper file not found at: {self.hyper_path.as_posix()}")

    with self.auth:
        # Finally, publish the Hyper File to the Tableau server
        self.log.info(f'Publishing Hyper File located at: "{self.hyper_path.as_posix()}"')
        self.log.debug(f"Create mode: {self.publish_mode}")

        datasource_item = self.server.datasources.publish(
            datasource_item=DatasourceItem(project_id=self.working_project.id, name=self.datasource_name),
            file=self.hyper_path.as_posix(),
            mode=self.publish_mode,
        )
        self.log.info(f"Published datasource to Tableau server with the id: {datasource_item.id}")

        self.output.datasource_item = datasource_item

publish #

publish()
Source code in src/koheesio/integrations/spark/tableau/server.py
def publish(self):
    self.execute()

koheesio.integrations.spark.tableau.server.TableauServer #

TableauServer(**data)

Base class for Tableau server interactions. Class provides authentication and project identification functionality.

Source code in src/koheesio/integrations/spark/tableau/server.py
def __init__(self, **data):
    super().__init__(**data)
    self.server = None

auth property #

Authenticate on the Tableau server.

Examples:

with self._authenticate():
    self.server.projects.get()

Returns:

Type Description
ContextManager for TableauAuth or PersonalAccessTokenAuth authorization object

parent_project class-attribute instance-attribute #

parent_project: Optional[str] = Field(
    default=None,
    alias="parent_project",
    description="Name of the parent project on the Tableau server, use 'root' for the root project.",
)

password class-attribute instance-attribute #

password: SecretStr = Field(
    default=...,
    alias="password",
    description="Password for the Tableau user",
)

project class-attribute instance-attribute #

project: Optional[str] = Field(
    default=None,
    alias="project",
    description="Name of the project on the Tableau server",
)

project_id class-attribute instance-attribute #

project_id: Optional[str] = Field(
    default=None,
    alias="project_id",
    description="ID of the project on the Tableau server",
)

server instance-attribute #

server = None

site_id class-attribute instance-attribute #

site_id: str = Field(
    default=...,
    alias="site_id",
    description="Identifier for the Tableau site, as used in the URL: https://tableau.my-org.com/#/site/SITE_ID",
)

token_name class-attribute instance-attribute #

token_name: Optional[str] = Field(
    default=None,
    alias="token_name",
    description="Name of the Tableau Personal Access Token",
)

token_value class-attribute instance-attribute #

token_value: Optional[SecretStr] = Field(
    default=None,
    alias="token_value",
    description="Value of the Tableau Personal Access Token",
)

url class-attribute instance-attribute #

url: str = Field(
    default=...,
    alias="url",
    description="Hostname for the Tableau server, e.g. tableau.my-org.com",
    examples=["tableau.my-org.com"],
)

user class-attribute instance-attribute #

user: str = Field(
    default=...,
    alias="user",
    description="Login name for the Tableau user",
)

version class-attribute instance-attribute #

version: str = Field(
    default="3.14",
    alias="version",
    description="Version of the Tableau server API",
)

working_project property #

working_project: Union[ProjectItem, None]

Identify working project by using project and parent_project (if necessary) class properties. The goal is to uniquely identify specific project on the server. If multiple projects have the same name, the parent_project attribute of the TableauServer is required.

Notes

Set parent_project value to 'root' if the project is located in the root directory.

If id of the project is known, it can be used in project_id parameter, then the detection of the working project using the project and parent_project attributes is skipped.

Returns:

Type Description
ProjectItem object representing the working project

execute #

execute()
Source code in src/koheesio/integrations/spark/tableau/server.py
def execute(self):
    raise NotImplementedError("Method `execute` must be implemented in the subclass.")

validate_project #

validate_project(data: dict) -> dict

Validate when project and project_id are provided at the same time.

Source code in src/koheesio/integrations/spark/tableau/server.py
@model_validator(mode="after")
def validate_project(cls, data: dict) -> dict:
    """Validate when project and project_id are provided at the same time."""
    project = data.get("project")
    project_id = data.get("project_id")

    if project and project_id:
        raise ValueError("Both 'project' and 'project_id' parameters cannot be provided at the same time.")

    if not project and not project_id:
        raise ValueError("Either 'project' or 'project_id' parameters should be provided, none is set")