io.substrait.relation.Join Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of core Show documentation
Show all versions of core Show documentation
Create a well-defined, cross-language specification for data compute operations
package io.substrait.relation;
import io.substrait.expression.Expression;
import io.substrait.proto.JoinRel;
import io.substrait.type.Type;
import io.substrait.type.TypeCreator;
import java.util.Optional;
import java.util.stream.Stream;
import org.immutables.value.Value;
@Value.Immutable
public abstract class Join extends BiRel implements HasExtension {
public abstract Optional getCondition();
public abstract Optional getPostJoinFilter();
public abstract JoinType getJoinType();
public enum JoinType {
UNKNOWN(JoinRel.JoinType.JOIN_TYPE_UNSPECIFIED),
INNER(JoinRel.JoinType.JOIN_TYPE_INNER),
OUTER(JoinRel.JoinType.JOIN_TYPE_OUTER),
LEFT(JoinRel.JoinType.JOIN_TYPE_LEFT),
RIGHT(JoinRel.JoinType.JOIN_TYPE_RIGHT),
SEMI(JoinRel.JoinType.JOIN_TYPE_LEFT_SEMI),
ANTI(JoinRel.JoinType.JOIN_TYPE_LEFT_ANTI);
private JoinRel.JoinType proto;
JoinType(JoinRel.JoinType proto) {
this.proto = proto;
}
public JoinRel.JoinType toProto() {
return proto;
}
public static JoinType fromProto(JoinRel.JoinType proto) {
for (var v : values()) {
if (v.proto == proto) {
return v;
}
}
throw new IllegalArgumentException("Unknown type: " + proto);
}
}
@Override
protected Type.Struct deriveRecordType() {
Stream leftTypes =
switch (getJoinType()) {
case RIGHT, OUTER -> getLeft().getRecordType().fields().stream()
.map(TypeCreator::asNullable);
default -> getLeft().getRecordType().fields().stream();
};
Stream rightTypes =
switch (getJoinType()) {
case LEFT, OUTER -> getRight().getRecordType().fields().stream()
.map(TypeCreator::asNullable);
default -> getRight().getRecordType().fields().stream();
};
return TypeCreator.REQUIRED.struct(Stream.concat(leftTypes, rightTypes));
}
@Override
public O accept(RelVisitor visitor) throws E {
return visitor.visit(this);
}
public static ImmutableJoin.Builder builder() {
return ImmutableJoin.builder();
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy