This file contains hidden or 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
| default_args = { | |
| 'owner': 'airflow', | |
| 'depends_on_past': False, | |
| 'start_date': airflow.utils.dates.days_ago(2), | |
| # All the parameters below are BigQuery specific and will be available to all the tasks | |
| 'bigquery_conn_id': 'gcp-bigquery-connection', | |
| 'write_disposition': 'WRITE_EMPTY', | |
| 'create_disposition': 'CREATE_IF_NEEDED', | |
| 'labels': {'client': 'client-1'} | |
| } |
This file contains hidden or 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
| # You can pass `params` dict to DAG object | |
| default_args = { | |
| 'owner': 'airflow', | |
| 'depends_on_past': False, | |
| 'start_date': airflow.utils.dates.days_ago(2), | |
| } | |
| dag = DAG( | |
| dag_id='airflow_tutorial_2', | |
| default_args=default_args, |
This file contains hidden or 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
| # Setting task dependencies (the NORMAL way) | |
| task_one >> task_two | |
| task_two >> task_two_1 >> end | |
| task_two >> task_two_2 >> end | |
| task_two >> task_two_3 >> end | |
| # Using Lists (being a PRO :-D ) | |
| task_one >> task_two >> [task_two_1, task_two_2, task_two_3] >> end |
This file contains hidden or 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
| # Normal DAG without Context Manager | |
| args = { | |
| 'owner': 'airflow', | |
| 'start_date': airflow.utils.dates.days_ago(2), | |
| } | |
| dag = DAG( | |
| dag_id='example_dag', | |
| default_args=args, | |
| schedule_interval='0 0 * * *', |
This file contains hidden or 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
| #!/usr/bin/env python | |
| # encoding: utf-8 | |
| from pprint import pformat, pprint | |
| import logging | |
| class PasswordMaskingFilter(logging.Filter): | |
| """Demonstrate how to filter sensitive data:""" |
This file contains hidden or 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
| # airflow/plugins/slack.py | |
| import logging | |
| from airflow.operators.python_operator import PythonOperator | |
| from airflow.plugins_manager import AirflowPlugin | |
| from slackclient import SlackClient | |
| from titan.utils import config | |
This file contains hidden or 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
| # Get all metadata | |
| curl -H Metadata:true "http://169.254.169.254/metadata/instance?api-version=2017-04-02" | |
| # Get all network metadata | |
| curl -H Metadata:true "http://169.254.169.254/metadata/instance/network?api-version=2017-04-02" | |
| # Get public ip only | |
| curl -H Metadata:true "http://169.254.169.254/metadata/instance/network/interface/0/ipv4/ipAddress/0/publicIpAddress?api-version=2017-04-02&format=text" |
This file contains hidden or 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
| # User module to receive tweets | |
| from recevie_tweets_pubsub import receive_tweets | |
| import pandas | |
| from bokeh.io import curdoc | |
| from bokeh.models import ColumnDataSource | |
| from bokeh.models import DatetimeTickFormatter | |
| from bokeh.plotting import figure, output_file | |
| import sys |
This file contains hidden or 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
| def publish(client, pubsub_topic, data_lines): | |
| """Publish to the given pubsub topic.""" | |
| messages = [] | |
| for line in data_lines: | |
| messages.append({'data': line}) | |
| body = {'messages': messages} | |
| str_body = json.dumps(body) | |
| data = base64.urlsafe_b64encode(bytearray(str_body, 'utf8')) | |
| client.publish(topic=pubsub_topic, data=data) |
This file contains hidden or 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
| package ... | |
| import com.google.api.services.bigquery.model.TableFieldSchema; | |
| import com.google.api.services.bigquery.model.TableRow; | |
| import com.google.api.services.bigquery.model.TableSchema; | |
| import com.google.api.services.bigquery.model.TimePartitioning; | |
| import com.google.common.collect.ImmutableList; | |
| import org.apache.beam.sdk.Pipeline; | |
| import org.apache.beam.sdk.coders.Coder; | |
| import org.apache.beam.sdk.io.gcp.bigquery.BigQueryIO; |