Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_session_logon_success(self):
conn = connect(user='admin', password='HyperInteractive',
host='localhost', dbname='omnisci')
sessionid = conn._session
connnew = connect(sessionid=sessionid, host='localhost')
assert connnew._session == sessionid
def test_bad_protocol(self, mock_client):
with pytest.raises(ValueError) as m:
connect(user='user', host='localhost', dbname='dbname',
protocol='fake-proto')
assert m.match('fake-proto')
def _connect(self):
return connect(user="admin",
password='HyperInteractive',
host='localhost',
port=6274, protocol='binary', dbname='omnisci')
)
database = params["database"]
stmt = "DROP DATABASE {}".format(database)
try:
conn.execute(stmt)
except Exception:
logger.warning('OmniSci DDL statement %r failed', stmt)
stmt = 'CREATE DATABASE {}'.format(database)
try:
conn.execute(stmt)
except Exception:
logger.exception('OmniSci DDL statement %r failed', stmt)
conn.close()
conn = pymapd.connect(
host=params['host'],
user=params['user'],
password=params['password'],
port=params['port'],
dbname=database,
protocol=params['protocol'],
)
# create tables
for stmt in filter(None, map(str.strip, schema.read().split(';'))):
try:
conn.execute(stmt)
except Exception:
logger.exception('OmniSci DDL statement \n%r\n failed', stmt)
# import data
def connect_database(self):
connection = pymapd.connect(
user=self.configuration['user'],
password=self.configuration['password'],
host=self.configuration['host'],
port=self.configuration['port'],
dbname=self.configuration['database']
)
return connection
def omniscidb(schema, tables, data_directory, **params):
import pymapd
data_directory = Path(data_directory)
reserved_words = ['table', 'year', 'month']
# connection
logger.info('Initializing OmniSci...')
default_db = 'omnisci'
if params['database'] != default_db:
conn = pymapd.connect(
host=params['host'],
user=params['user'],
password=params['password'],
port=params['port'],
dbname=default_db,
protocol=params['protocol'],
)
database = params["database"]
stmt = "DROP DATABASE {}".format(database)
try:
conn.execute(stmt)
except Exception:
logger.warning('OmniSci DDL statement %r failed', stmt)
stmt = 'CREATE DATABASE {}'.format(database)
try:
def make_reflap_options(notused, value, values):
#placing connection inside to avoid having stale connection
conn = pymapd.connect(host = host, user= user, password= password, dbname= dbname, port=port)
df = pd.read_sql("""select distinct
sessionuid,
lapnumber,
laptime,
lapstarttime,
lapendtime,
playercarindex
from v_leaderboard_melbourne
where laptime >= 60 and lapstarttime >= '2019-05-04 21:00:00'
order by laptime
limit 50
""", conn)
#formatting for session column to make table width smaller
df["session"] = [f"""S{x[-4:]}""" for x in df["sessionuid"]]
def get_lapdata(sessionuid, lapstarttime, lapendtime):
#placing connection inside to avoid having stale connection
conn = pymapd.connect(host = host, user = user, password = password, dbname = dbname, port = port)
cm = f"""select
gforcelateral,
gforcelongitudinal,
gforcevertical,
worldpositionx,
worldpositionz,
worldvelocityx,
worldvelocityy,
worldvelocityz
from
gtc_carmotion_v2
where sessionuid = '{sessionuid}' and
packettime between '{lapstarttime}' and '{lapendtime}' and
playerscar = true
"""
def main(args=None):
args = parse_args(args)
fh = logging.FileHandler(args.output)
fh.setLevel(logging.INFO)
fh.setFormatter(formatter)
logger.addHandler(fh)
con = pymapd.connect(
user='admin',
password='HyperInteractive',
dbname='omnisci',
host='localhost')
grid = product(selects.keys(), _benchmarks)
if args.benchmarks:
xpr = re.compile(args.benchmarks)
else:
xpr = None
for kind, bench in grid:
if xpr:
if not xpr.search(bench.__name__):
continue
logger.debug("Starting %s[%s]", bench.__name__, kind)
https://pymapd.readthedocs.io/en/latest/usage.html#connecting
Kwargs:
db_user(str): DB username
db_passwd(str): DB password
db_server(str): DB host
db_port(int): DB port
db_name(str): DB name
Returns:
con(class): Connection class
False(bool): The connection failed. Exception should be logged.
"""
try:
logging.debug("Connecting to mapd db...")
con = pymapd.connect(
user=kwargs["db_user"],
password=kwargs["db_passwd"],
host=kwargs["db_server"],
port=kwargs["db_port"],
dbname=kwargs["db_name"],
)
logging.info("Succesfully connected to mapd db")
return con
except (pymapd.exceptions.OperationalError, pymapd.exceptions.Error):
logging.exception("Error connecting to database.")
return False