Skip to content
Merged
Show file tree
Hide file tree
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
3 changes: 1 addition & 2 deletions core/src/main/java/org/projectnessie/cel/CEL.java
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,7 @@ private static Program initInterpretable(
}
// When the AST has been checked it contains metadata that can be used to speed up program
// execution.
CheckedExpr checked = astToCheckedExpr(ast);
p.interpretable = p.interpreter.newInterpretable(checked, decs);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there still a valid use case for the old method? should we remove or deprecate it?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The existing CheckedExpr overload appears useful, it has direct callers, and is the abstract compatibility point for external Interpreter implementations (if those exist 🤷). The new overload is deliberately a default method.

p.interpretable = p.interpreter.newInterpretable(ast.getExpr(), ast.refMap, ast.typeMap, decs);

return p;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,22 @@ static InterpretablePlanner newPlanner(
decorators);
}

/**
* newPlanner creates an interpretablePlanner from checked expression metadata without requiring a
* CheckedExpr wrapper.
*/
static InterpretablePlanner newPlanner(
Dispatcher disp,
TypeProvider provider,
TypeAdapter adapter,
AttributeFactory attrFactory,
Container cont,
Map<Long, Reference> refMap,
Map<Long, Type> typeMap,
InterpretableDecorator... decorators) {
return new Planner(disp, provider, adapter, attrFactory, cont, refMap, typeMap, decorators);
}

/**
* newUncheckedPlanner creates an interpretablePlanner which references a Dispatcher,
* TypeProvider, TypeAdapter, and Container to resolve functions and types at plan time.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,38 @@

import com.google.api.expr.v1alpha1.CheckedExpr;
import com.google.api.expr.v1alpha1.Expr;
import com.google.api.expr.v1alpha1.Reference;
import com.google.api.expr.v1alpha1.Type;
import java.util.Map;
import org.projectnessie.cel.common.containers.Container;
import org.projectnessie.cel.common.types.ref.TypeAdapter;
import org.projectnessie.cel.common.types.ref.TypeProvider;
import org.projectnessie.cel.interpreter.functions.Overload;

/** Interpreter generates a new Interpretable from a checked or unchecked expression. */
public interface Interpreter {
/**
* NewInterpretable creates an Interpretable from a checked expression and an optional list of
* InterpretableDecorator values.
*/
/** Creates an {@link Interpretable} from a checked expression and optional decorators. */
Interpretable newInterpretable(CheckedExpr checked, InterpretableDecorator... decorators);

/**
* NewUncheckedInterpretable returns an Interpretable from a parsed expression and an optional
* list of InterpretableDecorator values.
* Creates an {@link Interpretable} directly from an expression and its checked metadata without
* constructing a {@link CheckedExpr} wrapper.
*/
default Interpretable newInterpretable(
Expr expr,
Map<Long, Reference> refMap,
Map<Long, Type> typeMap,
InterpretableDecorator... decorators) {
CheckedExpr checked =
CheckedExpr.newBuilder()
.setExpr(expr)
.putAllReferenceMap(refMap)
.putAllTypeMap(typeMap)
.build();
return newInterpretable(checked, decorators);
}

/** Creates an {@link Interpretable} from a parsed expression and optional decorators. */
Interpretable newUncheckedInterpretable(Expr expr, InterpretableDecorator... decorators);

/**
Expand Down Expand Up @@ -119,7 +134,6 @@ final class ExprInterpreter implements Interpreter {
this.attrFactory = attrFactory;
}

/** NewIntepretable implements the Interpreter interface method. */
@Override
public Interpretable newInterpretable(
CheckedExpr checked, InterpretableDecorator... decorators) {
Expand All @@ -128,7 +142,18 @@ public Interpretable newInterpretable(
return p.plan(checked.getExpr());
}

/** NewUncheckedIntepretable implements the Interpreter interface method. */
@Override
public Interpretable newInterpretable(
Expr expr,
Map<Long, Reference> refMap,
Map<Long, Type> typeMap,
InterpretableDecorator... decorators) {
InterpretablePlanner p =
newPlanner(
dispatcher, provider, adapter, attrFactory, container, refMap, typeMap, decorators);
return p.plan(expr);
}

@Override
public Interpretable newUncheckedInterpretable(
Expr expr, InterpretableDecorator... decorators) {
Expand Down
Loading