@@ -40,36 +40,28 @@ int32_t BinaryArray::GetElementOffset(int32_t ordinal, int32_t element_size) con
4040}
4141
4242void BinaryArray::PointTo (const MemorySegment& segment, int32_t offset, int32_t size_in_bytes) {
43- std::vector<MemorySegment> segments = {segment};
44- PointTo (segments, offset, size_in_bytes);
45- }
46-
47- void BinaryArray::PointTo (const std::vector<MemorySegment>& segments, int32_t offset,
48- int32_t size_in_bytes) {
49- // Read the number of elements from the first 4 bytes.
50- auto size = MemorySegmentUtils::GetValue<int32_t >(segments, offset);
43+ auto size = MemorySegmentUtils::GetValue<int32_t >({segment}, offset);
5144 assert (size >= 0 );
52-
5345 size_ = size;
54- segments_ = segments ;
46+ segment_ = segment ;
5547 offset_ = offset;
5648 size_in_bytes_ = size_in_bytes;
5749 element_offset_ = offset_ + CalculateHeaderInBytes (size_);
5850}
5951
6052bool BinaryArray::IsNullAt (int32_t pos) const {
6153 AssertIndexIsValid (pos);
62- return MemorySegmentUtils::BitGet (segments_ , offset_ + 4 , pos);
54+ return MemorySegmentUtils::BitGet ({segment_} , offset_ + 4 , pos);
6355}
6456
6557int64_t BinaryArray::GetLong (int32_t pos) const {
6658 AssertIndexIsValid (pos);
67- return MemorySegmentUtils::GetValue<int64_t >(segments_ , GetElementOffset (pos, 8 ));
59+ return MemorySegmentUtils::GetValue<int64_t >({segment_} , GetElementOffset (pos, 8 ));
6860}
6961
7062int32_t BinaryArray::GetInt (int32_t pos) const {
7163 AssertIndexIsValid (pos);
72- return MemorySegmentUtils::GetValue<int32_t >(segments_ , GetElementOffset (pos, 4 ));
64+ return MemorySegmentUtils::GetValue<int32_t >({segment_} , GetElementOffset (pos, 4 ));
7365}
7466int32_t BinaryArray::GetDate (int32_t pos) const {
7567 return GetInt (pos);
@@ -78,90 +70,96 @@ int32_t BinaryArray::GetDate(int32_t pos) const {
7870BinaryString BinaryArray::GetString (int32_t pos) const {
7971 AssertIndexIsValid (pos);
8072 int32_t field_offset = GetElementOffset (pos, 8 );
81- const auto offset_and_size = MemorySegmentUtils::GetValue<int64_t >(segments_, field_offset);
82- return BinaryDataReadUtils::ReadBinaryString (segments_, offset_, field_offset, offset_and_size);
73+ const auto offset_and_size = MemorySegmentUtils::GetValue<int64_t >({segment_}, field_offset);
74+ return BinaryDataReadUtils::ReadBinaryString (segment_, offset_, field_offset, offset_and_size);
75+ }
76+
77+ std::string_view BinaryArray::GetStringView (int32_t pos) const {
78+ BinaryString binary_string = GetString (pos);
79+ return binary_string.GetStringView ();
8380}
8481
8582Decimal BinaryArray::GetDecimal (int32_t pos, int32_t precision, int32_t scale) const {
8683 AssertIndexIsValid (pos);
8784 if (Decimal::IsCompact (precision)) {
8885 return Decimal::FromUnscaledLong (
89- MemorySegmentUtils::GetValue<int64_t >(segments_ , GetElementOffset (pos, 8 )), precision,
86+ MemorySegmentUtils::GetValue<int64_t >({segment_} , GetElementOffset (pos, 8 )), precision,
9087 scale);
9188 }
9289
9390 int32_t field_offset = GetElementOffset (pos, 8 );
94- const auto offset_and_size = MemorySegmentUtils::GetValue<int64_t >(segments_ , field_offset);
95- return BinaryDataReadUtils::ReadDecimal (segments_ , offset_, offset_and_size, precision, scale);
91+ const auto offset_and_size = MemorySegmentUtils::GetValue<int64_t >({segment_} , field_offset);
92+ return BinaryDataReadUtils::ReadDecimal (segment_ , offset_, offset_and_size, precision, scale);
9693}
9794
9895Timestamp BinaryArray::GetTimestamp (int32_t pos, int32_t precision) const {
9996 AssertIndexIsValid (pos);
10097
10198 if (Timestamp::IsCompact (precision)) {
10299 return Timestamp::FromEpochMillis (
103- MemorySegmentUtils::GetValue<int64_t >(segments_ , GetElementOffset (pos, 8 )));
100+ MemorySegmentUtils::GetValue<int64_t >({segment_} , GetElementOffset (pos, 8 )));
104101 }
105102
106103 int32_t field_offset = GetElementOffset (pos, 8 );
107104 const auto offset_and_nano_of_milli =
108- MemorySegmentUtils::GetValue<int64_t >(segments_ , field_offset);
109- return BinaryDataReadUtils::ReadTimestampData (segments_ , offset_, offset_and_nano_of_milli);
105+ MemorySegmentUtils::GetValue<int64_t >({segment_} , field_offset);
106+ return BinaryDataReadUtils::ReadTimestampData (segment_ , offset_, offset_and_nano_of_milli);
110107}
111108
112109std::shared_ptr<Bytes> BinaryArray::GetBinary (int32_t pos) const {
113110 AssertIndexIsValid (pos);
114111 int32_t field_offset = GetElementOffset (pos, 8 );
115- const auto offset_and_size = MemorySegmentUtils::GetValue<int64_t >(segments_ , field_offset);
116- return BinarySection::ReadBinary (segments_ , offset_, field_offset, offset_and_size,
112+ const auto offset_and_size = MemorySegmentUtils::GetValue<int64_t >({segment_} , field_offset);
113+ return BinarySection::ReadBinary (segment_ , offset_, field_offset, offset_and_size,
117114 GetDefaultPool ().get ());
118115}
119116
120117std::shared_ptr<InternalArray> BinaryArray::GetArray (int32_t pos) const {
121118 AssertIndexIsValid (pos);
122- return BinaryDataReadUtils::ReadArrayData (segments_ , offset_, GetLong (pos));
119+ return BinaryDataReadUtils::ReadArrayData (segment_ , offset_, GetLong (pos));
123120}
124121
125122std::shared_ptr<InternalMap> BinaryArray::GetMap (int32_t pos) const {
126123 AssertIndexIsValid (pos);
127- return BinaryDataReadUtils::ReadMapData (segments_ , offset_, GetLong (pos));
124+ return BinaryDataReadUtils::ReadMapData (segment_ , offset_, GetLong (pos));
128125}
129126
130127std::shared_ptr<InternalRow> BinaryArray::GetRow (int32_t pos, int32_t num_fields) const {
131128 AssertIndexIsValid (pos);
132129 int32_t field_offset = GetElementOffset (pos, 8 );
133- const auto offset_and_size = MemorySegmentUtils::GetValue<int64_t >(segments_ , field_offset);
134- return BinaryDataReadUtils::ReadRowData (segments_ , num_fields, offset_, offset_and_size);
130+ const auto offset_and_size = MemorySegmentUtils::GetValue<int64_t >({segment_} , field_offset);
131+ return BinaryDataReadUtils::ReadRowData (segment_ , num_fields, offset_, offset_and_size);
135132}
136133
137134bool BinaryArray::GetBoolean (int32_t pos) const {
138135 AssertIndexIsValid (pos);
139- return MemorySegmentUtils::GetValue<bool >(segments_ , GetElementOffset (pos, 1 ));
136+ return MemorySegmentUtils::GetValue<bool >({segment_} , GetElementOffset (pos, 1 ));
140137}
141138
142139char BinaryArray::GetByte (int32_t pos) const {
143140 AssertIndexIsValid (pos);
144- return MemorySegmentUtils::GetValue<char >(segments_ , GetElementOffset (pos, 1 ));
141+ return MemorySegmentUtils::GetValue<char >({segment_} , GetElementOffset (pos, 1 ));
145142}
146143
147144int16_t BinaryArray::GetShort (int32_t pos) const {
148145 AssertIndexIsValid (pos);
149- return MemorySegmentUtils::GetValue<int16_t >(segments_, GetElementOffset (pos, sizeof (int16_t )));
146+ return MemorySegmentUtils::GetValue<int16_t >({segment_},
147+ GetElementOffset (pos, sizeof (int16_t )));
150148}
151149
152150float BinaryArray::GetFloat (int32_t pos) const {
153151 AssertIndexIsValid (pos);
154- return MemorySegmentUtils::GetValue<float >(segments_ , GetElementOffset (pos, sizeof (float )));
152+ return MemorySegmentUtils::GetValue<float >({segment_} , GetElementOffset (pos, sizeof (float )));
155153}
156154
157155double BinaryArray::GetDouble (int32_t pos) const {
158156 AssertIndexIsValid (pos);
159- return MemorySegmentUtils::GetValue<double >(segments_ , GetElementOffset (pos, sizeof (double )));
157+ return MemorySegmentUtils::GetValue<double >({segment_} , GetElementOffset (pos, sizeof (double )));
160158}
161159
162160bool BinaryArray::AnyNull () const {
163161 for (int32_t i = offset_ + 4 ; i < element_offset_; i += 4 ) {
164- if (MemorySegmentUtils::GetValue<int32_t >(segments_ , i) != 0 ) {
162+ if (MemorySegmentUtils::GetValue<int32_t >({segment_} , i) != 0 ) {
165163 return true ;
166164 }
167165 }
@@ -172,7 +170,7 @@ Result<std::vector<char>> BinaryArray::ToBooleanArray() const {
172170 PAIMON_RETURN_NOT_OK (CheckNoNull ());
173171 std::vector<char > values;
174172 values.resize (size_);
175- MemorySegmentUtils::CopyToUnsafe (segments_ , element_offset_,
173+ MemorySegmentUtils::CopyToUnsafe ({segment_} , element_offset_,
176174 const_cast <void *>(static_cast <const void *>(values.data ())),
177175 size_);
178176 return values;
@@ -182,7 +180,7 @@ Result<std::vector<char>> BinaryArray::ToByteArray() const {
182180 PAIMON_RETURN_NOT_OK (CheckNoNull ());
183181 std::vector<char > values;
184182 values.resize (size_);
185- MemorySegmentUtils::CopyToUnsafe (segments_ , element_offset_,
183+ MemorySegmentUtils::CopyToUnsafe ({segment_} , element_offset_,
186184 const_cast <void *>(static_cast <const void *>(values.data ())),
187185 size_);
188186 return values;
@@ -192,7 +190,7 @@ Result<std::vector<int16_t>> BinaryArray::ToShortArray() const {
192190 PAIMON_RETURN_NOT_OK (CheckNoNull ());
193191 std::vector<int16_t > values;
194192 values.resize (size_);
195- MemorySegmentUtils::CopyToUnsafe (segments_ , element_offset_,
193+ MemorySegmentUtils::CopyToUnsafe ({segment_} , element_offset_,
196194 const_cast <void *>(static_cast <const void *>(values.data ())),
197195 size_ * sizeof (int16_t ));
198196 return values;
@@ -202,7 +200,7 @@ Result<std::vector<int32_t>> BinaryArray::ToIntArray() const {
202200 PAIMON_RETURN_NOT_OK (CheckNoNull ());
203201 std::vector<int32_t > values;
204202 values.resize (size_);
205- MemorySegmentUtils::CopyToUnsafe (segments_ , element_offset_,
203+ MemorySegmentUtils::CopyToUnsafe ({segment_} , element_offset_,
206204 const_cast <void *>(static_cast <const void *>(values.data ())),
207205 size_ * sizeof (int32_t ));
208206 return values;
@@ -212,7 +210,7 @@ Result<std::vector<int64_t>> BinaryArray::ToLongArray() const {
212210 PAIMON_RETURN_NOT_OK (CheckNoNull ());
213211 std::vector<int64_t > values;
214212 values.resize (size_);
215- MemorySegmentUtils::CopyToUnsafe (segments_ , element_offset_,
213+ MemorySegmentUtils::CopyToUnsafe ({segment_} , element_offset_,
216214 const_cast <void *>(static_cast <const void *>(values.data ())),
217215 size_ * sizeof (int64_t ));
218216 return values;
@@ -222,7 +220,7 @@ Result<std::vector<float>> BinaryArray::ToFloatArray() const {
222220 PAIMON_RETURN_NOT_OK (CheckNoNull ());
223221 std::vector<float > values;
224222 values.resize (size_);
225- MemorySegmentUtils::CopyToUnsafe (segments_ , element_offset_,
223+ MemorySegmentUtils::CopyToUnsafe ({segment_} , element_offset_,
226224 const_cast <void *>(static_cast <const void *>(values.data ())),
227225 size_ * sizeof (float ));
228226 return values;
@@ -232,7 +230,7 @@ Result<std::vector<double>> BinaryArray::ToDoubleArray() const {
232230 PAIMON_RETURN_NOT_OK (CheckNoNull ());
233231 std::vector<double > values;
234232 values.resize (size_);
235- MemorySegmentUtils::CopyToUnsafe (segments_ , element_offset_,
233+ MemorySegmentUtils::CopyToUnsafe ({segment_} , element_offset_,
236234 const_cast <void *>(static_cast <const void *>(values.data ())),
237235 size_ * sizeof (double ));
238236 return values;
@@ -246,7 +244,7 @@ BinaryArray BinaryArray::Copy(MemoryPool* pool) const {
246244
247245void BinaryArray::Copy (BinaryArray* reuse, MemoryPool* pool) const {
248246 std::shared_ptr<Bytes> bytes =
249- MemorySegmentUtils::CopyToBytes (segments_ , offset_, size_in_bytes_, pool);
247+ MemorySegmentUtils::CopyToBytes ({segment_} , offset_, size_in_bytes_, pool);
250248 reuse->PointTo (MemorySegment::Wrap (bytes), 0 , size_in_bytes_);
251249}
252250
0 commit comments