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

expression: wrap arguments when new built-in function #3520

Merged
merged 9 commits into from
Jun 22, 2017
Merged

Conversation

XuHuaiyu
Copy link
Contributor

Types of every arguments and return type should be determined
when building built-in function signatures,
before this commit, we wrap cast in runtime which is not efficient,
this commit wrap cast for args when getFunction.

PTAL @hanfei1991 @shenli

@XuHuaiyu XuHuaiyu added priority/P1 The issue has P1 priority. non-release-blocker labels Jun 21, 2017
return baseBuiltinFunc{
args: args,
argValues: make([]types.Datum, len(args)),
ctx: ctx,
deterministic: true,
tp: tp,
}
tp: retType}, errors.Trace(err)
Copy link
Member

Choose a reason for hiding this comment

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

At this line, err must be nil

@XuHuaiyu
Copy link
Contributor Author

PTAL @hanfei1991

@hanfei1991
Copy link
Member

LGTM

@XuHuaiyu
Copy link
Contributor Author

PTAL @shenli

// thus the `tp` attribute is needed for `baseBuiltinFunc`
// to obtain the FieldType of a ScalarFunction.
func newBaseBuiltinFuncWithTp(args []Expression, tp *types.FieldType, ctx context.Context) baseBuiltinFunc {
// newBaseBuiltinFuncWithTp create a built-in function signature with specified types of arguments and return type.
Copy link
Contributor

Choose a reason for hiding this comment

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

s/create/creates
s/return type/ returns a type

// Every built-in function needs determined argTps and retType when we create it.
func newBaseBuiltinFuncWithTp(args []Expression, retType *types.FieldType, ctx context.Context, argTps ...argTp) (bf baseBuiltinFunc, err error) {
if len(args) != len(argTps) {
panic("unexpected length of args and argTps")
Copy link
Contributor

Choose a reason for hiding this comment

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

Why use panic?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

len(args) must equals to len(argTps),
and argTps is set by the coder,
so here I use panic to give warning.

args[i], err = WrapWithCastAsTime(args[i], types.NewFieldType(mysql.TypeDatetime), ctx)
case tpDuration:
args[i], err = WrapWithCastAsDuration(args[i], ctx)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

The err value will be covered.

// but what we actually get is store as float64 in Datum.
// So if we wrap `CastDecimalAsInt` upon the result, we'll get <nil> when call `arg.EvalDecimal()`.
// This will be fixed after all built-in functions be rewrite correctlly.
// return val.GetMysqlDecimal(), false, nil
Copy link
Contributor

Choose a reason for hiding this comment

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

Complete this comment.

case *builtinValuesSig:
switch sf.FuncName.L {
case ast.Cast:
newFunc, _ := buildCastFunction(sf.GetArgs()[0], sf.GetType(), sf.GetCtx())
Copy link
Contributor

Choose a reason for hiding this comment

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

Why omit this error?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a Clone func of ScalarFunction,
the error will never happen.

@XuHuaiyu
Copy link
Contributor Author

PTAL @zimulala

@@ -171,7 +171,7 @@ func (s *testEvaluatorSuite) TestConcat(c *C) {
}
fc := funcs[fcName].(*concatFunctionClass)
for _, t := range typeCases {
retType := fc.inferType(t.args)
retType, _ := fc.inferType(t.args)
Copy link
Contributor

Choose a reason for hiding this comment

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

Check this result?

@@ -249,7 +253,7 @@ func (b *castAsStringFunctionClass) getFunction(args []Expression, ctx context.C
sig = &builtinCastStringAsStringSig{bf}
}
}
return sig, errors.Trace(b.verifyArgs(args))
return sig.setSelf(sig), errors.Trace(b.verifyArgs(args))
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need to set self-value?
If we really need to do that,line 237 also need to be set.

@zimulala
Copy link
Contributor

LGTM

@XuHuaiyu XuHuaiyu merged commit 6f1bc82 into master Jun 22, 2017
@XuHuaiyu XuHuaiyu deleted the xhy/wrap-cast branch June 22, 2017 03:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority/P1 The issue has P1 priority.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants