This is an automated email from the ASF dual-hosted git repository.
lidavidm pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-adbc.git
The following commit(s) were added to refs/heads/main by this push:
new f79adb7 feat(glib): add gadbc_connection_get_table_types() (#560)
f79adb7 is described below
commit f79adb70da69ce1671e7ef910baa49abad076132
Author: Sutou Kouhei <[email protected]>
AuthorDate: Tue Mar 28 10:15:12 2023 +0900
feat(glib): add gadbc_connection_get_table_types() (#560)
Fixes #550.
---
glib/adbc-glib/connection.c | 39 +++++++++++++++++++++++++++++++++++++++
glib/adbc-glib/connection.h | 3 +++
glib/test/test-connection.rb | 30 ++++++++++++++++++++----------
3 files changed, 62 insertions(+), 10 deletions(-)
diff --git a/glib/adbc-glib/connection.c b/glib/adbc-glib/connection.c
index eea47d6..0c83b1e 100644
--- a/glib/adbc-glib/connection.c
+++ b/glib/adbc-glib/connection.c
@@ -183,6 +183,45 @@ gboolean gadbc_connection_init(GADBCConnection*
connection, GADBCDatabase* datab
return success;
}
+/**
+ * gadbc_connection_get_table_types:
+ * @connection: A #GADBCConnection.
+ * @error: (nullable): Return location for a #GError or %NULL.
+ *
+ * Get a list of table types in the database.
+ *
+ * The result is an Arrow dataset with the following schema:
+ *
+ * Field Name | Field Type
+ * ---------------|--------------
+ * table_type | utf8 not null
+ *
+ *
+ * Returns: The result set as `struct ArrowArrayStream *`. It should
+ * be freed with the `ArrowArrayStream::release` callback then
+ * g_free() when no longer needed.
+ *
+ * Since: 0.4.0
+ */
+gpointer gadbc_connection_get_table_types(GADBCConnection* connection,
GError** error) {
+ const gchar* context = "[adbc][connection][get-table-types]";
+ struct AdbcConnection* adbc_connection =
+ gadbc_connection_get_raw(connection, context, error);
+ if (!adbc_connection) {
+ return NULL;
+ }
+ struct ArrowArrayStream* array_stream = g_new0(struct ArrowArrayStream, 1);
+ struct AdbcError adbc_error = {};
+ AdbcStatusCode status_code =
+ AdbcConnectionGetTableTypes(adbc_connection, array_stream, &adbc_error);
+ if (gadbc_error_check(error, status_code, &adbc_error, context)) {
+ return array_stream;
+ } else {
+ g_free(array_stream);
+ return NULL;
+ }
+}
+
/**
* gadbc_connection_get_raw:
* @connection: A #GADBCConnection.
diff --git a/glib/adbc-glib/connection.h b/glib/adbc-glib/connection.h
index 8ca33bf..50d1a15 100644
--- a/glib/adbc-glib/connection.h
+++ b/glib/adbc-glib/connection.h
@@ -40,4 +40,7 @@ GADBC_AVAILABLE_IN_0_1
gboolean gadbc_connection_init(GADBCConnection* connection, GADBCDatabase*
database,
GError** error);
+GADBC_AVAILABLE_IN_0_4
+gpointer gadbc_connection_get_table_types(GADBCConnection* connection,
GError** error);
+
G_END_DECLS
diff --git a/glib/test/test-connection.rb b/glib/test/test-connection.rb
index 02c0086..c219178 100644
--- a/glib/test/test-connection.rb
+++ b/glib/test/test-connection.rb
@@ -21,19 +21,29 @@ class ConnectionTest < Test::Unit::TestCase
@database.set_option("driver", "adbc_driver_sqlite")
@database.set_option("uri", ":memory:")
@database.init
- end
-
- def test_init
- connection = ADBC::Connection.new
- assert do
- connection.init(@database)
+ @connection = ADBC::Connection.new
+ begin
+ @connection.init(@database)
+ yield
+ ensure
+ @connection.release
end
end
- def test_release
- connection = ADBC::Connection.new
- assert do
- connection.release
+ def test_table_types
+ c_abi_array_stream = @connection.table_types
+ begin
+ reader = Arrow::RecordBatchReader.import(c_abi_array_stream)
+ table = reader.read_all
+ fields = [
+ Arrow::Field.new("table_type", :string, false),
+ ]
+ schema = Arrow::Schema.new(fields)
+ table_types = Arrow::StringArray.new(["table", "view"])
+ assert_equal(Arrow::Table.new(schema, [table_types]),
+ table)
+ ensure
+ GLib.free(c_abi_array_stream)
end
end
end