Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use Immutables for Argument subclasses #179

Merged
merged 1 commit into from
Sep 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 37 additions & 84 deletions core/src/main/java/io/substrait/extension/SimpleExtension.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.substrait.extension;

import com.fasterxml.jackson.annotation.JacksonInject;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
Expand Down Expand Up @@ -77,6 +76,11 @@ private SimpleExtension() {}
public interface Argument {
String toTypeString();

@JsonProperty()
@Nullable
String name();

@JsonProperty()
@Nullable
String description();

Expand All @@ -92,82 +96,39 @@ public interface Option {
List<String> getValues();
}

public static class ValueArgument implements Argument {

@JsonCreator
public ValueArgument(
@JsonProperty("value") ParameterizedType value,
@JsonProperty("name") String name,
@JsonProperty("constant") boolean constant,
@JsonProperty("description") String description) {
this.value = value;
this.constant = constant;
this.name = name;
this.description = description;
}
@JsonSerialize(as = ImmutableSimpleExtension.ValueArgument.class)
@JsonDeserialize(as = ImmutableSimpleExtension.ValueArgument.class)
@Value.Immutable
public abstract static class ValueArgument implements Argument {

@JsonProperty(required = true)
ParameterizedType value;

String name;
public abstract ParameterizedType value();

boolean constant;

String description;

public ParameterizedType value() {
return value;
}

public String name() {
return name;
}

public boolean constant() {
return constant;
}

public String description() {
return description;
}
@JsonProperty()
@Nullable
public abstract Boolean constant();

@Override
public String toTypeString() {
return value.accept(ToTypeString.INSTANCE);
return value().accept(ToTypeString.INSTANCE);
}

public boolean required() {
return true;
}
}

public static class TypeArgument implements Argument {

@JsonCreator
public TypeArgument(
@JsonProperty("type") ParameterizedType type,
@JsonProperty("name") String name,
@JsonProperty("description") String description) {
this.type = type;
this.name = name;
this.description = description;
}

private ParameterizedType type;
private String name;
private String description;

public ParameterizedType getType() {
return type;
public static ImmutableSimpleExtension.ValueArgument.Builder builder() {
return ImmutableSimpleExtension.ValueArgument.builder();
}
}

public void setType(final ParameterizedType type) {
this.type = type;
}
@JsonSerialize(as = ImmutableSimpleExtension.TypeArgument.class)
@JsonDeserialize(as = ImmutableSimpleExtension.TypeArgument.class)
@Value.Immutable
public abstract static class TypeArgument implements Argument {

public String description() {
return description;
}
@JsonProperty(required = true)
public abstract ParameterizedType type();

public String toTypeString() {
return "type";
Expand All @@ -176,6 +137,10 @@ public String toTypeString() {
public boolean required() {
return true;
}

public static ImmutableSimpleExtension.TypeArgument.Builder builder() {
return ImmutableSimpleExtension.TypeArgument.builder();
}
}

/**
Expand All @@ -187,29 +152,13 @@ public boolean required() {
* href="https://github.com/substrait-io/substrait-java/pull/55#issuecomment-1154484254">comments
* in this issue</a>
*/
public static class EnumArgument implements Argument {

@JsonCreator
public EnumArgument(
@JsonProperty("options") List<String> options,
@JsonProperty("name") String name,
@JsonProperty("description") String description) {
this.options = options;
this.name = name;
this.description = description;
}

private final List<String> options;
private final String name;
private final String description;

public List<String> options() {
return options;
}
@JsonSerialize(as = ImmutableSimpleExtension.EnumArgument.class)
@JsonDeserialize(as = ImmutableSimpleExtension.EnumArgument.class)
@Value.Immutable
public abstract static class EnumArgument implements Argument {

public String description() {
return description;
}
@JsonProperty(required = true)
public abstract List<String> options();

@Override
public boolean required() {
Expand All @@ -219,6 +168,10 @@ public boolean required() {
public String toTypeString() {
return "req";
}

public static ImmutableSimpleExtension.EnumArgument.Builder builder() {
return ImmutableSimpleExtension.EnumArgument.builder();
}
}

public interface Anchor {
Expand Down