/
remove_versions

remove_versions

The remove_versions operator removes older versions of an array.

Synopsis

remove_versions(named_array, version_id);
remove_versions(named_array, keep: count);
remove_versions(named_array);


Summary

The first form of the remove_versions operator removes all versions of an array older than the specified version_id.  The second form keeps the count  most recent versions, removing all earlier versions.  The third form removes all but the most recent version.

Inputs

  • named_array - the name of the array from which you are removing versions.
  • version_id - removes all versions up to the version_id, but not including the version_id.
  • keep: N - remove all but the last N versions

Examples

Using the Operator

To demonstrate remove_versions operator, do the following:

  1. From the command shell, use iquery to create an array and store several versions of data into it:

    $ iquery -aq "create array A<val:double>[i=0:4]"
    Query was executed successfully
    $ for x in $(seq 1 5) ;do iquery -naq "store(build(A, 10 + $x), A)" ;done 
    Query was executed successfully 
    Query was executed successfully
    Query was executed successfully
    Query was executed successfully
    Query was executed successfully
    $ 
  2. Use list('arrays', true) to see all versions of the array, and inspect the values from some older versions:

    $ iquery -a
    AFL%  list('arrays', true);
    {No} name,uaid,aid,schema,availability,temporary,namespace
    {0} 'A',60,60,'A<val:double> [i=0:4:0:*]',true,false,'public'
    {1} 'A@1',60,61,'A@1<val:double> [i=0:4:0:1000000]',true,false,'public'
    {2} 'A@2',60,62,'A@2<val:double> [i=0:4:0:1000000]',true,false,'public'
    {3} 'A@3',60,63,'A@3<val:double> [i=0:4:0:1000000]',true,false,'public'
    {4} 'A@4',60,64,'A@4<val:double> [i=0:4:0:1000000]',true,false,'public'
    {5} 'A@5',60,65,'A@5<val:double> [i=0:4:0:1000000]',true,false,'public'
    AFL% 
    AFL% scan(A@3);
    {i} val
    {0} 13
    {1} 13
    {2} 13
    {3} 13
    {4} 13
    AFL% scan(A@2);
    {i} val
    {0} 12
    {1} 12
    {2} 12
    {3} 12
    {4} 12
  3. Remove all versions earlier than version 3:

    AFL% remove_versions(A, 3);
    Query was executed successfully
    AFL%
    AFL% list('arrays', true);
    {No} name,uaid,aid,schema,availability,temporary,namespace
    {0} 'A',60,60,'A<val:double> [i=0:4:0:*]',true,false,'public'
    {1} 'A@3',60,63,'A@3<val:double> [i=0:4:0:1000000]',true,false,'public'
    {2} 'A@4',60,64,'A@4<val:double> [i=0:4:0:1000000]',true,false,'public'
    {3} 'A@5',60,65,'A@5<val:double> [i=0:4:0:1000000]',true,false,'public'
    {4} 'foo',53,53,'foo<a:int32> [i=0:50000:0:1000]',true,false,'public'
  4. Remove all but the last two versions:

    AFL% remove_versions(A, keep: 2);
    Query was executed successfully
    AFL% 
    AFL% list('arrays', true);
    {No} name,uaid,aid,schema,availability,temporary,namespace
    {0} 'A',60,60,'A<val:double> [i=0:4:0:*]',true,false,'public'
    {1} 'A@4',60,64,'A@4<val:double> [i=0:4:0:1000000]',true,false,'public'
    {2} 'A@5',60,65,'A@5<val:double> [i=0:4:0:1000000]',true,false,'public'
    
  5. Keep the latest version, removing everything else:

    AFL% remove_versions(A);
    Query was executed successfully
    AFL% 
    AFL% list('arrays', true);
    {No} name,uaid,aid,schema,availability,temporary,namespace
    {0} 'A',60,60,'A<val:double> [i=0:4:0:*]',true,false,'public'
    {1} 'A@5',60,65,'A@5<val:double> [i=0:4:0:1000000]',true,false,'public'
  6.  Remove the rest of the versions of the array:

    AFL% remove(A);
    Query was executed successfully
    AFL%