8000 Cesql v1 fixes by Cali0707 · Pull Request #641 · cloudevents/sdk-java · GitHub
[go: up one dir, main page]

Skip to content

Cesql v1 fixes #641

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

Merged
merged 15 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
feat: update interfaces for cesql runtime and context
Signed-off-by: Calum Murray <cmurray@redhat.com>
  • Loading branch information
Cali0707 committed Jun 19, 2024
commit 588648110fb719b0b79d8731c8f95330acbd635f
16 changes: 1 addition & 15 deletions sql/src/main/java/io/cloudevents/sql/EvaluationContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,5 @@ public interface EvaluationContext {
*/
String expressionText();

/**
* Append a new exception to the evaluation context.
* This exception will be propagated back in the evaluation result.
*
* @param exception exception to append
*/
void appendException(EvaluationException exception);

/**
* Append a new exception to the evaluation context.
* This exception will be propagated back in the evaluation result.
*
* @param exceptionFactory exception factory, which will automatically include expression interval and text
*/
void appendException(EvaluationException.EvaluationExceptionFactory exceptionFactory);
ExceptionFactory exceptionFactory();
}
12 changes: 8 additions & 4 deletions sql/src/main/java/io/cloudevents/sql/EvaluationException.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,27 @@ public enum ErrorKind {
/**
* An implicit or an explicit casting failed.
*/
INVALID_CAST,
CAST,
/**
* An event attribute was addressed, but missing.
*/
MISSING_ATTRIBUTE,
/**
* Error happened while dispatching a function invocation. Reasons may be invalid function name or invalid arguments number.
*/
FUNCTION_DISPATCH,
MISSING_FUNCTION,
/**
* Error happened while executing a function. This usually contains a non null cause.
*/
FUNCTION_EXECUTION,
FUNCTION_EVALUATION,
/**
* Error happened while executing a math operation. Reason may be a division by zero.
*/
MATH
MATH,
/**
* Any error that does not fall into the other error kinds
*/
GENERIC,
}

private final ErrorKind errorKind;
Expand Down
29 changes: 0 additions & 29 deletions sql/src/main/java/io/cloudevents/sql/EvaluationRuntime.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,6 @@
* The evaluation runtime takes care of the function resolution, casting and other core functionalities to execute an expression.
*/
public interface EvaluationRuntime {

/**
* Check if the cast can be executed from {@code value} to the {@code target} type.
*
* @param value the value to cast
* @param target the type cast target
* @return false if the cast trigger an error, true otherwise.
*/
boolean canCast(Object value, Type target);

/**
* Return the {@code value} casted to the {@code target} type.
*
* @param ctx the evaluation context
* @param value the value to cast
* @param target the type cast target
* @return the casted value, if the cast succeeds, otherwise the default value of the target type
*/
Object cast(EvaluationContext ctx, Object value, Type target);

/**
* Return the {@code value} casted to the {@code target} type. If fails, this is going to throw an exception without the evaluation context.
*
* @param value the value to cast
* @param target the type cast target
* @return the casted value, if the cast succeeds, otherwise the default value of the target type
*/
Object cast(Object value, Type target) throws EvaluationException;

/**
* Resolve a {@link Function} starting from its name and the concrete number of arguments.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import io.cloudevents.CloudEvent;
import io.cloudevents.sql.EvaluationRuntime;
import io.cloudevents.sql.ExceptionFactory;
import io.cloudevents.sql.impl.runtime.EvaluationResult;
import org.antlr.v4.runtime.misc.Interval;

public interface ExpressionInternal {
Expand All @@ -10,7 +12,7 @@ public interface ExpressionInternal {

String expressionText();

Object evaluate(EvaluationRuntime runtime, CloudEvent event, ExceptionThrower thrower);
EvaluationResult evaluate(EvaluationRuntime runtime, CloudEvent event, ExceptionFactory exceptionFactory);

<T> T visit(ExpressionInternalVisitor<T> visitor);

Expand Down
0