-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
expression: add more optional properties for EvalContext
#51725
Conversation
Hi @lcwangchao. Thanks for your PR. PRs from untrusted users cannot be marked as trusted with I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
c50af36
to
1be614f
Compare
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## master #51725 +/- ##
=================================================
- Coverage 70.6646% 54.8357% -15.8290%
=================================================
Files 1477 1592 +115
Lines 438720 614532 +175812
=================================================
+ Hits 310020 336983 +26963
- Misses 109181 254329 +145148
- Partials 19519 23220 +3701
Flags with carried forward coverage won't be shown. Click here to find out more.
|
|
||
// GetSessionVars returns the session vars from the context | ||
func (SessionVarsPropReader) GetSessionVars(ctx context.EvalContext) (*variable.SessionVars, error) { | ||
p, err := getPropProvider[*SessionVarsPropProvider](ctx, context.OptPropSessionVars) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The key itself must exist, what is the point of adding this judgment? The main thing is that an extra error judgment feels that the code is not very elegant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is an impossible situation, is it better to just panic instead of return an error?
Specifically, when will a return error occur?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the future, we may have multiple implementations for EvalContext
and not all of them are required to contain all properties. The expression should fail when a property is not provided but required by an expression.
Usually, the error occurs when a coder constructs a EvalContext
but missing to provide some required properties or using some unsupported expression in a specified scene. For example, only some simple expressions are allowed in a partition expression, but if someone uses function GetVar
, it will fail.
Though in the above partition expression case, we should do some prior checks but we should also have a check in GetSessionVars
to make the code strong. IMO, panic is not a good option because it will make tidb (at leat a session) crash.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it to be changed in the future, and panic is handled at present?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it to be changed in the future, and panic is handled at present?
I don't think it is necessary because EvalContext
API is defined as "some property is optional" (You can see GetOptionalPropProvider
returns bool
to indicate it). It is natural for an expression to return an error because it does not need to care about some hard limitations about its callers.
If we want to do some asserts, it's better to do it somewhere else, for example, I've added check here:
intest.Assert(impl.props.PropKeySet().IsFull()) |
ExprCtxExtendedImpl
should have all optional properties...
/retest |
@lcwangchao: Cannot trigger testing until a trusted user reviews the PR and leaves an In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: windtalker, YangKeao The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
[LGTM Timeline notifier]Timeline:
|
@lcwangchao: The following test failed, say
Full PR test history. Your PR dashboard. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here. |
/retest |
@lcwangchao: Cannot trigger testing until a trusted user reviews the PR and leaves an In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
What problem does this PR solve?
Issue Number: ref #51477
What changed and how does it work?
Add more optional properties for
EvalContext
variable.SessionVars
.Check List
Tests
Side effects
Documentation
Release note
Please refer to Release Notes Language Style Guide to write a quality release note.