1919
2020#include " iceberg/manifest_adapter.h"
2121
22+ #include < nanoarrow/nanoarrow.h>
23+
2224#include " iceberg/arrow/nanoarrow_error_transform_internal.h"
2325#include " iceberg/manifest_entry.h"
2426#include " iceberg/manifest_list.h"
2527#include " iceberg/schema.h"
2628#include " iceberg/schema_internal.h"
2729#include " iceberg/util/checked_cast.h"
2830#include " iceberg/util/macros.h"
29- #include " nanoarrow/nanoarrow.h"
3031
31- #define NANOARROW_RETURN_IF_FAILED (status ) \
32- if (status != NANOARROW_OK) [[unlikely]] { \
33- return InvalidArrowData (" Nanoarrow error code : {}" , status); \
32+ #define NANOARROW_RETURN_IF_FAILED (status ) \
33+ if (status != NANOARROW_OK) [[unlikely]] { \
34+ return InvalidArrowData (" nanoarrow error: {}" , status); \
3435 }
3536
3637namespace {
@@ -43,20 +44,20 @@ Status ManifestAdapter::StartAppending() {
4344 if (size_ > 0 ) {
4445 return InvalidArgument (" Adapter buffer not empty, cannot start appending." );
4546 }
46- array_ = std::make_shared<ArrowArray>() ;
47+ array_ = {} ;
4748 size_ = 0 ;
4849 ArrowError error;
49- ICEBERG_NANOARROW_RETURN_IF_NOT_OK (
50- ArrowArrayInitFromSchema (array_. get (), &schema_, &error), error);
51- NANOARROW_RETURN_IF_FAILED (ArrowArrayStartAppending (array_. get () ));
50+ ICEBERG_NANOARROW_RETURN_IF_NOT_OK (ArrowArrayInitFromSchema (&array_, &schema_, &error),
51+ error);
52+ NANOARROW_RETURN_IF_FAILED (ArrowArrayStartAppending (& array_));
5253 return {};
5354}
5455
55- Result<std::shared_ptr< ArrowArray> > ManifestAdapter::FinishAppending () {
56+ Result<ArrowArray* > ManifestAdapter::FinishAppending () {
5657 ArrowError error;
57- ICEBERG_NANOARROW_RETURN_IF_NOT_OK (
58- ArrowArrayFinishBuildingDefault (array_. get (), &error), error);
59- return array_;
58+ ICEBERG_NANOARROW_RETURN_IF_NOT_OK (ArrowArrayFinishBuildingDefault (&array_, &error),
59+ error);
60+ return & array_;
6061}
6162
6263Status ManifestAdapter::AppendField (ArrowArray* arrowArray, int64_t value) {
@@ -90,8 +91,8 @@ Status ManifestAdapter::AppendField(ArrowArray* arrowArray,
9091}
9192
9293ManifestEntryAdapter::~ManifestEntryAdapter () {
93- if (array_ != nullptr && array_-> release != nullptr ) {
94- ArrowArrayRelease (array_. get () );
94+ if (array_. release != nullptr ) {
95+ ArrowArrayRelease (& array_);
9596 }
9697 if (schema_.release != nullptr ) {
9798 ArrowSchemaRelease (&schema_);
@@ -102,7 +103,7 @@ Result<std::shared_ptr<StructType>> ManifestEntryAdapter::GetManifestEntryStruct
102103 if (partition_spec_ == nullptr ) {
103104 return ManifestEntry::TypeFromPartitionType (nullptr );
104105 }
105- ICEBERG_ASSIGN_OR_RAISE (auto partition_schema, partition_spec_->partition_schema ());
106+ ICEBERG_ASSIGN_OR_RAISE (auto partition_schema, partition_spec_->GetPartitionSchema ());
106107 return ManifestEntry::TypeFromPartitionType (std::move (partition_schema));
107108}
108109
@@ -215,6 +216,7 @@ Status ManifestEntryAdapter::AppendMap(ArrowArray* arrow_array,
215216 auto value_array = map_array->children [1 ];
216217 ICEBERG_RETURN_UNEXPECTED (AppendField (key_array, static_cast <int64_t >(key)));
217218 ICEBERG_RETURN_UNEXPECTED (AppendField (value_array, value));
219+ NANOARROW_RETURN_IF_FAILED (ArrowArrayFinishElement (map_array));
218220 }
219221 NANOARROW_RETURN_IF_FAILED (ArrowArrayFinishElement (arrow_array));
220222 return {};
@@ -231,6 +233,7 @@ Status ManifestEntryAdapter::AppendMap(
231233 auto value_array = map_array->children [1 ];
232234 ICEBERG_RETURN_UNEXPECTED (AppendField (key_array, static_cast <int64_t >(key)));
233235 ICEBERG_RETURN_UNEXPECTED (AppendField (value_array, value));
236+ NANOARROW_RETURN_IF_FAILED (ArrowArrayFinishElement (map_array));
234237 }
235238 NANOARROW_RETURN_IF_FAILED (ArrowArrayFinishElement (arrow_array));
236239 return {};
@@ -380,7 +383,7 @@ Status ManifestEntryAdapter::AppendInternal(const ManifestEntry& entry) {
380383 const auto & fields = manifest_schema_->fields ();
381384 for (int32_t i = 0 ; i < fields.size (); i++) {
382385 const auto & field = fields[i];
383- auto array = array_-> children [i];
386+ auto array = array_. children [i];
384387
385388 switch (field.field_id ()) {
386389 case 0 : // status (required int32)
@@ -427,7 +430,7 @@ Status ManifestEntryAdapter::AppendInternal(const ManifestEntry& entry) {
427430 }
428431 }
429432
430- NANOARROW_RETURN_IF_FAILED (ArrowArrayFinishElement (array_. get () ));
433+ NANOARROW_RETURN_IF_FAILED (ArrowArrayFinishElement (& array_));
431434 size_++;
432435 return {};
433436}
@@ -464,8 +467,8 @@ Status ManifestEntryAdapter::InitSchema(const std::unordered_set<int32_t>& field
464467}
465468
466469ManifestFileAdapter::~ManifestFileAdapter () {
467- if (array_ != nullptr && array_-> release != nullptr ) {
468- ArrowArrayRelease (array_. get () );
470+ if (array_. release != nullptr ) {
471+ ArrowArrayRelease (& array_);
469472 }
470473 if (schema_.release != nullptr ) {
471474 ArrowSchemaRelease (&schema_);
@@ -553,7 +556,7 @@ Status ManifestFileAdapter::AppendInternal(const ManifestFile& file) {
553556 const auto & fields = manifest_list_schema_->fields ();
554557 for (int32_t i = 0 ; i < fields.size (); i++) {
555558 const auto & field = fields[i];
556- auto array = array_-> children [i];
559+ auto array = array_. children [i];
557560 switch (field.field_id ()) {
558561 case 500 : // manifest_path
559562 ICEBERG_RETURN_UNEXPECTED (AppendField (array, file.manifest_path ));
@@ -662,7 +665,7 @@ Status ManifestFileAdapter::AppendInternal(const ManifestFile& file) {
662665 return InvalidManifestList (" Unknown field id: {}" , field.field_id ());
663666 }
664667 }
665- NANOARROW_RETURN_IF_FAILED (ArrowArrayFinishElement (array_. get () ));
668+ NANOARROW_RETURN_IF_FAILED (ArrowArrayFinishElement (& array_));
666669 size_++;
667670 return {};
668671}
0 commit comments