|
10 | 10 | import io.substrait.proto.AggregateRel;
|
11 | 11 | import io.substrait.proto.ConsistentPartitionWindowRel;
|
12 | 12 | import io.substrait.proto.CrossRel;
|
| 13 | +import io.substrait.proto.ExpandRel; |
13 | 14 | import io.substrait.proto.ExtensionLeafRel;
|
14 | 15 | import io.substrait.proto.ExtensionMultiRel;
|
15 | 16 | import io.substrait.proto.ExtensionSingleRel;
|
|
21 | 22 | import io.substrait.proto.NestedLoopJoinRel;
|
22 | 23 | import io.substrait.proto.ProjectRel;
|
23 | 24 | import io.substrait.proto.ReadRel;
|
| 25 | +import io.substrait.proto.RelCommon; |
24 | 26 | import io.substrait.proto.SetRel;
|
25 | 27 | import io.substrait.proto.SortRel;
|
26 | 28 | import io.substrait.relation.extensions.EmptyDetail;
|
@@ -87,6 +89,9 @@ public Rel from(io.substrait.proto.Rel rel) {
|
87 | 89 | case PROJECT -> {
|
88 | 90 | return newProject(rel.getProject());
|
89 | 91 | }
|
| 92 | + case EXPAND -> { |
| 93 | + return newExpand(rel.getExpand()); |
| 94 | + } |
90 | 95 | case CROSS -> {
|
91 | 96 | return newCross(rel.getCross());
|
92 | 97 | }
|
@@ -155,7 +160,10 @@ protected Filter newFilter(FilterRel rel) {
|
155 | 160 | }
|
156 | 161 |
|
157 | 162 | protected NamedStruct newNamedStruct(ReadRel rel) {
|
158 |
| - var namedStruct = rel.getBaseSchema(); |
| 163 | + return newNamedStruct(rel.getBaseSchema()); |
| 164 | + } |
| 165 | + |
| 166 | + protected NamedStruct newNamedStruct(io.substrait.proto.NamedStruct namedStruct) { |
159 | 167 | var struct = namedStruct.getStruct();
|
160 | 168 | return ImmutableNamedStruct.builder()
|
161 | 169 | .names(namedStruct.getNamesList())
|
@@ -389,6 +397,43 @@ protected Project newProject(ProjectRel rel) {
|
389 | 397 | return builder.build();
|
390 | 398 | }
|
391 | 399 |
|
| 400 | + protected Expand newExpand(ExpandRel rel) { |
| 401 | + var input = from(rel.getInput()); |
| 402 | + var converter = new ProtoExpressionConverter(lookup, extensions, input.getRecordType(), this); |
| 403 | + var builder = |
| 404 | + Expand.builder() |
| 405 | + .input(input) |
| 406 | + .fields( |
| 407 | + rel.getFieldsList().stream() |
| 408 | + .map( |
| 409 | + expandField -> |
| 410 | + switch (expandField.getFieldTypeCase()) { |
| 411 | + case CONSISTENT_FIELD -> Expand.ExpandField.builder() |
| 412 | + .consistentField(converter.from(expandField.getConsistentField())) |
| 413 | + .build(); |
| 414 | + case SWITCHING_FIELD -> Expand.ExpandField.builder() |
| 415 | + .switchingField( |
| 416 | + Expand.SwitchingField.builder() |
| 417 | + .duplicates( |
| 418 | + expandField |
| 419 | + .getSwitchingField() |
| 420 | + .getDuplicatesList() |
| 421 | + .stream() |
| 422 | + .map(converter::from) |
| 423 | + .collect(java.util.stream.Collectors.toList())) |
| 424 | + .build()) |
| 425 | + .build(); |
| 426 | + case FIELDTYPE_NOT_SET -> Expand.ExpandField.builder().build(); |
| 427 | + }) |
| 428 | + .collect(java.util.stream.Collectors.toList())); |
| 429 | + |
| 430 | + builder |
| 431 | + .commonExtension(optionalAdvancedExtension(rel.getCommon())) |
| 432 | + .remap(optionalRelmap(rel.getCommon())) |
| 433 | + .hint(optionalHint(rel.getCommon())); |
| 434 | + return builder.build(); |
| 435 | + } |
| 436 | + |
392 | 437 | protected Aggregate newAggregate(AggregateRel rel) {
|
393 | 438 | var input = from(rel.getInput());
|
394 | 439 | var protoExprConverter =
|
@@ -647,6 +692,16 @@ protected static Optional<Rel.Remap> optionalRelmap(io.substrait.proto.RelCommon
|
647 | 692 | relCommon.hasEmit() ? Rel.Remap.of(relCommon.getEmit().getOutputMappingList()) : null);
|
648 | 693 | }
|
649 | 694 |
|
| 695 | + protected static Optional<RelCommon.Hint> optionalHint(io.substrait.proto.RelCommon relCommon) { |
| 696 | + return Optional.ofNullable( |
| 697 | + relCommon.hasHint() |
| 698 | + ? RelCommon.Hint.newBuilder() |
| 699 | + .setAlias(relCommon.getHint().getAlias()) |
| 700 | + .addAllOutputNames(relCommon.getHint().getOutputNamesList()) |
| 701 | + .build() |
| 702 | + : null); |
| 703 | + } |
| 704 | + |
650 | 705 | protected Optional<AdvancedExtension> optionalAdvancedExtension(
|
651 | 706 | io.substrait.proto.RelCommon relCommon) {
|
652 | 707 | return Optional.ofNullable(
|
|
0 commit comments