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: fix convert number base for hybrid type #21554

Merged
merged 3 commits into from
Dec 9, 2020

Conversation

lzmhhh123
Copy link
Contributor

Signed-off-by: lzmhhh123 [email protected]<!-- Thank you for contributing to TiDB!

PR Title Format:

  1. pkg [, pkg2, pkg3]: what's changed
  2. *: what's changed

-->

What problem does this PR solve?

Issue Number: close #5817

What is changed and how it works?

How it Works: specified handle hybrid type for conv function.

Related changes

  • Need to cherry-pick to the release branch

Check List

Tests

  • Unit test
  • Integration test

Side effects

  • Performance regression
    • Consumes more CPU

Release note

  • fix convert number base for hybrid type

@lzmhhh123 lzmhhh123 requested a review from a team as a code owner December 8, 2020 07:22
@lzmhhh123 lzmhhh123 requested review from SunRunAway and removed request for a team December 8, 2020 07:22
@lzmhhh123
Copy link
Contributor Author

/cc @ichn-hu

@ti-srebot ti-srebot requested a review from ichn-hu December 8, 2020 07:23
@lzmhhh123
Copy link
Contributor Author

/cc @XuHuaiyu

@ti-srebot ti-srebot requested a review from XuHuaiyu December 8, 2020 07:23
@lzmhhh123 lzmhhh123 added needs-cherry-pick-4.0 sig/execution SIG execution type/bugfix This PR fixes a bug. labels Dec 8, 2020
@XuHuaiyu XuHuaiyu requested review from wshwsh12 and removed request for SunRunAway December 8, 2020 08:09
@ichn-hu ichn-hu mentioned this pull request Dec 8, 2020
Comment on lines +1174 to +1184
if x.FuncName.L == ast.Cast {
arg0 := x.GetArgs()[0]
if arg0.GetType().Hybrid() || IsBinaryLiteral(arg0) {
str, isNull, err = arg0.EvalString(b.ctx, row)
if isNull || err != nil {
return str, isNull, err
}
d := types.NewStringDatum(str)
str = d.GetBinaryLiteral().ToBitLiteralString(true)
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

what if the func is not Cast but produces string that needs to be converted?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When we build conv function. If the first argument is NOT string type. The cast would be wrapped. No other cases. You can refer to this code.

func (c *convFunctionClass) getFunction(ctx sessionctx.Context, args []Expression) (builtinFunc, error) {
	if err := c.verifyArgs(args); err != nil {
		return nil, err
	}

	bf, err := newBaseBuiltinFuncWithTp(ctx, c.funcName, args, types.ETString, types.ETString, types.ETInt, types.ETInt)
	if err != nil {
		return nil, err
	}
	bf.tp.Charset, bf.tp.Collate = ctx.GetSessionVars().GetCharsetInfo()
	bf.tp.Flen = 64
	sig := &builtinConvSig{bf}
	sig.setPbCode(tipb.ScalarFuncSig_Conv)
	return sig, nil
}

Comment on lines +1073 to +1074
// TODO: change the vecEval match hybrid type fixing. Then open the vectorized evaluation.
return false
Copy link
Contributor

Choose a reason for hiding this comment

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

would you like to create an issue for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will update #12106, since the PR merged.

Copy link
Contributor

@ichn-hu ichn-hu left a comment

Choose a reason for hiding this comment

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

Rest LGTM

Copy link
Contributor

@XuHuaiyu XuHuaiyu left a comment

Choose a reason for hiding this comment

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

LGTM

@ti-srebot ti-srebot added the status/LGT1 Indicates that a PR has LGTM 1. label Dec 8, 2020
Copy link
Contributor

@wshwsh12 wshwsh12 left a comment

Choose a reason for hiding this comment

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

LGTM

@ti-srebot ti-srebot removed the status/LGT1 Indicates that a PR has LGTM 1. label Dec 9, 2020
@ti-srebot ti-srebot added the status/LGT2 Indicates that a PR has LGTM 2. label Dec 9, 2020
@wjhuang2016
Copy link
Member

/merge

@ti-srebot ti-srebot added the status/can-merge Indicates a PR has been approved by a committer. label Dec 9, 2020
@ti-srebot
Copy link
Contributor

/run-all-tests

@ti-srebot ti-srebot merged commit 6cd3c65 into pingcap:master Dec 9, 2020
ti-srebot pushed a commit to ti-srebot/tidb that referenced this pull request Dec 9, 2020
@ti-srebot
Copy link
Contributor

cherry pick to release-4.0 in PR #21593

ti-srebot added a commit that referenced this pull request Jan 25, 2021
@lzmhhh123 lzmhhh123 deleted the bug-fix/fix_convert_bit branch February 18, 2021 08:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/expression sig/execution SIG execution status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2. type/bugfix This PR fixes a bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

conv bit error
6 participants