SCRIPTING Queries

Pentaho CTools

Version
10.2.x
Audience
anonymous
Part Number
MK-95PDIA006-12

These data sources allow you to create ad hoc result sets, such as a small table, for prototyping purposes using Beanshell scripts. These result sets are useful during the dashboard development phase for generating data for a dashboard’s components when real data is not yet available. This data source can be one of two types:

scriptable over scripting
Using the Beanshell scripting language, we can define a data structure and then create a result set based on this same structure to use in a component. You will need to define the column names, column types, and the result set rows.
import org.pentaho.reporting.engine.classic.core.util.TypedTableModel;
String[] columnNames = new String[]{
    "value","name2"
};
Class[] columnTypes = new Class[]{
    Integer.class,
    String.class
};
TypedTableModel model = new TypedTableModel(columnNames, columnTypes);
model.addRow(new Object[]{ new Integer("0"), new String("Name") });
return model;
JSONscriptable over scripting
This data source is similar to the scriptable data source in that it uses Beanshell script to generate a result set. However, rather than specifying the column names and column types, you just need to define the metadata and create the result set you want to use. This is simple and less prone to bugs than using the scriptable data source.
{
  "resultset":[
        ["Name", 0]
  ],
  "metadata":[
    {"colIndex":0,"colType":"String","colName":"value"},
    {"colIndex":1,"colType":"Integer","colName":"name2"}
  ]
}