pitrou commented on code in PR #42174:
URL: https://github.com/apache/arrow/pull/42174#discussion_r1683085621


##########
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:
   > 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.
   
   It would be more idiomatic, and would also allow defining the error message 
at the point where the error is emitted.
   
   > Also there are no appropriate error codes in arrow/status.h.
   
   There are a bunch of different error categories, and you can (and should) of 
course attach a custom error message.



-- 
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: github-unsubscr...@arrow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to