alkis commented on code in PR #42174: URL: https://github.com/apache/arrow/pull/42174#discussion_r1683022180
########## cpp/tools/parquet/parquet_dump_footer.cc: ########## @@ -0,0 +1,248 @@ +// 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 <cstdint> +#include <cstring> +#include <exception> +#include <fstream> +#include <iostream> +#include <limits> +#include <optional> +#include <random> + +#include <thrift/protocol/TCompactProtocol.h> +#include <thrift/transport/TBufferTransports.h> + +#include "arrow/filesystem/filesystem.h" +#include "arrow/util/endian.h" +#include "arrow/util/ubsan.h" +#include "generated/parquet_types.h" +#include "parquet/thrift_internal.h" + +using apache::thrift::protocol::TCompactProtocol; +using apache::thrift::transport::TMemoryBuffer; +using apache::thrift::transport::TTransport; + +namespace { +int PrintHelp() { + std::cerr << R"( +Usage: parquet-dump-footer + -h|--help Print help and exit + --no-scrub Do not scrub potentially PII metadata + --json Output JSON instead of binary + --in Input file: required + --out Output file: defaults to stdout + + Dumps the footer of a Parquet file to stdout or a file, optionally with + potentially user specific metadata scrubbed. +)"; + return 1; +} + +uint32_t ReadLE32(const void* p) { + uint32_t x = arrow::util::SafeLoadAs<uint32_t>(static_cast<const uint8_t*>(p)); + return arrow::bit_util::FromLittleEndian(x); +} + +void AppendLE32(uint32_t v, std::string* out) { + v = arrow::bit_util::ToLittleEndian(v); + out->append(reinterpret_cast<const char*>(&v), sizeof(v)); +} + +template <typename T> +bool Deserialize(const char* data, uint32_t len, T* obj) { Review Comment: Yes the macros are great when used in a larger codebase and where errors are terminal and only propagate up. The macros are not going to work here for all callsites because the errors are handled. I have to switch on the error code because I need to disambiguate between the footer being too small or the footer being corrupt and act differently depending on this being the first fetch or the second. Also there are no appropriate error codes in arrow/status.h. To make all errors terminal I could return a `Result<int64_t>` from `ParseFooter` where error is a terminal error, `Ok(0)` is success and `Ok(size)` the size of the footer if the tail is too small. I am not sure that's a particularly great improvement though. -- 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]
