2010YOUY01 commented on code in PR #17017:
URL: https://github.com/apache/datafusion/pull/17017#discussion_r2265200081


##########
datafusion/sqllogictest/bin/sqllogictests.rs:
##########
@@ -738,3 +753,66 @@ impl Options {
         }
     }
 }
+
+/// Performs scratch file check for all test files.
+///
+/// Scratch file rule: In each .slt test file, the temporary file created must
+/// be under a folder that is has the same name as the test file.
+/// e.g. In `join.slt`, temporary files must be created under 
`.../scratch/join/`
+///
+/// This funciton searches for `scratch/[target]/...` patterns and verifies
+/// that the target matches the file name.
+///
+/// Returns a vector of error strings for incorrectly created scratch files.
+fn scratch_file_check(test_files: &[TestFile]) -> Result<Vec<String>> {
+    let mut errors = Vec::new();
+
+    for test_file in test_files {
+        // Get the file content
+        let content = match fs::read_to_string(&test_file.path) {
+            Ok(content) => content,
+            Err(e) => {
+                errors.push(format!(
+                    "Failed to read file {}: {}",
+                    test_file.path.display(),
+                    e
+                ));
+                continue;
+            }
+        };
+
+        // Get the expected target name (file name without extension)
+        let expected_target = match test_file.path.file_stem() {
+            Some(stem) => stem.to_string_lossy().to_string(),
+            None => {
+                errors.push(format!("File {} has no stem", 
test_file.path.display()));
+                continue;
+            }
+        };
+
+        // Search for any scratch/[target]/... patterns and check if they 
match the file name
+        let lines: Vec<&str> = content.lines().collect();
+        for (line_num, line) in lines.iter().enumerate() {
+            if line.contains("scratch/") {
+                // Extract the target from the pattern
+                if let Some(target_start) = line.find("scratch/") {
+                    let after_scratch = &line[target_start + 8..]; // 
"scratch/" is 8 chars
+                    if let Some(target_end) = after_scratch.find('/') {
+                        let found_target = &after_scratch[..target_end];
+                        if found_target != expected_target {
+                            errors.push(format!(
+                                "File {}:{}: scratch target '{}' does not 
match file name '{}'",
+                                test_file.path.display(),
+                                line_num + 1,
+                                found_target,
+                                expected_target
+                            ));
+                        }
+                    }
+                }
+            }

Review Comment:
   Good idea, updated!



-- 
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...@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org
For additional commands, e-mail: github-h...@datafusion.apache.org

Reply via email to