public void resolveRangeTable(
      Session session,
      RangeVariable[] rangeVariables,
      int rangeCount,
      RangeVariable[] outerRanges) {

    Table table = rangeTable;
    SubQuery subQuery = table.getSubQuery();

    if (subQuery != null && !subQuery.isResolved()) {
      if (subQuery.dataExpression != null) {
        HsqlList unresolved =
            subQuery.dataExpression.resolveColumnReferences(
                session, RangeVariable.emptyArray, null);

        if (unresolved != null) {
          unresolved =
              subQuery.dataExpression.resolveColumnReferences(
                  session, rangeVariables, rangeCount, null, true);
        }

        if (unresolved != null) {
          unresolved = subQuery.dataExpression.resolveColumnReferences(session, outerRanges, null);
        }

        if (unresolved != null) {
          throw Error.error(ErrorCode.X_42501, ((Expression) unresolved.get(0)).getSQL());
        }

        subQuery.dataExpression.resolveTypes(session, null);
        setRangeTableVariables();
      }

      if (subQuery.queryExpression != null) {
        subQuery.queryExpression.resolveReferences(session, outerRanges);

        HsqlList list = subQuery.queryExpression.getUnresolvedExpressions();

        // todo resolve against i ranges
        HsqlList unresolved =
            Expression.resolveColumnSet(session, rangeVariables, rangeCount, list, null);

        if (unresolved != null) {
          throw Error.error(ErrorCode.X_42501, ((Expression) unresolved.get(0)).getSQL());
        }

        subQuery.queryExpression.resolveTypes(session);
        subQuery.prepareTable(session);
        subQuery.setCorrelated();
        setRangeTableVariables();
      }
    }
  }
  public void resolveRangeTable(Session session, RangeGroup rangeGroup, RangeGroup[] rangeGroups) {

    QueryExpression queryExpression = rangeTable.getQueryExpression();
    Expression dataExpression = rangeTable.getDataExpression();

    if (queryExpression == null && dataExpression == null) {
      return;
    }

    rangeGroups =
        (RangeGroup[]) ArrayUtil.toAdjustedArray(rangeGroups, rangeGroup, rangeGroups.length, 1);

    if (dataExpression != null) {
      HsqlList unresolved =
          dataExpression.resolveColumnReferences(session, RangeGroup.emptyGroup, rangeGroups, null);

      unresolved =
          Expression.resolveColumnSet(
              session, RangeVariable.emptyArray, RangeGroup.emptyArray, unresolved);

      ExpressionColumn.checkColumnsResolved(unresolved);
      dataExpression.resolveTypes(session, null);
      setRangeTableVariables();
    }

    if (queryExpression != null) {
      queryExpression.resolveReferences(session, rangeGroups);

      HsqlList unresolved = queryExpression.getUnresolvedExpressions();

      unresolved =
          Expression.resolveColumnSet(
              session, RangeVariable.emptyArray, RangeGroup.emptyArray, unresolved);

      ExpressionColumn.checkColumnsResolved(unresolved);
      queryExpression.resolveTypesPartOne(session);
      queryExpression.resolveTypesPartTwo(session);
      rangeTable.prepareTable();
      setRangeTableVariables();
    }
  }
  public RangeVariable(
      Table table,
      SimpleName alias,
      OrderedHashSet columnList,
      SimpleName[] columnNameList,
      CompileContext compileContext) {

    rangeType = TABLE_RANGE;
    rangeTable = table;
    tableAlias = alias;
    columnAliases = columnList;
    columnAliasNames = columnNameList;
    joinConditions = new RangeVariableConditions[] {new RangeVariableConditions(this, true)};
    whereConditions = new RangeVariableConditions[] {new RangeVariableConditions(this, false)};

    compileContext.registerRangeVariable(this);

    if (rangeTable.getColumnCount() != 0) {
      setRangeTableVariables();
    }
  }
  RangeVariable(
      Table table,
      SimpleName alias,
      OrderedHashSet columnList,
      SimpleName[] columnNameList,
      CompileContext compileContext) {

    rangeType = TABLE_RANGE;
    rangeTable = table;
    tableAlias = alias;
    columnAliases = columnList;
    columnAliasNames = columnNameList;
    joinConditions = new RangeVariableConditions[] {new RangeVariableConditions(this, true)};
    whereConditions = new RangeVariableConditions[] {new RangeVariableConditions(this, false)};

    compileContext.registerRangeVariable(this);

    SubQuery subQuery = rangeTable.getSubQuery();

    if (subQuery == null || subQuery.isResolved()) {
      setRangeTableVariables();
    }
  }