Search code examples
hpcchpcc-ecl

HPCC-ECL Logical Operators - Why is OR not short-circuiting?


The documentation indicates that the OR logical operator should short-circuit:

If the probability of occurrence is known, you should order them from the most likely to occur to the least likely to occur, because once any part of a compound OR condition evaluates to TRUE, the remainder of the expression is bypassed

Unless I am mistaken, this is not behaving as expected. When it has to evaluate an expression that returns TRUE, it seems to continue to evaluate the next expression after the OR. It seems that for a hard-coded value of TRUE, it works as expected.

Am I doing something wrong or misunderstanding the code/documentation?

Consider the below code:

IMPORT STD;
superFileName   := 'temp::superFile';
fileName        := 'temp::regularFile';
returnsTrue     := ~STD.File.FileExists(fileName, TRUE); // File does not exist, so will return true as expression is negated
getSubCount     := NOTHOR(STD.File.GetSuperFileSubCount(superFileName)) > 0; // "Could not locate superfile: thor::nonExistent"

deleteFile      := STD.File.DeleteLogicalFile(fileName);
deleteSuperFile := STD.File.DeleteSuperFile(superFileName);

SEQUENTIAL(
  deleteFile,
  deleteSuperFile,
  OUTPUT(returnsTrue), // true
  OUTPUT(IF ((TRUE OR getSubCount), 'true', 'false')), // 'true'
  OUTPUT(IF ((returnsTrue OR getSubCount), 'true', 'false')), // "Could not locate superfile: thor::temp::superFile"
);

Solution

  • The response provided on the HPCC forum topic here indicates that this is a known issue:

    In this case, your getSubCount definition is an Action, and the compiler executing all actions in a condition is a known issue.

    I have raised a bug for this here, however I guess the answer to this question is currently "it should short-circuit, but it doesn't"