Developing JavaScript functions

When developing JavaScript functions that are more complicated than just simple logic, it is recommended to use the jjs command-line utility to create and iterate while writing functions.

After the function performs the required task, migrate it to the console. Additionally these files/functions can be saved in a source code control system like git/Github.
  1. Create a file for your function.
  2. Create some sample input when calling the function.
  3. Call jjs on the command line to test the function.
    $>cat TO_EPOCH.js
    function TO_EPOCH(strDate) {
       var strFmt = "yyyy-MM-dd HH:ss:mm";
       var c = new java.text.SimpleDateFormat(strFmt).parse(strDate).getTime()/1000;
       return c.toString();
    }
    
    print(TO_EPOCH("2019-02-02 22:23:13"));
    
    then
    $>jjs TO_EPOCH.js
    1549167203
    
After you have successfully developed the JavaScript code, copy and paste only the function to your code window when creating the JavaScript function in SQL Stream Builder.