Skip to content

Commit

Permalink
feat: Onboard BLS - CPSAAT 2020 dataset (#105)
Browse files Browse the repository at this point in the history
* bls.cpsaat18 YAML config

* generate terraform files

* generate DAG

* set schedule to yearly

* set source_objects to match all CSV files

* use multiline YAML block for BLS dataset description
  • Loading branch information
adlersantos committed Jun 24, 2021
1 parent ef01fe6 commit 61f4394
Show file tree
Hide file tree
Showing 7 changed files with 306 additions and 0 deletions.
35 changes: 35 additions & 0 deletions 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
}
36 changes: 36 additions & 0 deletions 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
}
28 changes: 28 additions & 0 deletions 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
}
23 changes: 23 additions & 0 deletions 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" {}

67 changes: 67 additions & 0 deletions 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="@yearly",
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/*.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
80 changes: 80 additions & 0 deletions 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: "@yearly"
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/*.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"
37 changes: 37 additions & 0 deletions datasets/bls/dataset.yaml
@@ -0,0 +1,37 @@
# 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).
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

0 comments on commit 61f4394

Please sign in to comment.