Tableau Hyper API Samples

repository·main·Indexed 41 days ago

https://github.com/tableau/hyper-api-samples

A 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.

Tokens
13.8K
Snippets
40
Records
70
Agent score
99%

What's inside Tableau Hyper API Samples

  1. Overview of Tableau-Supported Hyper API Samples

    main
    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.
  2. Overview of clouddb-extractor

    main

    The clouddb-extractor is 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 via BaseExtractor) 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.
  3. Understand the types of Hyper API samples

    main

    This repository contains two distinct categories of samples:

    1. 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.
    2. 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.
  4. Explore Community Supported Python Samples

    main

    The Community-Supported directory 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 .hyper files between formats, defragmenting files to optimize storage, and converting .hyper to CSV or Parquet to .hyper.
    • Cloud & External Integration: Extracting data from cloud databases, creating .hyper files 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 .hyper files to Tableau Server/Online, including workflows involving .tdsx packaging.
    • Data Maintenance: Implementing incremental refreshes using the Hyper API and Hyper Update API, and adjusting vertex order for GEOGRAPHY type columns.
    • Analysis Tools: Using the hyper-jupyter-kernel CLI to inspect files and run ad-hoc SQL queries.
  5. Query external data like Parquet or CSV with Hyper

    main

    The query-external-data sample 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.
  6. What is the Hyper API?

    main

    The 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 .hyper files 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.
  7. Publish multi-table Hyper files to Tableau Server/Online

    main

    Starting with Tableau Server version 2021.4, you can publish multi-table .hyper files directly to Tableau Server or Tableau Online. Tableau automatically infers the data model by using the foreign key constraints defined within the .hyper file.

    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.
  8. How the clouddb-extractor Extractor Interface works

    main

    The 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:

    1. Connection Management: Handling database-specific authentication and connectivity.
    2. Schema Discovery: Identifying table structures.
    3. Query Optimization: Overriding generic query processing to use database-specific optimizations (following DBAPIv2 standards).

    Developers can either use the provided extractor_cli.py or import a specific implementation class directly into their own Python scripts for custom automation.

  9. How incremental refresh works in this sample

    main

    The 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:

    1. Initial Publication: If no datasource with the specified datasource_name_on_server exists on the server, the script creates and publishes a new initial datasource. This establishes the baseline for future updates.
    2. 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.
  10. How GEOGRAPHY vertex ordering affects Tableau

    main

    In 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.
  11. Setup the tde-to-hyper script

    main

    To 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.

    1. Navigate to the directory containing tde_to_hyper.py.
    2. 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