Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: Tableau Server Import Exception #179

Merged
merged 1 commit into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 18 additions & 14 deletions python_src/src/lamp_py/tableau/pipeline.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import os
from typing import List

from lamp_py.runtime_utils.env_validation import validate_environment

from lamp_py.tableau.hyper import HyperJob
from lamp_py.tableau.jobs.rt_rail import HyperRtRail
from lamp_py.tableau.jobs.gtfs_rail import (
HyperServiceIdByRoute,
Expand All @@ -14,17 +16,20 @@
HyperStaticTrips,
)

HYPER_JOBS = (
HyperRtRail(),
HyperServiceIdByRoute(),
HyperStaticCalendar(),
HyperStaticCalendarDates(),
HyperStaticFeedInfo(),
HyperStaticRoutes(),
HyperStaticStops(),
HyperStaticStopTimes(),
HyperStaticTrips(),
)

def create_hyper_jobs() -> List[HyperJob]:
"""Create Hyper Jobs to Run"""
return [
HyperRtRail(),
HyperServiceIdByRoute(),
HyperStaticCalendar(),
HyperStaticCalendarDates(),
HyperStaticFeedInfo(),
HyperStaticRoutes(),
HyperStaticStops(),
HyperStaticStopTimes(),
HyperStaticTrips(),
]


def start_hyper_updates() -> None:
Expand All @@ -39,12 +44,11 @@ def start_hyper_updates() -> None:
"PUBLIC_ARCHIVE_BUCKET",
],
)

for job in HYPER_JOBS:
for job in create_hyper_jobs():
job.run_hyper()


def start_parquet_updates() -> None:
"""Run all Parquet Update jobs"""
for job in HYPER_JOBS:
for job in create_hyper_jobs():
job.run_parquet()
40 changes: 30 additions & 10 deletions python_src/src/lamp_py/tableau/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ def tableau_authentication(


def project_list(
server: TSC.server.server.Server = tableau_server(),
auth: TSC.models.tableau_auth.TableauAuth = tableau_authentication(),
server: Optional[TSC.server.server.Server] = None,
auth: Optional[TSC.models.tableau_auth.TableauAuth] = None,
) -> List[TSC.models.project_item.ProjectItem]:
"""
Get List of all projects from Tablea server
Expand All @@ -53,13 +53,18 @@ def project_list(

:return List[ProjectItem]
"""
if server is None:
server = tableau_server()
if auth is None:
auth = tableau_authentication()

with server.auth.sign_in(auth):
return list(TSC.Pager(server.projects))


def datasource_list(
server: TSC.server.server.Server = tableau_server(),
auth: TSC.models.tableau_auth.TableauAuth = tableau_authentication(),
server: Optional[TSC.server.server.Server] = None,
auth: Optional[TSC.models.tableau_auth.TableauAuth] = None,
) -> List[TSC.models.datasource_item.DatasourceItem]:
"""
Get List of all datasources from Tablea server
Expand All @@ -69,14 +74,19 @@ def datasource_list(

:return List[DatasourceItem]
"""
if server is None:
server = tableau_server()
if auth is None:
auth = tableau_authentication()

with server.auth.sign_in(auth):
return list(TSC.Pager(server.datasources))


def project_from_name(
project_name: str,
server: TSC.server.server.Server = tableau_server(),
auth: TSC.models.tableau_auth.TableauAuth = tableau_authentication(),
server: Optional[TSC.server.server.Server] = None,
auth: Optional[TSC.models.tableau_auth.TableauAuth] = None,
) -> Optional[TSC.models.project_item.ProjectItem]:
"""
Get Tableau ProjectItem from name
Expand All @@ -90,12 +100,17 @@ def project_from_name(

def datasource_from_name(
datasource_name: str,
server: TSC.server.server.Server = tableau_server(),
auth: TSC.models.tableau_auth.TableauAuth = tableau_authentication(),
server: Optional[TSC.server.server.Server] = None,
auth: Optional[TSC.models.tableau_auth.TableauAuth] = None,
) -> Optional[TSC.models.datasource_item.DatasourceItem]:
"""
Get Tableau DatasourceItem from name
"""
if server is None:
server = tableau_server()
if auth is None:
auth = tableau_authentication()

for datasource in datasource_list(server, auth):
if datasource.name == datasource_name:
return datasource
Expand All @@ -106,12 +121,17 @@ def datasource_from_name(
def overwrite_datasource(
project_name: str,
hyper_path: str,
server: TSC.server.server.Server = tableau_server(),
auth: TSC.models.tableau_auth.TableauAuth = tableau_authentication(),
server: Optional[TSC.server.server.Server] = None,
auth: Optional[TSC.models.tableau_auth.TableauAuth] = None,
) -> TSC.models.datasource_item.DatasourceItem:
"""
Publish locally saved hyperfile to Tableau
"""
if server is None:
server = tableau_server()
if auth is None:
auth = tableau_authentication()

publish_mode = TSC.Server.PublishMode.Overwrite

project = project_from_name(project_name)
Expand Down
Loading