Beispiel #1
0
 private void bindDeferred(JavaFrame frame, final RelNode rel) {
   final StatementList statementList = getStatementList();
   if (frame.bind == null) {
     // this relational expression has not bound itself, so we presume
     // that we can call its implementSelf() method
     if (!(rel instanceof JavaSelfRel)) {
       throw Util.newInternal(
           "In order to bind-deferred, a "
               + "relational expression must implement JavaSelfRel: "
               + rel);
     }
     final JavaSelfRel selfRel = (JavaSelfRel) rel;
     LazyBind lazyBind =
         new LazyBind(
             newVariable(),
             statementList,
             getTypeFactory(),
             rel.getRowType(),
             new VariableInitializerThunk() {
               public VariableInitializer getInitializer() {
                 return selfRel.implementSelf(JavaRelImplementor.this);
               }
             });
     bind(rel, lazyBind);
   } else if ((frame.bind instanceof LazyBind)
       && (((LazyBind) frame.bind).statementList != statementList)) {
     // Frame is already bound, but to a variable declared in a different
     // scope. Re-bind it.
     final LazyBind lazyBind = (LazyBind) frame.bind;
     lazyBind.statementList = statementList;
     lazyBind.bound = false;
   }
 }
Beispiel #2
0
  /**
   * Declares a variable, and binds it lazily, so it only gets initialized if it is actually used.
   *
   * @return the Variable so declared
   */
  public Variable bind(
      RelNode rel, StatementList statementList, final VariableInitializer initializer) {
    VariableInitializerThunk thunk =
        new VariableInitializerThunk() {
          public VariableInitializer getInitializer() {
            return initializer;
          }
        };

    Variable variable = newVariable();
    LazyBind bind =
        new LazyBind(variable, statementList, getTypeFactory(), rel.getRowType(), thunk);
    bind(rel, bind);
    return bind.getVariable();
  }