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
| export RESOURCE_GROUP=demo-k8s-rg | |
| export CLUSTER_NAME=my-k8s-cluster | |
| az group create --name=${RESOURCE_GROUP} --location eastus | |
| az aks create -g ${RESOURCE_GROUP} -n ${CLUSTER_NAME} --enable-managed-identity --enable-pod-identity --network-plugin azure --enable-addons monitoring --node-count 1 --generate-ssh-keys |
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
| t_export_bq_to_s3 >> check_s3_for_key >> t_check_dataset_group | |
| t_check_dataset_group >> t_init_personalize | |
| t_check_dataset_group >> t_skip_init_personalize >> t_init_personalize_done | |
| t_init_personalize >> [ | |
| t_create_dataset_group, | |
| t_create_schema, | |
| t_put_bucket_policies, | |
| t_create_iam_role | |
| ] >> t_create_dataset_type | |
| t_create_dataset_type >> t_init_personalize_done |
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': days_ago(1), | |
| 'email': ['yi.ai@afox.mobi'], | |
| 'email_on_failure': False, | |
| 'email_on_retry': False, | |
| 'retries': 1, | |
| 'retry_delay': timedelta(minutes=5), | |
| } |
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
| BQ_SQL = """ | |
| SELECT REGEXP_EXTRACT(USER_ID, r'(\d+)\.') AS USER_ID, UNIX_SECONDS(EVENT_DATE) AS TIMESTAMP, REGEXP_EXTRACT(page_location,r'product/([^?&#]*)') as ITEM_ID, LOCATION, DEVICE, EVENT_NAME AS EVENT_TYPE | |
| FROM | |
| ( | |
| SELECT user_pseudo_id AS USER_ID, (SELECT value.string_value FROM UNNEST(event_params) | |
| WHERE key = "page_location") as page_location, TIMESTAMP_TRUNC(TIMESTAMP_MICROS(event_timestamp), | |
| MINUTE) AS EVENT_DATE, device.category AS DEVICE, geo.country AS LOCATION, event_name AS EVENT_NAME | |
| FROM `lively-metrics-295911.analytics_254171871.events_intraday_*` | |
| WHERE | |
| _TABLE_SUFFIX = FORMAT_DATE('%Y%m%d', DATE_SUB(CURRENT_DATE(), INTERVAL 1 DAY)) |
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 create_dataset_group(**kwargs): | |
| create_dg_response = personalize.create_dataset_group( | |
| name=DATASET_GROUP_NAME | |
| ) | |
| dataset_group_arn = create_dg_response["datasetGroupArn"] | |
| status = None | |
| max_time = time.time() + 2*60*60 # 2 hours | |
| while time.time() < max_time: | |
| describe_dataset_group_response = personalize.describe_dataset_group( |
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 bq_to_s3(): | |
| s3 = boto3.resource('s3') | |
| logger.info( | |
| "Download google bigquery and google client dependencies from S3") | |
| s3.Bucket(BUCKET_NAME).download_file(LIB_KEY, '/tmp/site-packages.zip') | |
| with zipfile.ZipFile('/tmp/site-packages.zip', 'r') as zip_ref: | |
| zip_ref.extractall('/tmp/python3.7/site-packages') | |
| sys.path.insert(1, "/tmp/python3.7/site-packages/site-packages/") |
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
| s3 = boto3.resource('s3') | |
| logger.info( | |
| "Download google bigquery and google client dependencies from S3") | |
| s3.Bucket(BUCKET_NAME).download_file(LIB_KEY, '/tmp/site-packages.zip') | |
| with zipfile.ZipFile('/tmp/site-packages.zip', 'r') as zip_ref: | |
| zip_ref.extractall('/tmp/python3.7/site-packages') | |
| sys.path.insert(1, "/tmp/python3.7/site-packages/site-packages/") |
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
| cachetools==4.2.0 | |
| certifi==2020.12.5 | |
| cffi==1.14.4 | |
| chardet==3.0.4 | |
| google-api-core==1.24.0 | |
| google-auth==1.24.0 | |
| google-auth-oauthlib==0.4.2 | |
| google-cloud-bigquery==2.6.1 | |
| google-cloud-bigquery-storage==2.1.0 | |
| google-cloud-core==1.5.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
| #!/bin/bash | |
| virtualenv -p python3.7 venv | |
| source venv/bin/activate | |
| pip install -r requirements.txt | |
| cd venv/lib/python3.7 |
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
| { | |
| "Version": "2012-10-17", | |
| "Id": "AirflowPersonalizePolicy", | |
| "Statement": [ | |
| { | |
| "Sid": "PersonalizeAccessPolicy", | |
| "Effect": "Allow", | |
| "Action": [ | |
| "personalize:*" | |
| ], |