Exemple #1
0
  protected RelNode optimizeLoopbackLink(
      RelOptCluster cluster, RelOptConnection connection, String[] actualName) throws SQLException {
    if (directory == null) {
      return null;
    }
    if (directory.server == null) {
      return null;
    }
    if ((directory.server.schemaName != null)
        && !directory.server.useSchemaNameAsForeignQualifier) {
      // Schema name should never be specified for a connection to
      // Farrago; if it is, bail.
      return null;
    }

    Connection loopbackConnection = directory.server.getConnection();
    if (!(loopbackConnection instanceof FarragoJdbcEngineConnection)) {
      Connection conn = loopbackConnection;
      while ((conn != null) && (conn instanceof DelegatingConnection)) {
        conn = ((DelegatingConnection) conn).getDelegate();
      }
      if (!(conn instanceof FarragoJdbcEngineConnection)) {
        return null;
      }
    }

    String catalogName = directory.server.catalogName;
    if (catalogName == null) {
      // No catalog name specified, so try to query the connection for
      // it.
      catalogName = loopbackConnection.getCatalog();
      if (catalogName == null) {
        return null;
      }
    }

    if (actualName[0] == null) {
      actualName[0] = catalogName;
    }

    // REVIEW jvs 14-Aug-2006:  Security security security.
    RelOptTable realTable = getPreparingStmt().getTableForMember(actualName);
    if (realTable == null) {
      return null;
    }
    return realTable.toRel(cluster, connection);
  }
 /** Creates a RelOptMaterialization. */
 public RelOptMaterialization(RelNode tableRel, RelNode queryRel, RelOptTable starRelOptTable) {
   this.tableRel = tableRel;
   this.starRelOptTable = starRelOptTable;
   if (starRelOptTable == null) {
     this.starTable = null;
   } else {
     this.starTable = starRelOptTable.unwrap(StarTable.class);
     assert starTable != null;
   }
   this.table = tableRel.getTable();
   this.queryRel = queryRel;
 }
  /**
   * Converts a relational expression to one that uses a {@link
   * net.hydromatic.optiq.impl.StarTable}. The relational expression is already in leaf-join-form,
   * per {@link #toLeafJoinForm(org.eigenbase.rel.RelNode)}.
   */
  public static RelNode tryUseStar(RelNode rel, final RelOptTable starRelOptTable) {
    final StarTable starTable = starRelOptTable.unwrap(StarTable.class);
    assert starTable != null;
    return rel.accept(
        new RelShuttleImpl() {
          @Override
          public RelNode visit(TableAccessRelBase scan) {
            RelOptTable relOptTable = scan.getTable();
            final Table table = relOptTable.unwrap(Table.class);
            if (table.equals(starTable.tables.get(0))) {
              Mappings.TargetMapping mapping =
                  Mappings.createShiftMapping(
                      starRelOptTable.getRowType().getFieldCount(),
                      0,
                      0,
                      relOptTable.getRowType().getFieldCount());

              return CalcRel.createProject(
                  new TableAccessRel(scan.getCluster(), starRelOptTable),
                  Mappings.asList(mapping.inverse()));
            }
            return scan;
          }

          @Override
          public RelNode visit(JoinRel join) {
            for (; ; ) {
              RelNode rel = super.visit(join);
              if (rel == join || !(rel instanceof JoinRel)) {
                return rel;
              }
              join = (JoinRel) rel;
              final RelNode left = join.getLeft();
              final RelNode right = join.getRight();
              try {
                if (left instanceof TableAccessRelBase && right instanceof TableAccessRelBase) {
                  match(left, null, right, null, join.getCluster());
                }
                if (isProjectedTable(left) && right instanceof TableAccessRelBase) {
                  final ProjectRel leftProject = (ProjectRel) left;
                  match(
                      leftProject.getChild(),
                      leftProject.getMapping(),
                      right,
                      null,
                      join.getCluster());
                }
                if (left instanceof TableAccessRelBase && isProjectedTable(right)) {
                  final ProjectRel rightProject = (ProjectRel) right;
                  match(
                      left,
                      null,
                      rightProject.getChild(),
                      rightProject.getMapping(),
                      join.getCluster());
                }
                if (isProjectedTable(left) && isProjectedTable(right)) {
                  final ProjectRel leftProject = (ProjectRel) left;
                  final ProjectRel rightProject = (ProjectRel) right;
                  match(
                      leftProject.getChild(),
                      leftProject.getMapping(),
                      rightProject.getChild(),
                      rightProject.getMapping(),
                      join.getCluster());
                }
              } catch (Util.FoundOne e) {
                return (RelNode) e.getNode();
              }
            }
          }

          private boolean isProjectedTable(RelNode rel) {
            return rel instanceof ProjectRel
                && ((ProjectRel) rel).isMapping()
                && ((ProjectRel) rel).getChild() instanceof TableAccessRelBase;
          }

          /**
           * Throws a {@link org.eigenbase.util.Util.FoundOne} containing a {@link
           * org.eigenbase.rel.TableAccessRel} on success. (Yes, an exception for normal operation.)
           */
          private void match(
              RelNode left,
              Mappings.TargetMapping leftMapping,
              RelNode right,
              Mappings.TargetMapping rightMapping,
              RelOptCluster cluster) {
            if (leftMapping == null) {
              leftMapping = Mappings.createIdentity(left.getRowType().getFieldCount());
            }
            if (rightMapping == null) {
              rightMapping = Mappings.createIdentity(right.getRowType().getFieldCount());
            }
            final RelOptTable leftRelOptTable = left.getTable();
            final Table leftTable = leftRelOptTable.unwrap(Table.class);
            final RelOptTable rightRelOptTable = right.getTable();
            final Table rightTable = rightRelOptTable.unwrap(Table.class);
            if (leftTable instanceof StarTable
                && ((StarTable) leftTable).tables.contains(rightTable)) {
              System.out.println("left: " + leftMapping);
              System.out.println("right: " + rightMapping);
              Mappings.TargetMapping mapping =
                  Mappings.merge(
                      leftMapping,
                      Mappings.offset(
                          rightMapping,
                          ((StarTable) leftTable).columnOffset(rightTable),
                          leftRelOptTable.getRowType().getFieldCount()));
              throw new Util.FoundOne(
                  CalcRel.createProject(
                      new TableAccessRel(cluster, leftRelOptTable),
                      Mappings.asList(mapping.inverse())));
            }
            if (rightTable instanceof StarTable
                && ((StarTable) rightTable).tables.contains(leftTable)) {
              assert false; // TODO:
              Mappings.TargetMapping mapping = Mappings.append(leftMapping, rightMapping);
              throw new Util.FoundOne(
                  CalcRel.createProject(
                      new TableAccessRel(cluster, rightRelOptTable),
                      Mappings.asList(mapping.inverse())));
            }
          }
        });
  }
Exemple #4
0
 public boolean isKey(BitSet columns) {
   return parent.isKey(columns);
 }
Exemple #5
0
 public List<RelCollation> getCollationList() {
   return parent.getCollationList();
 }
Exemple #6
0
 public RelOptSchema getRelOptSchema() {
   return parent.getRelOptSchema();
 }
Exemple #7
0
 public RelDataType getRowType() {
   return parent.getRowType();
 }
Exemple #8
0
 public double getRowCount() {
   return parent.getRowCount();
 }
Exemple #9
0
 public List<String> getQualifiedName() {
   return parent.getQualifiedName();
 }
Exemple #10
0
 public Expression getExpression(Class clazz) {
   return parent.getExpression(clazz);
 }
Exemple #11
0
 public <T> T unwrap(Class<T> clazz) {
   if (clazz.isInstance(this)) {
     return clazz.cast(this);
   }
   return parent.unwrap(clazz);
 }