forked from apache/airflow
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds 'Trino' provider (with lower memory footprint for tests) (apache…
…#15187) While checking the test status of various CI tests we came to conclusion that Presto integration took a lot of memory (~1GB) and was the main source of failures during integration tests, especially with MySQL8. The attempt to fine-tune the memory used turned out in the discovery, that Presto DB stopped publishing their Docker image (prestosql/presto) - apparently after the aftermath of splitting-off Trino from Presto. Th split-off was already discussed in apache#14281 and it was planned to add support for Trino (which is the more community-driven fork of the Presto - Presto remained at Facebook Governance, where Trino is an effort continued by the original creators. You can read more about it in the announcement: https://trino.io/blog/2020/12/27/announcing-trino.html. While Presto continues their way under The Linux Foundation, Trino lives its own live and keeps on maintaining all artifacts and libraries (including the image). That allowed us to update our tests and decrease the memory footprint by around 400MB. This commit: * adds the new Trino provider * removes `presto` integration and replaces it with `trino` * the `trino` integartion image is built with 400MB less memory requirementes and published as `apache/airflow:trino-*` * moves the integration tests from Presto to Trino Fixes: apache#14281
- Loading branch information
Showing
49 changed files
with
1,901 additions
and
96 deletions.
There are no files selected for viewing
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
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
150 changes: 150 additions & 0 deletions
150
airflow/providers/google/cloud/example_dags/example_trino_to_gcs.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,150 @@ | ||
# | ||
# 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. | ||
""" | ||
Example DAG using TrinoToGCSOperator. | ||
""" | ||
import os | ||
import re | ||
|
||
from airflow import models | ||
from airflow.providers.google.cloud.operators.bigquery import ( | ||
BigQueryCreateEmptyDatasetOperator, | ||
BigQueryCreateExternalTableOperator, | ||
BigQueryDeleteDatasetOperator, | ||
BigQueryExecuteQueryOperator, | ||
) | ||
from airflow.providers.google.cloud.transfers.trino_to_gcs import TrinoToGCSOperator | ||
from airflow.utils.dates import days_ago | ||
|
||
GCP_PROJECT_ID = os.environ.get("GCP_PROJECT_ID", 'example-project') | ||
GCS_BUCKET = os.environ.get("GCP_TRINO_TO_GCS_BUCKET_NAME", "test-trino-to-gcs-bucket") | ||
DATASET_NAME = os.environ.get("GCP_TRINO_TO_GCS_DATASET_NAME", "test_trino_to_gcs_dataset") | ||
|
||
SOURCE_MULTIPLE_TYPES = "memory.default.test_multiple_types" | ||
SOURCE_CUSTOMER_TABLE = "tpch.sf1.customer" | ||
|
||
|
||
def safe_name(s: str) -> str: | ||
""" | ||
Remove invalid characters for filename | ||
""" | ||
return re.sub("[^0-9a-zA-Z_]+", "_", s) | ||
|
||
|
||
with models.DAG( | ||
dag_id="example_trino_to_gcs", | ||
schedule_interval=None, # Override to match your needs | ||
start_date=days_ago(1), | ||
tags=["example"], | ||
) as dag: | ||
|
||
create_dataset = BigQueryCreateEmptyDatasetOperator(task_id="create-dataset", dataset_id=DATASET_NAME) | ||
|
||
delete_dataset = BigQueryDeleteDatasetOperator( | ||
task_id="delete_dataset", dataset_id=DATASET_NAME, delete_contents=True | ||
) | ||
|
||
# [START howto_operator_trino_to_gcs_basic] | ||
trino_to_gcs_basic = TrinoToGCSOperator( | ||
task_id="trino_to_gcs_basic", | ||
sql=f"select * from {SOURCE_MULTIPLE_TYPES}", | ||
bucket=GCS_BUCKET, | ||
filename=f"{safe_name(SOURCE_MULTIPLE_TYPES)}.{{}}.json", | ||
) | ||
# [END howto_operator_trino_to_gcs_basic] | ||
|
||
# [START howto_operator_trino_to_gcs_multiple_types] | ||
trino_to_gcs_multiple_types = TrinoToGCSOperator( | ||
task_id="trino_to_gcs_multiple_types", | ||
sql=f"select * from {SOURCE_MULTIPLE_TYPES}", | ||
bucket=GCS_BUCKET, | ||
filename=f"{safe_name(SOURCE_MULTIPLE_TYPES)}.{{}}.json", | ||
schema_filename=f"{safe_name(SOURCE_MULTIPLE_TYPES)}-schema.json", | ||
gzip=False, | ||
) | ||
# [END howto_operator_trino_to_gcs_multiple_types] | ||
|
||
# [START howto_operator_create_external_table_multiple_types] | ||
create_external_table_multiple_types = BigQueryCreateExternalTableOperator( | ||
task_id="create_external_table_multiple_types", | ||
bucket=GCS_BUCKET, | ||
source_objects=[f"{safe_name(SOURCE_MULTIPLE_TYPES)}.*.json"], | ||
source_format="NEWLINE_DELIMITED_JSON", | ||
destination_project_dataset_table=f"{DATASET_NAME}.{safe_name(SOURCE_MULTIPLE_TYPES)}", | ||
schema_object=f"{safe_name(SOURCE_MULTIPLE_TYPES)}-schema.json", | ||
) | ||
# [END howto_operator_create_external_table_multiple_types] | ||
|
||
read_data_from_gcs_multiple_types = BigQueryExecuteQueryOperator( | ||
task_id="read_data_from_gcs_multiple_types", | ||
sql=f"SELECT COUNT(*) FROM `{GCP_PROJECT_ID}.{DATASET_NAME}.{safe_name(SOURCE_MULTIPLE_TYPES)}`", | ||
use_legacy_sql=False, | ||
) | ||
|
||
# [START howto_operator_trino_to_gcs_many_chunks] | ||
trino_to_gcs_many_chunks = TrinoToGCSOperator( | ||
task_id="trino_to_gcs_many_chunks", | ||
sql=f"select * from {SOURCE_CUSTOMER_TABLE}", | ||
bucket=GCS_BUCKET, | ||
filename=f"{safe_name(SOURCE_CUSTOMER_TABLE)}.{{}}.json", | ||
schema_filename=f"{safe_name(SOURCE_CUSTOMER_TABLE)}-schema.json", | ||
approx_max_file_size_bytes=10_000_000, | ||
gzip=False, | ||
) | ||
# [END howto_operator_trino_to_gcs_many_chunks] | ||
|
||
create_external_table_many_chunks = BigQueryCreateExternalTableOperator( | ||
task_id="create_external_table_many_chunks", | ||
bucket=GCS_BUCKET, | ||
source_objects=[f"{safe_name(SOURCE_CUSTOMER_TABLE)}.*.json"], | ||
source_format="NEWLINE_DELIMITED_JSON", | ||
destination_project_dataset_table=f"{DATASET_NAME}.{safe_name(SOURCE_CUSTOMER_TABLE)}", | ||
schema_object=f"{safe_name(SOURCE_CUSTOMER_TABLE)}-schema.json", | ||
) | ||
|
||
# [START howto_operator_read_data_from_gcs_many_chunks] | ||
read_data_from_gcs_many_chunks = BigQueryExecuteQueryOperator( | ||
task_id="read_data_from_gcs_many_chunks", | ||
sql=f"SELECT COUNT(*) FROM `{GCP_PROJECT_ID}.{DATASET_NAME}.{safe_name(SOURCE_CUSTOMER_TABLE)}`", | ||
use_legacy_sql=False, | ||
) | ||
# [END howto_operator_read_data_from_gcs_many_chunks] | ||
|
||
# [START howto_operator_trino_to_gcs_csv] | ||
trino_to_gcs_csv = TrinoToGCSOperator( | ||
task_id="trino_to_gcs_csv", | ||
sql=f"select * from {SOURCE_MULTIPLE_TYPES}", | ||
bucket=GCS_BUCKET, | ||
filename=f"{safe_name(SOURCE_MULTIPLE_TYPES)}.{{}}.csv", | ||
schema_filename=f"{safe_name(SOURCE_MULTIPLE_TYPES)}-schema.json", | ||
export_format="csv", | ||
) | ||
# [END howto_operator_trino_to_gcs_csv] | ||
|
||
create_dataset >> trino_to_gcs_basic | ||
create_dataset >> trino_to_gcs_multiple_types | ||
create_dataset >> trino_to_gcs_many_chunks | ||
create_dataset >> trino_to_gcs_csv | ||
|
||
trino_to_gcs_multiple_types >> create_external_table_multiple_types >> read_data_from_gcs_multiple_types | ||
trino_to_gcs_many_chunks >> create_external_table_many_chunks >> read_data_from_gcs_many_chunks | ||
|
||
trino_to_gcs_basic >> delete_dataset | ||
trino_to_gcs_csv >> delete_dataset | ||
read_data_from_gcs_multiple_types >> delete_dataset | ||
read_data_from_gcs_many_chunks >> delete_dataset |
Oops, something went wrong.