FLOW
  • FLOW
  • Getting Started with FLOW
    • Overview
    • The Basics
      • FLOW Concepts
      • Events & Schemas
        • Event Metadata
        • Sample Event
        • Sample Schema
      • Connections
    • Architecture
    • FLOW Schedule
      • Cron Expression
  • Stages
    • Validations
    • Transform
    • Actions
    • Mapper
  • Recipes
  • Scripts
  • Webhooks
  • REST Connector
  • Flow Monitoring
  • Live Monitoring
  • Advanced Topics
    • Post Process
    • Naming Policy
    • Manage Patches
  • Installation
  • FAQ
  • Tutorials
    • Creating a Connection
    • Creating a Flow
    • Creating a Script
    • Creating a Recipe
  • How To
    • OTBI Input
    • CSV File from Amazon S3
  • Changelog
  • Environment Variables
  • Data Security & Privacy
Powered by GitBook
On this page
  • Variables Available
  • Redshift Stored Procedure Exception Handling
  • Sample Script to invoke a Stored Procedure in Redshift
  • Invoking REST API from Scripts

Was this helpful?

Scripts

Automated post processing & advanced metrics collection

PreviousRecipesNextWebhooks

Last updated 5 years ago

Was this helpful?

You can use Scripts to execute java code or to invoke a stored procedure on your target data lake e.g. Redshift or Snowflake after every flow run. You can setup different script to run based on the status of the flow run.

To obtain the connection to the target data lake instance use db.getTargetDBConnection() and db.getSourceDBConnection() to get the connection to the source instance provided you use any relational datasource as the input for the flow.

  1. Script Name

  2. Script Status

  3. Schedule Type

  4. Script written in Java and/or Groovy

  5. View Script Run History

Variables Available

The following are the variables available to the script

Variable

Description

flowCode

Flow code

outputEventType

Table name in the target DB

inputEventType

Table/Object name in the source system

inputType

Input Connector Type e.g. Oracle, MySQL

outputType

Output Connector Type e.g. Oracle, MySQL

logger

Log4j logger for debug purpose

db

Redshift Stored Procedure Exception Handling

When calling a stored procedure on redshift the connection would become stale when an exception occurs. If you want to execute another procedure or SQL from the catch block, use db.resetAndGetTargetDBConnection() to close the existing stale connection and get a new connection for perform additional calls.

Sample Script to invoke a Stored Procedure in Redshift

    try {
      Map result = SQL.createCall(db.getTargetDBConnection(), "sp_cp_1()")
              .execute();
    } catch (Exception e) {
      try {
        String msg = "Error-" + System.currentTimeMillis() + ": " + e.getMessage();
        // call resetAndGetTargetDBConnection instead of getTargetDBConnection,
        // as the connection is getting stale in case of exception
        SQL.createCall(db.resetAndGetTargetDBConnection(), "sp_cp_y(?)")
                .bind(1, msg)
                .registerOutParameter(1, java.sql.Types.VARCHAR).execute();
      } catch (Exception exp) {
        logger.error(exp);
      }
    }

Invoking REST API from Scripts

Map result = Unirest.post("https://example.com")
    .basicAuth("user", "password")
    .asObject(Mapord.class)
    .getBody();

An instance of

Apart from performing JDBC calls, you can use to make any REST web-service call from scripts

Unirest
Setup Script Page
FlowScript