How to use the pyexasol.exasol_mapper function in pyexasol

To help you get started, we’ve selected a few pyexasol 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 revolut-engineering / data-libs / connections / revlibs / connections / connectors.py View on Github external
def _connect(config: Config) -> pyexasol.ExaConnection:
        """Establish connection with exasol"""
        params = {"compression": True}
        if "schema" in config:
            params["schema"] = config.schema
        params.update(config.params)

        try:
            return pyexasol.connect(
                dsn=config.dsn,
                user=config.user,
                password=config.password,
                fetch_dict=True,
                fetch_mapper=pyexasol.exasol_mapper,
                **params,
            )
        except pyexasol.exceptions.ExaConnectionDsnError as exc:
            raise ConnectionEstablishError(config.name, reason="Bad dsn", dsn=config.dsn) from exc
        except pyexasol.exceptions.ExaAuthError as exc:
            raise ConnectionEstablishError(
                config.name, reason="Authentication failed", dsn=config.dsn, user=config.user,
            ) from exc
        except pyexasol.exceptions.ExaConnectionFailedError as exc:
            raise ConnectionEstablishError(
                config.name, reason="Connection refused", dsn=config.dsn,
            ) from exc
        except pyexasol.exceptions.ExaError as exc:
            raise ConnectionEstablishError(config.name, dsn=config.dsn) from exc
github badoo / pyexasol / examples / 16_ujson.py View on Github external
select_q = 'SELECT dec36_0, dec36_36, dbl, bl, dt, ts, var100, LENGTH(var2000000) AS len_var FROM edge_case'

C.execute('TRUNCATE TABLE edge_case')

# Insert (test formatting)
C.execute(insert_q, dict(edge_cases[0]))
C.execute(insert_q, dict(edge_cases[1]))
C.execute(insert_q, dict(edge_cases[2]))

# Select and fetch
stmt = C.execute(select_q)
printer.pprint(stmt.fetchall())


# Same actions with "exasol_mapper"
C.fetch_mapper = pyexasol.exasol_mapper
C.execute('TRUNCATE TABLE edge_case')

# Insert (test formatting)
C.execute(insert_q, dict(edge_cases[0]))
C.execute(insert_q, dict(edge_cases[1]))
C.execute(insert_q, dict(edge_cases[2]))

# Select and fetch
stmt = C.execute(select_q)
printer.pprint(stmt.fetchall())

# Import and export
edge_tuples = C.execute("SELECT * FROM edge_case").fetchall()
github badoo / pyexasol / examples / 11_edge_case.py View on Github external
select_q = 'SELECT dec36_0, dec36_36, dbl, bl, dt, ts, var100, LENGTH(var2000000) AS len_var FROM edge_case'

C.execute('TRUNCATE TABLE edge_case')

# Insert (test formatting)
C.execute(insert_q, dict(edge_cases[0]))
C.execute(insert_q, dict(edge_cases[1]))
C.execute(insert_q, dict(edge_cases[2]))

# Select and fetch
stmt = C.execute(select_q)
printer.pprint(stmt.fetchall())


# Same actions with "exasol_mapper"
C.fetch_mapper = pyexasol.exasol_mapper
C.execute('TRUNCATE TABLE edge_case')

# Insert (test formatting)
C.execute(insert_q, dict(edge_cases[0]))
C.execute(insert_q, dict(edge_cases[1]))
C.execute(insert_q, dict(edge_cases[2]))

# Select and fetch
stmt = C.execute(select_q)
printer.pprint(stmt.fetchall())

# Import and export
edge_tuples = C.execute("SELECT * FROM edge_case").fetchall()

C.execute('TRUNCATE TABLE edge_case')
github badoo / pyexasol / examples / 04_fetch_mapper.py View on Github external
TIMESTAMP    -> datetime.datetime
BOOLEAN      -> bool
VARCHAR      -> str
CHAR         -> str
     -> str
"""

import pyexasol
import _config as config

import pprint
printer = pprint.PrettyPrinter(indent=4, width=180)

# Basic connect (custom mapper
C = pyexasol.connect(dsn=config.dsn, user=config.user, password=config.password, schema=config.schema,
                     fetch_mapper=pyexasol.exasol_mapper)

# Fetch objects
stmt = C.execute("SELECT * FROM users ORDER BY user_id LIMIT 5")
printer.pprint(stmt.fetchall())

# Test timestamp formats with different amount of decimal places
# Please note: Exasol stores timestamps with millisecond precision (3 decimal places)
# Lack of precision is not a bug, it's the documented feature

for i in range(0, 9):
    C.execute(f"ALTER SESSION SET NLS_TIMESTAMP_FORMAT='YYYY-MM-DD HH24:MI:SS.FF{i}'")
    printer.pprint(C.execute("SELECT TIMESTAMP'2018-01-01 03:04:05.123456'").fetchval())
github badoo / pyexasol / examples / 17_rapidjson.py View on Github external
select_q = 'SELECT dec36_0, dec36_36, dbl, bl, dt, ts, var100, LENGTH(var2000000) AS len_var FROM edge_case'

C.execute('TRUNCATE TABLE edge_case')

# Insert (test formatting)
C.execute(insert_q, dict(edge_cases[0]))
C.execute(insert_q, dict(edge_cases[1]))
C.execute(insert_q, dict(edge_cases[2]))

# Select and fetch
stmt = C.execute(select_q)
printer.pprint(stmt.fetchall())


# Same actions with "exasol_mapper"
C.fetch_mapper = pyexasol.exasol_mapper
C.execute('TRUNCATE TABLE edge_case')

# Insert (test formatting)
C.execute(insert_q, dict(edge_cases[0]))
C.execute(insert_q, dict(edge_cases[1]))
C.execute(insert_q, dict(edge_cases[2]))

# Select and fetch
stmt = C.execute(select_q)
printer.pprint(stmt.fetchall())

# Import and export
edge_tuples = C.execute("SELECT * FROM edge_case").fetchall()