Tailer Documentation
  • What is Tailer Platform?
  • Getting Started
    • Prepare your local environment for Tailer
    • Install Tailer SDK
    • Set up Google Cloud Platform
    • Encrypt your credentials
  • [Tutorial] Create a first data pipeline
    • Introduction
    • Prepare the demonstration environment
    • Copy files from one bucket to another
    • Load files into BigQuery tables
    • Prepare data
    • Build predictions
    • Export data
    • Congratulations!
    • [Video] Automatic Script
      • SQL script file
      • DDL script file
      • Tables to Tables script file
      • Launch configuration and furthermore
  • Data Pipeline Operations
    • Overview
    • Set constants with Context
      • Context configuration file
    • Move files with Storage to Storage
      • Storage to Storage configuration file
    • Load data with Storage to Tables
      • Storage to Tables configuration file
      • Storage to Tables DDL files
    • Stream incoming data with API To Storage
      • API To Storage configuration file
      • API To Storage usage examples
    • Transform data with Tables to Tables
      • Tables to Tables configuration file
      • Table to Table SQL and DDL files
    • Export data with Tables to Storage
      • [V3] Table to Storage configuration file
      • Table to Storage SQL file
      • [V1-V2: deprecated] Table to Storage configuration file
    • Orchestrate processings with Workflow
      • [V2] Workflow configuration file
      • [V1: deprecated] Workflow configuration file
    • Convert XML to CSV
      • Convert XML to CSV configuration file
    • Use advanced features with VM Launcher
      • Process code with VM Launcher
        • VM Launcher configuration file for code processing
      • Encrypt/Decrypt data with VM Launcher
        • VM Launcher configuration file for data encryption
        • VM Launcher configuration file for data decryption
    • Monitoring and Alerting
      • Monitoring and alerting parameters
    • Asserting Data quality with Expectations
      • List of Expectations
    • Modify files with File Utilities
      • Encrypt/Decrypt data with File Utilities
        • Configuration file for data encryption
        • Configuration file for data decryption
    • Transfer data with GBQ to Firestore
      • Table to Storage: configuration file
      • Table to Storage: SQL file
      • VM Launcher: configuration file
      • File-to-firestore python file
  • Tailer Studio
    • Overview
    • Check data operations' details
    • Monitor data operations' status
    • Execute data operations
    • Reset Workflow data operations
    • Archive data operations
    • Add notes to data operations and runs
    • View your data catalog
    • Time your data with freshness
  • Tailer API
    • Overview
    • Getting started
    • API features
  • Release Notes
    • Tailer SDK Stable Releases
    • Tailer Beta Releases
      • Beta features
      • Beta configuration
      • Tailer SDK API
    • Tailer Status
Powered by GitBook
On this page
  • Overview
  • SQL tasks
  • SQL script video

Was this helpful?

Edit on GitHub
  1. [Tutorial] Create a first data pipeline
  2. [Video] Automatic Script

SQL script file

Learn how to create the SQL file corresponding to the workflow tasks of a Table to Table data operation.

Previous[Video] Automatic ScriptNextDDL script file

Last updated 2 years ago

Was this helpful?

Overview

A SQL workflow is a sequence of tasks that feed tables in parallel or sequentially. It gives instructions to load, merge and reorganize data.

SQL tasks

SQL tasks are steps from the workflow. Each SQL task is defined by a .sql file that contains the query. You can write the queries directly in the query editor of and then save them into .sql files.

There can be only one SQL query for each task. If a table needs several SQL queries to be well loaded, you need to execute a task for each of them.

The name of the SQL file should be the same as the SQL task.

SQL script video

From the sales, we will retrieve the weekly sales for each store for each category of alcohol sold and calculate the sales ratio as Pwisky + Prum + ... + Pspecial = Ptotal = 1.

#standardSQL
with week_categories as (
    select
        store_number,
        store_name,
        sale__dollars_ as sale_dollars,
        volume_sold__liters_ as volume_sold_liters,
        DATE_TRUNC(date, WEEK(monday)) as isoweek_monday,
        EXTRACT(isoweek from date) as isoweek_number,
        case when(LOWER(category_name) like '%vodka%') then 'vodka'
            when(LOWER(category_name) like '%whiskies%') then 'whisky'
            when(LOWER(category_name) like '%scotch%') then 'whisky'
            when(LOWER(category_name) like '%bourbon%') then 'whisky'
            when(LOWER(category_name) like '%rum%') then 'rum'
            when(LOWER(category_name) like '%liqueur%') then 'liqueur'
            when(LOWER(category_name) like '%triple sec%') then 'liqueur'
            when(LOWER(category_name) like '%tequila%') then 'tequila'
            when(LOWER(category_name) like '%schnapps%') then 'schnapps'
            when(LOWER(category_name) like '%gin%') then 'gin'
            when(LOWER(category_name) like '%cocktails%') then 'cocktail'
            when(LOWER(category_name) like '%brandies%') then 'brandy'
            when(LOWER(category_name) like '%mezcal%') then 'brandy'
            when(LOWER(category_name) like '%spirit%') then 'spirit'
            when(LOWER(category_name) like '%special%') then 'special_packages'
            else 'others' end as cat_alcool
    from `fd-io-jarvis-demo-dlk.dlk_demo_iowa_liquor_psa.sales_details_2019`
    where date >= '2019-01-01' and date < '2020-01-01'
)

select
    isoweek_monday,
    isoweek_number,
    store_name,
    CAST(store_number as string) as store_number,
    ROUND(SUM(sale_dollars), 2) as sale_dollars,
    ROUND(SUM(volume_sold_liters), 2) as volume_sold_liters,
    ROUND(
        SUM(
            case when(cat_alcool = 'vodka') then sale_dollars else 0 end
        ) / SUM(sale_dollars),
        2
    ) as p_vodka,
    ROUND(
        SUM(
            case when(cat_alcool = 'whisky') then sale_dollars else 0 end
        ) / SUM(sale_dollars),
        2
    ) as p_whisky,
    ROUND(
        SUM(
            case when(cat_alcool = 'rum') then sale_dollars else 0 end
        ) / SUM(sale_dollars),
        2
    ) as p_rum,
    ROUND(
        SUM(
            case when(cat_alcool = 'liqueur') then sale_dollars else 0 end
        ) / SUM(sale_dollars),
        2
    ) as p_liqueur,
    ROUND(
        SUM(
            case when(cat_alcool = 'tequila') then sale_dollars else 0 end
        ) / SUM(sale_dollars),
        2
    ) as p_tequila,
    ROUND(
        SUM(
            case when(cat_alcool = 'schnapps') then sale_dollars else 0 end
        ) / SUM(sale_dollars),
        2
    ) as p_schnapps,
    ROUND(
        SUM(
            case when(cat_alcool = 'gin') then sale_dollars else 0 end
        ) / SUM(sale_dollars),
        2
    ) as p_gin,
    ROUND(
        SUM(
            case when(cat_alcool = 'cocktail') then sale_dollars else 0 end
        ) / SUM(sale_dollars),
        2
    ) as p_cocktail,
    ROUND(
        SUM(
            case when(cat_alcool = 'brandy') then sale_dollars else 0 end
        ) / SUM(sale_dollars),
        2
    ) as p_brandy,
    ROUND(
        SUM(
            case when(cat_alcool = 'spirit') then sale_dollars else 0 end
        ) / SUM(sale_dollars),
        2
    ) as p_spirit,
    ROUND(
        SUM(
            case
                when(cat_alcool = 'special_packages') then sale_dollars else 0
            end
        ) / SUM(sale_dollars),
        2
    ) as p_special
from week_categories
group by store_number, store_name, isoweek_number, isoweek_monday
🗺️
🛢️
📹
BigQuery