Skip to content

Instantly share code, notes, and snippets.

View pelaospeed's full-sized avatar

Esteban Andres Araya Jiménez "pelaospeed" pelaospeed

  • Santiago, Chile
View GitHub Profile
@pelaospeed
pelaospeed / import-sql.sql
Created May 7, 2022 22:19 — forked from William9923/import-sql.sql
Gist for importing data from csv into PostgreSQL
COPY live.order (order_id, user_name, order_status, order_date, order_approved_date, pickup_date, delivered_date, estimated_time_delivery)
FROM 'C:\Users\William\Documents\DataScience\blibli\e-commerce-datsci-proj\data\raw\order_dataset.csv'
DELIMITER ','
CSV HEADER;
-- and so on
select user_name , customer_zip_code , customer_city , customer_state
from (
SELECT
DISTINCT *,
RANK() over(
PARTITION BY user_name
ORDER BY customer_zip_code DESC, customer_state DESC , customer_city DESC
) as rank
FROM
live.user u
insert into staging.dim_product (
product_id,
product_category,
product_name_length,
product_description_length,
product_photos_qty,
product_weight_g,
product_length_cm,
product_height_cm,
product_width_cm,
-- Notes : Inserting updated data on product dimenstion table
insert into staging.dim_product (
product_id,
product_category,
product_name_length,
product_description_length,
product_photos_qty,
product_weight_g,
product_length_cm,
product_height_cm,
-- Fact table
with stg_snapshot_user as (
select distinct
user_name,
count(order_id) as num_order
from live."order"
where order_status is not null and order_status not in ('canceled', 'unavailable')
group by user_name
), stg_snapshot_spending as (
select distinct
"""
Code that goes along with the Airflow tutorial located at:
https://github.com/airbnb/airflow/blob/master/airflow/example_dags/tutorial.py
"""
from airflow import DAG
from airflow.operators.python_operator import PythonOperator
from airflow.operators.generic_transfer import GenericTransfer
from airflow.contrib.hooks import FTPHook
from airflow.hooks.mysql_hook import MySqlHook