Skip to content

Commit

Permalink
Adds 'Trino' provider (with lower memory footprint for tests) (#15187)
Browse files Browse the repository at this point in the history
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 #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: #14281
  • Loading branch information
potiuk committed Apr 6, 2021
1 parent bc5ced3 commit eae22ce
Show file tree
Hide file tree
Showing 49 changed files with 1,901 additions and 96 deletions.
2 changes: 1 addition & 1 deletion BREEZE.rst
Expand Up @@ -2444,7 +2444,7 @@ This is the current syntax for `./breeze <./breeze>`_:
start all integrations. Selected integrations are not saved for future execution.
One of:
cassandra kerberos mongo openldap pinot presto rabbitmq redis statsd all
cassandra kerberos mongo openldap pinot rabbitmq redis statsd trino all
--init-script INIT_SCRIPT_FILE
Initialization script name - Sourced from files/airflow-breeze-config. Default value
Expand Down
8 changes: 4 additions & 4 deletions CONTRIBUTING.rst
Expand Up @@ -594,7 +594,7 @@ github_enterprise, google, google_auth, grpc, hashicorp, hdfs, hive, http, imap,
jira, kerberos, kubernetes, ldap, microsoft.azure, microsoft.mssql, microsoft.winrm, mongo, mssql,
mysql, neo4j, odbc, openfaas, opsgenie, oracle, pagerduty, papermill, password, pinot, plexus,
postgres, presto, qds, qubole, rabbitmq, redis, s3, salesforce, samba, segment, sendgrid, sentry,
sftp, singularity, slack, snowflake, spark, sqlite, ssh, statsd, tableau, telegram, vertica,
sftp, singularity, slack, snowflake, spark, sqlite, ssh, statsd, tableau, telegram, trino, vertica,
virtualenv, webhdfs, winrm, yandex, zendesk

.. END EXTRAS HERE
Expand Down Expand Up @@ -661,11 +661,11 @@ apache.hive amazon,microsoft.mssql,mysql,presto,samba,vertica
apache.livy http
dingding http
discord http
google amazon,apache.beam,apache.cassandra,cncf.kubernetes,facebook,microsoft.azure,microsoft.mssql,mysql,oracle,postgres,presto,salesforce,sftp,ssh
google amazon,apache.beam,apache.cassandra,cncf.kubernetes,facebook,microsoft.azure,microsoft.mssql,mysql,oracle,postgres,presto,salesforce,sftp,ssh,trino
hashicorp google
microsoft.azure google,oracle
microsoft.mssql odbc
mysql amazon,presto,vertica
mysql amazon,presto,trino,vertica
opsgenie http
postgres amazon
salesforce tableau
Expand Down Expand Up @@ -756,7 +756,7 @@ providers.
not only "green path"

* Integration tests where 'local' integration with a component is possible (for example tests with
MySQL/Postgres DB/Presto/Kerberos all have integration tests which run with real, dockerised components
MySQL/Postgres DB/Trino/Kerberos all have integration tests which run with real, dockerized components

* System Tests which provide end-to-end testing, usually testing together several operators, sensors,
transfers connecting to a real external system
Expand Down
4 changes: 2 additions & 2 deletions IMAGES.rst
Expand Up @@ -116,7 +116,7 @@ parameter to Breeze:

.. code-block:: bash
./breeze build-image --python 3.7 --additional-extras=presto \
./breeze build-image --python 3.7 --additional-extras=trino \
--production-image --install-airflow-version=2.0.0
Expand Down Expand Up @@ -163,7 +163,7 @@ You can also skip installing airflow and install it from locally provided files

.. code-block:: bash
./breeze build-image --python 3.7 --additional-extras=presto \
./breeze build-image --python 3.7 --additional-extras=trino \
--production-image --disable-pypi-when-building --install-from-local-files-when-building
In this case you airflow and all packages (.whl files) should be placed in ``docker-context-files`` folder.
Expand Down
2 changes: 1 addition & 1 deletion INSTALL
Expand Up @@ -106,7 +106,7 @@ github_enterprise, google, google_auth, grpc, hashicorp, hdfs, hive, http, imap,
jira, kerberos, kubernetes, ldap, microsoft.azure, microsoft.mssql, microsoft.winrm, mongo, mssql,
mysql, neo4j, odbc, openfaas, opsgenie, oracle, pagerduty, papermill, password, pinot, plexus,
postgres, presto, qds, qubole, rabbitmq, redis, s3, salesforce, samba, segment, sendgrid, sentry,
sftp, singularity, slack, snowflake, spark, sqlite, ssh, statsd, tableau, telegram, vertica,
sftp, singularity, slack, snowflake, spark, sqlite, ssh, statsd, tableau, telegram, trino, vertica,
virtualenv, webhdfs, winrm, yandex, zendesk

# END EXTRAS HERE
Expand Down
4 changes: 2 additions & 2 deletions TESTING.rst
Expand Up @@ -281,12 +281,12 @@ The following integrations are available:
- Integration required for OpenLDAP hooks
* - pinot
- Integration required for Apache Pinot hooks
* - presto
- Integration required for Presto hooks
* - rabbitmq
- Integration required for Celery executor tests
* - redis
- Integration required for Celery executor tests
* - trino
- Integration required for Trino hooks

To start the ``mongo`` integration only, enter:

Expand Down
4 changes: 3 additions & 1 deletion airflow/providers/dependencies.json
Expand Up @@ -50,7 +50,8 @@
"presto",
"salesforce",
"sftp",
"ssh"
"ssh",
"trino"
],
"hashicorp": [
"google"
Expand All @@ -65,6 +66,7 @@
"mysql": [
"amazon",
"presto",
"trino",
"vertica"
],
"opsgenie": [
Expand Down
150 changes: 150 additions & 0 deletions airflow/providers/google/cloud/example_dags/example_trino_to_gcs.py
@@ -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

0 comments on commit eae22ce

Please sign in to comment.