MCPcopy Create free account
hub / github.com/apache/impala / CacheFileCmp

Function CacheFileCmp

be/src/exec/tuple-text-file-util.cc:144–189  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

142}
143
144static Status CacheFileCmp(
145 const std::string& path_a, const std::string& path_b, bool* passed) {
146 DCHECK(passed != nullptr);
147 *passed = false;
148
149 // Create readers for the two files.
150 TupleTextFileReader reader_a(path_a);
151 TupleTextFileReader reader_b(path_b);
152
153 // Validate and open files
154 RETURN_IF_ERROR(ValidateAndOpenFile(path_a, reader_a));
155 RETURN_IF_ERROR(ValidateAndOpenFile(path_b, reader_b));
156
157 // Compare file sizes.
158 // Files are supposed to be written in tuple-text-file-writer.cc, and are plain
159 // text with '\n' as row delimiters and no padding, so a size mismatch likely
160 // indicates content differences.
161 // If the sizes are different, we leave "passed" as false to let the caller to proceed
162 // with a slower check. This may provide a clearer error message and prevent false
163 // mismatches when identical rows appear in a different order, which may result in
164 // different sizes.
165 if (reader_a.GetFileSize() != reader_b.GetFileSize()) return Status::OK();
166
167 // Reset readers to the beginning of the files.
168 reader_a.Rewind();
169 reader_b.Rewind();
170
171 // Compare the content line by line.
172 string line_a, line_b;
173 bool eos_a = false, eos_b = false;
174 *passed = true;
175 while (true) {
176 // Read the next line from each file.
177 RETURN_IF_ERROR(reader_a.GetNext(&line_a, &eos_a));
178 RETURN_IF_ERROR(reader_b.GetNext(&line_b, &eos_b));
179 // If both files reached the end, the comparison is complete.
180 if (eos_a && eos_b) break;
181 DCHECK_EQ(eos_a, eos_b);
182 // If the lines differ, the files are not identical.
183 if (line_a != line_b) {
184 *passed = false;
185 break;
186 }
187 }
188 return Status::OK();
189}
190
191Status TupleTextFileUtil::VerifyDebugDumpCache(
192 const string& file_name, const string& ref_file_name, bool* passed) {

Callers 1

VerifyDebugDumpCacheMethod · 0.85

Calls 5

ValidateAndOpenFileFunction · 0.85
OKFunction · 0.85
GetFileSizeMethod · 0.45
RewindMethod · 0.45
GetNextMethod · 0.45

Tested by

no test coverage detected