Exemplo n.º 1
0
 public void testWriteArray() {
   assertEquals(
       "1 + integers[2 + index]",
       Expressions.toString(
           Expressions.add(
               Expressions.constant(1),
               Expressions.arrayIndex(
                   Expressions.variable(int[].class, "integers"),
                   Expressions.add(
                       Expressions.constant(2), Expressions.variable(int.class, "index"))))));
 }
  public Result implement(EnumerableRelImplementor implementor, Prefer pref) {
    logger.debug("implementing enumerable");

    final DrillImplementor drillImplementor = new DrillImplementor(this.client == null);
    DrillRel input = (DrillRel) getChild();

    drillImplementor.go(input);
    String plan = drillImplementor.getJsonString();
    Hook.LOGICAL_PLAN.run(plan);

    // not quite sure where this list was supposed to be set earlier, leaving it null got me back
    // the full result set

    final List<String> fieldNameList = rowType.getFieldNames();
    // final List<String> fieldNameList = null;
    BlockStatement expr =
        new BlockBuilder()
            .append(
                Expressions.call(
                    OF_METHOD,
                    Expressions.constant(plan), //
                    Expressions.call(
                        Arrays.class,
                        "asList", //
                        Expressions.newArrayInit(
                            String.class, Functions.apply(fieldNameList, TO_LITERAL)) //
                        ),
                    Expressions.constant(Object.class), //
                    Expressions.variable(DataContext.class, "root")))
            .toBlock();
    final PhysType physType =
        PhysTypeImpl.of(
            implementor.getTypeFactory(), getRowType(), pref.prefer(JavaRowFormat.ARRAY));
    return new Result(expr, physType, JavaRowFormat.ARRAY);
  }