Skip to content

Commit

Permalink
refactor: move WindowFunctionInvocation into Expression
Browse files Browse the repository at this point in the history
  • Loading branch information
vbarua committed Aug 30, 2023
1 parent 00d52fc commit 082139c
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public OUTPUT visit(Expression.ScalarFunctionInvocation expr) throws EXCEPTION {
}

@Override
public OUTPUT visit(WindowFunctionInvocation expr) throws EXCEPTION {
public OUTPUT visit(Expression.WindowFunctionInvocation expr) throws EXCEPTION {
return visitFallback(expr);
}

Expand Down
36 changes: 36 additions & 0 deletions core/src/main/java/io/substrait/expression/Expression.java
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,42 @@ public <R, E extends Throwable> R accept(ExpressionVisitor<R, E> visitor) throws
}
}

@Value.Immutable
abstract class WindowFunctionInvocation implements Expression {

public abstract SimpleExtension.WindowFunctionVariant declaration();

public abstract List<FunctionArg> arguments();

public abstract Map<String, FunctionOption> options();

public abstract AggregationPhase aggregationPhase();

public abstract List<Expression> partitionBy();

public abstract List<SortField> sort();

public abstract WindowBound lowerBound();

public abstract WindowBound upperBound();

public abstract Type outputType();

public Type getType() {
return outputType();
}

public abstract AggregationInvocation invocation();

public static ImmutableExpression.WindowFunctionInvocation.Builder builder() {
return ImmutableExpression.WindowFunctionInvocation.builder();
}

public <R, E extends Throwable> R accept(ExpressionVisitor<R, E> visitor) throws E {
return visitor.visit(this);
}
}

@Value.Immutable
abstract static class SingleOrList implements Expression {
public abstract Expression condition();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ public static AggregateFunctionInvocation aggregateFunction(
.build();
}

public static WindowFunctionInvocation windowFunction(
public static Expression.WindowFunctionInvocation windowFunction(
SimpleExtension.WindowFunctionVariant declaration,
Type outputType,
Expression.AggregationPhase phase,
Expand All @@ -323,7 +323,7 @@ public static WindowFunctionInvocation windowFunction(
WindowBound lowerBound,
WindowBound upperBound,
Iterable<? extends FunctionArg> arguments) {
return WindowFunctionInvocation.builder()
return Expression.WindowFunctionInvocation.builder()
.declaration(declaration)
.outputType(outputType)
.aggregationPhase(phase)
Expand All @@ -336,7 +336,7 @@ public static WindowFunctionInvocation windowFunction(
.build();
}

public static WindowFunctionInvocation windowFunction(
public static Expression.WindowFunctionInvocation windowFunction(
SimpleExtension.WindowFunctionVariant declaration,
Type outputType,
Expression.AggregationPhase phase,
Expand All @@ -346,7 +346,7 @@ public static WindowFunctionInvocation windowFunction(
WindowBound lowerBound,
WindowBound upperBound,
FunctionArg... arguments) {
return WindowFunctionInvocation.builder()
return Expression.WindowFunctionInvocation.builder()
.declaration(declaration)
.outputType(outputType)
.aggregationPhase(phase)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public interface ExpressionVisitor<R, E extends Throwable> {

R visit(Expression.ScalarFunctionInvocation expr) throws E;

R visit(WindowFunctionInvocation expr) throws E;
R visit(Expression.WindowFunctionInvocation expr) throws E;

R visit(Expression.Cast expr) throws E;

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ public Expression visit(io.substrait.expression.Expression.InPredicate expr)
.build();
}

public Expression visit(io.substrait.expression.WindowFunctionInvocation expr)
public Expression visit(io.substrait.expression.Expression.WindowFunctionInvocation expr)
throws RuntimeException {
var argVisitor = FunctionArg.toProto(typeProtoConverter, this);
List<FunctionArgument> args =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import io.substrait.expression.FunctionArg;
import io.substrait.expression.ImmutableExpression;
import io.substrait.expression.WindowBound;
import io.substrait.expression.WindowFunctionInvocation;
import io.substrait.extension.ExtensionLookup;
import io.substrait.extension.SimpleExtension;
import io.substrait.relation.ProtoRelConverter;
Expand Down Expand Up @@ -142,7 +141,7 @@ public Expression from(io.substrait.proto.Expression expr) {
WindowBound lowerBound = toLowerBound(windowFunction.getLowerBound());
WindowBound upperBound = toUpperBound(windowFunction.getUpperBound());

yield WindowFunctionInvocation.builder()
yield Expression.WindowFunctionInvocation.builder()
.arguments(args)
.declaration(declaration)
.outputType(protoTypeConverter.from(windowFunction.getOutputType()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ public RexNode visit(Expression.ScalarFunctionInvocation expr) throws RuntimeExc
}

@Override
public RexNode visit(WindowFunctionInvocation expr) throws RuntimeException {
public RexNode visit(Expression.WindowFunctionInvocation expr) throws RuntimeException {
// todo:to construct the RexOver
return visitFallback(expr);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import io.substrait.expression.FunctionArg;
import io.substrait.expression.ImmutableWindowBound;
import io.substrait.expression.WindowBound;
import io.substrait.expression.WindowFunctionInvocation;
import io.substrait.extension.SimpleExtension;
import io.substrait.type.Type;
import java.math.BigDecimal;
Expand All @@ -29,7 +28,7 @@
public class WindowFunctionConverter
extends FunctionConverter<
SimpleExtension.WindowFunctionVariant,
WindowFunctionInvocation,
Expression.WindowFunctionInvocation,
WindowFunctionConverter.WrappedWindowCall> {

@Override
Expand All @@ -43,7 +42,7 @@ public WindowFunctionConverter(
}

@Override
protected WindowFunctionInvocation generateBinding(
protected Expression.WindowFunctionInvocation generateBinding(
WrappedWindowCall call,
SimpleExtension.WindowFunctionVariant function,
List<FunctionArg> arguments,
Expand Down Expand Up @@ -82,7 +81,7 @@ protected WindowFunctionInvocation generateBinding(
arguments);
}

public Optional<WindowFunctionInvocation> convert(
public Optional<Expression.WindowFunctionInvocation> convert(
RexOver over,
Function<RexNode, Expression> topLevelConverter,
RexExpressionConverter rexExpressionConverter) {
Expand Down

0 comments on commit 082139c

Please sign in to comment.