MCPcopy Create free account
hub / github.com/apache/arrow / GetReader

Function GetReader

cpp/src/parquet/arrow/reader.cc:944–1102  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

942// File reader implementation
943
944Status GetReader(const SchemaField& field, const std::shared_ptr<Field>& arrow_field,
945 const std::shared_ptr<ReaderContext>& ctx,
946 std::unique_ptr<ColumnReaderImpl>* out) {
947 BEGIN_PARQUET_CATCH_EXCEPTIONS
948
949 auto type_id = arrow_field->type()->id();
950
951 if (type_id == ::arrow::Type::EXTENSION) {
952 auto storage_field = arrow_field->WithType(
953 checked_cast<const ExtensionType&>(*arrow_field->type()).storage_type());
954 RETURN_NOT_OK(GetReader(field, storage_field, ctx, out));
955 if (*out) {
956 auto storage_type = (*out)->field()->type();
957 if (!storage_type->Equals(storage_field->type())) {
958 return Status::Invalid(
959 "Due to column pruning only part of an extension's storage type was loaded. "
960 "An extension type cannot be created without all of its fields");
961 }
962 *out = std::make_unique<ExtensionReader>(arrow_field, std::move(*out));
963 }
964 return Status::OK();
965 }
966
967 if (field.children.size() == 0) {
968 if (!field.is_leaf()) {
969 return Status::Invalid("Parquet non-leaf node has no children");
970 }
971 if (!ctx->IncludesLeaf(field.column_index)) {
972 *out = nullptr;
973 return Status::OK();
974 }
975 std::unique_ptr<FileColumnIterator> input(
976 ctx->iterator_factory(field.column_index, ctx->reader));
977 *out = std::make_unique<LeafReader>(ctx, arrow_field, std::move(input),
978 field.level_info);
979 } else if (type_id == ::arrow::Type::LIST || type_id == ::arrow::Type::MAP ||
980 type_id == ::arrow::Type::FIXED_SIZE_LIST ||
981 type_id == ::arrow::Type::LARGE_LIST ||
982 type_id == ::arrow::Type::LIST_VIEW ||
983 type_id == ::arrow::Type::LARGE_LIST_VIEW) {
984 auto list_field = arrow_field;
985 auto child = &field.children[0];
986 std::unique_ptr<ColumnReaderImpl> child_reader;
987 RETURN_NOT_OK(GetReader(*child, ctx, &child_reader));
988 if (child_reader == nullptr) {
989 *out = nullptr;
990 return Status::OK();
991 }
992
993 // These two types might not be equal if there is column pruning occurred.
994 // further down the stack.
995 const std::shared_ptr<DataType> reader_child_type = child_reader->field()->type();
996 // This should really never happen but was raised as a question on the code
997 // review, this should be pretty cheap check so leave it in.
998 if (ARROW_PREDICT_FALSE(list_field->type()->num_fields() != 1)) {
999 return Status::Invalid("expected exactly one child field for: ",
1000 list_field->ToString());
1001 }

Callers 4

GetReaderMethod · 0.85
GetFieldReaderMethod · 0.85
GetColumnMethod · 0.85
TEST_PFunction · 0.85

Calls 15

listFunction · 0.85
large_listFunction · 0.85
list_viewFunction · 0.85
large_list_viewFunction · 0.85
fixed_size_listFunction · 0.85
UnknownErrorFunction · 0.85
struct_Function · 0.85
WithTypeMethod · 0.80
storage_typeMethod · 0.80
IncludesLeafMethod · 0.80
push_backMethod · 0.80
emplace_backMethod · 0.80

Tested by 1

TEST_PFunction · 0.68