forked from apache/arrow-adbc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: add Flight SQL driver recipes (apache#1547)
Fixes apache#935.
- Loading branch information
Showing
9 changed files
with
231 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
.. Licensed to the Apache Software Foundation (ASF) under one | ||
.. or more contributor license agreements. See the NOTICE file | ||
.. distributed with this work for additional information | ||
.. regarding copyright ownership. The ASF licenses this file | ||
.. to you 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. | ||
================== | ||
Flight SQL Recipes | ||
================== | ||
|
||
Some of these recipes are written againt a demo Flight SQL service backed by | ||
SQLite. You can run it yourself as follows: | ||
|
||
.. code-block:: shell | ||
$ go install github.com/apache/arrow/go/v${ARROW_MAJOR_VERSION}/arrow/flight/flightsql/example/cmd/sqlite_flightsql_server@latest | ||
$ sqlite_flightsql_server -host 0.0.0.0 -port 8080 | ||
Other recipes work using the OSS version of Dremio_: | ||
|
||
.. code-block:: shell | ||
$ docker run -p 9047:9047 -p 31010:31010 -p 45678:45678 dremio/dremio-oss | ||
If you have the ADBC repository checked out and Docker Compose installed, you | ||
can use our configuration to run both services: | ||
|
||
.. code-block:: shell | ||
$ docker compose up --detach --wait dremio dremio-init flightsql-sqlite-test | ||
.. _Dremio: https://www.dremio.com/ | ||
|
||
Connect to an unsecured Flight SQL service | ||
------------------------------------------ | ||
|
||
.. recipe:: flightsql_sqlite_connect.py | ||
|
||
Connect to a Flight SQL service with username and password | ||
---------------------------------------------------------- | ||
|
||
.. recipe:: flightsql_dremio_connect.py | ||
|
||
Set timeouts and other options | ||
------------------------------ | ||
|
||
.. recipe:: flightsql_sqlite_options.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you 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. | ||
|
||
# RECIPE STARTS HERE | ||
|
||
#: Dremio requires a username and password. To connect to a Flight SQL | ||
#: service with authentication, provide the options at connection time. | ||
|
||
import os | ||
|
||
import adbc_driver_flightsql.dbapi | ||
import adbc_driver_manager | ||
|
||
uri = os.environ["ADBC_DREMIO_FLIGHTSQL_URI"] | ||
username = os.environ["ADBC_DREMIO_FLIGHTSQL_USER"] | ||
password = os.environ["ADBC_DREMIO_FLIGHTSQL_PASS"] | ||
conn = adbc_driver_flightsql.dbapi.connect( | ||
uri, | ||
db_kwargs={ | ||
adbc_driver_manager.DatabaseOptions.USERNAME.value: username, | ||
adbc_driver_manager.DatabaseOptions.PASSWORD.value: password, | ||
}, | ||
) | ||
|
||
#: We can then execute a simple query. | ||
|
||
with conn.cursor() as cur: | ||
cur.execute("SELECT 1") | ||
|
||
assert cur.fetchone() == (1,) | ||
|
||
conn.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you 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. | ||
|
||
# RECIPE STARTS HERE | ||
|
||
#: To connect to an unsecured Flight SQL service, just provide the URI. | ||
|
||
import os | ||
|
||
import adbc_driver_flightsql.dbapi | ||
|
||
uri = os.environ["ADBC_SQLITE_FLIGHTSQL_URI"] | ||
conn = adbc_driver_flightsql.dbapi.connect(uri) | ||
|
||
#: We can then execute a simple query. | ||
|
||
with conn.cursor() as cur: | ||
cur.execute("SELECT 1") | ||
|
||
assert cur.fetchone() == (1,) | ||
|
||
conn.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you 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. | ||
|
||
# RECIPE STARTS HERE | ||
|
||
#: The Flight SQL driver supports various options. | ||
|
||
import os | ||
|
||
import adbc_driver_flightsql.dbapi | ||
from adbc_driver_flightsql import ConnectionOptions, DatabaseOptions | ||
|
||
uri = os.environ["ADBC_SQLITE_FLIGHTSQL_URI"] | ||
#: We can enable cookie support, which some server implementations require. | ||
conn = adbc_driver_flightsql.dbapi.connect( | ||
uri, | ||
db_kwargs={DatabaseOptions.WITH_COOKIE_MIDDLEWARE.value: "true"}, | ||
) | ||
|
||
#: Other options are set on the connection or statement. | ||
|
||
#: For example, we can add a custom header to all outgoing requests. | ||
custom_header = f"{ConnectionOptions.RPC_CALL_HEADER_PREFIX.value}x-custom-header" | ||
conn.adbc_connection.set_options(**{custom_header: "value"}) | ||
|
||
#: We can also set timeouts. These are in floating-point seconds. | ||
conn.adbc_connection.set_options( | ||
**{ | ||
ConnectionOptions.TIMEOUT_FETCH.value: 30.0, | ||
ConnectionOptions.TIMEOUT_QUERY.value: 30.0, | ||
ConnectionOptions.TIMEOUT_UPDATE.value: 30.0, | ||
} | ||
) | ||
|
||
#: These options will apply to all cursors we create. | ||
|
||
with conn.cursor() as cur: | ||
cur.execute("SELECT 1") | ||
|
||
assert cur.fetchone() == (1,) | ||
|
||
conn.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,4 +26,5 @@ Python. | |
:maxdepth: 2 | ||
|
||
driver_manager | ||
flight_sql | ||
postgresql |