This is an old revision of the document!


Use the TimEL facade to compile and run a program:

// Assemble the evaluation interval as [now, now + 1 second)
long now = new Date().getTime();
Interval interval = Interval.of(now, now + 1000L);
// Compile the expression 1 + 1
Expression<Double> expression = TimEL
    .getCompiler("1 + 1") // Get the compiler builder for the expression 1+1
    .compileExpression(Types.getNumericDoubleType()); // Compile the source as an expression 
                                                      // that returns a double
// Execute the expression
TimeIterator<Double> itor = TimEL
    .getExecutor(expression) // Get executor for the expression
    .evaluateFor(interval); // Evaluate for the given interval
// Since 1+1 is constant we'll have a single sample for the whole interval
double v =;

Note that all the job is done through the TimEL facade, first compiling the expression and then executing it.

The following example shows how to provide non constant values to TimEL using a *variable*.

TreeMapVariable<Double> variable = new TreeMapVariable<Double>();
long now = new Date().getTime();
// Retrieve the map backing the TreeMapVariable
TreeMap<Interval, Double> values = variable.getBackMap();
// Add some values to the variable
values.put(Interval.of(now, now + 1000), 1.0); // [now, now + 1s) = 1.0
values.put(Interval.of(now + 1000, now + 2000), 2.0); // [now + 1s, now + 2s) = 2.0
values.put(Interval.of(now + 2000, now + 3000), 3.0); // [now + 2s, now + 3s) = 3.0
// Compile the A * A expression
Expression<Double> expression = TimEL
        .getCompiler("A * A")
        .declareVariable("A", Types.getNumericDoubleType()) // Declare A as a numeric type
        .compileExpression(Types.getNumericDoubleType()); // Expect a numeric result
// Evaluate the expression in the interval [now, now + 3 seconds)
TimeIterator<Double> itor = TimEL
        .bindVariable("A", variable)
        .evaluateFor(Interval.of(now, now + 3000));
System.out.println("Starting evaluation...");
// Now trigger the evaluation reading the output
// This will print 3 lines, one for each interval,
// with the value 1, 4 and 9.

Note that TimEL works in a streaming way, that is it pulls values from input and computes the result as soon as the output iterator is advanced. This way allows the library to work incrementally, thus the whole dataset is not required to fit in memory (imagine having various year of samples at a second resolution!) but can be instead streamed when needed.

To provide values to a TimEL program or expression the followings steps are needed, as shown above:

  1. The variable needs to be declared at compile time with its relative type;
  2. An instance of the variable needs to be bounded at execution time.

TimEL is agnostic to data storage and requires the user to implement the Variable interface to allow read and write operations. Note that reading an interval in both directions is required.

The commodity TreeMapVariable class is a Variable implementation backed by a TreeMap can be used when the dataset is not large.

Please consider the API not mature yet and subject to change. Although no major changes are expected in the TimEL facade, the type mechanism is still prototypal an might be subject to changes.

Anything in the impl package is to be considered private, and therefore, unstable.

  • quickstart.1456528775.txt.gz
  • Last modified: 2016/02/26 23:19
  • by a.leofreddi