| 27 | #include "./safe-call-into-r.h" |
| 28 | |
| 29 | bool RExtensionType::ExtensionEquals(const arrow::ExtensionType& other) const { |
| 30 | // Avoid materializing the R6 instance if at all possible |
| 31 | if (other.extension_name() != extension_name()) { |
| 32 | return false; |
| 33 | } |
| 34 | |
| 35 | if (other.Serialize() == Serialize()) { |
| 36 | return true; |
| 37 | } |
| 38 | |
| 39 | // With any ambiguity, we need to materialize the R6 instance and call its |
| 40 | // ExtensionEquals method. We can't do this on the non-R thread. |
| 41 | arrow::Result<bool> result = SafeCallIntoR<bool>( |
| 42 | [&]() { |
| 43 | cpp11::environment instance = r6_instance(); |
| 44 | cpp11::function instance_ExtensionEquals(instance["ExtensionEquals"]); |
| 45 | |
| 46 | std::shared_ptr<DataType> other_shared = |
| 47 | ValueOrStop(other.Deserialize(other.storage_type(), other.Serialize())); |
| 48 | cpp11::sexp other_r6 = cpp11::to_r6<DataType>(other_shared, "ExtensionType"); |
| 49 | |
| 50 | cpp11::logicals result(instance_ExtensionEquals(other_r6)); |
| 51 | return cpp11::as_cpp<bool>(result); |
| 52 | }, |
| 53 | "RExtensionType$ExtensionEquals()"); |
| 54 | |
| 55 | if (!result.ok()) { |
| 56 | throw std::runtime_error(result.status().message()); |
| 57 | } |
| 58 | |
| 59 | return result.ValueUnsafe(); |
| 60 | } |
| 61 | |
| 62 | std::shared_ptr<arrow::Array> RExtensionType::MakeArray( |
| 63 | std::shared_ptr<arrow::ArrayData> data) const { |
nothing calls this directly
no test coverage detected