Repository navigation
Description
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
- I agree to follow this project's Code of Conduct
Activity
boring-cyborg commentedon Mar 10, 2025
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.
luke-hoffman1 commentedon Mar 19, 2025
cc: @kacpermuda can you take a look at this as well please.
kacpermuda commentedon Mar 19, 2025
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.
luke-hoffman1 commentedon Mar 19, 2025
I am relatively new to posting on GitHub :) Is there a place to submit feature requests, or can this issue be converted to one?
kacpermuda commentedon Mar 19, 2025
I think an Airflow committer can add proper labels that will identify this as a feature request for OpenLineage provider ^^
aaron-y-chen commentedon Jul 9, 2026
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 :)
luke-hoffman1 commentedon Jul 23, 2026
@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
luke-hoffman1 commentedon Jul 23, 2026
@nailo2c , nvm, I think your PR solves this as well 😄