@@ -286,11 +286,7 @@ Status ConcreteTypeFromFlatbuffer(flatbuf::Type type, const void* type_data,
286286 case flatbuf::Type::Timestamp: {
287287 auto ts_type = static_cast <const flatbuf::Timestamp*>(type_data);
288288 TimeUnit::type unit = FromFlatbufferUnit (ts_type->unit ());
289- if (ts_type->timezone () != 0 && ts_type->timezone ()->Length () > 0 ) {
290- *out = timestamp (unit, ts_type->timezone ()->str ());
291- } else {
292- *out = timestamp (unit);
293- }
289+ *out = timestamp (unit, StringFromFlatbuffers (ts_type->timezone ()));
294290 return Status::OK ();
295291 }
296292 case flatbuf::Type::Duration: {
@@ -369,10 +365,7 @@ static Status TypeFromFlatbuffer(const flatbuf::Field* field,
369365 const KeyValueMetadata* field_metadata,
370366 std::shared_ptr<DataType>* out) {
371367 auto type_data = field->type ();
372- if (type_data == nullptr ) {
373- return Status::IOError (
374- " Type-pointer in custom metadata of flatbuffer-encoded Field is null." );
375- }
368+ CHECK_FLATBUFFERS_NOT_NULL (type_data, " Field.type" );
376369 RETURN_NOT_OK (ConcreteTypeFromFlatbuffer (field->type_type (), type_data, children, out));
377370
378371 // Look for extension metadata in custom_metadata field
@@ -474,14 +467,8 @@ Status KeyValueMetadataFromFlatbuffer(const KVVector* fb_metadata,
474467
475468 metadata->reserve (fb_metadata->size ());
476469 for (const auto & pair : *fb_metadata) {
477- if (pair->key () == nullptr ) {
478- return Status::IOError (
479- " Key-pointer in custom metadata of flatbuffer-encoded Schema is null." );
480- }
481- if (pair->value () == nullptr ) {
482- return Status::IOError (
483- " Value-pointer in custom metadata of flatbuffer-encoded Schema is null." );
484- }
470+ CHECK_FLATBUFFERS_NOT_NULL (pair->key (), " custom_metadata.key" );
471+ CHECK_FLATBUFFERS_NOT_NULL (pair->value (), " custom_metadata.value" );
485472 metadata->Append (pair->key ()->str (), pair->value ()->str ());
486473 }
487474
@@ -776,16 +763,16 @@ Status FieldFromFlatbuffer(const flatbuf::Field* field, DictionaryMemo* dictiona
776763
777764 // Reconstruct the data type
778765 auto children = field->children ();
779- if (children == nullptr ) {
780- return Status::IOError (" Children-pointer of flatbuffer-encoded Field is null." );
781- }
766+ CHECK_FLATBUFFERS_NOT_NULL (children, " Field.children" );
782767 std::vector<std::shared_ptr<Field>> child_fields (children->size ());
783768 for (int i = 0 ; i < static_cast <int >(children->size ()); ++i) {
784769 RETURN_NOT_OK (
785770 FieldFromFlatbuffer (children->Get (i), dictionary_memo, &child_fields[i]));
786771 }
787772 RETURN_NOT_OK (TypeFromFlatbuffer (field, child_fields, metadata.get (), &type));
788773
774+ auto field_name = StringFromFlatbuffers (field->name ());
775+
789776 const flatbuf::DictionaryEncoding* encoding = field->dictionary ();
790777
791778 if (encoding != nullptr ) {
@@ -794,22 +781,14 @@ Status FieldFromFlatbuffer(const flatbuf::Field* field, DictionaryMemo* dictiona
794781 // dictionary_memo
795782 std::shared_ptr<DataType> index_type;
796783 auto int_data = encoding->indexType ();
797- if (int_data == nullptr ) {
798- return Status::IOError (
799- " indexType-pointer in custom metadata of flatbuffer-encoded DictionaryEncoding "
800- " is null." );
801- }
784+ CHECK_FLATBUFFERS_NOT_NULL (int_data, " DictionaryEncoding.indexType" );
802785 RETURN_NOT_OK (IntFromFlatbuffer (int_data, &index_type));
803786 ARROW_ASSIGN_OR_RAISE (type,
804787 DictionaryType::Make (index_type, type, encoding->isOrdered ()));
805- *out = ::arrow::field (field-> name ()-> str () , type, field->nullable (), metadata);
788+ *out = ::arrow::field (field_name , type, field->nullable (), metadata);
806789 RETURN_NOT_OK (dictionary_memo->AddField (encoding->id (), *out));
807790 } else {
808- auto name = field->name ();
809- if (name == nullptr ) {
810- return Status::IOError (" Name-pointer of flatbuffer-encoded Field is null." );
811- }
812- *out = ::arrow::field (name->str (), type, field->nullable (), metadata);
791+ *out = ::arrow::field (field_name, type, field->nullable (), metadata);
813792 }
814793 return Status::OK ();
815794}
@@ -1183,17 +1162,15 @@ Status WriteFileFooter(const Schema& schema, const std::vector<FileBlock>& dicti
11831162Status GetSchema (const void * opaque_schema, DictionaryMemo* dictionary_memo,
11841163 std::shared_ptr<Schema>* out) {
11851164 auto schema = static_cast <const flatbuf::Schema*>(opaque_schema);
1186- if (schema->fields () == nullptr ) {
1187- return Status::IOError (" Fields-pointer of flatbuffer-encoded Schema is null." );
1188- }
1165+ CHECK_FLATBUFFERS_NOT_NULL (schema, " schema" );
1166+ CHECK_FLATBUFFERS_NOT_NULL (schema->fields (), " Schema.fields" );
11891167 int num_fields = static_cast <int >(schema->fields ()->size ());
11901168
11911169 std::vector<std::shared_ptr<Field>> fields (num_fields);
11921170 for (int i = 0 ; i < num_fields; ++i) {
11931171 const flatbuf::Field* field = schema->fields ()->Get (i);
1194- if (field == nullptr ) {
1195- return Status::IOError (" Field-pointer of flatbuffer-encoded Schema is null." );
1196- }
1172+ // XXX I don't think this check is necessary (AP)
1173+ CHECK_FLATBUFFERS_NOT_NULL (field, " DictionaryEncoding.indexType" );
11971174 RETURN_NOT_OK (FieldFromFlatbuffer (field, dictionary_memo, &fields[i]));
11981175 }
11991176
@@ -1225,12 +1202,7 @@ Status GetTensorMetadata(const Buffer& metadata, std::shared_ptr<DataType>* type
12251202 auto dim = tensor->shape ()->Get (i);
12261203
12271204 shape->push_back (dim->size ());
1228- auto fb_name = dim->name ();
1229- if (fb_name == 0 ) {
1230- dim_names->push_back (" " );
1231- } else {
1232- dim_names->push_back (fb_name->str ());
1233- }
1205+ dim_names->push_back (StringFromFlatbuffers (dim->name ()));
12341206 }
12351207
12361208 if (tensor->strides () && tensor->strides ()->size () > 0 ) {
@@ -1239,11 +1211,7 @@ Status GetTensorMetadata(const Buffer& metadata, std::shared_ptr<DataType>* type
12391211 }
12401212 }
12411213
1242- auto type_data = tensor->type ();
1243- if (type_data == nullptr ) {
1244- return Status::IOError (
1245- " Type-pointer in custom metadata of flatbuffer-encoded Tensor is null." );
1246- }
1214+ auto type_data = tensor->type (); // Required
12471215 return ConcreteTypeFromFlatbuffer (tensor->type_type (), type_data, {}, type);
12481216}
12491217
@@ -1283,12 +1251,7 @@ Status GetSparseTensorMetadata(const Buffer& metadata, std::shared_ptr<DataType>
12831251 }
12841252
12851253 if (dim_names) {
1286- auto fb_name = dim->name ();
1287- if (fb_name == 0 ) {
1288- dim_names->push_back (" " );
1289- } else {
1290- dim_names->push_back (fb_name->str ());
1291- }
1254+ dim_names->push_back (StringFromFlatbuffers (dim->name ()));
12921255 }
12931256 }
12941257 }
@@ -1324,11 +1287,7 @@ Status GetSparseTensorMetadata(const Buffer& metadata, std::shared_ptr<DataType>
13241287 }
13251288 }
13261289
1327- auto type_data = sparse_tensor->type ();
1328- if (type_data == nullptr ) {
1329- return Status::IOError (
1330- " Type-pointer in custom metadata of flatbuffer-encoded SparseTensor is null." );
1331- }
1290+ auto type_data = sparse_tensor->type (); // Required
13321291 if (type) {
13331292 return ConcreteTypeFromFlatbuffer (sparse_tensor->type_type (), type_data, {}, type);
13341293 } else {
0 commit comments