Example #1
0
 @Override
 public boolean equals(Relation arg) {
   if (arg == this) return true;
   if (arg == null || !(arg instanceof Relation)) return false;
   Relation other = (Relation) arg;
   return TYPE.equals(other.getType()) && other.stream().findFirst().isPresent();
 }
Example #2
0
 /**
  * we look for keys that are preserved by the projection and if so these keys are the new keys,
  * otherwise the 'on' attributes form the new key (key of the projection)
  */
 @Override
 public Keys lazyComputeKey() {
   Keys keys = operand.getKeys();
   Predicate<Key> p = (k) -> isKeyPreserving(k);
   Set<Key> kept = keys.stream().filter(p).collect(Collectors.toSet());
   if (kept.isEmpty()) {
     return new Keys(type.getLargestKey());
   } else {
     return new Keys(kept);
   }
 }
Example #3
0
/** Dee, the relation with no attribute but one tuple. */
public class Dee extends AbstractRelation {

  private static final RelationType TYPE = RelationType.dress();

  private static Relation INSTANCE;

  private static final Tuple EMPTY_TUPLE = Tuple.dress();

  private Dee() {}

  public static synchronized Relation instance() {
    if (INSTANCE == null) {
      INSTANCE = new Dee();
    }
    return INSTANCE;
  }

  @Override
  public RelationType getType() {
    return TYPE;
  }

  @Override
  public <R> R accept(Visitor<R> visitor) {
    return visitor.visit(this);
  }

  public Cog toCog() {
    return new BaseCog(this, () -> Collections.singleton(EMPTY_TUPLE).stream());
  }

  @Override
  public boolean equals(Relation arg) {
    if (arg == this) return true;
    if (arg == null || !(arg instanceof Relation)) return false;
    Relation other = (Relation) arg;
    return TYPE.equals(other.getType()) && other.stream().findFirst().isPresent();
  }
}