Giter Site home page Giter Site logo

mysql_gcp's Introduction

Mysql-to-GCP

An airflow dag that extracts data from Mysql db transforms and loads it to GCP-bigquery.

Accessing the Biquery

Create a gcp account activate biquery service and create IAM account. Extract keys/credentials in form of a json file that will be used to connect to biqguery.

Bigquery is accessed using the google-cloud-bigquery python library.Creating a client and and using given credentials provides connection to bigquery. C

to use bigquery, Create a bigquery service on GCP and acquire the keys.

bigquery dataset

Before loading data in biquery, a create_dataset method is used to create a dataset in bigquery where the tales/data will be stored

source data -classicmodels db

MySql contains a classicmodels db which is a database for a car retail company. From the database we can extract the following.

  • customers who made the most orders
  • products that have the highest number of purchases
  • customers who have spent more this data is then extracted and transformed using pandas.

airflow.hooks.mysql_hook import MySqlHook is used to connect to local db (MySql) fr0m airflow. setting host to host.docker.internal enables access to local db. Connection string/properties should be set in airflow web UI under admin/connections menu

inserting data into biquery

client.load_table_from_dataframe(df,'table_name') is a method used to insert data into biquery tables using dataframes created from queries and tables_names of the target tables in bigquery.

Automating with airflow

This job runs every 20 minutes. The ETL is seperated into 3 tasks creating_dataset >> truncating_tables >> inserting_data which are executed using PythonVirtualenvOperator in airflow

airflow is run in docker. A volume ./data:/opt/airflow/data is added into the docker-compose file to store the classicmodels db and the json file that contains google application credentials

the dag file gcp_dag.py which is the complete dag is contained in the dags folder

mysql_gcp's People

Contributors

james-wachuka avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.