Giter Site home page Giter Site logo

bq-create-scheduled-queries's Introduction

BIGQUERY CREATE SCHEDULED QUERIES

What Is This For?

This program is to create scheduled queries in GCP BigQuery. Commonly, when we create new scheduled query in BigQuery, it will use our personal/work credential/email. Once we left the company and our work credential is deactivated, the task that was created with our credential will stop and return error.

The purpose of this program is automatically create that with credential provided instead of our personal/work credential. This will maintain the scheduled queries we created keep running although our credential is deactivated.

Every run of this program is designed to create scheduled queries with the same schedule.

How it works

What Is In It?

There are 2 python files and 1 folder as a place to store queries.

  • Python files
    • main.py is the main file to run the program.
    • helpers.py is the file that contains a function to create the scheduled queries based on queries provided.
  • Folder for queries
    • scheduled_queries is a folder that is supposed to contain queries that will later create as scheduled queries in BigQuery. This folder can contains as many as query that has extension .sql. Each name of the file later will be the display name of the scheduled queries in BigQuery. The name of the folder can be specified later in .env file.

What Is Required To Setup?

  • You need to set a .env file to provide every configuration needed by the program to run. Below is the variables needed to provide in the file.
    QUERIES_DIR=folder-where-queries-are-stored
    GOOGLE_APPLICATION_CREDENTIALS=your-gcp-credential
    BQ_PROJECT_ID=your-project-id
    BQ_PROJECT_LOCATION=your-project-location-id
    
    QUERIES_DIR currently is set to scheduled_queries.
  • Generate IAM service credential file from GCP that has access to create scheduled query in BigQuery.

How To Run The Program?

I suggest you to use python virtual environment to separate the environment between project. You can find how to create and use it in python documentation page.

After activating virtual environment, please follow below steps.

  1. You need to install all the dependencies required. All dependencies are provided in file requirements.txt. To install this, you can run the command below.
    pip install -r requirements.txt
    
  2. Provide each query you want to make as scheduled queriy in provided folder (in current use case, we use scheduled_queries as folder name). Example as follows. create new table.sql
    CREATE OR REPLACE TABLE dest_dataset.dest_table
    AS
    SELECT *
    FROM source_dataset.source_table;
  3. Run the script by writing below command.
    python main.py [schedule]
    
    Example as follows.
    python main.py "every day 08:00"
    
    This will create all the queries in scheduled_queries as scheduled query in BigQuery with the schedule as every day at 8 o'clock.

bq-create-scheduled-queries's People

Contributors

hidayat9945 avatar

Watchers

 avatar

Forkers

uladotapp

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.