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.

When the function does what you want, then 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"));
    $>jjs TO_EPOCH.js
After you have successfully developed the javascript code, copy/paste only the function to your code window when creating the Javascript Function in SQL Stream Builder.