Documentation
Toggle Dark/Light/Auto modeToggle Dark/Light/Auto modeToggle Dark/Light/Auto modeBack to homepage

User Defined

The USER_DEFINED Pre-hook allows a user to write an arbitrary snippet of JavaScript that can modify the SQL text before submitting it to Snowflake.

Configuration Syntax

  {
      'body': <function_body>,
      'errorBehavior': <error_behavior>
  }

Arguments

<body>
A JavaScript body that exposes a single function called doAction(). Input and output of function are objects, each with a single field called sql.
<errorBehavior>
How the hook should behave in the case that the JavaScript function throws an exception. Options are BYPASS which causes the query to skip execution of this hook and continue down the flow and REJECT which causes the query to be rejected with information about the JavaScript failure. Typically set to REJECT during development and then run in production in BYPASS mode.

Usage Notes

  • The JavaScript function is bound by script size, memory and time executing.
  • The JavaScript is not executed in a browser and thus browser specific JavaScript objects (like window & document) are not available.
  • The body can include multiple separate variable and/or function declarations (to ease development modularity). Sundeck will only invoke the doAction() function.

Examples

CREATE SUNDECK FLOW ALWAYS_SELECT_1
      PRE HOOK CONVERT
      ALWAYS
      USER_DEFINED {
        'errorBehavior': 'BYPASS',
        'body':$$ function doAction(obj){
          return {"sql":"select 1"};
        } $$
      }
;