|
|
@ -52,8 +52,38 @@ from google.cloud import bigquery as bq
|
|
|
|
import nzpy as nz #--- netezza drivers
|
|
|
|
import nzpy as nz #--- netezza drivers
|
|
|
|
import os
|
|
|
|
import os
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class providers :
|
|
|
|
|
|
|
|
POSTGRESQL = 'postgresql'
|
|
|
|
|
|
|
|
MONGODB = 'mongodb'
|
|
|
|
|
|
|
|
BIGQUERY ='bigquery'
|
|
|
|
|
|
|
|
FILE = 'file'
|
|
|
|
|
|
|
|
ETL = 'etl'
|
|
|
|
|
|
|
|
SQLITE = 'sqlite'
|
|
|
|
|
|
|
|
REDSHIFT = 'redshift'
|
|
|
|
|
|
|
|
NETEZZA = 'netezza'
|
|
|
|
|
|
|
|
MYSQL = 'mysql'
|
|
|
|
|
|
|
|
RABBITMQ = 'rabbitmq'
|
|
|
|
|
|
|
|
MARIADB = 'mariadb'
|
|
|
|
|
|
|
|
COUCHDB = 'couch'
|
|
|
|
|
|
|
|
CONSOLE = 'console'
|
|
|
|
|
|
|
|
ETL = 'etl'
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
# synonyms of the above
|
|
|
|
|
|
|
|
BQ = BIGQUERY
|
|
|
|
|
|
|
|
MONGO = MONGODB
|
|
|
|
|
|
|
|
PG = POSTGRESQL
|
|
|
|
|
|
|
|
PSQL = POSTGRESQL
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class IEncoder (json.JSONEncoder):
|
|
|
|
|
|
|
|
def default (self,object):
|
|
|
|
|
|
|
|
if type(object) == np.integer :
|
|
|
|
|
|
|
|
return int(object)
|
|
|
|
|
|
|
|
elif type(object) == np.floating:
|
|
|
|
|
|
|
|
return float(object)
|
|
|
|
|
|
|
|
elif type(object) == np.ndarray :
|
|
|
|
|
|
|
|
return object.tolist()
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
return super(IEncoder,self).default(object)
|
|
|
|
class factory :
|
|
|
|
class factory :
|
|
|
|
TYPE = {"sql":{"providers":["postgresql","mysql","neteeza","bigquery","mariadb","redshift"]}}
|
|
|
|
TYPE = {"sql":{"providers":["postgresql","mysql","neteeza","bigquery","mariadb","redshift"]}}
|
|
|
|
PROVIDERS = {
|
|
|
|
PROVIDERS = {
|
|
|
@ -149,9 +179,10 @@ def instance(**_args):
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# Let us try to establish an sqlalchemy wrapper
|
|
|
|
# Let us try to establish an sqlalchemy wrapper
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
|
|
|
|
account = ''
|
|
|
|
host = ''
|
|
|
|
host = ''
|
|
|
|
if provider not in ['bigquery','mongodb','mongo','couchdb','sqlite','console','etl','file','rabbitmq'] :
|
|
|
|
if provider not in [providers.BIGQUERY,providers.MONGODB, providers.COUCHDB, providers.SQLITE, providers.CONSOLE,providers.ETL, providers.FILE, providers.RABBITMQ] :
|
|
|
|
|
|
|
|
# if provider not in ['bigquery','mongodb','mongo','couchdb','sqlite','console','etl','file','rabbitmq'] :
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# In these cases we are assuming RDBMS and thus would exclude NoSQL and BigQuery
|
|
|
|
# In these cases we are assuming RDBMS and thus would exclude NoSQL and BigQuery
|
|
|
|
username = args['username'] if 'username' in args else ''
|
|
|
|
username = args['username'] if 'username' in args else ''
|
|
|
@ -165,11 +196,13 @@ def instance(**_args):
|
|
|
|
host = host+":"+str(args['port'])
|
|
|
|
host = host+":"+str(args['port'])
|
|
|
|
|
|
|
|
|
|
|
|
database = args['database']
|
|
|
|
database = args['database']
|
|
|
|
elif provider == 'sqlite':
|
|
|
|
elif provider in [providers.SQLITE,providers.FILE]:
|
|
|
|
account = ''
|
|
|
|
account = ''
|
|
|
|
host = ''
|
|
|
|
host = ''
|
|
|
|
database = args['path'] if 'path' in args else args['database']
|
|
|
|
database = args['path'] if 'path' in args else args['database']
|
|
|
|
if provider not in ['mongodb','mongo','couchdb','bigquery','console','etl','file','rabbitmq'] :
|
|
|
|
|
|
|
|
|
|
|
|
if provider not in [providers.MONGODB, providers.COUCHDB, providers.BIGQUERY, providers.CONSOLE, providers.ETL,providers.FILE,providers.RABBITMQ] :
|
|
|
|
|
|
|
|
# if provider not in ['mongodb','mongo','couchdb','bigquery','console','etl','file','rabbitmq'] :
|
|
|
|
uri = ''.join([provider,"://",account,host,'/',database])
|
|
|
|
uri = ''.join([provider,"://",account,host,'/',database])
|
|
|
|
|
|
|
|
|
|
|
|
e = sqlalchemy.create_engine (uri,future=True)
|
|
|
|
e = sqlalchemy.create_engine (uri,future=True)
|
|
|
@ -178,6 +211,7 @@ def instance(**_args):
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# @TODO: Include handling of bigquery with SQLAlchemy
|
|
|
|
# @TODO: Include handling of bigquery with SQLAlchemy
|
|
|
|
except Exception as e:
|
|
|
|
except Exception as e:
|
|
|
|
|
|
|
|
print (_args)
|
|
|
|
print (e)
|
|
|
|
print (e)
|
|
|
|
|
|
|
|
|
|
|
|
return pointer(**args)
|
|
|
|
return pointer(**args)
|
|
|
|