delete

The delete operator deletes data from an array that satisfy a supplied boolean expression.

Synopsis

delete(array,expression);

Summary

The delete operator deletes data from an array based on an expression over the attribute and dimension values. The result array has the same schema as the supplied array. Each cell of the result array is either empty or identical to the corresponding cell of the supplied array according to the following rules. If the expression at the cell evaluates to: 

  • TRUE, the result cell is deleted.
  • FALSE, the result cell is kept.
  • NULL, the result cell is kept.


Examples

Delete Outlying Values

To delete outlying values, do the following:

  1. Create a 4×4 array:

    AFL% CREATE ARRAY m4x4<val:double>[i=0:3; j=0:3];
  2. Put values between 0 and 15 into the non-diagonal elements of m4x4 and values greater than 100 into the diagonal elements:

    AFL% store(build(m4x4,iif(i=j,100+i,i*4+j)),m4x4); 
  3.  Scan the resulting array:

    AFL% scan(m4x4);
    [
    [(100),(1),(2),(3)],
    [(4),(101),(6),(7)],
    [(8),(9),(102),(11)],
    [(12),(13),(14),(103)]
    ] 
  4. Delete values of 100 or greater from m4x4:

    AFL% delete(m4x4,val>=100);  


  5. Scan the array again:

    AFL% scan(m4x4);
    [
    [(),(1),(2),(3)],
    [(4),(),(6),(7)],
    [(8),(9),(),(11)],
    [(12),(13),(14),()]
    ] 

Comparison with filter()

Conceptually, delete(A, expr) is like store(filter(A, not expr), A). However, the two are not the same  in case expr evaluates to null. This is due to the special semantics that both null and not null evaluate to false.

For instance, delete(A, null) will not delete anything (because null means false). However, store(filter(A, not null), A) will delete everything.

Hint on Deleting by Dimension

Like in filter, the delete operator focuses on processing data in the dimension ranges if specified in the expression. This can be significantly faster than the naive approach of evaluating the expression over every single array cell.

In order to receive full benefit of the optimization, structure your expression in the form of ((dimension_conjunctions or ...) and other_conditions). For instance, let your array have two dimensions x and y; in order to delete records in the first or the third quadrants, and with some other conditions, write your expression as: (((x>0 and y>0) or (x<0 and y<0)) and other_conditions).