You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Adds a sample demonstrating how to implement an incremental refresh based on the Hyper API and Hyper Update REST API. (#64)
* Adds an incremental refresh sample based on the Hyper Update REST API.
Adds a sample demonstrating how to implement an incremental refresh based on the Hyper API and the Hyper Update REST API. The sample is based on the content the Hyper team presented in the Hands on Training session "Hands-on: Leverage the Hyper Update API and Hyper API to Keep Your Data Fresh on Tableau Server" at Tableau Conference 2022.
* Minor: Added argparser to pass in arguments and minor rephrasing of the README file.
* Added the OpenSkyAPI to the requirements.txt file and removed the instructions to manually install it.
Copy file name to clipboardExpand all lines: Community-Supported/README.md
+3Lines changed: 3 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -30,7 +30,10 @@ The community samples focus on individual use cases and are Python-only. They ha
30
30
- Demonstrates the full end-to-end workflow of how to create a multi-table `.hyper` file, place the extract into a `.tdsx`, and publish to Tableau Online or Server.
- Demonstrates how to create a `.hyper` file from a wildcard union on text files held in an AWS S3 bucket. The extract is then placed in a `.tdsx` file and published to Tableau Online or Server.
- This sample is based on the content the Hyper team presented in the Hands on Training session "Hands-on: Leverage the Hyper Update API and Hyper API to Keep Your Data Fresh on Tableau Server" at Tableau Conference 2022 ([slides available here](https://mkt.tableau.com/tc22/sessions/live/430-HOT-D1_Hands-onLeverageTheHyperUpdate.pdf)).
33
35
36
+
It demonstrates how to implement an incremental refresh based on the Hyper API and the [Hyper Update API](https://help.tableau.com/current/api/rest_api/en-us/REST/rest_api_how_to_update_data_to_hyper.htm). It showcases this based on fligths data from the [OpenSkyAPI](https://github.com/openskynetwork/opensky-api).
This sample is based on the content the Hyper team presented in the Hands on Training session "Hands-on: Leverage the Hyper Update API and Hyper API to Keep Your Data Fresh on Tableau Server" at Tableau Conference 2022 ([slides available here](https://mkt.tableau.com/tc22/sessions/live/430-HOT-D1_Hands-onLeverageTheHyperUpdate.pdf)).
7
+
8
+
This script pulls down flights data from the [OpenSkyAPI](https://github.com/openskynetwork/opensky-api), creates a hyper database with this data and uses the [Hyper Update API](https://help.tableau.com/current/api/rest_api/en-us/REST/rest_api_how_to_update_data_to_hyper.htm) to implement an incremental refresh on your Tableau Server/Cloud. The first time this script is executed, the database file is simply published.
9
+
10
+
# Get started
11
+
12
+
## __Prerequisites__
13
+
To run the script, you will need:
14
+
- Windows, Linux, or Mac
15
+
- Python 3
16
+
- Run `pip install -r requirements.txt`
17
+
- Tableau Server Credentials, see below.
18
+
19
+
## Tableau Server Credentials
20
+
To run this sample with your Tableau Server/Cloud, you first need to get the following information:
21
+
- Tableau Server Url, e.g. 'https://us-west-2a.online.tableau.com'
22
+
- Site name, e.g., use 'default' for your default site (note that you cannot use 'default' in Tableau Cloud but must use the site name)
23
+
- Project name, e.g., use an empty string ('') for your default project
24
+
-[Token Name and Token Value](https://help.tableau.com/current/server/en-us/security_personal_access_tokens.htm)
25
+
26
+
Ensure that you have installed the requirements and then just run the sample Python file with the information from above. The syntax for running the script is:
The script consists of two parts: first it creates a Hyper database with flights data and then publishes the database to Tableau Server/Cloud.
32
+
33
+
## Create a database with flights data
34
+
The `create_hyper_database_with_flights_data` method creates an instance of the `OpenSkyAPI` and then pulls down states within a specific bounding box. This example just uses a subset of the available data as we are using the free version of the OpenSkyApi.
35
+
36
+
Then, a Hyper database is created with a table with name `TableName("public", "flights")`. Finally, an inserter is used to insert the flights data.
37
+
38
+
## Publish the hyper database to Tableau Server / Cloud
39
+
The `publish_to_server` method first signs into Tableau Server / Cloud. Then, it finds the respective project to which the database should be published to.
40
+
41
+
There are two cases for publishing the database to Server:
42
+
- No datasource with name `datasource_name_on_server` exists on Tableau Server. In this case, the script simply creates the initial datasource on Tableau server. This datasource is needed for the subsequent incremental refreshes as the data will be added to this datasource.
43
+
- The datasource with name `datasource_name_on_server` already exists on Tableau Server. In this case, the script uses the Hyper Update REST API to insert the data from the database into the respective table in the datasource on Tableau Server/Cloud.
44
+
45
+
## __Resources__
46
+
Check out these resources to learn more:
47
+
-[Hyper API documentation](https://help.tableau.com/current/api/hyper_api/en-us/index.html)
48
+
-[Hyper Update API documentation](https://help.tableau.com/current/api/rest_api/en-us/REST/rest_api_how_to_update_data_to_hyper.htm)
49
+
-[Tableau Server Client Docs](https://tableau.github.io/server-client-python/docs/)
50
+
-[REST API documentation](https://help.tableau.com/current/api/rest_api/en-us/REST/rest_api.htm)
Creates the datasource on Tableau Server if it has not yet been created. Otherwise, uses the
52
+
Hyper Update REST API (https://help.tableau.com/current/api/rest_api/en-us/REST/rest_api_how_to_update_data_to_hyper.htm) to append the data to the datasource.
53
+
"""
54
+
# Create a tableuserverclient object to interact with Tableau Server.
print(f"Update job posted (ID: {job.id}). Waiting for the job to complete...")
100
+
101
+
# Wait for the job to finish.
102
+
job=server.jobs.wait_for_job(job)
103
+
print("Job finished successfully")
104
+
105
+
106
+
if__name__=='__main__':
107
+
argparser=argparse.ArgumentParser(description="Incremental refresh with flights data.")
108
+
argparser.add_argument("server_url", help="The url of Tableau Server / Cloud, e.g. 'https://us-west-2a.online.tableau.com'")
109
+
argparser.add_argument("site_name", help="The name of your site, e.g., use 'default' for your default site. Note that you cannot use 'default' in Tableau Cloud but must use the site name.", default='default')
110
+
argparser.add_argument("project_name", help="The name of your project, e.g., use an empty string ('') for your default project.", default="")
111
+
argparser.add_argument("token_name", help="The name of your authentication token for Tableau Server/Cloud. See this url for more details: https://help.tableau.com/current/server/en-us/security_personal_access_tokens.htm")
112
+
argparser.add_argument("token_value", help="The value of your authentication token for Tableau Server/Cloud. See this url for more details: https://help.tableau.com/current/server/en-us/security_personal_access_tokens.htm")
113
+
args=argparser.parse_args()
114
+
115
+
# First create the hyper database with flights data.
0 commit comments