dongxiao1198 commented on code in PR #216: URL: https://github.com/apache/iceberg-cpp/pull/216#discussion_r2343292908
########## src/iceberg/manifest_adapter.cc: ########## @@ -0,0 +1,720 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#include "iceberg/manifest_adapter.h" + +#include "iceberg/manifest_entry.h" +#include "iceberg/manifest_list.h" +#include "iceberg/schema.h" +#include "iceberg/schema_internal.h" +#include "iceberg/util/macros.h" +#include "nanoarrow/nanoarrow.h" + +namespace { +static constexpr int64_t kBlockSizeInBytes = 64 * 1024 * 1024L; +} + +namespace iceberg { + +Status ManifestAdapter::StartAppending() { + if (size_ > 0) { + return InvalidArgument("Adapter buffer not empty, cannot start appending."); + } + array_ = {}; + size_ = 0; + ArrowError error; + auto status = ArrowArrayInitFromSchema(&array_, &schema_, &error); + NANOARROW_RETURN_IF_NOT_OK(status, error); + status = ArrowArrayStartAppending(&array_); + NANOARROW_RETURN_IF_NOT_OK(status, error); + return {}; +} + +Result<ArrowArray> ManifestAdapter::FinishAppending() { + ArrowError error; + auto status = ArrowArrayFinishBuildingDefault(&array_, &error); + NANOARROW_RETURN_IF_NOT_OK(status, error); + return array_; +} + +Status ManifestAdapter::AppendField(ArrowArray* arrowArray, int64_t value) { + auto status = ArrowArrayAppendInt(arrowArray, value); + NANOARROW_RETURN_IF_FAILED(status); + return {}; +} + +Status ManifestAdapter::AppendField(ArrowArray* arrowArray, uint64_t value) { + auto status = ArrowArrayAppendUInt(arrowArray, value); + NANOARROW_RETURN_IF_FAILED(status); + return {}; +} + +Status ManifestAdapter::AppendField(ArrowArray* arrowArray, double value) { + auto status = ArrowArrayAppendDouble(arrowArray, value); + NANOARROW_RETURN_IF_FAILED(status); + return {}; +} + +Status ManifestAdapter::AppendField(ArrowArray* arrowArray, std::string_view value) { + ArrowStringView view(value.data(), value.size()); + auto status = ArrowArrayAppendString(arrowArray, view); + NANOARROW_RETURN_IF_FAILED(status); + return {}; +} + +Status ManifestAdapter::AppendField(ArrowArray* arrowArray, + const std::vector<uint8_t>& value) { + ArrowBufferViewData data; + data.as_char = reinterpret_cast<const char*>(value.data()); + ArrowBufferView view(data, value.size()); + auto status = ArrowArrayAppendBytes(arrowArray, view); + NANOARROW_RETURN_IF_FAILED(status); + return {}; +} + +Status ManifestAdapter::AppendField(ArrowArray* arrowArray, + const std::array<uint8_t, 16>& value) { + ArrowBufferViewData data; + data.as_char = reinterpret_cast<const char*>(value.data()); + ArrowBufferView view(data, value.size()); + auto status = ArrowArrayAppendBytes(arrowArray, view); + NANOARROW_RETURN_IF_FAILED(status); + return {}; +} + +ManifestEntryAdapter::~ManifestEntryAdapter() { + if (is_initialized_) { + // arrow::ImportedArrayData::Release() bridge.cc:1478 will release the + // internal array, so we have no need to release it here. + // ArrowArrayRelease(&array_); + ArrowSchemaRelease(&schema_); Review Comment: But I think this is already a dtor, there is no need to import other guard -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
