From 1cf0db2ab0c2220489a1b1fe5ce580e974d8c677 Mon Sep 17 00:00:00 2001 From: Adler Santos Date: Thu, 24 Jun 2021 01:23:58 -0400 Subject: [PATCH 1/6] bls.cpsaat18 YAML config --- datasets/bls/cpsaat18/pipeline.yaml | 80 +++++++++++++++++++++++++++++ datasets/bls/dataset.yaml | 29 +++++++++++ 2 files changed, 109 insertions(+) create mode 100644 datasets/bls/cpsaat18/pipeline.yaml create mode 100644 datasets/bls/dataset.yaml diff --git a/datasets/bls/cpsaat18/pipeline.yaml b/datasets/bls/cpsaat18/pipeline.yaml new file mode 100644 index 000000000..84d21b238 --- /dev/null +++ b/datasets/bls/cpsaat18/pipeline.yaml @@ -0,0 +1,80 @@ +# Copyright 2021 Google LLC +# +# Licensed 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. + +--- +resources: + - type: bigquery_table + table_id: cpsaat18 + description: "Current population survey 18: Employed persons by detailed industry, sex, race, and Hispanic or Latino ethnicity" + +dag: + initialize: + dag_id: cpsaat18 + default_args: + owner: "Google" + depends_on_past: False + start_date: '2021-06-23' + max_active_runs: 1 + schedule_interval: "@once" + catchup: False + default_view: graph + + tasks: + - operator: "GoogleCloudStorageToBigQueryOperator" + description: "Task to load the CPSAAT18 data to the BigQuery table" + args: + task_id: "load_csv_to_bq" + bucket: "{{ var.json.bls.source_bucket }}" + source_objects: ["cpsaat18/2020.csv"] + source_format: "CSV" + destination_project_dataset_table: "bls.cpsaat18" + skip_leading_rows: 1 + write_disposition: "WRITE_TRUNCATE" + schema_fields: + - name: "year" + type: "integer" + nullable: false + - name: "sector" + type: "string" + nullable: false + - name: "subsector" + type: "string" + nullable: true + - name: "industry_group" + type: "string" + nullable: true + - name: "industry" + type: "string" + nullable: true + - name: "total_employed_in_thousands" + type: "integer" + nullable: true + - name: "percent_women" + type: "float" + nullable: true + - name: "percent_white" + type: "float" + nullable: true + - name: "percent_black_or_african_american" + type: "float" + nullable: true + - name: "percent_asian" + type: "float" + nullable: true + - name: "percent_hispanic_or_latino" + type: "float" + nullable: true + + graph_paths: + - "load_csv_to_bq" diff --git a/datasets/bls/dataset.yaml b/datasets/bls/dataset.yaml new file mode 100644 index 000000000..01b10282e --- /dev/null +++ b/datasets/bls/dataset.yaml @@ -0,0 +1,29 @@ +# Copyright 2021 Google LLC +# +# Licensed 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. + +dataset: + name: bls + friendly_name: ~ + description: ~ + dataset_sources: ~ + terms_of_use: ~ + + +resources: + - type: bigquery_dataset + dataset_id: bls + description: "Overview: This dataset includes economic statistics on inflation, prices, unemployment, and pay & benefits provided by the Bureau of Labor Statistics (BLS).\n\nUpdate frequency: Monthly\n\nDataset source: U.S. Bureau of Labor Statistics\n\nTerms of use: This dataset is publicly available for anyone to use under the following terms provided by the Dataset Source - http://www.data.gov/privacy-policy#data_policy - and is provided \"AS IS\" without any warranty, express or implied, from Google. Google disclaims all liability for any damages, direct or indirect, resulting from the use of the dataset.\n\nSee the GCP Marketplace listing for more details and sample queries: https://console.cloud.google.com/marketplace/details/bls-public-data/bureau-of-labor-statistics" + + - type: storage_bucket + name: bls From fe2a30100cbbef3ffa00ee5100076fb495b5eb31 Mon Sep 17 00:00:00 2001 From: Adler Santos Date: Thu, 24 Jun 2021 01:24:37 -0400 Subject: [PATCH 2/6] generate terraform files --- datasets/bls/_terraform/bls_dataset.tf | 35 +++++++++++++++++++ datasets/bls/_terraform/cpsaat18_pipeline.tf | 36 ++++++++++++++++++++ datasets/bls/_terraform/provider.tf | 28 +++++++++++++++ datasets/bls/_terraform/variables.tf | 23 +++++++++++++ 4 files changed, 122 insertions(+) create mode 100644 datasets/bls/_terraform/bls_dataset.tf create mode 100644 datasets/bls/_terraform/cpsaat18_pipeline.tf create mode 100644 datasets/bls/_terraform/provider.tf create mode 100644 datasets/bls/_terraform/variables.tf diff --git a/datasets/bls/_terraform/bls_dataset.tf b/datasets/bls/_terraform/bls_dataset.tf new file mode 100644 index 000000000..aa67382d2 --- /dev/null +++ b/datasets/bls/_terraform/bls_dataset.tf @@ -0,0 +1,35 @@ +/** + * Copyright 2021 Google LLC + * + * Licensed 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. + */ + + +resource "google_bigquery_dataset" "bls" { + dataset_id = "bls" + project = var.project_id + description = "Overview: This dataset includes economic statistics on inflation, prices, unemployment, and pay \u0026 benefits provided by the Bureau of Labor Statistics (BLS).\n\nUpdate frequency: Monthly\n\nDataset source: U.S. Bureau of Labor Statistics\n\nTerms of use: This dataset is publicly available for anyone to use under the following terms provided by the Dataset Source -\u00a0http://www.data.gov/privacy-policy#data_policy\u00a0- and is provided \"AS IS\" without any warranty, express or implied, from Google. Google disclaims all liability for any damages, direct or indirect, resulting from the use of the dataset.\n\nSee the GCP Marketplace listing for more details and sample queries: https://console.cloud.google.com/marketplace/details/bls-public-data/bureau-of-labor-statistics" +} + +output "bigquery_dataset-bls-dataset_id" { + value = google_bigquery_dataset.bls.dataset_id +} + +resource "google_storage_bucket" "bls" { + name = "${var.bucket_name_prefix}-bls" + force_destroy = true +} + +output "storage_bucket-bls-name" { + value = google_storage_bucket.bls.name +} diff --git a/datasets/bls/_terraform/cpsaat18_pipeline.tf b/datasets/bls/_terraform/cpsaat18_pipeline.tf new file mode 100644 index 000000000..ee26b2c32 --- /dev/null +++ b/datasets/bls/_terraform/cpsaat18_pipeline.tf @@ -0,0 +1,36 @@ +/** + * Copyright 2021 Google LLC + * + * Licensed 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. + */ + + +resource "google_bigquery_table" "cpsaat18" { + project = var.project_id + dataset_id = "bls" + table_id = "cpsaat18" + + description = "Current population survey 18: Employed persons by detailed industry, sex, race, and Hispanic or Latino ethnicity" + + depends_on = [ + google_bigquery_dataset.bls + ] +} + +output "bigquery_table-cpsaat18-table_id" { + value = google_bigquery_table.cpsaat18.table_id +} + +output "bigquery_table-cpsaat18-id" { + value = google_bigquery_table.cpsaat18.id +} diff --git a/datasets/bls/_terraform/provider.tf b/datasets/bls/_terraform/provider.tf new file mode 100644 index 000000000..23ab87dcd --- /dev/null +++ b/datasets/bls/_terraform/provider.tf @@ -0,0 +1,28 @@ +/** + * Copyright 2021 Google LLC + * + * Licensed 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. + */ + + +provider "google" { + project = var.project_id + impersonate_service_account = var.impersonating_acct + region = var.region +} + +data "google_client_openid_userinfo" "me" {} + +output "impersonating-account" { + value = data.google_client_openid_userinfo.me.email +} diff --git a/datasets/bls/_terraform/variables.tf b/datasets/bls/_terraform/variables.tf new file mode 100644 index 000000000..c3ec7c506 --- /dev/null +++ b/datasets/bls/_terraform/variables.tf @@ -0,0 +1,23 @@ +/** + * Copyright 2021 Google LLC + * + * Licensed 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. + */ + + +variable "project_id" {} +variable "bucket_name_prefix" {} +variable "impersonating_acct" {} +variable "region" {} +variable "env" {} + From 52914e2505c2f26e0bbf20df3dc90353d859c049 Mon Sep 17 00:00:00 2001 From: Adler Santos Date: Thu, 24 Jun 2021 01:24:47 -0400 Subject: [PATCH 3/6] generate DAG --- datasets/bls/cpsaat18/cpsaat18_dag.py | 67 +++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 datasets/bls/cpsaat18/cpsaat18_dag.py diff --git a/datasets/bls/cpsaat18/cpsaat18_dag.py b/datasets/bls/cpsaat18/cpsaat18_dag.py new file mode 100644 index 000000000..e1f0c517c --- /dev/null +++ b/datasets/bls/cpsaat18/cpsaat18_dag.py @@ -0,0 +1,67 @@ +# Copyright 2021 Google LLC +# +# Licensed 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 airflow import DAG +from airflow.contrib.operators import gcs_to_bq + +default_args = { + "owner": "Google", + "depends_on_past": False, + "start_date": "2021-06-23", +} + + +with DAG( + dag_id="bls.cpsaat18", + default_args=default_args, + max_active_runs=1, + schedule_interval="@once", + catchup=False, + default_view="graph", +) as dag: + + # Task to load the CPSAAT18 data to the BigQuery table + load_csv_to_bq = gcs_to_bq.GoogleCloudStorageToBigQueryOperator( + task_id="load_csv_to_bq", + bucket="{{ var.json.bls.source_bucket }}", + source_objects=["cpsaat18/2020.csv"], + source_format="CSV", + destination_project_dataset_table="bls.cpsaat18", + skip_leading_rows=1, + write_disposition="WRITE_TRUNCATE", + schema_fields=[ + {"name": "year", "type": "integer", "nullable": False}, + {"name": "sector", "type": "string", "nullable": False}, + {"name": "subsector", "type": "string", "nullable": True}, + {"name": "industry_group", "type": "string", "nullable": True}, + {"name": "industry", "type": "string", "nullable": True}, + { + "name": "total_employed_in_thousands", + "type": "integer", + "nullable": True, + }, + {"name": "percent_women", "type": "float", "nullable": True}, + {"name": "percent_white", "type": "float", "nullable": True}, + { + "name": "percent_black_or_african_american", + "type": "float", + "nullable": True, + }, + {"name": "percent_asian", "type": "float", "nullable": True}, + {"name": "percent_hispanic_or_latino", "type": "float", "nullable": True}, + ], + ) + + load_csv_to_bq From f309da6258cd7e63fc28f877dd86d9547ff68128 Mon Sep 17 00:00:00 2001 From: Adler Santos Date: Thu, 24 Jun 2021 16:59:05 -0400 Subject: [PATCH 4/6] set schedule to yearly --- datasets/bls/cpsaat18/cpsaat18_dag.py | 2 +- datasets/bls/cpsaat18/pipeline.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/datasets/bls/cpsaat18/cpsaat18_dag.py b/datasets/bls/cpsaat18/cpsaat18_dag.py index e1f0c517c..05a10932d 100644 --- a/datasets/bls/cpsaat18/cpsaat18_dag.py +++ b/datasets/bls/cpsaat18/cpsaat18_dag.py @@ -27,7 +27,7 @@ dag_id="bls.cpsaat18", default_args=default_args, max_active_runs=1, - schedule_interval="@once", + schedule_interval="@yearly", catchup=False, default_view="graph", ) as dag: diff --git a/datasets/bls/cpsaat18/pipeline.yaml b/datasets/bls/cpsaat18/pipeline.yaml index 84d21b238..e932b064e 100644 --- a/datasets/bls/cpsaat18/pipeline.yaml +++ b/datasets/bls/cpsaat18/pipeline.yaml @@ -26,7 +26,7 @@ dag: depends_on_past: False start_date: '2021-06-23' max_active_runs: 1 - schedule_interval: "@once" + schedule_interval: "@yearly" catchup: False default_view: graph From 3c831773137fe7281fc3a1a91c98b2690091d272 Mon Sep 17 00:00:00 2001 From: Adler Santos Date: Thu, 24 Jun 2021 16:59:26 -0400 Subject: [PATCH 5/6] set source_objects to match all CSV files --- datasets/bls/cpsaat18/cpsaat18_dag.py | 2 +- datasets/bls/cpsaat18/pipeline.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/datasets/bls/cpsaat18/cpsaat18_dag.py b/datasets/bls/cpsaat18/cpsaat18_dag.py index 05a10932d..3a655fa7d 100644 --- a/datasets/bls/cpsaat18/cpsaat18_dag.py +++ b/datasets/bls/cpsaat18/cpsaat18_dag.py @@ -36,7 +36,7 @@ load_csv_to_bq = gcs_to_bq.GoogleCloudStorageToBigQueryOperator( task_id="load_csv_to_bq", bucket="{{ var.json.bls.source_bucket }}", - source_objects=["cpsaat18/2020.csv"], + source_objects=["cpsaat18/*.csv"], source_format="CSV", destination_project_dataset_table="bls.cpsaat18", skip_leading_rows=1, diff --git a/datasets/bls/cpsaat18/pipeline.yaml b/datasets/bls/cpsaat18/pipeline.yaml index e932b064e..918756048 100644 --- a/datasets/bls/cpsaat18/pipeline.yaml +++ b/datasets/bls/cpsaat18/pipeline.yaml @@ -36,7 +36,7 @@ dag: args: task_id: "load_csv_to_bq" bucket: "{{ var.json.bls.source_bucket }}" - source_objects: ["cpsaat18/2020.csv"] + source_objects: ["cpsaat18/*.csv"] source_format: "CSV" destination_project_dataset_table: "bls.cpsaat18" skip_leading_rows: 1 From e0b82a4013fe2d48dd83a5ec6728395307bb8f3d Mon Sep 17 00:00:00 2001 From: Adler Santos Date: Thu, 24 Jun 2021 17:27:13 -0400 Subject: [PATCH 6/6] use multiline YAML block for BLS dataset description --- datasets/bls/dataset.yaml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/datasets/bls/dataset.yaml b/datasets/bls/dataset.yaml index 01b10282e..c2326d5b1 100644 --- a/datasets/bls/dataset.yaml +++ b/datasets/bls/dataset.yaml @@ -23,7 +23,15 @@ dataset: resources: - type: bigquery_dataset dataset_id: bls - description: "Overview: This dataset includes economic statistics on inflation, prices, unemployment, and pay & benefits provided by the Bureau of Labor Statistics (BLS).\n\nUpdate frequency: Monthly\n\nDataset source: U.S. Bureau of Labor Statistics\n\nTerms of use: This dataset is publicly available for anyone to use under the following terms provided by the Dataset Source - http://www.data.gov/privacy-policy#data_policy - and is provided \"AS IS\" without any warranty, express or implied, from Google. Google disclaims all liability for any damages, direct or indirect, resulting from the use of the dataset.\n\nSee the GCP Marketplace listing for more details and sample queries: https://console.cloud.google.com/marketplace/details/bls-public-data/bureau-of-labor-statistics" + description: |- + Overview: This dataset includes economic statistics on inflation, prices, unemployment, and pay & benefits provided by the Bureau of Labor Statistics (BLS). + Update frequency: Monthly + + Dataset source: U.S. Bureau of Labor Statistics + + Terms of use: This dataset is publicly available for anyone to use under the following terms provided by the Dataset Source - http://www.data.gov/privacy-policy#data_policy - and is provided "AS IS" without any warranty, express or implied, from Google. Google disclaims all liability for any damages, direct or indirect, resulting from the use of the dataset. + + See the GCP Marketplace listing for more details and sample queries: https://console.cloud.google.com/marketplace/details/bls-public-data/bureau-of-labor-statistics - type: storage_bucket name: bls