Skip to content

Commit

Permalink
Add file path into more error messages (#68)
Browse files Browse the repository at this point in the history
Without file path in error messages it is hard to understand what file throws an error since a foreign table can have many parquet files.
  • Loading branch information
za-arthur authored Mar 22, 2023
1 parent 365710b commit 4615d36
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 19 deletions.
18 changes: 10 additions & 8 deletions src/parquet_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,8 @@ extract_rowgroups_list(const char *filename,
&reader);

if (!status.ok())
throw Error("failed to open Parquet file %s", status.message().c_str());
throw Error("failed to open Parquet file: %s ('%s')",
status.message().c_str(), filename);

auto meta = reader->parquet_reader()->metadata();
parquet::ArrowReaderProperties props;
Expand All @@ -569,7 +570,7 @@ extract_rowgroups_list(const char *filename,
status = parquet::arrow::SchemaManifest::Make(meta->schema(), nullptr,
props, &manifest);
if (!status.ok())
throw Error("error creating arrow schema");
throw Error("error creating arrow schema ('%s')", filename);

/* Check each row group whether it matches the filters */
for (int r = 0; r < reader->num_row_groups(); r++)
Expand Down Expand Up @@ -725,12 +726,12 @@ extract_parquet_fields(const char *path) noexcept
parquet::ParquetFileReader::OpenFile(path, false),
&reader);
if (!status.ok())
throw Error("failed to open Parquet file %s",
status.message().c_str());
throw Error("failed to open Parquet file %s ('%s')",
status.message().c_str(), path);

auto p_schema = reader->parquet_reader()->metadata()->schema();
if (!parquet::arrow::SchemaManifest::Make(p_schema, nullptr, props, &manifest).ok())
throw std::runtime_error("error creating arrow schema");
throw Error("error creating arrow schema ('%s')", path);

fields = (FieldInfo *) exc_palloc(
sizeof(FieldInfo) * manifest.schema_fields.size());
Expand All @@ -750,7 +751,7 @@ extract_parquet_fields(const char *path) noexcept
bool error = false;

if (type->num_fields() != 1)
throw std::runtime_error("lists of structs are not supported");
throw Error("lists of structs are not supported ('%s')", path);

subtype_id = get_arrow_list_elem_type(type.get());
pg_subtype = to_postgres_type(subtype_id);
Expand All @@ -767,7 +768,8 @@ extract_parquet_fields(const char *path) noexcept
PG_END_TRY();

if (error)
throw std::runtime_error("failed to get the type of array elements");
throw Error("failed to get the type of array elements for %d",
pg_subtype);
break;
}
case arrow::Type::MAP:
Expand All @@ -789,7 +791,7 @@ extract_parquet_fields(const char *path) noexcept
}
else
{
throw Error("cannot convert field '%s' of type '%s' in %s",
throw Error("cannot convert field '%s' of type '%s' in '%s'",
field->name().c_str(), type->name().c_str(), path);
}
}
Expand Down
22 changes: 11 additions & 11 deletions src/reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ void ParquetReader::create_column_mapping(TupleDesc tupleDesc, const std::set<in
auto p_schema = this->reader->parquet_reader()->metadata()->schema();

if (!parquet::arrow::SchemaManifest::Make(p_schema, nullptr, props, &manifest).ok())
throw std::runtime_error("error creating arrow schema");
throw Error("error creating arrow schema ('%s')", this->filename.c_str());

this->map.resize(tupleDesc->natts);
for (int i = 0; i < tupleDesc->natts; i++)
Expand All @@ -190,8 +190,8 @@ void ParquetReader::create_column_mapping(TupleDesc tupleDesc, const std::set<in
char arrow_colname[255];

if (field_name.length() > NAMEDATALEN)
throw Error("parquet column name '%s' is too long (max: %d)",
field_name.c_str(), NAMEDATALEN - 1);
throw Error("parquet column name '%s' is too long (max: %d, file: '%s')",
field_name.c_str(), NAMEDATALEN - 1, this->filename.c_str());
tolowercase(schema_field.field->name().c_str(), arrow_colname);

/*
Expand Down Expand Up @@ -841,8 +841,8 @@ class DefaultParquetReader : public ParquetReader
parquet::ParquetFileReader::OpenFile(filename, use_mmap),
&reader);
if (!status.ok())
throw Error("failed to open Parquet file %s",
status.message().c_str());
throw Error("failed to open Parquet file %s ('%s')",
status.message().c_str(), filename.c_str());
this->reader = std::move(reader);

/* Enable parallel columns decoding/decompression if needed */
Expand Down Expand Up @@ -893,8 +893,8 @@ class DefaultParquetReader : public ParquetReader
->ReadTable(this->indices, &this->table);

if (!status.ok())
throw Error("failed to read rowgroup #%i: %s",
rowgroup, status.message().c_str());
throw Error("failed to read rowgroup #%i: %s ('%s')",
rowgroup, status.message().c_str(), this->filename.c_str());

if (!this->table)
throw std::runtime_error("got empty table");
Expand Down Expand Up @@ -1069,8 +1069,8 @@ class CachingParquetReader : public ParquetReader
parquet::ParquetFileReader::OpenFile(filename, use_mmap),
&reader);
if (!status.ok())
throw Error("failed to open Parquet file %s",
status.message().c_str());
throw Error("failed to open Parquet file %s ('%s')",
status.message().c_str(), filename.c_str());
this->reader = std::move(reader);

/* Enable parallel columns decoding/decompression if needed */
Expand Down Expand Up @@ -1128,8 +1128,8 @@ class CachingParquetReader : public ParquetReader
->RowGroup(rowgroup)
->ReadTable(this->indices, &table);
if (!status.ok())
throw Error("failed to read rowgroup #%i: %s",
rowgroup, status.message().c_str());
throw Error("failed to read rowgroup #%i: %s ('%s')",
rowgroup, status.message().c_str(), this->filename.c_str());

/* Release resources acquired in the previous iteration */
allocator->recycle();
Expand Down

0 comments on commit 4615d36

Please sign in to comment.