Skip to content

Calling a BigQuery Stored Procedure aggregates all inputs & outputs at the Airflow Task level #47579

Closed

Description

@luke-hoffman1

Apache Airflow Provider(s)

openlineage, google

Versions of Apache Airflow Providers

apache-airflow-providers-google==10.26.0
apache-airflow-providers-openlineage==2.1.0

Apache Airflow version

2.10.5

Operating System

macOS Sequoia Version 15.2 (24C101)

Deployment

Astronomer

Deployment details

FROM quay.io/astronomer/astro-runtime:12.7.1

What happened

When I call a BigQuery routine (stored procedure) that contains multiple CTAS statements using BigQueryInsertJobOperator, OpenLineage produces a COMPLETE Task event with aggregated inputs and outputs. The problem with this is that you don't get lineage at the "sub-task" CTAS level. For example,

CTAS 1: creates output_table1 from input_table1
CTAS 2: creates output_table2 from input_table2

mock OL event:

{
    "inputs": [
        {
            "namespace": "bigquery",
            "name": "input_table1"
        },
        {
            "namespace": "bigquery",
            "name": "input_table2"
        }
    ],
    "outputs": [
        {
            "namespace": "bigquery",
            "name": "output_table1"
        },
        {
            "namespace": "bigquery",
            "name": "output_table2"
        }
    ]
}

Now it looks like input_table1 and 2 went to both output tables, but that isn't accurate from the "sub-task" perspective.

What you think should happen instead

I'm not certain if this issue constitutes a bug or rather a potential design or implementation gap. The stored procedure operates at a 'sub-task' level, but OpenLineage appears to only support events at the DAG and Task levels. I'm unaware if there have been prior discussions on this topic, but ideally, it would be beneficial to obtain sub-task events from OpenLineage that provide a breakdown of inputs and outputs, aligning with the read and write operations performed by the CTAS statements in the stored procedure.

How to reproduce

DAG:

from airflow import DAG
from airflow.providers.google.cloud.operators.bigquery import (
    BigQueryInsertJobOperator
)
from datetime import datetime

dag = DAG(
    dag_id="dag_execute_bq_stored_proc",
    schedule_interval=None,
    start_date=datetime(2025, 3, 4),  # Start date
)

stored_proc = (
    "<bq-project-id>.<bq-dataset>.<bq-routine>"
)

task1 = BigQueryInsertJobOperator(
    task_id="task1",
    gcp_conn_id="bq_conn",
    configuration={
        "query": {
            "query": f"CALL `{stored_proc}`();",
            "useLegacySql": False,
            "priority": "BATCH",
        }
    },
    dag=dag,
)

task1

BigQuery Routine/Stored Procedure

BEGIN
  -- Create a dummy table
  CREATE TEMP TABLE dummy_table AS
  SELECT 1 AS id, 'row1' AS value
  UNION ALL
  SELECT 2 AS id, 'row2' AS value
  UNION ALL
  SELECT 3 AS id, 'row3' AS value;

   -- Create a dummy table
  CREATE TEMP TABLE dummy_table2 AS
  SELECT 1 AS id, 'row1' AS value
  UNION ALL
  SELECT 2 AS id, 'row2' AS value
  UNION ALL
  SELECT 3 AS id, 'row3' AS value;

  -- Read the dummy table and create another table via CTAS
  CREATE OR REPLACE TABLE <bq-dataset>.another_table AS
  SELECT * FROM dummy_table;

  CREATE OR REPLACE TABLE <bq-dataset>.another_table2 AS
  SELECT * FROM dummy_table2;
END

Anything else

No response

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Activity

  1. added
    kind:bug
    needs-triage
    on Mar 10, 2025
  2. boring-cyborg commented on Mar 10, 2025

    @boring-cyborg

    Thanks for opening your first issue here! Be sure to follow the issue template! If you are willing to raise PR to address this issue please do so, no need to wait for approval.

  3. added
    provider:google
    on Mar 10, 2025
  4. luke-hoffman1 commented on Mar 19, 2025

    @luke-hoffman1
    Author

    cc: @kacpermuda can you take a look at this as well please.

  5. kacpermuda commented on Mar 19, 2025

    @kacpermuda
    Collaborator

    I think we can consider this a feature request - to implement more granular approach for BigQuery lineage extraction. If there are in fact more "jobs" underneath, we could probably be emitting separate OL events for each of this "subtask" or "child query", and then we'd have the desired granularity of lineage.

  6. luke-hoffman1 commented on Mar 19, 2025

    @luke-hoffman1
    Author

    I am relatively new to posting on GitHub :) Is there a place to submit feature requests, or can this issue be converted to one?

  7. kacpermuda commented on Mar 19, 2025

    @kacpermuda
    Collaborator

    I think an Airflow committer can add proper labels that will identify this as a feature request for OpenLineage provider ^^

  8. added
    kind:feature
    and removed
    kind:bug
    needs-triage
    on Jan 24, 2026
  9. aaron-y-chen commented on Jul 9, 2026

    @aaron-y-chen
    Contributor

    Hi all, I opened #69234 to address this by emitting an additional OpenLineage QUERY event pair for each BigQuery child job. I hope this helps resolve the issue. Feel free to share any feedback :)

  10. luke-hoffman1 commented on Jul 23, 2026

    @luke-hoffman1
    Author

    @nailo2c, this is definitely helpful! Thanks for the PR. However, this specific use case is where the operator is executing an already existing Routine. So the SQL Query isn't defined in the DAG code itself. Any ideas on how we might solve this? I would assume the integration would have to pull logs/information from the execution of the Routine itself and I am not sure if Google provides the necessary metadata or not via their APIs..

    cc: @shahar1

  11. luke-hoffman1 commented on Jul 23, 2026

    @luke-hoffman1
    Author

    @nailo2c , nvm, I think your PR solves this as well 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:providersgood first issuekind:featureprovider:googleprovider:openlineage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions