20
20
#include < arrow/c/bridge.h>
21
21
#include < arrow/json/from_string.h>
22
22
#include < arrow/type.h>
23
+ #include < arrow/util/decimal.h>
23
24
24
25
#include " iceberg/arrow_c_data_guard_internal.h"
25
26
#include " iceberg/manifest_list.h"
@@ -39,6 +40,16 @@ namespace iceberg {
39
40
EXPECT_EQ (std::get<expected_type>(scalar), expected_value); \
40
41
} while (0 )
41
42
43
+ #define EXPECT_DECIMAL_EQ (result, scale, expected_value ) \
44
+ do { \
45
+ ASSERT_THAT (result, IsOk ()); \
46
+ auto scalar = result.value (); \
47
+ ASSERT_TRUE (std::holds_alternative<std::vector<uint8_t >>(scalar)); \
48
+ auto bytes = std::get<std::vector<uint8_t >>(scalar); \
49
+ ::arrow::Decimal128 decimal (bytes.data ()); \
50
+ EXPECT_EQ (decimal.ToString (scale), expected_value); \
51
+ } while (0 )
52
+
42
53
#define EXPECT_SCALAR_NULL (result ) \
43
54
do { \
44
55
ASSERT_THAT (result, IsOk ()); \
@@ -189,12 +200,22 @@ TEST(ArrowArrayStructLike, PrimitiveFields) {
189
200
{::arrow::field (" id" , ::arrow::int64 (), /* nullable=*/ false ),
190
201
::arrow::field (" name" , ::arrow::utf8(), /* nullable=*/ true),
191
202
::arrow::field(" score" , ::arrow::float32(), /* nullable=*/ true),
192
- ::arrow::field(" active" , ::arrow::boolean(), /* nullable=*/ false)});
203
+ ::arrow::field(" active" , ::arrow::boolean(), /* nullable=*/ false),
204
+ ::arrow::field(" date" , ::arrow::date32(), /* nullable=*/ false),
205
+ ::arrow::field(" time" , ::arrow::time64(::arrow::TimeUnit::MICRO),
206
+ /* nullable=*/ false),
207
+ ::arrow::field(" timestamp" , ::arrow::timestamp(::arrow::TimeUnit::MICRO),
208
+ /* nullable=*/ false),
209
+ ::arrow::field(" fixed" , ::arrow::fixed_size_binary(4 ), /* nullable=*/ false),
210
+ ::arrow::field(" decimal" , ::arrow::decimal128(10 , 2 ), /* nullable=*/ false)});
193
211
194
212
auto arrow_array = ::arrow::json::ArrayFromJSONString (struct_type, R"( [
195
- {"id": 1, "name": "Alice", "score": 95.5, "active": true},
196
- {"id": 2, "name": "Bob", "score": null, "active": false},
197
- {"id": 3, "name": null, "score": 87.2, "active": true}])" )
213
+ {"id": 1, "name": "Alice", "score": 95.5, "active": true, "date": 1714396800,
214
+ "time": 123456, "timestamp": 1714396800000000, "fixed": "aaaa", "decimal": "1234.56"},
215
+ {"id": 2, "name": "Bob", "score": null, "active": false, "date": 1714396801,
216
+ "time": 123457, "timestamp": 1714396800000001, "fixed": "bbbb", "decimal": "-1234.56"},
217
+ {"id": 3, "name": null, "score": 87.2, "active": true, "date": 1714396802,
218
+ "time": 123458, "timestamp": 1714396800000002, "fixed": "cccc", "decimal": "1234.00"}])" )
198
219
.ValueOrDie ();
199
220
200
221
ArrowSchema c_schema;
@@ -213,6 +234,12 @@ TEST(ArrowArrayStructLike, PrimitiveFields) {
213
234
std::array<std::optional<std::string>, kNumRows > names = {" Alice" , " Bob" , std::nullopt };
214
235
std::array<std::optional<float >, kNumRows > scores = {95 .5f , std::nullopt , 87 .2f };
215
236
std::array<bool , kNumRows > actives = {true , false , true };
237
+ std::array<int32_t , kNumRows > dates = {1714396800 , 1714396801 , 1714396802 };
238
+ std::array<int64_t , kNumRows > times = {123456 , 123457 , 123458 };
239
+ std::array<int64_t , kNumRows > timestamps = {1714396800000000 , 1714396800000001 ,
240
+ 1714396800000002 };
241
+ std::array<std::string, kNumRows > fixeds = {" aaaa" , " bbbb" , " cccc" };
242
+ std::array<std::string, kNumRows > decimals = {" 1234.56" , " -1234.56" , " 1234.00" };
216
243
217
244
for (int64_t i = 0 ; i < kNumRows ; ++i) {
218
245
ASSERT_THAT (struct_like->Reset (i), IsOk ());
@@ -228,6 +255,11 @@ TEST(ArrowArrayStructLike, PrimitiveFields) {
228
255
EXPECT_SCALAR_NULL (struct_like->GetField (2 ));
229
256
}
230
257
EXPECT_SCALAR_EQ (struct_like->GetField (3 ), bool , actives[i]);
258
+ EXPECT_SCALAR_EQ (struct_like->GetField (4 ), int32_t , dates[i]);
259
+ EXPECT_SCALAR_EQ (struct_like->GetField (5 ), int64_t , times[i]);
260
+ EXPECT_SCALAR_EQ (struct_like->GetField (6 ), int64_t , timestamps[i]);
261
+ EXPECT_SCALAR_EQ (struct_like->GetField (7 ), std::string_view, fixeds[i]);
262
+ EXPECT_DECIMAL_EQ (struct_like->GetField (8 ), /* scale=*/ 2 , decimals[i]);
231
263
}
232
264
}
233
265
0 commit comments