Anonymous (inline) scripts

Normally you’d need to create a Kognitio external script as an SQL object but on this page we show how you can invoke these anonymously inline, note that a script environment is still required. This is useful for when the script is being developed and frequent changes need to be made.

Refer to the external script invocation syntax for more information about syntax and definitions.

Scripts can be anonymously invocated (without being created as objects in Kognitio), by slightly altering the syntax in the first line:

CREATE EXTERNAL SCRIPT <script-name> ENVIRONMENT <script-env>

and omitting the CREATE and substituting script name for USING:

EXTERNAL SCRIPT USING ENVIRONMENT <script-env>

Example: anonymous python number generator script

Below is an example of an anonymous script for generating some random integers in Python:

EXTERNAL SCRIPT USING ENVIRONMENT python27
SENDS(res int)
SCRIPT S'EOF(
#
#Package import
import os, csv, sys, random
#
#Input and output streams
input = csv.reader(sys.stdin)
result = csv.writer(sys.stdout)
#
#Write out results
result.writerow([random.randint(1,10)])
)EOF';

For a data generation script like this you may only choose to run it once so there’s no need to save the script to the schema tree. To keep the data this produces though, we can use this in a derived table to create a view and place it into memory. Then to change the data it produces, it can be recreated with different parameters using the replace syntax for views.