Skip to main content
Use the WherobotsSqlOperator to execute SQL queries on Wherobots Cloud against your datasets in your Wherobots catalogs.

Using the Operator

The WherobotsSqlOperator requires a sql argument, which can be a SQL query string, or a list of query strings. You can also optionally specify the runtime you want to use to power your query. Below is a simple example of using the operator.
simple-operator-example.py

Runtime and region selection

You can choose the Wherobots runtime you want to use with the runtime parameter, passing in one of the Runtime enum values. For guidance on runtime sizing and selection, see Runtimes.
Region parameter will become mandatoryTo prepare for the expansion of Wherobots Cloud to new regions and cloud providers, the region parameter will become mandatory in a future SDK version. Before this support for new regions is added, we will release an updated version of the SDK. If you continue using an older SDK version, your existing Airflow tasks will still work. However, any new or existing tasks you create without specifying the region parameter will be hosted in the aws-us-west-2 region.
For a full list of Wherobots’ supported AWS regions, see Cloud and Cloud Region Availability section You can see the runtimes available to your organization within the Start a Notebook dropdown in Wherobots Cloud.

Build ETL pipelines with the WherobotsSqlOperator

Loading or creating tables into the Wherobots Catalog allows you to query, process, and work with your data using pure SQL queries. In this example, we’ll use a SQL query to create a new table from the result of a query on an existing table of the Overture Maps public dataset. First, create a new database in your wherobots catalog. You can execute those SQL queries using our Spatial SQL API or from a notebook.
Now we build a new table called org_catalog.test_db.top_100_hot_buildings_daily from the query result on tables in the wherobots_open_data catalog. It finds out the 100 buildings from wherobots_open_data.overture_maps_foundation.buildings_building table that contains the most points recorded in wherobots_open_data.overture_maps_foundation.places_place table at 2023-07-24.
Now you can query the resulting table to verify the results:
To turn this ETL into a daily process orchestrated by Apache Airflow, bring the query into your DAG’s definition of the WherobotsSqlOperator, changing the CREATE TABLE ... AS into INSERT INTO ... to append new data each day into your table, and leveraging Apache Airflow’s macros for the daily date range. Below is an example DAG file. The macros variables {{ ds }} and {{ next_ds }} will be replaced dynamically by the actual schedule time.
example-DAG.py

Test your DAG file

There are two ways to test the DAG file, within the Airflow UI or through pytest framework. You can also refer to the official Apache Airflow Guidance for DAG testing best practices.

Test in Airflow UI

You can put the DAG file into the $AIRFLOW_HOME/dags directory and trigger the DAG from the Airflow UI. Below is an example run of the DAG file. You will find the exact queries executed from the logs. example-dag-run
  • If you are launching Apache Airflow instance through airflow standalone, and you are working on macOS, you may need to execute the following line:
  • The second batch will fail because there is no data in the source tables at after 2023-07-24.

Test using pytest

Pytest is an open-source testing framework for Python. It can be used to write various types of software tests, including unit tests, integration tests, end-to-end tests, and functional tests. For more information on installing and using pytest, refer to the pytest PyPi page.

Example DAG with pytest

The following is an example Python file that demonstrates how to use your DAG with pytest:
example-DAG-with-pytest.py

Execute the test

To execute this test:
  1. Copy this DAG example into a Python file.
  2. Save the file with a name of your choosing (e.g., YOUR_DAG_FILE_EXAMPLE_NAME.py).
  3. Execute it using the command: pytest YOUR_DAG_FILE_EXAMPLE_NAME.py
It can take a few minutes for your WherobotsDB SQL Session to initialize. Logs will appear once the test completes.