Page tree
Skip to end of metadata
Go to start of metadata

Rapid Prototyping Feature

The Rapid Prototyping Feature allows the usage of data stream processing in arbitrary programming languages. To do so, the feature provides multiple operators that reads a text file with the instructions.

Script Languages

The SCRIPT operator allows the usage of arbitrary so called script languages. Access to the elements of the data stream is available using the public variables attrN (depending on the script language) where N is the index of the attribute. The total number of attributes is available in the attrs variable.

Supported Languages

The following script languages are supported by this feature:

  • JavaScript
  • Python
  • Ruby
  • Groovy

To support other languages a JSR 223 ScriptEngine has to be implemented. In addition, you can use the operators JS, PYTHON, RUBY, and GROOVY as an alias for the SCRIPT operator to increase the readability of your query.

Example

Rapid Prototyping
output = SCRIPT({path=‘script.rb'}, input)

This example calls the file script.rb with the following Ruby script to calculate the Fibonacci number of the first attribute value.

script.rb
#!/usr/bin/env ruby

def f(n) x=y=1;(n-1).times{x,y=y,x+y};y end

$attr1 = f $attr1 if $attrs>=1

Java

You are also free to write a program in Java that will be compiled together with the query.

Example

Rapid Prototyping
output = JAVA({path=‘Example.java'}, input)

This example compiles the file Example.java with the following Java program.

Example.java
import java.util.Map;

public class Example {

   public Object[] process(Object[] payload, Map<String,Object> metadata){
      return new Object[]{"result"};
   }
}

You do not need any annotation. The only important thing is the function name "process" with the two parameters and the return type. The program will be compiled on every start of the query so you can just change something in your prototype and restart the query again without restarting the complete Odysseus system.