Skip to content

Commit 68ee7ab

Browse files
committed
Move forward declarations into type_fwd.h
Change-Id: I26ff705a285af0217fc1f9b71e646ebda1111016
1 parent 1edf2a9 commit 68ee7ab

File tree

6 files changed

+168
-75
lines changed

6 files changed

+168
-75
lines changed

cpp/src/arrow/ipc/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ ADD_ARROW_TEST(ipc-metadata-test)
8080
ARROW_TEST_LINK_LIBRARIES(ipc-metadata-test
8181
${ARROW_IPC_TEST_LINK_LIBS})
8282

83+
ADD_ARROW_TEST(ipc-json-test)
84+
ARROW_TEST_LINK_LIBRARIES(ipc-json-test
85+
${ARROW_IPC_TEST_LINK_LIBS})
86+
8387
# make clean will delete the generated file
8488
set_source_files_properties(Metadata_generated.h PROPERTIES GENERATED TRUE)
8589

cpp/src/arrow/ipc/json.cc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,12 @@ class JsonSchemaWriter : public TypeVisitor {
130130
writer_->EndArray();
131131
}
132132

133-
void WriteChildren(const std::vector<std::shared_ptr<Field>>& children) {}
133+
Status WriteChildren(const std::vector<std::shared_ptr<Field>>& children) {
134+
for (const std::shared_ptr<Field>& field : children) {
135+
RETURN_NOT_OK(VisitField(*field.get()));
136+
}
137+
return Status::OK();
138+
}
134139

135140
void SetNoChildren() {
136141
writer_->Key("children");
@@ -238,7 +243,7 @@ class JsonSchemaWriter : public TypeVisitor {
238243

239244
Status Visit(const ListType& type) override {
240245
WriteName(type);
241-
WriteChildren(type.children());
246+
RETURN_NOT_OK(WriteChildren(type.children()));
242247
WriteBufferLayout({kValidityBuffer, kOffsetBuffer});
243248
return Status::OK();
244249
}

cpp/src/arrow/ipc/json.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@
2020
#ifndef ARROW_IPC_JSON_H
2121
#define ARROW_IPC_JSON_H
2222

23-
#include "arrow/type.h"
23+
#include "arrow/type_fwd.h"
2424

2525
namespace arrow {
26-
namespace ipc {} // namespace ipc
26+
namespace ipc {
27+
28+
} // namespace ipc
2729
} // namespace arrow
2830

2931
#endif // ARROW_IPC_FILE_H

cpp/src/arrow/type.h

Lines changed: 1 addition & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -23,67 +23,13 @@
2323
#include <string>
2424
#include <vector>
2525

26+
#include "arrow/type_fwd.h"
2627
#include "arrow/util/macros.h"
2728
#include "arrow/util/status.h"
2829
#include "arrow/util/visibility.h"
2930

3031
namespace arrow {
3132

32-
struct Field;
33-
34-
// Type forward declarations for the TypeVisitor
35-
struct DataType;
36-
struct NullType;
37-
struct BooleanType;
38-
struct Int8Type;
39-
struct Int16Type;
40-
struct Int32Type;
41-
struct Int64Type;
42-
struct UInt8Type;
43-
struct UInt16Type;
44-
struct UInt32Type;
45-
struct UInt64Type;
46-
struct HalfFloatType;
47-
struct FloatType;
48-
struct DoubleType;
49-
struct StringType;
50-
struct BinaryType;
51-
struct DateType;
52-
struct TimeType;
53-
struct TimestampType;
54-
struct DecimalType;
55-
struct ListType;
56-
struct StructType;
57-
struct DenseUnionType;
58-
struct SparseUnionType;
59-
60-
class TypeVisitor {
61-
public:
62-
virtual Status Visit(const NullType& type) = 0;
63-
virtual Status Visit(const BooleanType& type) = 0;
64-
virtual Status Visit(const Int8Type& type) = 0;
65-
virtual Status Visit(const Int16Type& type) = 0;
66-
virtual Status Visit(const Int32Type& type) = 0;
67-
virtual Status Visit(const Int64Type& type) = 0;
68-
virtual Status Visit(const UInt8Type& type) = 0;
69-
virtual Status Visit(const UInt16Type& type) = 0;
70-
virtual Status Visit(const UInt32Type& type) = 0;
71-
virtual Status Visit(const UInt64Type& type) = 0;
72-
virtual Status Visit(const HalfFloatType& type) = 0;
73-
virtual Status Visit(const FloatType& type) = 0;
74-
virtual Status Visit(const DoubleType& type) = 0;
75-
virtual Status Visit(const StringType& type) = 0;
76-
virtual Status Visit(const BinaryType& type) = 0;
77-
virtual Status Visit(const DateType& type) = 0;
78-
virtual Status Visit(const TimeType& type) = 0;
79-
virtual Status Visit(const TimestampType& type) = 0;
80-
virtual Status Visit(const DecimalType& type) = 0;
81-
virtual Status Visit(const ListType& type) = 0;
82-
virtual Status Visit(const StructType& type) = 0;
83-
virtual Status Visit(const DenseUnionType& type) = 0;
84-
virtual Status Visit(const SparseUnionType& type) = 0;
85-
};
86-
8733
// Data types in this library are all *logical*. They can be expressed as
8834
// either a primitive physical type (bytes or bits of some fixed size), a
8935
// nested type consisting of other data types, or another data type (e.g. a

cpp/src/arrow/type_fwd.h

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
#ifndef ARROW_TYPE_FWD_H
19+
#define ARROW_TYPE_FWD_H
20+
21+
namespace arrow {
22+
23+
class Status;
24+
25+
// Type forward declarations for the TypeVisitor
26+
struct DataType;
27+
struct Field;
28+
struct NullType;
29+
struct BooleanType;
30+
struct Int8Type;
31+
struct Int16Type;
32+
struct Int32Type;
33+
struct Int64Type;
34+
struct UInt8Type;
35+
struct UInt16Type;
36+
struct UInt32Type;
37+
struct UInt64Type;
38+
struct HalfFloatType;
39+
struct FloatType;
40+
struct DoubleType;
41+
struct StringType;
42+
struct BinaryType;
43+
struct DateType;
44+
struct TimeType;
45+
struct TimestampType;
46+
struct DecimalType;
47+
struct ListType;
48+
struct StructType;
49+
struct DenseUnionType;
50+
struct SparseUnionType;
51+
52+
class TypeVisitor {
53+
public:
54+
virtual Status Visit(const NullType& type) = 0;
55+
virtual Status Visit(const BooleanType& type) = 0;
56+
virtual Status Visit(const Int8Type& type) = 0;
57+
virtual Status Visit(const Int16Type& type) = 0;
58+
virtual Status Visit(const Int32Type& type) = 0;
59+
virtual Status Visit(const Int64Type& type) = 0;
60+
virtual Status Visit(const UInt8Type& type) = 0;
61+
virtual Status Visit(const UInt16Type& type) = 0;
62+
virtual Status Visit(const UInt32Type& type) = 0;
63+
virtual Status Visit(const UInt64Type& type) = 0;
64+
virtual Status Visit(const HalfFloatType& type) = 0;
65+
virtual Status Visit(const FloatType& type) = 0;
66+
virtual Status Visit(const DoubleType& type) = 0;
67+
virtual Status Visit(const StringType& type) = 0;
68+
virtual Status Visit(const BinaryType& type) = 0;
69+
virtual Status Visit(const DateType& type) = 0;
70+
virtual Status Visit(const TimeType& type) = 0;
71+
virtual Status Visit(const TimestampType& type) = 0;
72+
virtual Status Visit(const DecimalType& type) = 0;
73+
virtual Status Visit(const ListType& type) = 0;
74+
virtual Status Visit(const StructType& type) = 0;
75+
virtual Status Visit(const DenseUnionType& type) = 0;
76+
virtual Status Visit(const SparseUnionType& type) = 0;
77+
};
78+
79+
class NullArray;
80+
class BooleanArray;
81+
class StringArray;
82+
class BinaryArray;
83+
class DecimalArray;
84+
class ListArray;
85+
class StructArray;
86+
class DenseUnionArray;
87+
class SparseUnionArray;
88+
89+
template <typename TypeClass>
90+
class NumericArray;
91+
92+
class DateArray;
93+
class TimeArray;
94+
95+
using HalfFloatArray = NumericArray<HalfFloatType>;
96+
using FloatArray = NumericArray<FloatType>;
97+
using DoubleArray = NumericArray<DoubleType>;
98+
using Int8Array = NumericArray<Int8Type>;
99+
using UInt8Array = NumericArray<UInt8Type>;
100+
using Int16Array = NumericArray<Int16Type>;
101+
using UInt16Array = NumericArray<UInt16Type>;
102+
using Int32Array = NumericArray<Int32Type>;
103+
using UInt32Array = NumericArray<UInt32Type>;
104+
using Int64Array = NumericArray<Int64Type>;
105+
using UInt64Array = NumericArray<UInt64Type>;
106+
using TimestampArray = NumericArray<TimestampType>;
107+
108+
class ArrayVisitor {
109+
public:
110+
virtual Status Visit(const NullArray& array) = 0;
111+
virtual Status Visit(const BooleanArray& array) = 0;
112+
virtual Status Visit(const Int8Array& array) = 0;
113+
virtual Status Visit(const Int16Array& array) = 0;
114+
virtual Status Visit(const Int32Array& array) = 0;
115+
virtual Status Visit(const Int64Array& array) = 0;
116+
virtual Status Visit(const UInt8Array& array) = 0;
117+
virtual Status Visit(const UInt16Array& array) = 0;
118+
virtual Status Visit(const UInt32Array& array) = 0;
119+
virtual Status Visit(const UInt64Array& array) = 0;
120+
virtual Status Visit(const HalfFloatArray& array) = 0;
121+
virtual Status Visit(const FloatArray& array) = 0;
122+
virtual Status Visit(const DoubleArray& array) = 0;
123+
virtual Status Visit(const StringArray& array) = 0;
124+
virtual Status Visit(const BinaryArray& array) = 0;
125+
virtual Status Visit(const DateArray& array) = 0;
126+
virtual Status Visit(const TimeArray& array) = 0;
127+
virtual Status Visit(const TimestampArray& array) = 0;
128+
virtual Status Visit(const DecimalArray& array) = 0;
129+
virtual Status Visit(const ListArray& array) = 0;
130+
virtual Status Visit(const StructArray& array) = 0;
131+
virtual Status Visit(const DenseUnionArray& array) = 0;
132+
virtual Status Visit(const SparseUnionArray& array) = 0;
133+
};
134+
135+
} // namespace arrow
136+
137+
#endif // ARROW_TYPE_FWD_H

cpp/src/arrow/types/primitive.h

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "arrow/array.h"
2727
#include "arrow/builder.h"
2828
#include "arrow/type.h"
29+
#include "arrow/type_fwd.h"
2930
#include "arrow/types/datetime.h"
3031
#include "arrow/util/bit-util.h"
3132
#include "arrow/util/buffer.h"
@@ -91,22 +92,6 @@ class ARROW_EXPORT NumericArray : public PrimitiveArray {
9192
value_type Value(int i) const { return raw_data()[i]; }
9293
};
9394

94-
#define NUMERIC_ARRAY_DECL(NAME, TypeClass) \
95-
using NAME = NumericArray<TypeClass>; \
96-
extern template class ARROW_EXPORT NumericArray<TypeClass>;
97-
98-
NUMERIC_ARRAY_DECL(UInt8Array, UInt8Type);
99-
NUMERIC_ARRAY_DECL(Int8Array, Int8Type);
100-
NUMERIC_ARRAY_DECL(UInt16Array, UInt16Type);
101-
NUMERIC_ARRAY_DECL(Int16Array, Int16Type);
102-
NUMERIC_ARRAY_DECL(UInt32Array, UInt32Type);
103-
NUMERIC_ARRAY_DECL(Int32Array, Int32Type);
104-
NUMERIC_ARRAY_DECL(UInt64Array, UInt64Type);
105-
NUMERIC_ARRAY_DECL(Int64Array, Int64Type);
106-
NUMERIC_ARRAY_DECL(TimestampArray, TimestampType);
107-
NUMERIC_ARRAY_DECL(FloatArray, FloatType);
108-
NUMERIC_ARRAY_DECL(DoubleArray, DoubleType);
109-
11095
template <typename Type>
11196
class ARROW_EXPORT PrimitiveBuilder : public ArrayBuilder {
11297
public:
@@ -327,6 +312,20 @@ class ARROW_EXPORT BooleanBuilder : public PrimitiveBuilder<BooleanType> {
327312
Status Append(uint8_t val) { return Append(static_cast<bool>(val)); }
328313
};
329314

315+
// Only instantiate these templates once
316+
extern template class ARROW_EXPORT NumericArray<Int8Type>;
317+
extern template class ARROW_EXPORT NumericArray<UInt8Type>;
318+
extern template class ARROW_EXPORT NumericArray<Int16Type>;
319+
extern template class ARROW_EXPORT NumericArray<UInt16Type>;
320+
extern template class ARROW_EXPORT NumericArray<Int32Type>;
321+
extern template class ARROW_EXPORT NumericArray<UInt32Type>;
322+
extern template class ARROW_EXPORT NumericArray<Int64Type>;
323+
extern template class ARROW_EXPORT NumericArray<UInt64Type>;
324+
extern template class ARROW_EXPORT NumericArray<HalfFloatType>;
325+
extern template class ARROW_EXPORT NumericArray<FloatType>;
326+
extern template class ARROW_EXPORT NumericArray<DoubleType>;
327+
extern template class ARROW_EXPORT NumericArray<TimestampType>;
328+
330329
} // namespace arrow
331330

332331
#endif // ARROW_TYPES_PRIMITIVE_H

0 commit comments

Comments
 (0)