Skip to main content

SQL Task

Task Components in Ascend let you execute arbitrary SQL code as a Component. Unlike Transforms, SQL Tasks aren't directly tied to the Data Plane, giving you more flexibility.

Structuring Your SQL Component

In SQL Task Components, the config function defines the task type and its dependencies. This function specifies the input data and any Components that your task relies on.

Example

Here's a SQL Task Component example:

{{
config(
type="task",
dependencies=[ref("route_closures")]
)
}}

-- Identify routes with closures today and log a warning
WITH closures_today AS (
SELECT
route_id
FROM
{{ ref("route_closures") }}
WHERE
start_date >= CURRENT_DATE
AND end_date <= CURRENT_DATE
)

SELECT
route_id
FROM
closures_today;

This example identifies routes with active closures today:

  • Config function: Defines the task type and dependencies. The task depends on the route_closures Component for its data source.

  • Common table expression (CTE): The WITH clause creates a temporary result set closures_today that filters the route_closures data for routes where closures are active on the current date.

  • Final selection: The query selects route_id from the filtered data, which can be used for warnings or further processing.

Next Steps