Helper to create an int32 array from vector
| 105 | |
| 106 | // Helper to create an int32 array from vector |
| 107 | inline void createInt32Array(ArrowArray* array, const std::vector<int32_t>& data) { |
| 108 | struct ArrayPrivateData { |
| 109 | void* validity = nullptr; |
| 110 | void* data = nullptr; |
| 111 | int32_t* offsets = nullptr; |
| 112 | }; |
| 113 | |
| 114 | auto* private_data = new ArrayPrivateData(); |
| 115 | private_data->validity = nullptr; // No nulls |
| 116 | private_data->data = malloc(data.size() * sizeof(int32_t)); |
| 117 | memcpy(private_data->data, data.data(), data.size() * sizeof(int32_t)); |
| 118 | |
| 119 | array->length = data.size(); |
| 120 | array->null_count = 0; |
| 121 | array->offset = 0; |
| 122 | array->n_buffers = 2; // validity and data |
| 123 | array->n_children = 0; |
| 124 | array->buffers = static_cast<const void**>(malloc(sizeof(void*) * 2)); |
| 125 | array->buffers[0] = nullptr; // validity buffer (no nulls) |
| 126 | array->buffers[1] = private_data->data; |
| 127 | array->children = nullptr; |
| 128 | array->dictionary = nullptr; |
| 129 | array->release = [](ArrowArray* a) { |
| 130 | if (a->private_data) { |
| 131 | auto* pd = static_cast<ArrayPrivateData*>(a->private_data); |
| 132 | free(pd->validity); |
| 133 | free(pd->data); |
| 134 | free(pd->offsets); |
| 135 | delete pd; |
| 136 | } |
| 137 | if (a->buffers) { |
| 138 | free(const_cast<void**>(a->buffers)); |
| 139 | } |
| 140 | if (a->children) { |
| 141 | for (int64_t i = 0; i < a->n_children; i++) { |
| 142 | if (a->children[i]->release) { |
| 143 | a->children[i]->release(a->children[i]); |
| 144 | } |
| 145 | free(a->children[i]); |
| 146 | } |
| 147 | free(a->children); |
| 148 | } |
| 149 | a->release = nullptr; |
| 150 | }; |
| 151 | array->private_data = private_data; |
| 152 | } |
| 153 | |
| 154 | // Helper to create an int64 array from vector |
| 155 | inline void createInt64Array(ArrowArray* array, const std::vector<int64_t>& data) { |