-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add ExpandRel support to core and spark
Signed-off-by: Andrew Coleman <[email protected]>
- Loading branch information
1 parent
e24ce6f
commit 6ad28ae
Showing
18 changed files
with
385 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package io.substrait.relation; | ||
|
||
import io.substrait.expression.Expression; | ||
import io.substrait.type.Type; | ||
import io.substrait.type.TypeCreator; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.stream.Stream; | ||
import org.immutables.value.Value; | ||
|
||
@Value.Enclosing | ||
@Value.Immutable | ||
public abstract class Expand extends SingleInputRel { | ||
static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(Expand.class); | ||
|
||
public abstract List<ExpandField> getFields(); | ||
|
||
@Override | ||
public Type.Struct deriveRecordType() { | ||
Type.Struct initial = getInput().getRecordType(); | ||
return TypeCreator.of(initial.nullable()) | ||
.struct( | ||
Stream.concat( | ||
initial.fields().stream(), | ||
getFields().stream() | ||
.map( | ||
f -> { | ||
if (f.getSwitchingField().isPresent()) { | ||
return f.getSwitchingField().get().getDuplicates().get(0).getType(); | ||
} else { | ||
return f.getConsistentField().get().getType(); | ||
} | ||
}))); | ||
} | ||
|
||
@Override | ||
public <O, E extends Exception> O accept(RelVisitor<O, E> visitor) throws E { | ||
return visitor.visit(this); | ||
} | ||
|
||
public static ImmutableExpand.Builder builder() { | ||
return ImmutableExpand.builder(); | ||
} | ||
|
||
@Value.Immutable | ||
public abstract static class ExpandField { | ||
public abstract Optional<SwitchingField> getSwitchingField(); | ||
|
||
public abstract Optional<Expression> getConsistentField(); | ||
|
||
public static ImmutableExpand.ExpandField.Builder builder() { | ||
return ImmutableExpand.ExpandField.builder(); | ||
} | ||
} | ||
|
||
@Value.Immutable | ||
public abstract static class SwitchingField { | ||
public abstract List<Expression> getDuplicates(); | ||
|
||
public static ImmutableExpand.SwitchingField.Builder builder() { | ||
return ImmutableExpand.SwitchingField.builder(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.