Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision Both sides next revision
image_expression_null_value_handling [2022/08/21 13:24]
admin [Proper Way of Testing for Image Values -- Guarding Against Null Values]
image_expression_null_value_handling [2022/08/21 13:28]
admin [Null Evaluation]
Line 13: Line 13:
   * Every time the expression being evaluated results in null, the entire ​ expression becomes null. So, ''​i1 + null''​ will always be null since  something ''​+''​ null is always null.   * Every time the expression being evaluated results in null, the entire ​ expression becomes null. So, ''​i1 + null''​ will always be null since  something ''​+''​ null is always null.
  
-  * The only operators that can contain the //​destructive power// of a null value are ''​isnull(  expression )''​ or ''​expression1 ? expression2'':​ +  * The only operators that can contain the //​destructive power// of a null value are ''​isNull(  expression )''​ or ''​expression1 ? expression2'':​ 
-    - ''​isnull( expression )''​ evaluates the expression and results 1 if the ''​expression''​ evaluates to null, and 0 otherwise.+    - ''​isNull( expression )''​ evaluates the expression and results 1 if the ''​expression''​ evaluates to null, and 0 otherwise.
     - ''​expression1 ​ ? expression2''​ evaluates the ''​expression1''​ and, if the result is  non-null, returns that value. Otherwise, it evaluates ''​expression2''​ and returns the resulting value as its own result.     - ''​expression1 ​ ? expression2''​ evaluates the ''​expression1''​ and, if the result is  non-null, returns that value. Otherwise, it evaluates ''​expression2''​ and returns the resulting value as its own result.
  
Line 30: Line 30:
         - Now, null is being caught by the expression ''​null ? 20'',​ since the ''​if then else + 10''​ is null, and the result is 20.         - Now, null is being caught by the expression ''​null ? 20'',​ since the ''​if then else + 10''​ is null, and the result is 20.
  
-The  null evaluation mechanism allows us to write short expressions like ''​i1 + 10''​ to add 10 to every //valid cell// of the ''​i1''​ map, or ''​i1 * i2''​ to  multiply two maps. If one of the map cells is null, the result is null, so in the last example, we are basically just multiplying the corresponding cells where the  two values are valid: **everything else will be null**.+The null evaluation mechanism allows us to write short expressions like ''​i1 + 10''​ to add 10 to every //valid cell// of the ''​i1''​ map, or ''​i1 * i2''​ to  multiply two maps. If one of the map cells is null, the result is null, so in the last example, we are basically just multiplying the corresponding cells where the  two values are valid: **everything else will be null**.
  
-If we  want to treat all null values as values 1s, in the previous expression, we can write ''​(i1 ? 1) * (i2 ? 1)''​. We can also use the more complicated form using the ''​if then else''​ to achieve the same result such as ''​(if ​isnull(i1) then 1 else i1) * (if isnull(i2) then 1 else i2)'',​ or even +If we  want to treat all null values as values 1s, in the previous expression, we can write ''​(i1 ? 1) * (i2 ? 1)''​. We can also use the more complicated form using the ''​if then else''​ to achieve the same result such as ''​(if ​isNull(i1) then 1 else i1) * (if isNull(i2) then 1 else i2)'',​ or even 
-  if isnull(i1) and isnull(i2) then 1 +  if isNull(i1) and isNull(i2) then 1 
-  else if not isnull(i1) and not isnull(i2) then i1*i2 +  else if not isNull(i1) and not isNull(i2) then i1*i2 
-  else if not isnull(i1) and isnull(i2) then i1+  else if not isNull(i1) and isNull(i2) then i1
   else i2   else i2