Repository: incubator-quickstep Updated Branches: refs/heads/use_hdfs_flag c88fdecc1 -> dda085c7a (forced update)
Extract getFilesize as a method. Project: http://git-wip-us.apache.org/repos/asf/incubator-quickstep/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-quickstep/commit/43a9b398 Tree: http://git-wip-us.apache.org/repos/asf/incubator-quickstep/tree/43a9b398 Diff: http://git-wip-us.apache.org/repos/asf/incubator-quickstep/diff/43a9b398 Branch: refs/heads/use_hdfs_flag Commit: 43a9b3981146ffaa6da125faf7bc0fa2a918834d Parents: 61391ca Author: Zuyu Zhang <zu...@apache.org> Authored: Sat Feb 4 16:08:02 2017 -0800 Committer: Zuyu Zhang <zu...@apache.org> Committed: Sat Feb 4 16:08:02 2017 -0800 ---------------------------------------------------------------------- relational_operators/TextScanOperator.cpp | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/43a9b398/relational_operators/TextScanOperator.cpp ---------------------------------------------------------------------- diff --git a/relational_operators/TextScanOperator.cpp b/relational_operators/TextScanOperator.cpp index aa734d3..6650319 100644 --- a/relational_operators/TextScanOperator.cpp +++ b/relational_operators/TextScanOperator.cpp @@ -78,6 +78,20 @@ static bool ValidateTextScanTextSegmentSize(const char *flagname, static const volatile bool text_scan_text_segment_size_dummy = gflags::RegisterFlagValidator( &FLAGS_textscan_text_segment_size, &ValidateTextScanTextSegmentSize); +namespace { + +size_t getFileSize(const string &file_name) { + // Use standard C libary to retrieve the file size. + FILE *fp = std::fopen(file_name.c_str(), "rb"); + std::fseek(fp, 0, SEEK_END); + const std::size_t file_size = std::ftell(fp); + std::fclose(fp); + + return file_size; +} + +} // namespace + bool TextScanOperator::getAllWorkOrders( WorkOrdersContainer *container, QueryContext *query_context, @@ -105,10 +119,7 @@ bool TextScanOperator::getAllWorkOrders( << "File " << file << " is not readable due to permission issues."; #endif // QUICKSTEP_HAVE_UNISTD - FILE *fp = std::fopen(file.c_str(), "rb"); - std::fseek(fp, 0, SEEK_END); - const std::size_t file_size = std::ftell(fp); - std::fclose(fp); + const std::size_t file_size = getFileSize(file); std::size_t text_offset = 0; for (size_t num_full_segments = file_size / FLAGS_textscan_text_segment_size; @@ -148,11 +159,7 @@ bool TextScanOperator::getAllWorkOrderProtos(WorkOrderProtosContainer *container const std::vector<std::string> files = utility::file::GlobExpand(file_pattern_); if (blocking_dependencies_met_ && !work_generated_) { for (const string &file : files) { - // Use standard C libary to retrieve the file size. - FILE *fp = std::fopen(file.c_str(), "rb"); - std::fseek(fp, 0, SEEK_END); - const std::size_t file_size = std::ftell(fp); - std::fclose(fp); + const std::size_t file_size = getFileSize(file); size_t text_offset = 0; for (size_t num_full_segments = file_size / FLAGS_textscan_text_segment_size;