WherobotsSqlOperator to execute SQL queries on Wherobots Cloud
against your datasets in your Wherobots catalogs.
Using the Operator
TheWherobotsSqlOperator 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 theruntime
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.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 yourwherobots catalog. You can execute those SQL queries
using our Spatial SQL API or from a
notebook.
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.
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.

-
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:- Copy this DAG example into a Python file.
- Save the file with a name of your choosing (e.g.,
YOUR_DAG_FILE_EXAMPLE_NAME.py). - Execute it using the command:
pytest YOUR_DAG_FILE_EXAMPLE_NAME.py

