Skip to content

Commit

Permalink
docs: add page for DuckDB (#915)
Browse files Browse the repository at this point in the history
Fixes #874.
  • Loading branch information
lidavidm authored Jul 19, 2023
1 parent 32c3f15 commit 796ae09
Show file tree
Hide file tree
Showing 5 changed files with 140 additions and 36 deletions.
102 changes: 102 additions & 0 deletions docs/source/driver/duckdb.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
.. 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.
==============
DuckDB Support
==============

**Available for:** C/C++, GLib/Ruby, Go, Python

`DuckDB`_ provides ADBC support since `version 0.8.0
<https://duckdb.org/2023/05/17/announcing-duckdb-080.html>`_.

.. note:: DuckDB is not part of the Apache Arrow project and is
developed separately.

.. _DuckDB: https://duckdb.org/

Installation
============

See the `DuckDB documentation
<https://duckdb.org/docs/installation/>`_.

Usage
=====

ADBC support in DuckDB requires the driver manager.

.. tab-set::

.. tab-item:: C++
:sync: cpp

.. code-block:: cpp
#include "adbc.h"
// Ignoring error handling
struct AdbcDatabase database;
AdbcDatabaseNew(&database, nullptr);
AdbcDatabaseSetOption(&database, "driver", "PATH/TO/libduckdb.so", nullptr);
AdbcDatabaseSetOption(&database, "entrypoint", "duckdb_adbc_init", nullptr);
AdbcDatabaseInit(&database, nullptr);
.. tab-item:: Go
:sync: go

You must have ``libduckdb.so`` on your ``LD_LIBRARY_PATH``, or
in the same directory as the executable when you run this. This
requires CGO and loads the DuckDB driver.

.. code-block:: go
import (
"context"
"github.com/apache/arrow-adbc/go/adbc"
"github.com/apache/arrow-adbc/go/adbc/drivermgr"
)
func main() {
var drv drivermgr.Driver
db, err := drv.NewDatabase(map[string]string{
"driver": "libduckdb.so",
"entrypoint": "duckdb_adbc_init",
})
if err != nil {
// handle error
}
cnxn, err := db.Open(context.Background())
if err != nil {
// handle error
}
defer cnxn.Close()
}
.. tab-item:: Python
:sync: python

See :ref:`recipe-driver-manager-duckdb`.


Supported Features
==================

ADBC support in DuckDB is still in progress. See `duckdb/duckdb#7141
<https://github.com/duckdb/duckdb/issues/7141>`_ for details.
50 changes: 25 additions & 25 deletions docs/source/driver/postgresql.rst
Original file line number Diff line number Diff line change
Expand Up @@ -100,31 +100,6 @@ the :cpp:class:`AdbcDatabase`. This should be a `connection URI
AdbcDatabaseSetOption(&database, "uri", "postgresql://localhost:5433", nullptr);
AdbcDatabaseInit(&database, nullptr);
.. tab-item:: Python
:sync: python

.. code-block:: python
import adbc_driver_postgresql.dbapi
uri = "postgresql://user:pass@localhost:5433/postgres"
with adbc_driver_postgresql.dbapi.connect(uri) as conn:
pass
For more examples, see :doc:`../python/recipe/postgresql`.

.. tab-item:: R
:sync: r

.. code-block:: r
library(adbcdrivermanager)
# Use the driver manager to connect to a database
uri <- Sys.getenv("ADBC_POSTGRESQL_TEST_URI")
db <- adbc_database_init(adbcpostgresql::adbcpostgresql(), uri = uri)
con <- adbc_connection_init(db)
.. tab-item:: Go
:sync: go

Expand Down Expand Up @@ -158,6 +133,31 @@ the :cpp:class:`AdbcDatabase`. This should be a `connection URI
defer cnxn.Close()
}
.. tab-item:: Python
:sync: python

.. code-block:: python
import adbc_driver_postgresql.dbapi
uri = "postgresql://user:pass@localhost:5433/postgres"
with adbc_driver_postgresql.dbapi.connect(uri) as conn:
pass
For more examples, see :doc:`../python/recipe/postgresql`.

.. tab-item:: R
:sync: r

.. code-block:: r
library(adbcdrivermanager)
# Use the driver manager to connect to a database
uri <- Sys.getenv("ADBC_POSTGRESQL_TEST_URI")
db <- adbc_database_init(adbcpostgresql::adbcpostgresql(), uri = uri)
con <- adbc_connection_init(db)
Supported Features
==================

Expand Down
21 changes: 10 additions & 11 deletions docs/source/driver/sqlite.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ Installation
mamba install libadbc-driver-sqlite
.. tab-item:: Go
:sync: go

Install the C/C++ package and use the Go driver manager.
Requires CGO.

.. code-block:: shell
go get github.com/apache/arrow-adbc/go/adbc/drivermgr
.. tab-item:: Python
:sync: python

Expand All @@ -60,17 +70,6 @@ Installation
# install.packages("pak")
pak::pak("apache/arrow-adbc/r/adbcsqlite")
.. tab-item:: Go
:sync: go

Install the C/C++ package and use the Go driver manager.
Requires CGO.

.. code-block:: shell
go get github.com/apache/arrow-adbc/go/adbc/drivermgr
Usage
=====

Expand Down
1 change: 1 addition & 0 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ To learn more about ADBC, see the `introductory blog post

driver/installation
driver/status
driver/duckdb
driver/flight_sql
driver/jdbc
driver/postgresql
Expand Down
2 changes: 2 additions & 0 deletions docs/source/python/recipe/driver_manager.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
Driver Manager Recipes
======================

.. _recipe-driver-manager-duckdb:

Load a driver from a shared library (DuckDB)
============================================

Expand Down

0 comments on commit 796ae09

Please sign in to comment.