kou commented on PR #1152:
URL: https://github.com/apache/arrow-adbc/pull/1152#issuecomment-1758748272

   Sure. We can use `garrow_record_batch_reader_import()` in Arrow GLib to read 
data from `ArrowArrayStream`:
   
   ```diff
   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);
    ```
    


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to