load_module

The load_module operator loads a module text file containing user-defined macros.

Synopsis

load_module('module_pathname');

Summary

The load_module operator loads a SciDB module file. A module is text file containing a collection of user-defined macros. Before invoking load_module(), only system macros are available. After invoking load_module(), both system macros and the macros you loaded are available.

Note the following:

  • The contents stay in memory until you restart SciDB, whereupon you must reload them.
  • Once loaded, the user-defined macros become globally available to all subsequent queries evaluated on the SciDB cluster.
  • Any call of load_module invalidates previously loaded user-defined macros, even if the particular macro is not defined in the newly loaded file.
  • System macros are not affected by the load_module() operator.
  • A macro named m hides any existing identically named applicable entity in the system, including operators, functions, and their user defined counterparts (UDO's and UDF's), and other macros.

Example

  1. Create a module file /tmp/my_module.txt that contains the following user-defined macro:

    /**
     *  Return the Euclidean distance between the two points (x1,y1) and (x2,y2).
     */
    distance(x1,y1,x2,y2) = sqrt(sq(x2-x1) + sq(y2-y1)) where
    {
        sq(x) = x * x;
    };
  2. Load the module:

    AFL% load_module('/tmp/my_module.txt');
  3. Verify that the macro loads:

    AFL% filter(list('macros'), name='distance');


    The output is:

    {No} name,type
    {0} 'distance','distance(x1,y1,x2,y2)'
  4. Use the user-defined macro:

    AFL% build(<v:double>[i=0:2; j=0:2], distance(i,i,j,j));


    The output is:

    {i,j} v
    {0,0} 0
    {0,1} 1.41421
    {0,2} 2.82843
    {1,0} 1.41421
    {1,1} 0
    {1,2} 1.41421
    {2,0} 2.82843
    {2,1} 1.41421
    {2,2} 0
  5. Unload the module, by loading an empty module:

    AFL% load_module('/dev/null');
  6. Verify the removal of the user-defined macro:

    AFL% filter(list('macros'), name='distance');


    The output is:

    {No} name,type