-
Notifications
You must be signed in to change notification settings - Fork 97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(glib): add Vala VAPI for GADBC #1152
Conversation
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you also add a simple example like https://github.com/apache/arrow/blob/main/c_glib/example/vala/build.vala ?
Or do you want me to do it?
Could you also read the auto-generated comment: #1152 (comment) |
edb9c77
to
46da11d
Compare
Should be done now. |
I've added a C and Vala example for SQLite |
I would like to add an example on how to access a data from a SELECT statement, could you guide me on how can I do that? I have a problem: GArrow.Statement.execute() returns an out pointer (void*) but it seams to be a ArrowArrayStream which seams doesn't exists in the GLib/API, it is like an interface to be implemented, but no one in the API seems to be used to provide this functionality. I think is required a GArrowArrayStream as a GInterface to be implemented by a GArrowSimpleStream that can be used to bind an ArrowArrayStream returns from execute(). By adding the above interface should be easy to bind to Vala and simple to use from GLIb/C API I think. This interface could be defined to contain the methods: get_schema() and get_next(); don't think release() is usable, as it will be a GObject and g_object_unref(), calling release() internally, can be used. GArrowSimpleStream could be a simple object that can be used to provide a GArrowArrayStream interface, and constructed from an ArrowArrayStream to access the functionality. Also, this will help others to write C or even, Vala or any other supported GObject Introspection languages, drivers to databases or sources using Arrow format. |
Sure. We can use diff --git a/glib/example/meson.build b/glib/example/meson.build
index bc365d72..01932312 100644
--- a/glib/example/meson.build
+++ b/glib/example/meson.build
@@ -18,7 +18,7 @@
# under the License.
executable('sqlite', 'sqlite.c',
- dependencies: [adbc_glib],
+ dependencies: [adbc_glib, dependency('arrow-glib')],
link_language: 'c')
install_data('README.md',
diff --git a/glib/example/sqlite.c b/glib/example/sqlite.c
index 254c8ab5..3d2bd282 100644
--- a/glib/example/sqlite.c
+++ b/glib/example/sqlite.c
@@ -19,6 +19,8 @@
#include <stdlib.h>
+#include <arrow-glib/arrow-glib.h>
+
#include <adbc-glib/adbc-glib.h>
int main(int argc, char** argv) {
@@ -68,6 +70,77 @@ int main(int argc, char** argv) {
return EXIT_FAILURE;
}
+ GADBCStatement *statement = gadbc_statement_new(conn, &error);
+ if (!statement) {
+ g_print("Error initializing a statement: %s", error->message);
+ g_object_unref(conn);
+ g_object_unref(database);
+ return EXIT_FAILURE;
+ }
+ if (!gadbc_statement_set_sql_query(statement,
+ "select sqlite_version() as version",
+ &error)) {
+ g_print("Error setting a query: %s", error->message);
+ g_object_unref(statement);
+ g_object_unref(conn);
+ g_object_unref(database);
+ return EXIT_FAILURE;
+ }
+ gpointer c_abi_array_stream;
+ gint64 n_rows_affected;
+ if (!gadbc_statement_execute(statement,
+ TRUE,
+ &c_abi_array_stream,
+ &n_rows_affected,
+ &error)) {
+ g_print("Error executing a query: %s", error->message);
+ g_error_free(error);
+ g_object_unref(statement);
+ g_object_unref(conn);
+ g_object_unref(database);
+ return EXIT_FAILURE;
+ }
+ GArrowRecordBatchReader *reader =
+ garrow_record_batch_reader_import(c_abi_array_stream, &error);
+ g_free(c_abi_array_stream);
+ if (!reader) {
+ g_print("Error importing a result: %s", error->message);
+ g_error_free(error);
+ g_object_unref(statement);
+ g_object_unref(conn);
+ g_object_unref(database);
+ return EXIT_FAILURE;
+ }
+ GArrowTable *table = garrow_record_batch_reader_read_all(reader, &error);
+ g_object_unref(reader);
+ if (!table) {
+ g_print("Error reading a result: %s", error->message);
+ g_error_free(error);
+ g_object_unref(statement);
+ g_object_unref(conn);
+ g_object_unref(database);
+ return EXIT_FAILURE;
+ }
+ gchar *table_content = garrow_table_to_string(table, &error);
+ g_object_unref(table);
+ if (!table_content) {
+ g_print("Error stringify a result: %s", error->message);
+ g_error_free(error);
+ g_object_unref(statement);
+ g_object_unref(conn);
+ g_object_unref(database);
+ return EXIT_FAILURE;
+ }
+ g_print("Result:\n%s\n", table_content);
+ g_free(table_content);
+ gadbc_statement_release(statement, &error);
+ if (error) {
+ g_print("Error releasing a statement: %s", error->message);
+ g_error_free(error);
+ error = NULL;
+ }
+ g_object_unref(statement);
+
g_object_unref(conn);
g_object_unref(database); |
For Vala: diff --git a/glib/example/meson.build b/glib/example/meson.build
index bc365d72..76a07079 100644
--- a/glib/example/meson.build
+++ b/glib/example/meson.build
@@ -17,8 +17,10 @@
# specific language governing permissions and limitations
# under the License.
+arrow_glib = dependency('arrow-glib')
+
executable('sqlite', 'sqlite.c',
- dependencies: [adbc_glib],
+ dependencies: [adbc_glib, arrow_glib],
link_language: 'c')
install_data('README.md',
diff --git a/glib/example/vala/meson.build b/glib/example/vala/meson.build
index f5debcd7..731e0439 100644
--- a/glib/example/vala/meson.build
+++ b/glib/example/vala/meson.build
@@ -25,10 +25,11 @@ if generate_vapi
],
'dependencies': [
adbc_glib_vapi,
- dependency('gobject-2.0'),
+ arrow_glib,
],
'vala_args': [
'--pkg', 'posix',
+ '--vapidir', arrow_glib.get_variable('vapidir'),
],
}
executable('sqlite', 'sqlite.vala',
diff --git a/glib/example/vala/sqlite.vala b/glib/example/vala/sqlite.vala
index dedb42a3..8d7d2068 100644
--- a/glib/example/vala/sqlite.vala
+++ b/glib/example/vala/sqlite.vala
@@ -29,10 +29,18 @@ int main (string[] args) {
GLib.message ("Connection to database initialized...");
try {
var stm = new GADBC.Statement (conn);
- string sql = "CREATE TABLE IF NOT EXISTS test (id INTEGER, name TEXT)";
+ string sql = "SELECT sqlite_version() AS version";
stm.set_sql_query (sql);
- stm.execute (false, null, null);
- GLib.message ("Statement executed: %s", sql);
+ void *c_abi_array_stream = null;
+ stm.execute (true, out c_abi_array_stream, null);
+ try {
+ GLib.message ("Statement executed: %s", sql);
+ var reader = GArrow.RecordBatchReader.import (c_abi_array_stream);
+ var table = reader.read_all ();
+ GLib.message ("Executed result: %s", table.to_string ());
+ } finally {
+ GLib.free (c_abi_array_stream);
+ }
}
catch (GLib.Error e) {
GLib.message ("Error executing statement: %s", e.message); |
Now all suggestions and examples are in place. |
Vala VAPI file is generated for current GADBC 1.0 API version. It is disable by default, but recommended to be enable when a development package is distributed. This commit force a 1.0 API versioning, replacing the old one where 0 were used for GIR API version (gir_version), so now shows '1.0' instead of '0.0'. Also examples are provided for C and Vala.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
Vala VAPI file is generated for current GADBC 1.0 API version.
It is disable by default, but recommended to be enable when a development package is distributed.
This commit force a 1.0 API versioning, replacing the old one where 0 were used for GIR API version (gir_version), so now shows '1.0' instead of '0.0'.