@Test public void testVariableExecution() throws Exception {
check(new Action() {
public void check(RexBuilder rexBuilder, RexExecutorImpl executor) {
Object[] values = new Object[1];
final DataContext testContext = new TestDataContext(values);
final RelDataType varchar = rexBuilder.getTypeFactory().createSqlType(
SqlTypeName.VARCHAR);
final RelDataType integer = rexBuilder.getTypeFactory().createSqlType(
SqlTypeName.INTEGER);
// optiq is internally creating the creating the input ref via a
// RexRangeRef
// which eventually leads to a RexInputRef. So we are good.
final RexInputRef input = rexBuilder.makeInputRef(varchar, 0);
final RexNode lengthArg = rexBuilder.makeLiteral(3, integer, true);
final RexNode substr =
rexBuilder.makeCall(SqlStdOperatorTable.SUBSTRING, input,
lengthArg);
ImmutableList<RexNode> constExps = ImmutableList.of(substr);
final RelDataTypeFactory typeFactory = rexBuilder.getTypeFactory();
final RelDataType rowType = typeFactory.builder()
.add("someStr", varchar)
.build();
final RexExecutable exec = executor.getExecutable(rexBuilder,
constExps, rowType);