How to use the pymapd.connect function in pymapd

To help you get started, we’ve selected a few pymapd examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github omnisci / pymapd / tests / test_connection.py View on Github external
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
github omnisci / pymapd / tests / test_connection.py View on Github external
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')
github omnisci / pymapd / tests / test_deallocate.py View on Github external
def _connect(self):

        return connect(user="admin",
                       password='HyperInteractive',
                       host='localhost',
                       port=6274, protocol='binary', dbname='omnisci')
github ibis-project / ibis / ci / datamgr.py View on Github external
)
        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
github getredash / redash / redash / query_runner / mapd.py View on Github external
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
github ibis-project / ibis / ci / datamgr.py View on Github external
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:
github omnisci / vehicle-telematics-analytics-demo / f1dash / app.py View on Github external
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"]]
github omnisci / vehicle-telematics-analytics-demo / f1dash / track.py View on Github external
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
    """
github omnisci / pymapd / scripts / bench.py View on Github external
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)
github omnisci / omniscidb / Benchmarks / run_benchmark_import.py View on Github external
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