apache / arrow-adbc

Database connectivity API standard and libraries for Apache Arrow
https://arrow.apache.org/adbc/
Apache License 2.0
385 stars 97 forks source link

feat: C++ Client Helpers #2274

Open paleolimbot opened 1 month ago

paleolimbot commented 1 month ago

Just a preliminary go at #598!

This PR implements a C++ wrapper around the C API to cut down on some of the verbosity of using ADBC from C++ and ensure the assumptions made by drivers (e.g., that parent objects are valid). One of the difficulties of building an ADBC driver is testing it...the validation library helps here but is still rather verbose. I'm hoping this will help make it easier to write great tests for new drivers!

Current syntax:

#include "driver/framework/client.h"

Driver driver;
UNWRAP_STATUS(driver.Load(...));

UNWRAP_RESULT(Database database = driver.NewDatabase());
UNWRAP_RESULT(Connection connection = database.NewConnection());
UNWRAP_RESULT(Statement statement = connection.NewStatement());

UNWRAP_STATUS(statement.SetSqlQuery("SELECT * from foofy"));
UNWRAP_RESULT(StatementStream stream, statement.ExecuteQuery());

struct ArrowArrayStream cstream;
stream.Export(&cstream);

cstream.release(&cstream);
UNWRAP_STATUS(statement.Release());
UNWRAP_STATUS(connection.Release());
UNWRAP_STATUS(database.Release());
UNWRAP_STATUS(driver.Release());

The implementation is probably more verbose than it has to be but has some nice properties:

Work in progress!

paleolimbot commented 1 month ago

@lidavidm This is still very early but I'd like to make sure it's headed in vaguely the right direction before I get too far!