-
Notifications
You must be signed in to change notification settings - Fork 14.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Dataproc operators fail to import without OpenLineage
Signed-off-by: Kacper Muda <[email protected]>
- Loading branch information
1 parent
764bf20
commit 8d9f817
Showing
6 changed files
with
153 additions
and
56 deletions.
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
providers/google/src/airflow/providers/google/cloud/openlineage/facets.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# | ||
# 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. | ||
from __future__ import annotations | ||
|
||
from attr import define, field | ||
|
||
from airflow.providers.google import __version__ as provider_version | ||
|
||
try: | ||
try: | ||
from openlineage.client.generated.base import RunFacet | ||
except ImportError: # Old OpenLineage client is used | ||
from openlineage.client.facet import BaseFacet as RunFacet | ||
|
||
@define | ||
class BigQueryJobRunFacet(RunFacet): | ||
""" | ||
Facet that represents relevant statistics of bigquery run. | ||
:param cached: BigQuery caches query results. Rest of the statistics will not be provided for cached queries. | ||
:param billedBytes: How many bytes BigQuery bills for. | ||
:param properties: Full property tree of BigQUery run. | ||
""" | ||
|
||
cached: bool | ||
billedBytes: int | None = field(default=None) | ||
properties: str | None = field(default=None) | ||
|
||
@staticmethod | ||
def _get_schema() -> str: | ||
return ( | ||
"https://raw.githubusercontent.com/apache/airflow/" | ||
f"providers-google/{provider_version}/airflow/providers/google/" | ||
"openlineage/BigQueryJobRunFacet.json" | ||
) | ||
except ImportError: # OpenLineage is not available | ||
|
||
def create_no_op(*_, **__) -> None: | ||
""" | ||
Create a no-op placeholder. | ||
This function creates and returns a None value, used as a placeholder when the OpenLineage client | ||
library is available. It represents an action that has no effect. | ||
""" | ||
return None | ||
|
||
BigQueryJobRunFacet = create_no_op |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
providers/google/tests/provider_tests/google/cloud/openlineage/test_facets.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# 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. | ||
from __future__ import annotations | ||
|
||
from airflow.providers.google.cloud.openlineage.facets import BigQueryJobRunFacet | ||
|
||
|
||
def test_bigquery_job_run_facet(): | ||
facet = BigQueryJobRunFacet(cached=True, billedBytes=123, properties="some_properties") | ||
assert facet.cached is True | ||
assert facet.billedBytes == 123 | ||
assert facet.properties == "some_properties" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters