Skip to content

Commit 25b351f

Browse files
authored
GH-47887: [C++][Integration] Enable extension types with C Data Interface tests (#47888)
### Rationale for this change Extension type tests were skipped in the C Data Interface tests. ### What changes are included in this PR? * Move C Data Integration testing entrypoints into a dedicated DLL, and make them link to the `arrow_testing` library * Register the required extension types in those entrypoints * Remove the associated skip in the Archery integration testing harness ### Are these changes tested? Yes. ### Are there any user-facing changes? No. * GitHub Issue: #47887 Authored-by: Antoine Pitrou <[email protected]> Signed-off-by: Antoine Pitrou <[email protected]>
1 parent c72572e commit 25b351f

File tree

5 files changed

+34
-14
lines changed

5 files changed

+34
-14
lines changed

cpp/src/arrow/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -679,8 +679,8 @@ set(ARROW_TESTING_SRCS
679679
#
680680

681681
if(ARROW_BUILD_INTEGRATION OR ARROW_BUILD_TESTS)
682-
arrow_add_object_library(ARROW_INTEGRATION integration/c_data_integration_internal.cc
683-
integration/json_integration.cc integration/json_internal.cc)
682+
arrow_add_object_library(ARROW_INTEGRATION integration/json_integration.cc
683+
integration/json_internal.cc)
684684
foreach(ARROW_INTEGRATION_TARGET ${ARROW_INTEGRATION_TARGETS})
685685
target_link_libraries(${ARROW_INTEGRATION_TARGET} PRIVATE RapidJSON)
686686
endforeach()

cpp/src/arrow/integration/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,12 @@ elseif(ARROW_BUILD_INTEGRATION)
3333

3434
add_dependencies(arrow-json-integration-test arrow arrow_testing)
3535
add_dependencies(arrow-integration arrow-json-integration-test)
36+
37+
add_arrow_lib(arrow_c_data_integration
38+
SOURCES
39+
c_data_integration_internal.cc
40+
SHARED_LINK_LIBS
41+
arrow_testing_shared
42+
STATIC_LINK_LIBS
43+
arrow_testing_static)
3644
endif()

cpp/src/arrow/integration/c_data_integration_internal.cc

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,19 @@
2828
#include "arrow/record_batch.h"
2929
#include "arrow/result.h"
3030
#include "arrow/status.h"
31+
#include "arrow/testing/extension_type.h"
3132
#include "arrow/type.h"
3233
#include "arrow/type_fwd.h"
3334
#include "arrow/util/logging.h"
3435

3536
namespace arrow::internal::integration {
3637
namespace {
3738

39+
// Make sure the extension types referenced in test data are registered.
40+
[[nodiscard]] auto RequireExtensionTypes() {
41+
return ExtensionTypeGuard({uuid(), dict_extension_type()});
42+
}
43+
3844
template <typename Func>
3945
const char* StatusToErrorString(Func&& func) {
4046
static std::string error;
@@ -113,30 +119,39 @@ Status ImportBatchAndCompareToJson(std::string json_path, int num_batch,
113119
const char* ArrowCpp_CDataIntegration_ExportSchemaFromJson(const char* json_path,
114120
ArrowSchema* out) {
115121
using namespace arrow::internal::integration; // NOLINT(build/namespaces)
116-
return StatusToErrorString([=]() { return ExportSchemaFromJson(json_path, out); });
122+
return StatusToErrorString([=]() {
123+
auto guard = RequireExtensionTypes();
124+
return ExportSchemaFromJson(json_path, out);
125+
});
117126
}
118127

119128
const char* ArrowCpp_CDataIntegration_ImportSchemaAndCompareToJson(const char* json_path,
120129
ArrowSchema* schema) {
121130
using namespace arrow::internal::integration; // NOLINT(build/namespaces)
122-
return StatusToErrorString(
123-
[=]() { return ImportSchemaAndCompareToJson(json_path, schema); });
131+
return StatusToErrorString([=]() {
132+
auto guard = RequireExtensionTypes();
133+
return ImportSchemaAndCompareToJson(json_path, schema);
134+
});
124135
}
125136

126137
const char* ArrowCpp_CDataIntegration_ExportBatchFromJson(const char* json_path,
127138
int num_batch,
128139
ArrowArray* out) {
129140
using namespace arrow::internal::integration; // NOLINT(build/namespaces)
130-
return StatusToErrorString(
131-
[=]() { return ExportBatchFromJson(json_path, num_batch, out); });
141+
return StatusToErrorString([=]() {
142+
auto guard = RequireExtensionTypes();
143+
return ExportBatchFromJson(json_path, num_batch, out);
144+
});
132145
}
133146

134147
const char* ArrowCpp_CDataIntegration_ImportBatchAndCompareToJson(const char* json_path,
135148
int num_batch,
136149
ArrowArray* batch) {
137150
using namespace arrow::internal::integration; // NOLINT(build/namespaces)
138-
return StatusToErrorString(
139-
[=]() { return ImportBatchAndCompareToJson(json_path, num_batch, batch); });
151+
return StatusToErrorString([=]() {
152+
auto guard = RequireExtensionTypes();
153+
return ImportBatchAndCompareToJson(json_path, num_batch, batch);
154+
});
140155
}
141156

142157
int64_t ArrowCpp_BytesAllocated() {

dev/archery/archery/integration/datagen.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
import numpy as np
2929

3030
from .util import frombytes, tobytes, random_bytes, random_utf8
31-
from .util import SKIP_C_SCHEMA, SKIP_C_ARRAY, SKIP_FLIGHT
31+
from .util import SKIP_C_SCHEMA, SKIP_FLIGHT
3232

3333

3434
def metadata_key_values(pairs):
@@ -2017,9 +2017,6 @@ def get_generated_json_files(tempdir=None):
20172017

20182018
generate_extension_case()
20192019
.skip_tester('nanoarrow')
2020-
# TODO: ensure the extension is registered in the C++ entrypoint
2021-
.skip_format(SKIP_C_SCHEMA, 'C++')
2022-
.skip_format(SKIP_C_ARRAY, 'C++')
20232020
# TODO(https://github.com/apache/arrow/issues/38045)
20242021
.skip_format(SKIP_FLIGHT, '.NET'),
20252022
]

dev/archery/archery/integration/tester_cpp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
]
4343

4444
_DLL_PATH = _EXE_PATH
45-
_ARROW_DLL = os.path.join(_DLL_PATH, "libarrow" + cdata.dll_suffix)
45+
_ARROW_DLL = os.path.join(_DLL_PATH, "libarrow_c_data_integration" + cdata.dll_suffix)
4646

4747

4848
class CppTester(Tester):

0 commit comments

Comments
 (0)