cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Can SQL task pass its outputs to ForEach task?

Fikrat
New Contributor

Hi there,
If I understood correctly, Roland said output SQL task can be used as input to ForEach task in Workflows. I tried that and used the expression sqlTaskName.output.rows, but Databricks rejected that expression. Anyone know how to do that? 

1 REPLY 1

Walter_C
Databricks Employee
Databricks Employee

Can you confirm if this are the steps being followed:

  • Create the SQL Task: Ensure your SQL task is correctly set up and produces the desired output. For example:

    SELECT customer_name, market FROM example_customers;
  • Reference the SQL Task Output in ForEach Task:

    • Use the correct syntax to reference the rows output. The expression should be in the format {{ tasks.sqlTaskName.output.rows }}.
    • Ensure that the SQL task name (sqlTaskName) matches the task key you have defined in your workflow.
  • Configure the ForEach Task:

    • Set the inputs field of the ForEach task to {{ tasks.sqlTaskName.output.rows }}.
    • Define the nested task within the ForEach task to process each row. For example:
      {
        "task_key": "process_customers_iteration",
        "parameters": {
          "customer_name": "{{ input.customer_name }}",
          "market": "{{ input.market }}"
        },
        "sql_task": {
          "file": {
            "path": "/path/to/your/sql/file.sql"
          }
        }
      }

 

 

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you wonโ€™t want to miss the chance to attend and share knowledge.

If there isnโ€™t a group near you, start one and help create a community that brings people together.

Request a New Group