summaryrefslogtreecommitdiffstats
path: root/src/arrow/c_glib/example/build.c
blob: 9b2d58d2b2bba7d1838c5896d4f90edcc8ae22b5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

#include <stdlib.h>

#include <arrow-glib/arrow-glib.h>

int
main(int argc, char **argv)
{
  GArrowArray *array;

  {
    GArrowInt32ArrayBuilder *builder;
    gboolean success = TRUE;
    GError *error = NULL;

    builder = garrow_int32_array_builder_new();
    if (success) {
      success = garrow_int32_array_builder_append_value(builder, 29, &error);
    }
    if (success) {
      success = garrow_int32_array_builder_append_value(builder, 2929, &error);
    }
    if (success) {
      success = garrow_int32_array_builder_append_value(builder, 292929, &error);
    }
    if (!success) {
      g_print("failed to append: %s\n", error->message);
      g_error_free(error);
      g_object_unref(builder);
      return EXIT_FAILURE;
    }
    array = garrow_array_builder_finish(GARROW_ARRAY_BUILDER(builder), &error);
    if (!array) {
      g_print("failed to finish: %s\n", error->message);
      g_error_free(error);
      g_object_unref(builder);
      return EXIT_FAILURE;
    }
    g_object_unref(builder);
  }

  {
    gint64 i, n;

    n = garrow_array_get_length(array);
    g_print("length: %" G_GINT64_FORMAT "\n", n);
    for (i = 0; i < n; i++) {
      gint32 value;

      value = garrow_int32_array_get_value(GARROW_INT32_ARRAY(array), i);
      g_print("array[%" G_GINT64_FORMAT "] = %d\n",
              i, value);
    }
  }

  g_object_unref(array);

  return EXIT_SUCCESS;
}