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 6fbec4fd0 feat(glib): Add garrow_connection_get_statistic_names()
(#1748)
6fbec4fd0 is described below
commit 6fbec4fd05a1b2d94c54e66cfb7d45c6a88ab7b5
Author: Sutou Kouhei <[email protected]>
AuthorDate: Tue Apr 23 12:52:23 2024 +0900
feat(glib): Add garrow_connection_get_statistic_names() (#1748)
Fixes #1747.
This is the binding of `AdbcConnectionGetStatisticNames()`.
---
glib/adbc-glib/connection.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
glib/adbc-glib/connection.h | 3 +++
glib/test/test-connection.rb | 8 ++++++++
3 files changed, 55 insertions(+)
diff --git a/glib/adbc-glib/connection.c b/glib/adbc-glib/connection.c
index 14ec48f06..3bfb2b48b 100644
--- a/glib/adbc-glib/connection.c
+++ b/glib/adbc-glib/connection.c
@@ -581,6 +581,8 @@ gpointer gadbc_connection_get_table_types(GADBCConnection*
connection, GError**
* unsupported.
* @error: (nullable): Return location for a #GError or %NULL.
*
+ * Get statistics about the data distribution of table(s).
+ *
* The result is an Arrow dataset with the following schema:
*
* | Field Name | Field Type |
@@ -654,6 +656,48 @@ gpointer gadbc_connection_get_statistics(GADBCConnection*
connection,
}
}
+/**
+ * gadbc_connection_get_statistic_names:
+ * @connection: A #GADBCConnection.
+ * @error: (nullable): Return location for a #GError or %NULL.
+ *
+ * Get the names of statistics specific to this driver.
+ *
+ * The result is an Arrow dataset with the following schema:
+ *
+ * | Field Name | Field Type
+ * |----------------|----------------
+ * | statistic_name | utf8 not null
+ * | statistic_key | int16 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.
+ *
+ * This GADBCConnection must outlive the returned stream.
+ *
+ * Since: 1.0.0
+ */
+gpointer gadbc_connection_get_statistic_names(GADBCConnection* connection,
+ GError** error) {
+ const gchar* context = "[adbc][connection][get-statistic-names]";
+ 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 =
+ AdbcConnectionGetStatisticNames(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_commit:
* @connection: A #GADBCConnection.
diff --git a/glib/adbc-glib/connection.h b/glib/adbc-glib/connection.h
index 210af053f..2088986bf 100644
--- a/glib/adbc-glib/connection.h
+++ b/glib/adbc-glib/connection.h
@@ -252,6 +252,9 @@ gpointer gadbc_connection_get_statistics(GADBCConnection*
connection,
const gchar* catalog, const gchar*
db_schema,
const gchar* table_name, gboolean
approximate,
GError** error);
+GADBC_AVAILABLE_IN_1_0
+gpointer gadbc_connection_get_statistic_names(GADBCConnection* connection,
+ GError** error);
GADBC_AVAILABLE_IN_0_4
gboolean gadbc_connection_commit(GADBCConnection* connection, GError** error);
GADBC_AVAILABLE_IN_0_4
diff --git a/glib/test/test-connection.rb b/glib/test/test-connection.rb
index 12e906301..80b7bf1a1 100644
--- a/glib/test/test-connection.rb
+++ b/glib/test/test-connection.rb
@@ -714,6 +714,14 @@ class ConnectionTest < Test::Unit::TestCase
end
end
+ def test_statistic_names
+ c_abi_array_stream = @connection.statistic_names
+ import_array_stream(c_abi_array_stream) do |reader|
+ table = reader.read_all
+ assert_equal([], table.raw_records)
+ end
+ end
+
def test_commit
open_connection do |connection|
execute_sql(connection,