Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not add the source path of a view when it can be matched by the deletion pattern #14658

Merged
merged 2 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3521,6 +3521,18 @@ public Analysis visitDeleteData(
logicalViewSchema = (LogicalViewSchema) measurementSchema;
if (logicalViewSchema.isWritable()) {
sourcePathOfAliasSeries = logicalViewSchema.getSourcePathIfWritable();
// if the source path can be matched by any of the deletion pattern, do not add it
boolean pathMatched = false;
for (MeasurementPath deletionPattern : deleteDataStatement.getPathList()) {
if (deletionPattern.matchFullPath(sourcePathOfAliasSeries)) {
pathMatched = true;
break;
}
}
if (pathMatched) {
continue;
}

deletePatternSet.add(new MeasurementPath(sourcePathOfAliasSeries.getNodes()));
deduplicatedDeviceIDs.add(sourcePathOfAliasSeries.getIDeviceID());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileFilter;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
Expand All @@ -41,7 +42,10 @@
import java.nio.file.StandardCopyOption;
import java.text.CharacterIterator;
import java.text.StringCharacterIterator;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Stack;

public class FileUtils {
private static final Logger LOGGER = LoggerFactory.getLogger(FileUtils.class);
Expand All @@ -50,6 +54,29 @@ public class FileUtils {

private FileUtils() {}

public static List<File> listFilesRecursively(File dir, FileFilter fileFilter) {
List<File> result = new ArrayList<>();
Stack<File> stack = new Stack<>();
if (dir.exists()) {
stack.push(dir);
}
while (!stack.isEmpty()) {
File file = stack.pop();
if (file.isDirectory()) {
File[] files = file.listFiles();
if (files != null) {
for (File f : files) {
stack.push(f);
}
}
}
if (fileFilter.accept(file)) {
result.add(file);
}
}
return result;
}

public static boolean deleteFileIfExist(File file) {
try {
Files.deleteIfExists(file.toPath());
Expand Down
Loading