Skip to content

Commit 06e3b9a

Browse files
authored
GH-50859: [C++][Parquet] Move JsonWriter to simdjson utilities (#50990)
### Rationale for this change Parquet uses JsonWriter when ARROW_JSON=OFF, but its implementation was only built with Arrow JSON, causing link failures. ### What changes are included in this PR? Move JsonWriter to the simdjson utilities and update its callers and CMake/Meson builds. ### Are these changes tested? Yes. CMake shared/static and Meson Parquet builds pass with JSON disabled. Unit tests and pre-commit checks also pass. ### Are there any user-facing changes? No. This only fixes the affected build configuration. AI disclosure - this was AI generated to test alternative approach to #50900. * GitHub Issue: #50859 Authored-by: Rok Mihevc <[email protected]> Signed-off-by: Antoine Pitrou <[email protected]>
1 parent e9ec94b commit 06e3b9a

34 files changed

Lines changed: 869 additions & 966 deletions

‎cpp/cmake_modules/DefineOptions.cmake‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -599,8 +599,7 @@ takes precedence over ccache if a storage backend is configured" ON)
599599
"Build support for encryption. Fail if OpenSSL is not found"
600600
OFF
601601
DEPENDS
602-
ARROW_FILESYSTEM
603-
ARROW_JSON)
602+
ARROW_FILESYSTEM)
604603

605604
#----------------------------------------------------------------------
606605
set_option_category("Gandiva")

‎cpp/cmake_modules/ThirdpartyToolchain.cmake‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,6 @@ if(ARROW_WITH_OPENTELEMETRY)
383383
endif()
384384

385385
if(ARROW_PARQUET)
386-
set(ARROW_WITH_RAPIDJSON ON)
387386
set(ARROW_WITH_SIMDJSON ON)
388387
set(ARROW_WITH_THRIFT ON)
389388
endif()
@@ -411,11 +410,11 @@ if(ARROW_AZURE)
411410
set(ARROW_WITH_AZURE_SDK ON)
412411
endif()
413412

414-
if(ARROW_JSON OR ARROW_FLIGHT_SQL_ODBC)
413+
if(ARROW_JSON)
415414
set(ARROW_WITH_RAPIDJSON ON)
416415
endif()
417416

418-
if(ARROW_JSON)
417+
if(ARROW_JSON OR ARROW_FLIGHT_SQL_ODBC)
419418
set(ARROW_WITH_SIMDJSON ON)
420419
endif()
421420

‎cpp/meson.build‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ needs_testing = (get_option('testing').enabled()
104104
or needs_integration
105105
)
106106
needs_json = get_option('json').enabled() or needs_testing
107+
needs_simdjson = needs_json or needs_parquet
107108
needs_brotli = get_option('brotli').enabled() or needs_fuzzing
108109
needs_bz2 = get_option('bz2').enabled()
109110
needs_lz4 = get_option('lz4').enabled()

‎cpp/src/arrow/CMakeLists.txt‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,9 @@ endif()
644644
if(ARROW_WITH_OPENTELEMETRY)
645645
list(APPEND ARROW_UTIL_SRCS util/tracing_internal.cc)
646646
endif()
647+
if(ARROW_WITH_SIMDJSON)
648+
list(APPEND ARROW_UTIL_SRCS util/simdjson_internal.cc)
649+
endif()
647650
if(ARROW_WITH_SNAPPY)
648651
list(APPEND ARROW_UTIL_SRCS util/compression_snappy.cc)
649652
endif()
@@ -664,6 +667,12 @@ foreach(ARROW_UTIL_TARGET ${ARROW_UTIL_TARGETS})
664667
target_link_libraries(${ARROW_UTIL_TARGET} PRIVATE ${ARROW_XSIMD})
665668
endforeach()
666669

670+
if(ARROW_WITH_SIMDJSON)
671+
foreach(ARROW_UTIL_TARGET ${ARROW_UTIL_TARGETS})
672+
target_link_libraries(${ARROW_UTIL_TARGET} PRIVATE arrow::simdjson)
673+
endforeach()
674+
endif()
675+
667676
if(ARROW_USE_BOOST)
668677
foreach(ARROW_UTIL_TARGET ${ARROW_UTIL_TARGETS})
669678
target_link_libraries(${ARROW_UTIL_TARGET} PRIVATE Boost::headers)
@@ -1088,8 +1097,6 @@ if(ARROW_JSON)
10881097
json/chunker.cc
10891098
json/converter.cc
10901099
json/from_string.cc
1091-
json/json_writer_internal.cc
1092-
json/object_parser.cc
10931100
json/parser.cc
10941101
json/reader.cc)
10951102
foreach(ARROW_JSON_TARGET ${ARROW_JSON_TARGETS})

‎cpp/src/arrow/dataset/file_json_test.cc‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@
2020
#include "arrow/dataset/plan.h"
2121
#include "arrow/dataset/test_util_internal.h"
2222
#include "arrow/filesystem/mockfs.h"
23-
#include "arrow/json/json_writer_internal.h"
2423
#include "arrow/json/parser.h"
2524
#include "arrow/testing/gtest_util.h"
2625
#include "arrow/testing/util.h"
2726
#include "arrow/util/logging_internal.h"
27+
#include "arrow/util/simdjson_internal.h"
2828

2929
namespace arrow {
3030

@@ -104,11 +104,11 @@ struct WriteVisitor {
104104
return Status::OK();
105105
}
106106

107-
json::JsonWriter& writer_;
107+
::arrow::internal::JsonWriter& writer_;
108108
const Scalar& scalar_;
109109
};
110110

111-
Status WriteJson(const StructScalar& scalar, json::JsonWriter* writer) {
111+
Status WriteJson(const StructScalar& scalar, ::arrow::internal::JsonWriter* writer) {
112112
WriteVisitor visitor{*writer, scalar};
113113
return VisitWriteableTypeId(Type::STRUCT, &visitor);
114114
}
@@ -122,7 +122,7 @@ class JsonFormatHelper {
122122
std::stringstream ss;
123123

124124
for (const auto& scalar : scalars) {
125-
json::JsonWriter writer;
125+
::arrow::internal::JsonWriter writer;
126126
RETURN_NOT_OK(WriteJson(*scalar, &writer));
127127

128128
ARROW_ASSIGN_OR_RAISE(auto json, writer.GetString());

‎cpp/src/arrow/extension/fixed_shape_tensor.cc‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,14 @@
2727

2828
#include "arrow/array/array_nested.h"
2929
#include "arrow/array/array_primitive.h"
30-
#include "arrow/json/json_writer_internal.h"
3130
#include "arrow/tensor.h"
3231
#include "arrow/util/logging_internal.h"
3332
#include "arrow/util/print_internal.h"
3433
#include "arrow/util/simdjson_internal.h"
3534
#include "arrow/util/sort_internal.h"
3635
#include "arrow/util/string.h"
3736

38-
using ::arrow::json::JsonWriter;
37+
using ::arrow::internal::JsonWriter;
3938

4039
namespace arrow::extension {
4140

‎cpp/src/arrow/extension/opaque.cc‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,12 @@
1919

2020
#include <sstream>
2121

22-
#include "arrow/json/json_writer_internal.h"
2322
#include "arrow/util/logging_internal.h"
2423
#include "arrow/util/simdjson_internal.h"
2524

2625
#include <simdjson.h>
2726

28-
using ::arrow::json::JsonWriter;
27+
using ::arrow::internal::JsonWriter;
2928

3029
namespace arrow::extension {
3130

‎cpp/src/arrow/extension/variable_shape_tensor.cc‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
#include "arrow/extension/variable_shape_tensor.h"
2424

2525
#include "arrow/array/array_primitive.h"
26-
#include "arrow/json/json_writer_internal.h"
2726
#include "arrow/scalar.h"
2827
#include "arrow/tensor.h"
2928
#include "arrow/util/logging_internal.h"
@@ -32,7 +31,7 @@
3231
#include "arrow/util/sort_internal.h"
3332
#include "arrow/util/string.h"
3433

35-
using ::arrow::json::JsonWriter;
34+
using ::arrow::internal::JsonWriter;
3635

3736
namespace arrow::extension {
3837

‎cpp/src/arrow/flight/sql/odbc/odbc_impl/json_converter.cc‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
#include <boost/beast/core/detail/base64.hpp>
2121
#include "arrow/builder.h"
2222
#include "arrow/flight/sql/odbc/odbc_impl/util.h"
23-
#include "arrow/json/json_writer_internal.h"
2423
#include "arrow/scalar.h"
24+
#include "arrow/util/simdjson_internal.h"
2525
#include "arrow/visitor.h"
2626

2727
using boost::beast::detail::base64::encode;
@@ -30,7 +30,7 @@ namespace base64 = boost::beast::detail::base64;
3030

3131
namespace arrow::flight::sql::odbc {
3232

33-
using ::arrow::json::JsonWriter;
33+
using ::arrow::internal::JsonWriter;
3434
using util::ThrowIfNotOK;
3535

3636
namespace {

‎cpp/src/arrow/integration/json_integration.cc‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
#include "arrow/integration/json_internal.h"
3030
#include "arrow/io/file.h"
3131
#include "arrow/ipc/dictionary.h"
32-
#include "arrow/json/json_writer_internal.h"
3332
#include "arrow/record_batch.h"
3433
#include "arrow/result.h"
3534
#include "arrow/status.h"
@@ -40,7 +39,7 @@
4039
using arrow::ipc::DictionaryFieldMapper;
4140
using arrow::ipc::DictionaryMemo;
4241

43-
using JsonWriter = arrow::json::JsonWriter;
42+
using JsonWriter = arrow::internal::JsonWriter;
4443

4544
namespace arrow::internal::integration {
4645

0 commit comments

Comments
 (0)