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

SessionContext from ExecutionEngine #960

Closed

Conversation

MaxKsyunz
Copy link
Collaborator

Implement now function using SessionContext managed by the execution engine. Unlike #937 this implementation decouples the function definition from capturing query start time.

In addition, this declaration of Expression.valueOf allows for passing other metadata to function implementations.

Implementation overview

SessionContext is a class that stores query execution start time.

It is provided to now implementation through an argument to Expression.valueOf.

That is done by ProjectOperator while executing

ExecutionEngine provides an instance of SessionContext to each PhyiscalPlan by calling PhysicalPlan.open.

Remaining work

Ensure that SessionContext is passed in all instances where an expression can contain now() call.

Signed-off-by: MaxKsyunz [email protected]

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

The value is provided by ExecutionEngine at the start of execution.

This can be improved by changing PhysicalPlan.next to
return a tuple of (ResultSet, SessionContext) and adding
a SessionContextPlan that just returns (<Empty>, SessionContext<Time>)
 as a leaf plan.

Signed-off-by: MaxKsyunz <[email protected]>
@MaxKsyunz
Copy link
Collaborator Author

@penghuo what do you think of this implementation of query context (I called it SessionContext here). In this case, the value is provided at execution time, not function definition.

@@ -19,8 +20,11 @@ public interface Expression extends Serializable {
/**
* Evaluate the value of expression in the value environment.
*/
ExprValue valueOf(Environment<Expression, ExprValue> valueEnv);
ExprValue valueOf(Environment<Expression, ExprValue> valueEnv, SessionContext sessionContext);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does it make sense to provide an overloaded version of valueOf that takes just an Environment?

ExprValue valueOf(Environment<Expression, ExprValue> valueEnv) {
    return valueOf(valueEnv, SessionContext.None);
  }

This would cut down the number of changes needed in this PR

* @param valueEnv : Dataset to parse value from.
*
* @param valueEnv : Dataset to parse value from.
* @param sessionContext
Copy link
Collaborator

Choose a reason for hiding this comment

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

can you add a comment for what sessionContext is?

private final Clock epochStartClock = Clock.fixed(Instant.EPOCH, ZoneId.of("UTC"));
@Override
public Clock getQueryStartClock() {
return epochStartClock;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd prefer if this throws a runtime exception since it shouldn't be used.

Copy link
Collaborator

Choose a reason for hiding this comment

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

That being said, it might be better to use Optionals and this default class has an empty clock defined.


@Override
public Clock getSystemClock() {
return epochStartClock;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd prefer if this throws a runtime exception since it shouldn't be used.

@MaxKsyunz
Copy link
Collaborator Author

Will revisit this later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants