feat(connector): handle undefined database

feat(connector): fixed typo
This commit is contained in:
Taha Yassine Kraiem 2022-04-25 10:40:15 +02:00
parent 39fa397bc5
commit f30849d7b5

View file

@ -1,4 +1,5 @@
import os
DATABASE = os.environ['DATABASE_NAME']
from db.api import DBConnection
@ -7,16 +8,17 @@ from db.tables import *
if DATABASE == 'redshift':
from db.loaders.redshift_loader import transit_insert_to_redshift
if DATABASE == 'clickhouse':
elif DATABASE == 'clickhouse':
from db.loaders.clickhouse_loader import insert_to_clickhouse
if DATABASE == 'pg':
elif DATABASE == 'pg':
from db.loaders.postgres_loader import insert_to_postgres
if DATABASE == 'bigquery':
elif DATABASE == 'bigquery':
from db.loaders.bigquery_loader import insert_to_bigquery
from bigquery_utils.create_table import create_tables_bigquery
if DATABASE == 'snowflake':
elif DATABASE == 'snowflake':
from db.loaders.snowflake_loader import insert_to_snowflake
else:
raise Exception(f"{DATABASE}-database not supported")
# create tables if don't exist
try:
@ -35,12 +37,11 @@ try:
db = None
except Exception as e:
print(repr(e))
print("Please create the tables with scripts provided in "
"'/sql/{DATABASE}_sessions.sql' and '/sql/{DATABASE}_events.sql'")
print("Please create the tables with scripts provided in " +
f"'/sql/{DATABASE}_sessions.sql' and '/sql/{DATABASE}_events.sql'")
def insert_batch(db: DBConnection, batch, table, level='normal'):
if len(batch) == 0:
return
df = get_df_from_batch(batch, level=level)
@ -60,4 +61,3 @@ def insert_batch(db: DBConnection, batch, table, level='normal'):
if db.config == 'snowflake':
insert_to_snowflake(db=db, df=df, table=table)