-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
add support for the LEAST function #2360
Conversation
Good job! @zyguan |
} | ||
|
||
var cmp int | ||
if cmp, err = args[i].CompareDatum(sc, args[min]); err != nil { |
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.
When i == 0, it is not necessary to make this comparison.
sc := ctx.GetSessionVars().StmtCtx | ||
for i := 0; i < len(args); i++ { | ||
if args[i].IsNull() { | ||
d.SetNull() |
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.
d.IsNull() is true by default, so we don't need this d.SetNull().
Thanks @ngaut ! this is the simplest function to implement since there is already a GREATEST function implementation. I'm working on INTERVAL(), however, there is still a problem. eg:
will return I'll try to solve this as soon as possible. |
@zyguan Thanks! If you need any help, please let us know. |
@shenli 😄 |
func builtinLeast(args []types.Datum, ctx context.Context) (d types.Datum, err error) { | ||
min := 0 | ||
sc := ctx.GetSessionVars().StmtCtx | ||
for i := 1; i < len(args); i++ { |
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.
Should we check if args[0].IsNull() before the loop?
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.
Yes, you are right, I forget this.
GREATEST|LEAST should return NULL if any of its arguments is NULL.
PTAL |
LGTM Well done! @zyguan |
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
Hi, @shenli , here is the LEAST function wanted by #112 , PTAL :)