| 93 | } |
| 94 | |
| 95 | Result<Datum> ExecuteImpl(const std::vector<Datum>& args, |
| 96 | const FunctionOptions* options, |
| 97 | ExecContext* ctx) const override { |
| 98 | ARROW_ASSIGN_OR_RAISE(auto cast_options, ValidateOptions(options)); |
| 99 | // args[0].type() could be a nullptr so check for that before |
| 100 | // we do anything with it. |
| 101 | if (args[0].type() && args[0].type()->Equals(*cast_options->to_type)) { |
| 102 | // Nested types might differ in field names but still be considered equal, |
| 103 | // so we can only return non-nested types as-is. |
| 104 | if (!is_nested(args[0].type()->id())) { |
| 105 | return args[0]; |
| 106 | } else if (args[0].is_array()) { |
| 107 | ARROW_ASSIGN_OR_RAISE(std::shared_ptr<ArrayData> array, |
| 108 | ::arrow::internal::GetArrayView( |
| 109 | args[0].array(), cast_options->to_type.owned_type)); |
| 110 | return Datum(array); |
| 111 | } else if (args[0].is_chunked_array()) { |
| 112 | ARROW_ASSIGN_OR_RAISE( |
| 113 | std::shared_ptr<ChunkedArray> array, |
| 114 | args[0].chunked_array()->View(cast_options->to_type.owned_type)); |
| 115 | return Datum(array); |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | Result<std::shared_ptr<CastFunction>> result = |
| 120 | GetCastFunction(*cast_options->to_type); |
| 121 | if (!result.ok()) { |
| 122 | Status s = result.status(); |
| 123 | return s.WithMessage(s.message(), " from ", *args[0].type()); |
| 124 | } |
| 125 | return (*result)->Execute(args, options, ctx); |
| 126 | } |
| 127 | }; |
| 128 | |
| 129 | static auto kCastOptionsType = GetFunctionOptionsType<CastOptions>( |
nothing calls this directly
no test coverage detected