kacpermuda commented on code in PR #65788:
URL: https://github.com/apache/airflow/pull/65788#discussion_r3160532510


##########
providers/openlineage/src/airflow/providers/openlineage/api/sql.py:
##########
@@ -0,0 +1,172 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""Public helpers for emitting OpenLineage events describing SQL query 
executions."""
+
+from __future__ import annotations
+
+import logging
+from collections import defaultdict
+from typing import TYPE_CHECKING
+
+from openlineage.client.facet_v2 import error_message_run, external_query_run, 
sql_job
+
+from airflow.providers.openlineage.api.core import emit, is_openlineage_active
+from airflow.providers.openlineage.plugins.adapter import _PRODUCER
+from airflow.providers.openlineage.plugins.macros import lineage_job_name, 
lineage_run_id
+from airflow.providers.openlineage.utils.sql_hook_lineage import (
+    _create_ol_event_pair,
+    _parse_query_into_datasets,
+)
+from airflow.providers.openlineage.utils.utils import 
get_task_instance_from_context
+
+if TYPE_CHECKING:
+    from datetime import datetime
+
+    from openlineage.client.event_v2 import Dataset
+    from openlineage.client.facet_v2 import JobFacet, RunFacet
+
+    from airflow.models.taskinstance import TaskInstance
+    from airflow.sdk.execution_time.task_runner import RuntimeTaskInstance
+
+log = logging.getLogger(__name__)
+
+__all__ = ["emit_query_lineage"]
+
+# Per-task counters so repeated emit_query_lineage calls within one task get 
unique job names.
+_QUERY_COUNTERS: dict[str, int] = defaultdict(int)

Review Comment:
   Tested it manually, will check again, but even if the dict itself will not 
get rebuild, the key here is OL run id, so there is a low risk of collision.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to