Skip to content

Commit

Permalink
fix: optimization singular -> list
Browse files Browse the repository at this point in the history
  • Loading branch information
Blizzara committed Jul 16, 2024
1 parent d6d24eb commit 031dfd4
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
package io.substrait.extension;

import io.substrait.relation.Extension;
import java.util.List;
import java.util.Optional;
import org.immutables.value.Value;

@Value.Immutable
public abstract class AdvancedExtension {

public abstract Optional<Extension.Optimization> getOptimization();
public abstract List<Extension.Optimization> getOptimizations();

public abstract Optional<Extension.Enhancement> getEnhancement();

public io.substrait.proto.AdvancedExtension toProto() {
var builder = io.substrait.proto.AdvancedExtension.newBuilder();
getEnhancement().ifPresent(e -> builder.setEnhancement(e.toProto()));
getOptimization().ifPresent(e -> builder.setOptimization(e.toProto()));
getOptimizations().forEach(e -> builder.addOptimization(e.toProto()));
return builder.build();
}

Expand Down
11 changes: 7 additions & 4 deletions core/src/main/java/io/substrait/relation/ProtoRelConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -658,15 +658,18 @@ private AdvancedExtension advancedExtension(
if (advancedExtension.hasEnhancement()) {
builder.enhancement(enhancementFromAdvancedExtension(advancedExtension.getEnhancement()));
}
if (advancedExtension.hasOptimization()) {
builder.optimization(optimizationFromAdvancedExtension(advancedExtension.getOptimization()));
}
advancedExtension
.getOptimizationList()
.forEach(
optimization ->
builder.addOptimizations(optimizationFromAdvancedExtension(optimization)));

return builder.build();
}

/**
* Override to provide a custom converter for {@link
* io.substrait.proto.AdvancedExtension#getOptimization()} data
* io.substrait.proto.AdvancedExtension#getOptimizationList()} ()} data
*/
protected Extension.Optimization optimizationFromAdvancedExtension(com.google.protobuf.Any any) {
return new EmptyOptimization();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ Rel relWithExtension(AdvancedExtension advancedExtension) {

Rel emptyAdvancedExtension = relWithExtension(AdvancedExtension.builder().build());
Rel advancedExtensionWithOptimization =
relWithExtension(AdvancedExtension.builder().optimization(OPTIMIZED).build());
relWithExtension(AdvancedExtension.builder().addOptimizations(OPTIMIZED).build());
Rel advancedExtensionWithEnhancement =
relWithExtension(AdvancedExtension.builder().enhancement(ENHANCED).build());
Rel advancedExtensionWithEnhancementAndOptimization =
relWithExtension(
AdvancedExtension.builder().enhancement(ENHANCED).optimization(OPTIMIZED).build());
AdvancedExtension.builder().enhancement(ENHANCED).addOptimizations(OPTIMIZED).build());

@Test
void emptyAdvancedExtension() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ public class ExtensionRoundtripTest extends TestBase {
final AdvancedExtension commonExtension =
AdvancedExtension.builder()
.enhancement(new StringHolder("COMMON ENHANCEMENT"))
.optimization(new StringHolder("COMMON OPTIMIZATION"))
.addOptimizations(new StringHolder("COMMON OPTIMIZATION"))
.build();

final StringHolder detail = new StringHolder("DETAIL");

final AdvancedExtension relExtension =
AdvancedExtension.builder()
.enhancement(new StringHolder("REL ENHANCEMENT"))
.optimization(new StringHolder("REL OPTIMIZATION"))
.addOptimizations(new StringHolder("REL OPTIMIZATION"))
.build();

@Override
Expand Down

0 comments on commit 031dfd4

Please sign in to comment.