@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(); }
/** * 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); } }
public boolean isKeyPreserving() { Predicate<Key> pred = (k) -> isKeyPreserving(k); return operand.getKeys().stream().anyMatch(pred); }
@Override protected RelationType typeCheck() { return operand.getType().project(attributes); }