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

tidb_query: fix parse number to JSON #5842

Merged
merged 3 commits into from
Nov 7, 2019
Merged

tidb_query: fix parse number to JSON #5842

merged 3 commits into from
Nov 7, 2019

Conversation

lonng
Copy link
Member

@lonng lonng commented Nov 7, 2019

Signed-off-by: Lonng heng@lonng.org

What have you changed?

Fix parse string to JSON. According to TiDB implementation, all numbers will be treated as

func appendBinaryNumber(buf []byte, x json.Number) (TypeCode, []byte, error) {
	var typeCode TypeCode
	if strings.ContainsAny(string(x), "Ee.") {
		typeCode = TypeCodeFloat64
		f64, err := x.Float64()
		if err != nil {
			return typeCode, nil, errors.Trace(err)
		}
		buf = appendBinaryFloat64(buf, f64)
	} else {
		typeCode = TypeCodeInt64
		i64, err := x.Int64()
		if err != nil {
			typeCode = TypeCodeFloat64
			f64, err := x.Float64()
			if err != nil {
				return typeCode, nil, errors.Trace(err)
			}
			buf = appendBinaryFloat64(buf, f64)
		} else {
			buf = appendBinaryUint64(buf, uint64(i64))
		}
	}
	return typeCode, buf, nil
}

See playground: https://play.golang.org/p/Ps4nRxJykpr

What is the type of the changes?

Pick one of the following and delete the others:

  • Bugfix (a change which fixes an issue)

How is the PR tested?

Please select the tests that you ran to verify your changes:

  • Unit test

Signed-off-by: Lonng <heng@lonng.org>
breezewish
breezewish previously approved these changes Nov 7, 2019
Signed-off-by: Lonng <heng@lonng.org>
@lonng
Copy link
Member Author

lonng commented Nov 7, 2019

/test

@breezewish
Copy link
Member

/merge

@sre-bot sre-bot added the status/can-merge Indicates a PR has been approved by a committer. label Nov 7, 2019
@sre-bot
Copy link
Contributor

sre-bot commented Nov 7, 2019

/run-all-tests

@sre-bot
Copy link
Contributor

sre-bot commented Nov 7, 2019

@lonng merge failed.

@lonng
Copy link
Member Author

lonng commented Nov 7, 2019

/test

@lonng lonng merged commit d019cce into tikv:master Nov 7, 2019
@lonng lonng deleted the fix-json-parse branch November 7, 2019 11:40
hawkingrei pushed a commit to hawkingrei/tikv that referenced this pull request Dec 1, 2019
Signed-off-by: Lonng <heng@lonng.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status/can-merge Indicates a PR has been approved by a committer.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants