## Copyright (c) 2016-2024 Deephaven Data Labs and Patent Pending#"""This module supports ingesting data from external databases (relational and other types) into Deephaven via thePython DB-API 2.0 (PEP 249) and the Apache Arrow Database Connectivity (ADBC) interfaces. (Please refer tohttps://arrow.apache.org/docs/dev/format/ADBC.html for more details on ADBC).ADBC defines a standard API to fetch data in Arrow format from databases that support Arrow natively as well asfrom databases that only support ODBC/JDBC. By relying on ADBC, Deephaven is able to ingest data efficiently from awide variety of data sources. """fromdeephavenimportDHErrorfromdeephavenimportarrowasdharrowfromdeephaven.tableimportTabletry:importadbc_driver_manager.dbapiexceptImportError:raiseDHError(message="import ADBC driver manager failed, please install ADBC driver manager and your ""targeted database driver first.")
[docs]defread_cursor(cursor:adbc_driver_manager.dbapi.Cursor)->Table:"""Converts the result set of the provided cursor into a Deephaven table. Args: cursor (adbc_driver_manager.dbapi.Cursor): an ADBC DB-API cursor. Prior to it being passed in, its execute() method must be called to run a query operation that produces an Arrow table Returns: a new Table Raises: DHError, TypeError """ifnotisinstance(cursor,adbc_driver_manager.dbapi.Cursor):raiseTypeError(f"expect {adbc_driver_manager.dbapi.Cursor} got {type(cursor)} instead.")try:pa_table=cursor.fetch_arrow_table()exceptExceptionase:raiseDHError(e,message="failed to fetch ADBC result as an Arrow table.")fromereturndharrow.to_table(pa_table)