diff --git a/gortools/src/main/java/gorsat/Script/BaseScriptExecutionEngine.java b/gortools/src/main/java/gorsat/Script/BaseScriptExecutionEngine.java index dadac3fb..ccfe247d 100644 --- a/gortools/src/main/java/gorsat/Script/BaseScriptExecutionEngine.java +++ b/gortools/src/main/java/gorsat/Script/BaseScriptExecutionEngine.java @@ -22,6 +22,7 @@ import java.util.stream.Collectors; public class BaseScriptExecutionEngine { + Map executionBlocks = new ConcurrentHashMap<>(); Map aliases = new ConcurrentHashMap<>(); Map fileSignatureMap = new ConcurrentHashMap<>(); @@ -142,14 +143,17 @@ public String getFileSignatureAndUpdateSignatureMap(GorSession session, String c var signatureKey = AnalysisUtilities.getSignatureFromSignatureCommand(session, commandToExecute); var fileListKey = String.join(" ", usedFiles); - if (usedFiles.stream().anyMatch(DataUtil::isYml) || MacroUtilities.containsWriteCommand(commandToExecute)) { + boolean SIDE_EFFECTS_FORCE_RUN = Boolean.parseBoolean(System.getProperty("gor.gorpipe.sideeffects.force_run", "false")); + if (usedFiles.stream().anyMatch(DataUtil::isYml) + || (SIDE_EFFECTS_FORCE_RUN && MacroUtilities.containsWriteCommand(commandToExecute))) { // Cases were we always want to run the query: // 1. if any of the files is a template expansion, we treat this as if non-deterministic. We do not // model how expansion might depend on files and parameters. // We could expand the YML file and then signature that query according to its usedFiles etc., // but that is not too different from forcing a cache miss at this stage by using a never-reused // signature value. We don't save it for reuse. - // 2. if the command contains a write command, we always want to run it for the sideeffect of writing. + // 2. if the command contains a write command, we want to run it for the sideeffect of writing + // if gor.gorpipe.sideeffects.force_run is sett. fileSignature = StringUtilities.createMD5(System.nanoTime() + fileListKey + signatureKey); } else { fileSignature = fileSignatureMap.computeIfAbsent( diff --git a/gortools/src/test/java/gorsat/UTestGorWriteExplicit.java b/gortools/src/test/java/gorsat/UTestGorWriteExplicit.java index 77775a83..21ff4b23 100644 --- a/gortools/src/test/java/gorsat/UTestGorWriteExplicit.java +++ b/gortools/src/test/java/gorsat/UTestGorWriteExplicit.java @@ -2,6 +2,7 @@ import org.gorpipe.gor.table.dictionary.gor.GorDictionaryTableMeta; import org.junit.*; +import org.junit.contrib.java.lang.system.RestoreSystemProperties; import org.junit.rules.TemporaryFolder; import java.io.IOException; @@ -15,6 +16,10 @@ public class UTestGorWriteExplicit { + + @Rule + public final RestoreSystemProperties restoreSystemProperties = new RestoreSystemProperties(); + public static final String WRONG_RESULT = "Wrong results in write folder"; static final String GROUP_CHROM_COUNT = " | group chrom -count"; @@ -544,6 +549,8 @@ public void testGordFolder() { @Test public void testCreateWriteSignature() throws IOException { + System.setProperty("gor.gorpipe.sideeffects.force_run", "true"); + Path path = workDirPath.resolve("gorfile.gorz"); TestUtils.runGorPipe( "create a = gor -p chr21 ../tests/data/gor/genes.gor | write " + path + "; " +