Tableau Hyper API Samples
repository·main·Indexed 41 days ago
https://github.com/tableau/hyper-api-samplesA collection of sample implementations for the Tableau Hyper API to automate interactions with .hyper extract files. Includes utilities such as clouddb-extractor for synchronizing data from Azure SQL, BigQuery, MySQL, PostgreSQL, and Redshift, a tool to adjust GEOGRAPHY vertex order for 'interior-left' convention, and a script to convert .hyper file versions.
What's inside Tableau Hyper API Samples
- This repository contains officially supported, maintained, and tested samples for the Hyper API. These samples are available in all languages supported by the Hyper API and are updated alongside new releases. They serve as practical implementations of common Hyper API tasks, such as data ingestion, manipulation, and querying.
Overview of clouddb-extractor
mainThe
clouddb-extractoris a utility designed to extract data from cloud databases and synchronize it with published Tableau Hyper extracts. It supports appending, updating, upserting, and deleting rows to keep Tableau data sources up to date.It uses a standard
Extractor Interface(implemented viaBaseExtractor) which is extended for specific databases like Azure SQL, BigQuery, MySQL, PostgreSQL, and Redshift. For most automation tasks, you will interact with these core methods:load_sample: Extracts a sample of rows for testing.export_load: Performs an initial full extract of a source table.append_to_datasource: Appends rows from a query or table to an existing datasource.update_datasource: Updates an existing datasource using a changeset.delete_from_datasource: Deletes rows from a datasource based on conditions or primary keys in a changeset.
Understand the types of Hyper API samples
mainThis repository contains two distinct categories of samples:
- Tableau-Supported Samples: These are official samples packaged and shipped within the Hyper API itself. They are available for Python, Java, C++, and C#/.NET and are fully maintained by Tableau.
- Community-Supported Samples: These focus on specific use cases and are Python-only. While written by members of the Tableau development team, they are community-supported and may not be maintained for every new release. They are manually tested and reviewed before publishing.
Explore Community Supported Python Samples
mainThe
Community-Supporteddirectory contains Python-only samples focused on specific use cases. These samples are written by the Tableau development team but are provided with 'Community Supported' status, meaning they may not be maintained for every new release. They are useful for implementing common data engineering patterns with the Hyper API.Key capabilities demonstrated in these samples include:
- Data Conversion & Optimization: Converting
.hyperfiles between formats, defragmenting files to optimize storage, and converting.hyperto CSV or Parquet to.hyper. - Cloud & External Integration: Extracting data from cloud databases, creating
.hyperfiles from AWS S3 text files (using wildcard unions), and interacting with S3-compatible services (like Google Cloud Storage) natively. - Publishing Workflows: Publishing single-table or multi-table
.hyperfiles to Tableau Server/Online, including workflows involving.tdsxpackaging. - Data Maintenance: Implementing incremental refreshes using the Hyper API and Hyper Update API, and adjusting vertex order for
GEOGRAPHYtype columns. - Analysis Tools: Using the
hyper-jupyter-kernelCLI to inspect files and run ad-hoc SQL queries.
- Data Conversion & Optimization: Converting
Query external data like Parquet or CSV with Hyper
mainThe
query-external-datasample demonstrates how to use the Hyper API to query external data formats, such as Parquet or CSV files, directly. This pattern is useful for ETL (Extract, Transform, Load) workflows where you need to:- Access multiple files simultaneously.
- Filter data during the read process.
- Create additional calculated columns from external sources.
What is the Hyper API?
mainThe Hyper API provides a set of functions to automate interactions with Tableau extract (
.hyper) files. It allows developers and administrators to programmatically manage data within these files.Key capabilities include:
- Creating extract files: Generate new
.hyperfiles for data sources not natively supported by Tableau. - Data Manipulation: Open existing files to insert, delete, update, or read data.
- ETL Automation: Automate custom Extract, Transform, and Load (ETL) processes, such as implementing rolling window updates or custom incremental updates.
- Data Retrieval: Programmatically retrieve data from an existing extract file.
- Creating extract files: Generate new
Publish multi-table Hyper files to Tableau Server/Online
mainStarting with Tableau Server version 2021.4, you can publish multi-table
.hyperfiles directly to Tableau Server or Tableau Online. Tableau automatically infers the data model by using the foreign key constraints defined within the.hyperfile.Key behaviors:
- Data Model Inference: Relationships are generated based on foreign keys. If multiple columns are involved, a multi-expression relationship is created.
- Constraints: No referential integrity is enforced; the foreign keys are used solely for model inference.
- Limitations: Only simple relationship trees spanning all tables are supported. Publishing will fail if the file contains multiple tables without incoming foreign keys (e.g., multiple fact tables).
- Resulting Structure: The published data source contains a single connection to the Hyper file, with objects corresponding to the individual tables in the file.
How the clouddb-extractor Extractor Interface works
mainThe utility is built on an Abstract Base Class (ABC) called
BaseExtractor. This class provides the core logic for extracting from cloud databases to 'live to hyper' Tableau Datasources.Specific database implementations (e.g.,
azuresql_extractor.py,bigquery_extractor.py) extend this base class to handle:- Connection Management: Handling database-specific authentication and connectivity.
- Schema Discovery: Identifying table structures.
- Query Optimization: Overriding generic query processing to use database-specific optimizations (following DBAPIv2 standards).
Developers can either use the provided
extractor_cli.pyor import a specific implementation class directly into their own Python scripts for custom automation.How incremental refresh works in this sample
mainThe sample implements an incremental refresh pattern using the Hyper Update REST API. The logic follows two distinct paths based on the state of the Tableau Server/Cloud:
- Initial Publication: If no datasource with the specified
datasource_name_on_serverexists on the server, the script creates and publishes a new initial datasource. This establishes the baseline for future updates. - Incremental Update: If the datasource already exists, the script uses the Hyper Update REST API to insert only the new data from the local Hyper database into the existing table on the server. This avoids re-publishing the entire dataset and keeps the data fresh efficiently.
- Initial Publication: If no datasource with the specified
Important considerations for Hyper to CSV conversion
mainWhen using
pantabto transform.hyperdatabases, keep the following in mind:- Datatype Mapping: You must properly map datatypes between Hyper's
SQLTypesand pandas'dtypes. - Nullability: The
NULLABILITYspecified in the documentation must match the configuration in your.hyperfile to ensure data integrity during the conversion.
- Datatype Mapping: You must properly map datatypes between Hyper's
How GEOGRAPHY vertex ordering affects Tableau
mainIn the Hyper 'spheroidal' system, vertex order defines the polygon's interior. Tableau follows an 'interior-left' convention: as you progress through vertices in storage order, the interior of the polygon should be to the left.
Because the system is spheroidal, there is no technically 'incorrect' order, but a reverse order changes the space the polygon encloses. If data is imported with an 'interior-right' winding order, users may encounter:
- Incorrect auto-zoom behavior in Tableau maps.
- Unexpected results during spatial joins.
Setup the tde-to-hyper script
mainTo run the conversion script, ensure you have Python 3.7 or newer installed on Windows, macOS, or Linux. It is recommended to use a Python virtual environment.
- Navigate to the directory containing
tde_to_hyper.py. - Create a virtual environment and install the required Hyper API version (0.0.17537) using the provided
requirements.txt.
$ python3 -m venv .venv/ $ .venv/bin/python3 -m pip install -r requirements.txt- Navigate to the directory containing