Exemplo n.º 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);
  }
Exemplo n.º 2
0
 // override Object
 public boolean equals(Object obj) {
   if (!(obj instanceof RelColumnOrigin)) {
     return false;
   }
   RelColumnOrigin other = (RelColumnOrigin) obj;
   return Arrays.equals(originTable.getQualifiedName(), other.originTable.getQualifiedName())
       && (iOriginColumn == other.iOriginColumn)
       && (isDerived == other.isDerived);
 }
Exemplo n.º 3
0
 /** 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;
 }
 /**
  * Retrieves a materialized table that will satisfy an aggregate query on the star table.
  *
  * <p>The current implementation creates a materialization and populates it, provided that {@link
  * Lattice#auto} is true.
  *
  * <p>Future implementations might return materializations at a different level of aggregation,
  * from which the desired result can be obtained by rolling up.
  *
  * @param planner Current planner
  * @param groupSet Grouping key
  * @param measureList Calls to aggregate functions
  * @return Materialized table
  */
 public Pair<CalciteSchema.TableEntry, TileKey> getAggregate(
     RelOptPlanner planner, ImmutableBitSet groupSet, List<Lattice.Measure> measureList) {
   final CalciteConnectionConfig config =
       planner.getContext().unwrap(CalciteConnectionConfig.class);
   if (config == null) {
     return null;
   }
   final MaterializationService service = MaterializationService.instance();
   boolean create = lattice.auto && config.createMaterializations();
   final CalciteSchema schema = starRelOptTable.unwrap(CalciteSchema.class);
   return service.defineTile(lattice, groupSet, measureList, schema, create, false);
 }
Exemplo n.º 5
0
  /**
   * 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())));
            }
          }
        });
  }
Exemplo n.º 6
0
 // override Object
 public int hashCode() {
   return Arrays.hashCode(originTable.getQualifiedName()) + iOriginColumn + (isDerived ? 313 : 0);
 }
Exemplo n.º 7
0
 public boolean isKey(BitSet columns) {
   return parent.isKey(columns);
 }
Exemplo n.º 8
0
 public List<RelCollation> getCollationList() {
   return parent.getCollationList();
 }
Exemplo n.º 9
0
 public RelOptSchema getRelOptSchema() {
   return parent.getRelOptSchema();
 }
Exemplo n.º 10
0
 public RelDataType getRowType() {
   return parent.getRowType();
 }
Exemplo n.º 11
0
 public double getRowCount() {
   return parent.getRowCount();
 }
Exemplo n.º 12
0
 public List<String> getQualifiedName() {
   return parent.getQualifiedName();
 }
Exemplo n.º 13
0
 public Expression getExpression(Class clazz) {
   return parent.getExpression(clazz);
 }
Exemplo n.º 14
0
 public <T> T unwrap(Class<T> clazz) {
   if (clazz.isInstance(this)) {
     return clazz.cast(this);
   }
   return parent.unwrap(clazz);
 }