in c/validation/adbc_validation_util.h [289:354]
int MakeArray(struct ArrowArray* parent, struct ArrowArray* array,
const std::vector<std::optional<T>>& values) {
for (const auto& v : values) {
if (v.has_value()) {
if constexpr (std::is_same<T, bool>::value || std::is_same<T, int8_t>::value ||
std::is_same<T, int16_t>::value || std::is_same<T, int32_t>::value ||
std::is_same<T, int64_t>::value) {
CHECK_OK(ArrowArrayAppendInt(array, *v));
// XXX: cpplint gets weird here and thinks this is an unbraced if
} else if constexpr (std::is_same<T, // NOLINT(readability/braces)
uint8_t>::value ||
std::is_same<T, uint16_t>::value ||
std::is_same<T, uint32_t>::value ||
std::is_same<T, uint64_t>::value) {
CHECK_OK(ArrowArrayAppendUInt(array, *v));
} else if constexpr (std::is_same<T, float>::value || // NOLINT(readability/braces)
std::is_same<T, double>::value) {
CHECK_OK(ArrowArrayAppendDouble(array, *v));
} else if constexpr (std::is_same<T, std::string>::value) {
struct ArrowBufferView view;
view.data.as_char = v->c_str();
view.size_bytes = v->size();
CHECK_OK(ArrowArrayAppendBytes(array, view));
} else if constexpr (std::is_same<T, std::vector<std::byte>>::value) {
static_assert(std::is_same_v<uint8_t, unsigned char>);
struct ArrowBufferView view;
view.data.as_uint8 = reinterpret_cast<const uint8_t*>(v->data());
view.size_bytes = v->size();
CHECK_OK(ArrowArrayAppendBytes(array, view));
} else if constexpr (std::is_same<T, ArrowInterval*>::value) {
CHECK_OK(ArrowArrayAppendInterval(array, *v));
} else if constexpr (std::is_same<T, ArrowDecimal*>::value) {
CHECK_OK(ArrowArrayAppendDecimal(array, *v));
} else if constexpr (
// Possibly a more effective way to do this using template magic
// Not included but possible are the std::optional<> variants of this
std::is_same<T, std::vector<bool>>::value ||
std::is_same<T, std::vector<int8_t>>::value ||
std::is_same<T, std::vector<int16_t>>::value ||
std::is_same<T, std::vector<int32_t>>::value ||
std::is_same<T, std::vector<int64_t>>::value ||
std::is_same<T, std::vector<uint8_t>>::value ||
std::is_same<T, std::vector<uint16_t>>::value ||
std::is_same<T, std::vector<uint32_t>>::value ||
std::is_same<T, std::vector<uint64_t>>::value ||
std::is_same<T, std::vector<double>>::value ||
std::is_same<T, std::vector<float>>::value ||
std::is_same<T, std::vector<std::string>>::value ||
std::is_same<T, std::vector<std::vector<std::byte>>>::value) {
using child_t = typename T::value_type;
std::vector<std::optional<child_t>> value_nullable;
for (const auto& child_value : *v) {
value_nullable.push_back(child_value);
}
CHECK_OK(MakeArray(array, array->children[0], value_nullable));
CHECK_OK(ArrowArrayFinishElement(array));
} else {
static_assert(!sizeof(T), "Not yet implemented");
return ENOTSUP;
}
} else {
CHECK_OK(ArrowArrayAppendNull(array, 1));
}
}
return 0;
}