zhjwpku commented on code in PR #431:
URL: https://github.com/apache/iceberg-cpp/pull/431#discussion_r2643140612
##########
src/iceberg/manifest/manifest_reader.cc:
##########
@@ -19,61 +19,867 @@
#include "iceberg/manifest/manifest_reader.h"
+#include <algorithm>
+#include <memory>
+#include <unordered_set>
+
+#include <nanoarrow/nanoarrow.h>
+
+#include "iceberg/arrow/nanoarrow_status_internal.h"
+#include "iceberg/arrow_c_data_guard_internal.h"
+#include "iceberg/expression/expression.h"
+#include "iceberg/expression/projections.h"
+#include "iceberg/file_format.h"
#include "iceberg/manifest/manifest_entry.h"
#include "iceberg/manifest/manifest_list.h"
#include "iceberg/manifest/manifest_reader_internal.h"
+#include "iceberg/metadata_columns.h"
+#include "iceberg/partition_spec.h"
#include "iceberg/schema.h"
-#include "iceberg/schema_internal.h"
+#include "iceberg/schema_field.h"
#include "iceberg/type.h"
+#include "iceberg/util/checked_cast.h"
#include "iceberg/util/macros.h"
namespace iceberg {
+namespace {
+
+#define PARSE_PRIMITIVE_FIELD(item, array_view, type)
\
+ for (int64_t row_idx = 0; row_idx < array_view->length; row_idx++) {
\
+ if (!ArrowArrayViewIsNull(array_view, row_idx)) {
\
+ auto value = ArrowArrayViewGetIntUnsafe(array_view, row_idx);
\
+ item = static_cast<type>(value);
\
+ } else if (required) {
\
+ return InvalidManifestList("Field {} is required but null at row {}",
field_name, \
+ row_idx);
\
+ }
\
+ }
+
+#define PARSE_STRING_FIELD(item, array_view)
\
+ for (int64_t row_idx = 0; row_idx < array_view->length; row_idx++) {
\
+ if (!ArrowArrayViewIsNull(array_view, row_idx)) {
\
+ auto value = ArrowArrayViewGetStringUnsafe(array_view, row_idx);
\
+ item = std::string(value.data, value.size_bytes);
\
+ } else if (required) {
\
+ return InvalidManifestList("Field {} is required but null at row {}",
field_name, \
+ row_idx);
\
+ }
\
+ }
+
+#define PARSE_BINARY_FIELD(item, array_view)
\
+ for (int64_t row_idx = 0; row_idx < array_view->length; row_idx++) {
\
+ if (!ArrowArrayViewIsNull(view_of_column, row_idx)) {
\
+ item = ArrowArrayViewGetInt8Vector(array_view, row_idx);
\
+ } else if (required) {
\
+ return InvalidManifestList("Field {} is required but null at row {}",
field_name, \
+ row_idx);
\
+ }
\
+ }
+
+#define PARSE_INTEGER_VECTOR_FIELD(item, count, array_view, type)
\
+ for (int64_t manifest_idx = 0; manifest_idx < count; manifest_idx++) {
\
+ auto offset = ArrowArrayViewListChildOffset(array_view, manifest_idx);
\
+ auto next_offset = ArrowArrayViewListChildOffset(array_view, manifest_idx
+ 1); \
+ for (int64_t offset_idx = offset; offset_idx < next_offset; offset_idx++)
{ \
+ item.emplace_back(static_cast<type>(
\
+ ArrowArrayViewGetIntUnsafe(array_view->children[0], offset_idx)));
\
+ }
\
+ }
+
+#define PARSE_MAP_FIELD(item, count, array_view, key_type, value_type,
assignment) \
+ do {
\
+ if (array_view->storage_type != ArrowType::NANOARROW_TYPE_MAP) {
\
+ return InvalidManifest("Field:{} should be a map.", field_name);
\
+ }
\
+ auto view_of_map = array_view->children[0];
\
+ ASSERT_VIEW_TYPE_AND_CHILDREN(view_of_map,
ArrowType::NANOARROW_TYPE_STRUCT, 2); \
+ auto view_of_map_key = view_of_map->children[0];
\
+ ASSERT_VIEW_TYPE(view_of_map_key, key_type);
\
+ auto view_of_map_value = view_of_map->children[1];
\
+ ASSERT_VIEW_TYPE(view_of_map_value, value_type);
\
+ for (int64_t row_idx = 0; row_idx < count; row_idx++) {
\
+ auto offset = array_view->buffer_views[1].data.as_int32[row_idx];
\
+ auto next_offset = array_view->buffer_views[1].data.as_int32[row_idx +
1]; \
+ for (int32_t offset_idx = offset; offset_idx < next_offset;
offset_idx++) { \
+ auto key = ArrowArrayViewGetIntUnsafe(view_of_map_key, offset_idx);
\
+ item[key] = assignment;
\
+ }
\
+ }
\
+ } while (0)
+
+#define PARSE_INT_LONG_MAP_FIELD(item, count, array_view) \
+ PARSE_MAP_FIELD(item, count, array_view, ArrowType::NANOARROW_TYPE_INT32, \
+ ArrowType::NANOARROW_TYPE_INT64, \
+ ArrowArrayViewGetIntUnsafe(view_of_map_value, offset_idx));
+
+#define PARSE_INT_BINARY_MAP_FIELD(item, count, array_view) \
+ PARSE_MAP_FIELD(item, count, array_view, ArrowType::NANOARROW_TYPE_INT32, \
+ ArrowType::NANOARROW_TYPE_BINARY, \
+ ArrowArrayViewGetInt8Vector(view_of_map_value, offset_idx));
+
+#define ASSERT_VIEW_TYPE(view, type)
\
+ if (view->storage_type != type) {
\
+ return InvalidManifest("Sub Field:{} should be a {}.", field_name, #type);
\
+ }
+
+#define ASSERT_VIEW_TYPE_AND_CHILDREN(view, type, n_child)
\
+ if (view->storage_type != type) {
\
+ return InvalidManifest("Sub Field:{} should be a {}.", field_name, #type);
\
+ }
\
+ if (view->n_children != n_child) {
\
+ return InvalidManifest("Sub Field for:{} should have key&value:{}
columns.", \
+ field_name, n_child);
\
+ }
+
+std::vector<uint8_t> ArrowArrayViewGetInt8Vector(const ArrowArrayView* view,
+ int32_t offset_idx) {
+ auto buffer = ArrowArrayViewGetBytesUnsafe(view, offset_idx);
+ return {buffer.data.as_char, buffer.data.as_char + buffer.size_bytes};
+}
+
+Status ParsePartitionFieldSummaryList(ArrowArrayView* view_of_column,
+ std::vector<ManifestFile>&
manifest_files) {
+ auto manifest_count = view_of_column->length;
+ // view_of_column is list<struct<PartitionFieldSummary>>
+ if (view_of_column->storage_type != ArrowType::NANOARROW_TYPE_LIST) {
+ return InvalidManifestList("partitions field should be a list.");
+ }
+ auto view_of_list_iterm = view_of_column->children[0];
Review Comment:
```suggestion
auto view_of_list_item = view_of_column->children[0];
```
typo?
##########
src/iceberg/manifest/manifest_reader.cc:
##########
@@ -19,61 +19,867 @@
#include "iceberg/manifest/manifest_reader.h"
+#include <algorithm>
+#include <memory>
+#include <unordered_set>
+
+#include <nanoarrow/nanoarrow.h>
+
+#include "iceberg/arrow/nanoarrow_status_internal.h"
+#include "iceberg/arrow_c_data_guard_internal.h"
+#include "iceberg/expression/expression.h"
+#include "iceberg/expression/projections.h"
+#include "iceberg/file_format.h"
#include "iceberg/manifest/manifest_entry.h"
#include "iceberg/manifest/manifest_list.h"
#include "iceberg/manifest/manifest_reader_internal.h"
+#include "iceberg/metadata_columns.h"
+#include "iceberg/partition_spec.h"
#include "iceberg/schema.h"
-#include "iceberg/schema_internal.h"
+#include "iceberg/schema_field.h"
#include "iceberg/type.h"
+#include "iceberg/util/checked_cast.h"
#include "iceberg/util/macros.h"
namespace iceberg {
+namespace {
+
+#define PARSE_PRIMITIVE_FIELD(item, array_view, type)
\
+ for (int64_t row_idx = 0; row_idx < array_view->length; row_idx++) {
\
+ if (!ArrowArrayViewIsNull(array_view, row_idx)) {
\
+ auto value = ArrowArrayViewGetIntUnsafe(array_view, row_idx);
\
+ item = static_cast<type>(value);
\
+ } else if (required) {
\
+ return InvalidManifestList("Field {} is required but null at row {}",
field_name, \
+ row_idx);
\
+ }
\
+ }
+
+#define PARSE_STRING_FIELD(item, array_view)
\
+ for (int64_t row_idx = 0; row_idx < array_view->length; row_idx++) {
\
+ if (!ArrowArrayViewIsNull(array_view, row_idx)) {
\
+ auto value = ArrowArrayViewGetStringUnsafe(array_view, row_idx);
\
+ item = std::string(value.data, value.size_bytes);
\
+ } else if (required) {
\
+ return InvalidManifestList("Field {} is required but null at row {}",
field_name, \
+ row_idx);
\
+ }
\
+ }
+
+#define PARSE_BINARY_FIELD(item, array_view)
\
+ for (int64_t row_idx = 0; row_idx < array_view->length; row_idx++) {
\
+ if (!ArrowArrayViewIsNull(view_of_column, row_idx)) {
\
+ item = ArrowArrayViewGetInt8Vector(array_view, row_idx);
\
+ } else if (required) {
\
+ return InvalidManifestList("Field {} is required but null at row {}",
field_name, \
+ row_idx);
\
+ }
\
+ }
+
+#define PARSE_INTEGER_VECTOR_FIELD(item, count, array_view, type)
\
+ for (int64_t manifest_idx = 0; manifest_idx < count; manifest_idx++) {
\
+ auto offset = ArrowArrayViewListChildOffset(array_view, manifest_idx);
\
+ auto next_offset = ArrowArrayViewListChildOffset(array_view, manifest_idx
+ 1); \
+ for (int64_t offset_idx = offset; offset_idx < next_offset; offset_idx++)
{ \
+ item.emplace_back(static_cast<type>(
\
+ ArrowArrayViewGetIntUnsafe(array_view->children[0], offset_idx)));
\
+ }
\
+ }
+
+#define PARSE_MAP_FIELD(item, count, array_view, key_type, value_type,
assignment) \
+ do {
\
+ if (array_view->storage_type != ArrowType::NANOARROW_TYPE_MAP) {
\
+ return InvalidManifest("Field:{} should be a map.", field_name);
\
+ }
\
+ auto view_of_map = array_view->children[0];
\
+ ASSERT_VIEW_TYPE_AND_CHILDREN(view_of_map,
ArrowType::NANOARROW_TYPE_STRUCT, 2); \
+ auto view_of_map_key = view_of_map->children[0];
\
+ ASSERT_VIEW_TYPE(view_of_map_key, key_type);
\
+ auto view_of_map_value = view_of_map->children[1];
\
+ ASSERT_VIEW_TYPE(view_of_map_value, value_type);
\
+ for (int64_t row_idx = 0; row_idx < count; row_idx++) {
\
+ auto offset = array_view->buffer_views[1].data.as_int32[row_idx];
\
+ auto next_offset = array_view->buffer_views[1].data.as_int32[row_idx +
1]; \
+ for (int32_t offset_idx = offset; offset_idx < next_offset;
offset_idx++) { \
+ auto key = ArrowArrayViewGetIntUnsafe(view_of_map_key, offset_idx);
\
+ item[key] = assignment;
\
+ }
\
+ }
\
+ } while (0)
+
+#define PARSE_INT_LONG_MAP_FIELD(item, count, array_view) \
+ PARSE_MAP_FIELD(item, count, array_view, ArrowType::NANOARROW_TYPE_INT32, \
+ ArrowType::NANOARROW_TYPE_INT64, \
+ ArrowArrayViewGetIntUnsafe(view_of_map_value, offset_idx));
+
+#define PARSE_INT_BINARY_MAP_FIELD(item, count, array_view) \
+ PARSE_MAP_FIELD(item, count, array_view, ArrowType::NANOARROW_TYPE_INT32, \
+ ArrowType::NANOARROW_TYPE_BINARY, \
+ ArrowArrayViewGetInt8Vector(view_of_map_value, offset_idx));
+
+#define ASSERT_VIEW_TYPE(view, type)
\
+ if (view->storage_type != type) {
\
+ return InvalidManifest("Sub Field:{} should be a {}.", field_name, #type);
\
+ }
+
+#define ASSERT_VIEW_TYPE_AND_CHILDREN(view, type, n_child)
\
+ if (view->storage_type != type) {
\
+ return InvalidManifest("Sub Field:{} should be a {}.", field_name, #type);
\
+ }
\
+ if (view->n_children != n_child) {
\
+ return InvalidManifest("Sub Field for:{} should have key&value:{}
columns.", \
+ field_name, n_child);
\
+ }
+
+std::vector<uint8_t> ArrowArrayViewGetInt8Vector(const ArrowArrayView* view,
+ int32_t offset_idx) {
+ auto buffer = ArrowArrayViewGetBytesUnsafe(view, offset_idx);
+ return {buffer.data.as_char, buffer.data.as_char + buffer.size_bytes};
+}
+
+Status ParsePartitionFieldSummaryList(ArrowArrayView* view_of_column,
+ std::vector<ManifestFile>&
manifest_files) {
+ auto manifest_count = view_of_column->length;
+ // view_of_column is list<struct<PartitionFieldSummary>>
+ if (view_of_column->storage_type != ArrowType::NANOARROW_TYPE_LIST) {
+ return InvalidManifestList("partitions field should be a list.");
+ }
+ auto view_of_list_iterm = view_of_column->children[0];
+ // view_of_list_iterm is struct<PartitionFieldSummary>
+ if (view_of_list_iterm->storage_type != ArrowType::NANOARROW_TYPE_STRUCT) {
+ return InvalidManifestList("partitions list field should be a list.");
Review Comment:
```suggestion
return InvalidManifestList("partitions list item should be a struct.");
```
##########
src/iceberg/manifest/manifest_entry.h:
##########
@@ -178,94 +178,114 @@ struct ICEBERG_EXPORT DataFile {
/// present
std::optional<int64_t> content_size_in_bytes;
+ inline static constexpr int32_t kContentFieldId = 134;
Review Comment:
nit: constexpr implies inline, maybe remove the inline, not a strong opinion
##########
src/iceberg/manifest/manifest_reader.h:
##########
@@ -23,43 +23,71 @@
/// Data reader interface for manifest files.
#include <memory>
+#include <string>
+#include <unordered_map>
#include <vector>
#include "iceberg/iceberg_export.h"
#include "iceberg/result.h"
-#include "iceberg/type.h"
#include "iceberg/type_fwd.h"
namespace iceberg {
/// \brief Read manifest entries from a manifest file.
class ICEBERG_EXPORT ManifestReader {
public:
+ /// \brief Special value to select all columns from manifest files.
+ inline static const std::vector<std::string> kAllColumns{"*"};
Review Comment:
Why this is a vector, a single string should be enough?
##########
src/iceberg/manifest/manifest_reader.cc:
##########
@@ -19,61 +19,867 @@
#include "iceberg/manifest/manifest_reader.h"
+#include <algorithm>
+#include <memory>
+#include <unordered_set>
+
+#include <nanoarrow/nanoarrow.h>
+
+#include "iceberg/arrow/nanoarrow_status_internal.h"
+#include "iceberg/arrow_c_data_guard_internal.h"
+#include "iceberg/expression/expression.h"
+#include "iceberg/expression/projections.h"
+#include "iceberg/file_format.h"
#include "iceberg/manifest/manifest_entry.h"
#include "iceberg/manifest/manifest_list.h"
#include "iceberg/manifest/manifest_reader_internal.h"
+#include "iceberg/metadata_columns.h"
+#include "iceberg/partition_spec.h"
#include "iceberg/schema.h"
-#include "iceberg/schema_internal.h"
+#include "iceberg/schema_field.h"
#include "iceberg/type.h"
+#include "iceberg/util/checked_cast.h"
#include "iceberg/util/macros.h"
namespace iceberg {
+namespace {
+
+#define PARSE_PRIMITIVE_FIELD(item, array_view, type)
\
+ for (int64_t row_idx = 0; row_idx < array_view->length; row_idx++) {
\
+ if (!ArrowArrayViewIsNull(array_view, row_idx)) {
\
+ auto value = ArrowArrayViewGetIntUnsafe(array_view, row_idx);
\
+ item = static_cast<type>(value);
\
+ } else if (required) {
\
+ return InvalidManifestList("Field {} is required but null at row {}",
field_name, \
+ row_idx);
\
+ }
\
+ }
+
+#define PARSE_STRING_FIELD(item, array_view)
\
+ for (int64_t row_idx = 0; row_idx < array_view->length; row_idx++) {
\
+ if (!ArrowArrayViewIsNull(array_view, row_idx)) {
\
+ auto value = ArrowArrayViewGetStringUnsafe(array_view, row_idx);
\
+ item = std::string(value.data, value.size_bytes);
\
+ } else if (required) {
\
+ return InvalidManifestList("Field {} is required but null at row {}",
field_name, \
+ row_idx);
\
+ }
\
+ }
+
+#define PARSE_BINARY_FIELD(item, array_view)
\
+ for (int64_t row_idx = 0; row_idx < array_view->length; row_idx++) {
\
+ if (!ArrowArrayViewIsNull(view_of_column, row_idx)) {
\
+ item = ArrowArrayViewGetInt8Vector(array_view, row_idx);
\
+ } else if (required) {
\
+ return InvalidManifestList("Field {} is required but null at row {}",
field_name, \
+ row_idx);
\
+ }
\
+ }
+
+#define PARSE_INTEGER_VECTOR_FIELD(item, count, array_view, type)
\
+ for (int64_t manifest_idx = 0; manifest_idx < count; manifest_idx++) {
\
+ auto offset = ArrowArrayViewListChildOffset(array_view, manifest_idx);
\
+ auto next_offset = ArrowArrayViewListChildOffset(array_view, manifest_idx
+ 1); \
+ for (int64_t offset_idx = offset; offset_idx < next_offset; offset_idx++)
{ \
+ item.emplace_back(static_cast<type>(
\
+ ArrowArrayViewGetIntUnsafe(array_view->children[0], offset_idx)));
\
+ }
\
+ }
+
+#define PARSE_MAP_FIELD(item, count, array_view, key_type, value_type,
assignment) \
+ do {
\
+ if (array_view->storage_type != ArrowType::NANOARROW_TYPE_MAP) {
\
+ return InvalidManifest("Field:{} should be a map.", field_name);
\
+ }
\
+ auto view_of_map = array_view->children[0];
\
+ ASSERT_VIEW_TYPE_AND_CHILDREN(view_of_map,
ArrowType::NANOARROW_TYPE_STRUCT, 2); \
+ auto view_of_map_key = view_of_map->children[0];
\
+ ASSERT_VIEW_TYPE(view_of_map_key, key_type);
\
+ auto view_of_map_value = view_of_map->children[1];
\
+ ASSERT_VIEW_TYPE(view_of_map_value, value_type);
\
+ for (int64_t row_idx = 0; row_idx < count; row_idx++) {
\
+ auto offset = array_view->buffer_views[1].data.as_int32[row_idx];
\
+ auto next_offset = array_view->buffer_views[1].data.as_int32[row_idx +
1]; \
+ for (int32_t offset_idx = offset; offset_idx < next_offset;
offset_idx++) { \
+ auto key = ArrowArrayViewGetIntUnsafe(view_of_map_key, offset_idx);
\
+ item[key] = assignment;
\
+ }
\
+ }
\
+ } while (0)
+
+#define PARSE_INT_LONG_MAP_FIELD(item, count, array_view) \
+ PARSE_MAP_FIELD(item, count, array_view, ArrowType::NANOARROW_TYPE_INT32, \
+ ArrowType::NANOARROW_TYPE_INT64, \
+ ArrowArrayViewGetIntUnsafe(view_of_map_value, offset_idx));
+
+#define PARSE_INT_BINARY_MAP_FIELD(item, count, array_view) \
+ PARSE_MAP_FIELD(item, count, array_view, ArrowType::NANOARROW_TYPE_INT32, \
+ ArrowType::NANOARROW_TYPE_BINARY, \
+ ArrowArrayViewGetInt8Vector(view_of_map_value, offset_idx));
+
+#define ASSERT_VIEW_TYPE(view, type)
\
+ if (view->storage_type != type) {
\
+ return InvalidManifest("Sub Field:{} should be a {}.", field_name, #type);
\
+ }
+
+#define ASSERT_VIEW_TYPE_AND_CHILDREN(view, type, n_child)
\
+ if (view->storage_type != type) {
\
+ return InvalidManifest("Sub Field:{} should be a {}.", field_name, #type);
\
+ }
\
+ if (view->n_children != n_child) {
\
+ return InvalidManifest("Sub Field for:{} should have key&value:{}
columns.", \
+ field_name, n_child);
\
+ }
+
+std::vector<uint8_t> ArrowArrayViewGetInt8Vector(const ArrowArrayView* view,
+ int32_t offset_idx) {
+ auto buffer = ArrowArrayViewGetBytesUnsafe(view, offset_idx);
+ return {buffer.data.as_char, buffer.data.as_char + buffer.size_bytes};
+}
+
+Status ParsePartitionFieldSummaryList(ArrowArrayView* view_of_column,
+ std::vector<ManifestFile>&
manifest_files) {
+ auto manifest_count = view_of_column->length;
+ // view_of_column is list<struct<PartitionFieldSummary>>
+ if (view_of_column->storage_type != ArrowType::NANOARROW_TYPE_LIST) {
+ return InvalidManifestList("partitions field should be a list.");
+ }
+ auto view_of_list_iterm = view_of_column->children[0];
+ // view_of_list_iterm is struct<PartitionFieldSummary>
+ if (view_of_list_iterm->storage_type != ArrowType::NANOARROW_TYPE_STRUCT) {
+ return InvalidManifestList("partitions list field should be a list.");
+ }
+ if (view_of_list_iterm->n_children != 4) {
+ return InvalidManifestList("PartitionFieldSummary should have 4 fields.");
+ }
+ if (view_of_list_iterm->children[0]->storage_type !=
ArrowType::NANOARROW_TYPE_BOOL) {
+ return InvalidManifestList("contains_null should have be bool type
column.");
+ }
+ auto contains_null = view_of_list_iterm->children[0];
+ if (view_of_list_iterm->children[1]->storage_type !=
ArrowType::NANOARROW_TYPE_BOOL) {
+ return InvalidManifestList("contains_nan should have be bool type
column.");
+ }
+ auto contains_nan = view_of_list_iterm->children[1];
+ if (view_of_list_iterm->children[2]->storage_type !=
ArrowType::NANOARROW_TYPE_BINARY) {
+ return InvalidManifestList("lower_bound should have be binary type
column.");
+ }
+ auto lower_bound_list = view_of_list_iterm->children[2];
+ if (view_of_list_iterm->children[3]->storage_type !=
ArrowType::NANOARROW_TYPE_BINARY) {
+ return InvalidManifestList("upper_bound should have be binary type
column.");
+ }
+ auto upper_bound_list = view_of_list_iterm->children[3];
+ for (int64_t manifest_idx = 0; manifest_idx < manifest_count;
manifest_idx++) {
+ auto offset = ArrowArrayViewListChildOffset(view_of_column, manifest_idx);
+ auto next_offset = ArrowArrayViewListChildOffset(view_of_column,
manifest_idx + 1);
+ // partitions from offset to next_offset belongs to manifest_idx
+ auto& manifest_file = manifest_files[manifest_idx];
+ for (int64_t partition_idx = offset; partition_idx < next_offset;
partition_idx++) {
+ PartitionFieldSummary partition_field_summary;
+ if (!ArrowArrayViewIsNull(contains_null, partition_idx)) {
+ partition_field_summary.contains_null =
+ ArrowArrayViewGetIntUnsafe(contains_null, partition_idx);
+ } else {
+ return InvalidManifestList("contains_null is null at row {}",
partition_idx);
+ }
+ if (!ArrowArrayViewIsNull(contains_nan, partition_idx)) {
+ partition_field_summary.contains_nan =
+ ArrowArrayViewGetIntUnsafe(contains_nan, partition_idx);
+ }
+ if (!ArrowArrayViewIsNull(lower_bound_list, partition_idx)) {
+ partition_field_summary.lower_bound =
+ ArrowArrayViewGetInt8Vector(lower_bound_list, partition_idx);
+ }
+ if (!ArrowArrayViewIsNull(upper_bound_list, partition_idx)) {
+ partition_field_summary.upper_bound =
+ ArrowArrayViewGetInt8Vector(upper_bound_list, partition_idx);
+ }
+
+ manifest_file.partitions.emplace_back(partition_field_summary);
+ }
+ }
+ return {};
+}
+
+Result<std::vector<ManifestFile>> ParseManifestList(ArrowSchema* schema,
+ ArrowArray* array_in,
+ const Schema&
iceberg_schema) {
+ if (schema->n_children != array_in->n_children) {
+ return InvalidManifestList("Columns size not match between schema:{} and
array:{}",
+ schema->n_children, array_in->n_children);
+ }
+ if (iceberg_schema.fields().size() != array_in->n_children) {
+ return InvalidManifestList("Columns size not match between schema:{} and
array:{}",
+ iceberg_schema.fields().size(),
array_in->n_children);
+ }
+
+ ArrowError error;
+ ArrowArrayView array_view;
+ auto status = ArrowArrayViewInitFromSchema(&array_view, schema, &error);
+ ICEBERG_NANOARROW_RETURN_UNEXPECTED_WITH_ERROR(status, error);
+ internal::ArrowArrayViewGuard view_guard(&array_view);
+ status = ArrowArrayViewSetArray(&array_view, array_in, &error);
+ ICEBERG_NANOARROW_RETURN_UNEXPECTED_WITH_ERROR(status, error);
+ status = ArrowArrayViewValidate(&array_view,
NANOARROW_VALIDATION_LEVEL_FULL, &error);
+ ICEBERG_NANOARROW_RETURN_UNEXPECTED_WITH_ERROR(status, error);
+
+ std::vector<ManifestFile> manifest_files;
+ manifest_files.resize(array_in->length);
+
+ for (int64_t idx = 0; idx < array_in->n_children; idx++) {
+ ICEBERG_ASSIGN_OR_RAISE(auto field, iceberg_schema.GetFieldByIndex(idx));
+ ICEBERG_CHECK(field.has_value(), "Invalid index {} for data file schema",
idx);
+ auto field_name = field->get().name();
+ auto field_id = field->get().field_id();
+ auto required = !field->get().optional();
+ auto view_of_column = array_view.children[idx];
+ switch (field_id) {
+ case ManifestFile::kManifestPathFieldId:
+ PARSE_STRING_FIELD(manifest_files[row_idx].manifest_path,
view_of_column);
+ break;
+ case ManifestFile::kManifestLengthFieldId:
+ PARSE_PRIMITIVE_FIELD(manifest_files[row_idx].manifest_length,
view_of_column,
+ int64_t);
+ break;
+ case ManifestFile::kPartitionSpecIdFieldId:
+ PARSE_PRIMITIVE_FIELD(manifest_files[row_idx].partition_spec_id,
view_of_column,
+ int32_t);
+ break;
+ case ManifestFile::kContentFieldId:
+ PARSE_PRIMITIVE_FIELD(manifest_files[row_idx].content, view_of_column,
+ ManifestContent);
+ break;
+ case ManifestFile::kSequenceNumberFieldId:
+ PARSE_PRIMITIVE_FIELD(manifest_files[row_idx].sequence_number,
view_of_column,
+ int64_t);
+ break;
+ case ManifestFile::kMinSequenceNumberFieldId:
+ PARSE_PRIMITIVE_FIELD(manifest_files[row_idx].min_sequence_number,
view_of_column,
+ int64_t);
+ break;
+ case ManifestFile::kAddedSnapshotIdFieldId:
+ PARSE_PRIMITIVE_FIELD(manifest_files[row_idx].added_snapshot_id,
view_of_column,
+ int64_t);
+ break;
+ case ManifestFile::kAddedFilesCountFieldId:
+ PARSE_PRIMITIVE_FIELD(manifest_files[row_idx].added_files_count,
view_of_column,
+ int32_t);
+ break;
+ case ManifestFile::kExistingFilesCountFieldId:
+ PARSE_PRIMITIVE_FIELD(manifest_files[row_idx].existing_files_count,
+ view_of_column, int32_t);
+ break;
+ case ManifestFile::kDeletedFilesCountFieldId:
+ PARSE_PRIMITIVE_FIELD(manifest_files[row_idx].deleted_files_count,
view_of_column,
+ int32_t);
+ break;
+ case ManifestFile::kAddedRowsCountFieldId:
+ PARSE_PRIMITIVE_FIELD(manifest_files[row_idx].added_rows_count,
view_of_column,
+ int64_t);
+ break;
+ case ManifestFile::kExistingRowsCountFieldId:
+ PARSE_PRIMITIVE_FIELD(manifest_files[row_idx].existing_rows_count,
view_of_column,
+ int64_t);
+ break;
+ case ManifestFile::kDeletedRowsCountFieldId:
+ PARSE_PRIMITIVE_FIELD(manifest_files[row_idx].deleted_rows_count,
view_of_column,
+ int64_t);
+ break;
+ case ManifestFile::kPartitionSummaryFieldId:
+ ICEBERG_RETURN_UNEXPECTED(
+ ParsePartitionFieldSummaryList(view_of_column, manifest_files));
+ break;
+ case ManifestFile::kKeyMetadataFieldId:
+ PARSE_BINARY_FIELD(manifest_files[row_idx].key_metadata,
view_of_column);
+ break;
+ case ManifestFile::kFirstRowIdFieldId:
+ PARSE_PRIMITIVE_FIELD(manifest_files[row_idx].first_row_id,
view_of_column,
+ int64_t);
+ break;
+ default:
+ return InvalidManifestList("Unsupported field: {} in manifest file.",
field_name);
+ }
+ }
+ return manifest_files;
+}
+
+Status ParseLiteral(ArrowArrayView* view_of_partition, int64_t row_idx,
Review Comment:
Should we rename this to ParsePartitionValues, the current name is a little
bit confusing to me.
--
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]