Skip to main content
Version: devel

dlt.destinations.impl.dremio.pydremio

Copyright (C) 2017-2021 Dremio Corporation

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

The code in this module was original from https://github.com/dremio-hub/arrow-flight-client-examples/tree/main/python. The code has been modified and extended to provide a PEP 249 compatible interface.

This implementation will eagerly gather the full result set after every query. Eventually, this module should be replaced with ADBC Flight SQL client. See: https://github.com/apache/arrow-adbc/issues/1559

DremioCursor Objects

@dataclass
class DremioCursor()

View source on GitHub

execute

def execute(query: AnyStr,
parameters: Optional[Tuple[Any, ...]] = None,
*args: Any,
**kwargs: Any) -> None

View source on GitHub

Execute a query and prepare to stream results.

this configures a Flight stream reader so that results can be consumed incrementally via fetchone/fetchmany/fetchall or iter_arrow_tables.

Arguments:

  • query - SQL query string (or bytes)
  • parameters - optional positional parameters for the query

fetchmany

def fetchmany(size: Optional[int] = None) -> List[Tuple[Any, ...]]

View source on GitHub

Fetch up to size rows, streaming from the server as needed.

Arguments:

  • size - number of rows to return. If None, uses self.arraysize.

Returns:

list of row tuples with up to size elements. May be empty when no more rows are available.

fetch_arrow_table

def fetch_arrow_table() -> pyarrow.Table

View source on GitHub

Read and return the full remaining result as an Arrow table.

this drains the underlying Flight stream (if active) and returns all rows currently buffered plus all remaining rows from the server. The cursor buffer is reset to empty afterwards.

iter_arrow_tables

def iter_arrow_tables(size: Optional[int] = None) -> pyarrow.Table

View source on GitHub

Fetch up to size rows and return them as an Arrow table.

this mirrors fetchmany but returns a pyarrow.Table instead of a list of row tuples. It streams from the server as needed to satisfy the size.

Arguments:

  • size - number of rows to return. If None, uses self.arraysize.

Returns:

pyarrow.Table containing up to size rows. May be empty when no more rows are available.

DremioClientAuthMiddlewareFactory Objects

class DremioClientAuthMiddlewareFactory(flight.ClientMiddlewareFactory)

View source on GitHub

A factory that creates DremioClientAuthMiddleware(s).

DremioClientAuthMiddleware Objects

class DremioClientAuthMiddleware(flight.ClientMiddleware)

View source on GitHub

A ClientMiddleware that extracts the bearer token from the authorization header returned by the Dremio Flight Server Endpoint.

Parameters

factory : ClientHeaderAuthMiddlewareFactory The factory to set call credentials if an authorization header with bearer token is returned by the Dremio server.

CookieMiddlewareFactory Objects

class CookieMiddlewareFactory(flight.ClientMiddlewareFactory)

View source on GitHub

A factory that creates CookieMiddleware(s).

CookieMiddleware Objects

class CookieMiddleware(flight.ClientMiddleware)

View source on GitHub

A ClientMiddleware that receives and retransmits cookies. For simplicity, this does not auto-expire cookies.

Parameters

factory : CookieMiddlewareFactory The factory containing the currently cached cookies.

This demo works on codespaces. Codespaces is a development environment available for free to anyone with a Github account. You'll be asked to fork the demo repository and from there the README guides you with further steps.
The demo uses the Continue VSCode extension.

Off to codespaces!

DHelp

Ask a question

Welcome to "Codex Central", your next-gen help center, driven by OpenAI's GPT-4 model. It's more than just a forum or a FAQ hub – it's a dynamic knowledge base where coders can find AI-assisted solutions to their pressing problems. With GPT-4's powerful comprehension and predictive abilities, Codex Central provides instantaneous issue resolution, insightful debugging, and personalized guidance. Get your code running smoothly with the unparalleled support at Codex Central - coding help reimagined with AI prowess.