Skip to content

Instantly share code, notes, and snippets.

View Wittline's full-sized avatar
:octocat:
Hi there

Ramses Alexander Coraspe Valdez Wittline

:octocat:
Hi there
View GitHub Profile
insert into {project}.{dataset}.{tabledestination}
(id, category, lastdate)
select id, category, lastdate
from {project}.{dataset}.{tablesource}
WHERE EXTRACT(YEAR FROM lastdate) = {year} and category = '{category}'
insert into {project}.{dataset}.{tablefinal}
(id, category, lastdate)
select id, category, lastdate
from {project}.{dataset}.{table1}
union all
select id, category, lastdate
from {project}.{dataset}.{table2}
@Wittline
Wittline / docker-compose.yaml
Created June 5, 2022 16:11
docker-compose file with "wait-for-it"
version: '3.1'
services:
db:
container_name: pg_container
image: postgres
restart: always
environment:
POSTGRES_USER: "postgres"
POSTGRES_PASSWORD: "pg12345"
# DROP TABLES
users_table_drop = "DROP TABLE IF EXISTS users"
departments_table_drop = "DROP TABLE IF EXISTS departments"
companies_table_drop = "DROP TABLE IF EXISTS companies"
staging_table_drop = "DROP TABLE IF EXISTS staging"
# CREATE TABLES
staging_table_create = ("""
CREATE TABLE IF NOT EXISTS staging(
@Wittline
Wittline / db_engine.py
Created June 5, 2022 16:22
Class Responsible of handle the connection with PostgreSQL
import psycopg2
import pandas as pd
from sql_queries import create_table_queries, drop_table_queries, fill_table_queries, create_constraints
def create_connection(params):
"""
create a new connection with the postgreSQL
database and return the cur and conn object
:param params: connection string
@Wittline
Wittline / main.py
Created June 5, 2022 16:28
FastAPI Request
from typing import Optional
from fastapi import FastAPI
from fastapi.responses import JSONResponse
import uvicorn
import pandas as pd
import psycopg2
import db_engine as dbe
import os
from pydantic import BaseModel
import configparser
FROM python:3.8
WORKDIR /ingestion
COPY requirements.txt .
COPY wait-for-it.sh /usr/wait-for-it.sh
RUN pip install -r requirements.txt
@Wittline
Wittline / Dockerfile
Created June 12, 2022 22:37
Dockerfile for an Apache Livy server
FROM docker.io/bitnami/spark:2
USER root
ENV LIVY_HOME /opt/bitnami/livy
WORKDIR /opt/bitnami/
RUN install_packages unzip \
&& curl "https://downloads.apache.org/incubator/livy/0.7.1-incubating/apache-livy-0.7.1-incubating-bin.zip" -O \
&& unzip "apache-livy-0.7.1-incubating-bin" \
&& rm -rf "apache-livy-0.7.1-incubating-bin.zip" \
@Wittline
Wittline / docker-compose.yaml
Created June 12, 2022 22:44
docker-compose. with Apache Spark Cluster, PostgreSQL and Apache Livy server
version: '3'
services:
spark-master:
image: docker.io/bitnami/spark:2
environment:
- SPARK_MODE=master
- SPARK_RPC_AUTHENTICATION_ENABLED=no
- SPARK_RPC_ENCRYPTION_ENABLED=no
- SPARK_LOCAL_STORAGE_ENCRYPTION_ENABLED=no
@Wittline
Wittline / test_livy.ipynb
Last active June 13, 2022 09:53
test_livy.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.