예제 #1
0
 private ProjectOp(List<ProjectionSpec> projections, DatabaseOp wrapped) {
   super(wrapped);
   for (ProjectionSpec spec : projections) {
     if (!spec.getColumn().isQualified()) {
       // See if there is a qualified version of this column in the wrapped
       for (ColumnName wrappedColumn : wrapped.getColumns()) {
         if (wrappedColumn.isQualified()
             && wrappedColumn.getColumn().equals(spec.getColumn().getColumn())) {
           spec = ProjectionSpec.create(wrappedColumn);
         }
       }
     }
     this.projections.add(spec);
     columnList.add(spec.getColumn());
   }
   // Build columns map
   for (ProjectionSpec spec : this.projections) {
     // Qualified names only
     if (!spec.getColumn().isQualified()) continue;
     if (columns.containsKey(spec.getColumn())) {
       throw new IllegalArgumentException(
           "Duplicate column name " + spec.getColumn() + " in projection list: " + projections);
     }
     columns.put(spec.getColumn(), spec);
     if (columns.containsKey(spec.getColumn().getUnqualified())) {
       // Mark unqualified name as ambiguous
       columns.put(spec.getColumn().getUnqualified(), null);
     } else {
       columns.put(spec.getColumn().getUnqualified(), spec);
     }
   }
   for (ProjectionSpec spec : this.projections) {
     // Unqualified names only
     if (spec.getColumn().isQualified()) continue;
     if (columns.containsKey(spec.getColumn())) {
       throw new IllegalArgumentException(
           "Duplicate column name " + spec.getColumn() + " in projection list: " + projections);
     }
     columns.put(spec.getColumn(), spec);
   }
   for (Key key : wrapped.getUniqueKeys()) {
     if (key.isContainedIn(columnList)) {
       uniqueKeys.add(key);
     }
   }
 }