cfile: replace DumpIteratorOptions with number of rows As of commit 9884fab, DumpIterator() doesn't print anything at all when print_rows is false. That makes the option rather useless, so I'm replacing it here with the raw number of rows.
Change-Id: I5d9e80e50926a71d22de4f88a7af6a8091bb2063 Reviewed-on: http://gerrit.cloudera.org:8080/4150 Tested-by: Kudu Jenkins Reviewed-by: Todd Lipcon <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/kudu/repo Commit: http://git-wip-us.apache.org/repos/asf/kudu/commit/f5021e06 Tree: http://git-wip-us.apache.org/repos/asf/kudu/tree/f5021e06 Diff: http://git-wip-us.apache.org/repos/asf/kudu/diff/f5021e06 Branch: refs/heads/master Commit: f5021e0619a838d94beea24be015952122712c2f Parents: b5aa4a7 Author: Adar Dembo <[email protected]> Authored: Sun Aug 28 12:16:05 2016 -0700 Committer: Todd Lipcon <[email protected]> Committed: Mon Aug 29 21:19:46 2016 +0000 ---------------------------------------------------------------------- src/kudu/cfile/cfile-dump.cc | 9 +-------- src/kudu/cfile/cfile_util.cc | 41 +++++++++++++++++++-------------------- src/kudu/cfile/cfile_util.h | 20 ++----------------- src/kudu/tools/fs_tool.cc | 9 ++++----- 4 files changed, 27 insertions(+), 52 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/kudu/blob/f5021e06/src/kudu/cfile/cfile-dump.cc ---------------------------------------------------------------------- diff --git a/src/kudu/cfile/cfile-dump.cc b/src/kudu/cfile/cfile-dump.cc index 66c700f..2b279d0 100644 --- a/src/kudu/cfile/cfile-dump.cc +++ b/src/kudu/cfile/cfile-dump.cc @@ -28,7 +28,6 @@ DEFINE_bool(print_meta, true, "print the header and footer from the file"); DEFINE_bool(iterate_rows, true, "iterate each row in the file"); -DEFINE_bool(print_rows, true, "print each row in the file"); DEFINE_int32(num_iterations, 1, "number of times to iterate the file"); namespace kudu { @@ -63,11 +62,9 @@ Status DumpFile(const string& block_id_str) { gscoped_ptr<CFileIterator> it; RETURN_NOT_OK(reader->NewIterator(&it, CFileReader::DONT_CACHE_BLOCK)); - DumpIteratorOptions opts; - opts.print_rows = FLAGS_print_rows; for (int i = 0; i < FLAGS_num_iterations; i++) { RETURN_NOT_OK(it->SeekToFirst()); - RETURN_NOT_OK(DumpIterator(*reader, it.get(), &cout, opts, 0)); + RETURN_NOT_OK(DumpIterator(*reader, it.get(), &cout, 0, 0)); } } @@ -86,10 +83,6 @@ int main(int argc, char **argv) { return 1; } - if (!FLAGS_iterate_rows) { - FLAGS_print_rows = false; - } - kudu::Status s = kudu::cfile::DumpFile(argv[1]); if (!s.ok()) { std::cerr << "Error: " << s.ToString() << std::endl; http://git-wip-us.apache.org/repos/asf/kudu/blob/f5021e06/src/kudu/cfile/cfile_util.cc ---------------------------------------------------------------------- diff --git a/src/kudu/cfile/cfile_util.cc b/src/kudu/cfile/cfile_util.cc index fa6b20e..393e45c 100644 --- a/src/kudu/cfile/cfile_util.cc +++ b/src/kudu/cfile/cfile_util.cc @@ -35,7 +35,7 @@ static const int kBufSize = 1024*1024; Status DumpIterator(const CFileReader& reader, CFileIterator* it, std::ostream* out, - const DumpIteratorOptions& opts, + int num_rows, int indent) { Arena arena(8192, 8*1024*1024); @@ -48,33 +48,32 @@ Status DumpIterator(const CFileReader& reader, string strbuf; size_t count = 0; while (it->HasNext()) { - size_t n = opts.nrows == 0 ? max_rows : std::min(max_rows, opts.nrows - count); + size_t n = num_rows == 0 ? max_rows : std::min(max_rows, num_rows - count); if (n == 0) break; RETURN_NOT_OK(it->CopyNextValues(&n, &cb)); - if (opts.print_rows) { - if (reader.is_nullable()) { - for (size_t i = 0; i < n; i++) { - strbuf.append(indent, ' '); - const void *ptr = cb.nullable_cell_ptr(i); - if (ptr != nullptr) { - type->AppendDebugStringForValue(ptr, &strbuf); - } else { - strbuf.append("NULL"); - } - strbuf.push_back('\n'); - } - } else { - for (size_t i = 0; i < n; i++) { - strbuf.append(indent, ' '); - type->AppendDebugStringForValue(cb.cell_ptr(i), &strbuf); - strbuf.push_back('\n'); + if (reader.is_nullable()) { + for (size_t i = 0; i < n; i++) { + strbuf.append(indent, ' '); + const void *ptr = cb.nullable_cell_ptr(i); + if (ptr != nullptr) { + type->AppendDebugStringForValue(ptr, &strbuf); + } else { + strbuf.append("NULL"); } + strbuf.push_back('\n'); + } + } else { + for (size_t i = 0; i < n; i++) { + strbuf.append(indent, ' '); + type->AppendDebugStringForValue(cb.cell_ptr(i), &strbuf); + strbuf.push_back('\n'); } - *out << strbuf; - strbuf.clear(); } + + *out << strbuf; + strbuf.clear(); arena.Reset(); count += n; } http://git-wip-us.apache.org/repos/asf/kudu/blob/f5021e06/src/kudu/cfile/cfile_util.h ---------------------------------------------------------------------- diff --git a/src/kudu/cfile/cfile_util.h b/src/kudu/cfile/cfile_util.h index 2022141..54a456b 100644 --- a/src/kudu/cfile/cfile_util.h +++ b/src/kudu/cfile/cfile_util.h @@ -78,28 +78,12 @@ struct ReaderOptions { std::shared_ptr<MemTracker> parent_mem_tracker; }; -struct DumpIteratorOptions { - // If true, print values of rows, otherwise only print aggregate - // information. - bool print_rows; - - // Number of rows to iterate over. If 0, will iterate over all rows. - size_t nrows; - - DumpIteratorOptions() - : print_rows(false), nrows(0) { - } -}; - // Dumps the contents of a cfile to 'out'; 'reader' and 'iterator' -// must be initialized. See cfile/cfile-dump.cc and tools/fs_tool.cc -// for sample usage. -// -// See also: DumpIteratorOptions +// must be initialized. If 'num_rows' is 0, all rows will be printed. Status DumpIterator(const CFileReader& reader, CFileIterator* it, std::ostream* out, - const DumpIteratorOptions& opts, + int num_rows, int indent); // Return the length of the common prefix shared by the two strings. http://git-wip-us.apache.org/repos/asf/kudu/blob/f5021e06/src/kudu/tools/fs_tool.cc ---------------------------------------------------------------------- diff --git a/src/kudu/tools/fs_tool.cc b/src/kudu/tools/fs_tool.cc index 63543bf..960a82b 100644 --- a/src/kudu/tools/fs_tool.cc +++ b/src/kudu/tools/fs_tool.cc @@ -50,7 +50,6 @@ namespace tools { using cfile::CFileIterator; using cfile::CFileReader; using cfile::DumpIterator; -using cfile::DumpIteratorOptions; using cfile::ReaderOptions; using fs::ReadableBlock; using log::LogReader; @@ -454,16 +453,16 @@ Status FsTool::DumpCFileBlockInternal(const BlockId& block_id, std::cout << Indent(indent) << "CFile Header: " << reader->header().ShortDebugString() << std::endl; + if (detail_level_ <= HEADERS_ONLY) { + return Status::OK(); + } std::cout << Indent(indent) << reader->footer().num_values() << " values:" << std::endl; gscoped_ptr<CFileIterator> it; RETURN_NOT_OK(reader->NewIterator(&it, CFileReader::DONT_CACHE_BLOCK)); RETURN_NOT_OK(it->SeekToFirst()); - DumpIteratorOptions iter_opts; - iter_opts.nrows = opts.nrows; - iter_opts.print_rows = detail_level_ > HEADERS_ONLY; - return DumpIterator(*reader, it.get(), &std::cout, iter_opts, indent + 2); + return DumpIterator(*reader, it.get(), &std::cout, opts.nrows, indent + 2); } Status FsTool::DumpDeltaCFileBlockInternal(const Schema& schema,
