Skip to content

Commit fbed20a

Browse files
authored
GH-46439: [C++] Rename internal Converter class in from_string.cc (#46697)
### Rationale for this change In #45908 we moved the Converter class in from_string.cc to the internal namespace to avoid a symbol clash with the Converter class defined in arrow/util. It's better to keep the class in an anonymous namespace since it's internal to the file. This reverts the previous change and just renames the class. ### What changes are included in this PR? - Removed namespace, use anonymous namespace instead like before - Renamed from Converter to JSONConverter ### Are these changes tested? Yes. ### Are there any user-facing changes? No. These changes are internal-only. * GitHub Issue: #46439 Authored-by: Bryce Mecum <[email protected]> Signed-off-by: Sutou Kouhei <[email protected]>
1 parent 58b8a6f commit fbed20a

File tree

1 file changed

+22
-21
lines changed

1 file changed

+22
-21
lines changed

cpp/src/arrow/json/from_string.cc

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ namespace json {
6060
using ::arrow::internal::checked_cast;
6161
using ::arrow::internal::checked_pointer_cast;
6262

63-
namespace internal {
63+
namespace {
6464

6565
constexpr auto kParseFlags = rj::kParseFullPrecisionFlag | rj::kParseNanAndInfFlag;
6666

@@ -90,9 +90,9 @@ Status JSONTypeError(const char* expected_type, rj::Type json_type) {
9090
JsonTypeName(json_type));
9191
}
9292

93-
class Converter {
93+
class JSONConverter {
9494
public:
95-
virtual ~Converter() = default;
95+
virtual ~JSONConverter() = default;
9696

9797
virtual Status Init() { return Status::OK(); }
9898

@@ -117,11 +117,12 @@ class Converter {
117117
std::shared_ptr<DataType> type_;
118118
};
119119

120-
Status GetConverter(const std::shared_ptr<DataType>&, std::shared_ptr<Converter>* out);
120+
Status GetConverter(const std::shared_ptr<DataType>&,
121+
std::shared_ptr<JSONConverter>* out);
121122

122123
// CRTP
123124
template <class Derived>
124-
class ConcreteConverter : public Converter {
125+
class ConcreteConverter : public JSONConverter {
125126
public:
126127
Result<int64_t> SizeOfJSONArray(const rj::Value& json_obj) {
127128
if (!json_obj.IsArray()) {
@@ -601,7 +602,7 @@ class VarLengthListLikeConverter final
601602

602603
private:
603604
std::shared_ptr<BuilderType> builder_;
604-
std::shared_ptr<Converter> child_converter_;
605+
std::shared_ptr<JSONConverter> child_converter_;
605606
};
606607

607608
// ------------------------------------------------------------------------
@@ -653,7 +654,7 @@ class MapConverter final : public ConcreteConverter<MapConverter> {
653654

654655
private:
655656
std::shared_ptr<MapBuilder> builder_;
656-
std::shared_ptr<Converter> key_converter_, item_converter_;
657+
std::shared_ptr<JSONConverter> key_converter_, item_converter_;
657658
};
658659

659660
// ------------------------------------------------------------------------
@@ -691,7 +692,7 @@ class FixedSizeListConverter final : public ConcreteConverter<FixedSizeListConve
691692
private:
692693
int32_t list_size_;
693694
std::shared_ptr<FixedSizeListBuilder> builder_;
694-
std::shared_ptr<Converter> child_converter_;
695+
std::shared_ptr<JSONConverter> child_converter_;
695696
};
696697

697698
// ------------------------------------------------------------------------
@@ -704,7 +705,7 @@ class StructConverter final : public ConcreteConverter<StructConverter> {
704705
Status Init() override {
705706
std::vector<std::shared_ptr<ArrayBuilder>> child_builders;
706707
for (const auto& field : type_->fields()) {
707-
std::shared_ptr<Converter> child_converter;
708+
std::shared_ptr<JSONConverter> child_converter;
708709
RETURN_NOT_OK(GetConverter(field->type(), &child_converter));
709710
child_converters_.push_back(child_converter);
710711
child_builders.push_back(child_converter->builder());
@@ -762,7 +763,7 @@ class StructConverter final : public ConcreteConverter<StructConverter> {
762763

763764
private:
764765
std::shared_ptr<StructBuilder> builder_;
765-
std::vector<std::shared_ptr<Converter>> child_converters_;
766+
std::vector<std::shared_ptr<JSONConverter>> child_converters_;
766767
};
767768

768769
// ------------------------------------------------------------------------
@@ -783,7 +784,7 @@ class UnionConverter final : public ConcreteConverter<UnionConverter> {
783784
}
784785
std::vector<std::shared_ptr<ArrayBuilder>> child_builders;
785786
for (const auto& field : type_->fields()) {
786-
std::shared_ptr<Converter> child_converter;
787+
std::shared_ptr<JSONConverter> child_converter;
787788
RETURN_NOT_OK(GetConverter(field->type(), &child_converter));
788789
child_converters_.push_back(child_converter);
789790
child_builders.push_back(child_converter->builder());
@@ -841,7 +842,7 @@ class UnionConverter final : public ConcreteConverter<UnionConverter> {
841842
private:
842843
UnionMode::type mode_;
843844
std::shared_ptr<ArrayBuilder> builder_;
844-
std::vector<std::shared_ptr<Converter>> child_converters_;
845+
std::vector<std::shared_ptr<JSONConverter>> child_converters_;
845846
std::vector<int8_t> type_id_to_child_num_;
846847
};
847848

@@ -854,8 +855,8 @@ Status ConversionNotImplemented(const std::shared_ptr<DataType>& type) {
854855
}
855856

856857
Status GetDictConverter(const std::shared_ptr<DataType>& type,
857-
std::shared_ptr<Converter>* out) {
858-
std::shared_ptr<Converter> res;
858+
std::shared_ptr<JSONConverter>* out) {
859+
std::shared_ptr<JSONConverter> res;
859860

860861
const auto value_type = checked_cast<const DictionaryType&>(*type).value_type();
861862

@@ -905,12 +906,12 @@ Status GetDictConverter(const std::shared_ptr<DataType>& type,
905906
}
906907

907908
Status GetConverter(const std::shared_ptr<DataType>& type,
908-
std::shared_ptr<Converter>* out) {
909+
std::shared_ptr<JSONConverter>* out) {
909910
if (type->id() == Type::DICTIONARY) {
910911
return GetDictConverter(type, out);
911912
}
912913

913-
std::shared_ptr<Converter> res;
914+
std::shared_ptr<JSONConverter> res;
914915

915916
#define SIMPLE_CONVERTER_CASE(ID, CLASS) \
916917
case ID: \
@@ -972,15 +973,15 @@ Status GetConverter(const std::shared_ptr<DataType>& type,
972973
return Status::OK();
973974
}
974975

975-
} // namespace internal
976+
} // namespace
976977

977978
Result<std::shared_ptr<Array>> ArrayFromJSONString(const std::shared_ptr<DataType>& type,
978979
std::string_view json_string) {
979-
std::shared_ptr<internal::Converter> converter;
980+
std::shared_ptr<JSONConverter> converter;
980981
RETURN_NOT_OK(GetConverter(type, &converter));
981982

982983
rj::Document json_doc;
983-
json_doc.Parse<internal::kParseFlags>(json_string.data(), json_string.length());
984+
json_doc.Parse<kParseFlags>(json_string.data(), json_string.length());
984985
if (json_doc.HasParseError()) {
985986
return Status::Invalid("JSON parse error at offset ", json_doc.GetErrorOffset(), ": ",
986987
GetParseError_En(json_doc.GetParseError()));
@@ -1037,11 +1038,11 @@ Status DictArrayFromJSONString(const std::shared_ptr<DataType>& type,
10371038

10381039
Status ScalarFromJSONString(const std::shared_ptr<DataType>& type,
10391040
std::string_view json_string, std::shared_ptr<Scalar>* out) {
1040-
std::shared_ptr<internal::Converter> converter;
1041+
std::shared_ptr<JSONConverter> converter;
10411042
RETURN_NOT_OK(GetConverter(type, &converter));
10421043

10431044
rj::Document json_doc;
1044-
json_doc.Parse<internal::kParseFlags>(json_string.data(), json_string.length());
1045+
json_doc.Parse<kParseFlags>(json_string.data(), json_string.length());
10451046
if (json_doc.HasParseError()) {
10461047
return Status::Invalid("JSON parse error at offset ", json_doc.GetErrorOffset(), ": ",
10471048
GetParseError_En(json_doc.GetParseError()));

0 commit comments

Comments
 (0)