| 1 | /* |
| 2 | Copyright (C) 2019-2025 Sutou Kouhei <[email protected]> |
| 3 | |
| 4 | This library is free software; you can redistribute it and/or |
| 5 | modify it under the terms of the GNU Lesser General Public |
| 6 | License as published by the Free Software Foundation; either |
| 7 | version 2.1 of the License, or (at your option) any later version. |
| 8 | |
| 9 | This library is distributed in the hope that it will be useful, |
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 | Lesser General Public License for more details. |
| 13 | |
| 14 | You should have received a copy of the GNU Lesser General Public |
| 15 | License along with this library; if not, write to the Free Software |
| 16 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 17 | */ |
| 18 | |
| 19 | #pragma once |
| 20 | |
| 21 | #include "grn.h" |
| 22 | |
| 23 | #include <arrow/api.h> |
| 24 | |
| 25 | namespace grnarrow { |
| 26 | grn_rc |
| 27 | status_to_rc(const arrow::Status &status); |
| 28 | arrow::Status |
| 29 | check(grn_ctx *ctx, grn_rc rc, const char *context); |
| 30 | bool |
| 31 | check(grn_ctx *ctx, const arrow::Status &status, const char *context); |
| 32 | bool |
| 33 | check(grn_ctx *ctx, const arrow::Status &status, const std::string &context); |
| 34 | bool |
| 35 | check(grn_ctx *ctx, const arrow::Status &status, std::ostream &output); |
| 36 | |
| 37 | template <typename TYPE> |
| 38 | bool |
| 39 | check(grn_ctx *ctx, arrow::Result<TYPE> &result, const char *context) |
| 40 | { |
| 41 | return check(ctx, result.status(), context); |
| 42 | } |
| 43 | |
| 44 | template <typename TYPE> |
| 45 | bool |
| 46 | check(grn_ctx *ctx, arrow::Result<TYPE> &result, const std::string &context) |
| 47 | { |
| 48 | return check(ctx, result.status(), context); |
| 49 | } |
| 50 | |
| 51 | template <typename TYPE> |
| 52 | bool |
| 53 | check(grn_ctx *ctx, arrow::Result<TYPE> &result, std::ostream &output) |
| 54 | { |
| 55 | return check(ctx, result.status(), output); |
| 56 | } |
| 57 | |
| 58 | template <typename... ARGS> |
| 59 | std::string |
| 60 | join_to_string(ARGS &&...args) |
| 61 | { |
| 62 | #if ARROW_VERSION_MAJOR >= 21 |
| 63 | return ::arrow::internal::JoinToString(std::forward<ARGS>(args)...); |
| 64 | #else |
| 65 | return ::arrow::util::StringBuilder(std::forward<ARGS>(args)...); |
| 66 | #endif |
| 67 | } |
| 68 | |
| 69 | template <typename... ARGS> |
| 70 | bool |
| 71 | check(grn_ctx *ctx, const arrow::Status &status, ARGS &&...args) |
| 72 | { |
| 73 | auto context = join_to_string(std::forward<ARGS>(args)...); |
| 74 | return check(ctx, status, context.c_str()); |
| 75 | } |
| 76 | |
| 77 | template <typename TYPE, typename... ARGS> |
| 78 | bool |
| 79 | check(grn_ctx *ctx, arrow::Result<TYPE> &result, ARGS &&...args) |
| 80 | { |
| 81 | auto context = join_to_string(std::forward<ARGS>(args)...); |
| 82 | return check(ctx, result.status(), context.c_str()); |
| 83 | } |
| 84 | } // namespace grnarrow |
| 85 | |
| 86 | namespace grn { |
| 87 | namespace arrow { |
| 88 | grn_rc |
| 89 | get_value(grn_ctx *ctx, |
| 90 | const ::arrow::Array *array, |
| 91 | int64_t index, |
| 92 | grn_obj *value); |
| 93 | } |
| 94 | } // namespace grn |