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

sqltostr: fix str_to_date('2018-6-14', '%Y-%m-%d') bug #6919

Merged
merged 10 commits into from
Jun 28, 2018

Conversation

mail2fish
Copy link
Contributor

@mail2fish mail2fish commented Jun 27, 2018

What have you changed? (mandatory)

fix #6835

What are the type of the changes (mandatory)?

bug fixed

How has this PR been tested (mandatory)?

make dev

Does this PR affect documentation (docs/docs-cn) update? (optional)

Refer to a related PR or issue link (optional)

#6835

Benchmark result if necessary (optional)

Add a few positive/negative examples (optional)

@sre-bot
Copy link
Contributor

sre-bot commented Jun 27, 2018

Hi contributor, thanks for your PR.

This patch needs to be approved by someone of admins. They should reply with "/ok-to-test" to accept this PR for running test automatically.

@lysu
Copy link
Contributor

lysu commented Jun 27, 2018

@mail2fish Thanks for your PR!

@lysu
Copy link
Contributor

lysu commented Jun 27, 2018

/run-all-tests

@zz-jason
Copy link
Member

Review status: 0 of 2 files reviewed, 2 unresolved discussions (waiting on @mail2fish)


types/time.go, line 2321 at r1 (raw file):

}

var digitRegex = regexp.MustCompile("^[0-9]+")

It'e better to put these two regex patterns together to a code block and make some comment for each one.


types/time.go, line 2348 at r1 (raw file):

	if length > 2 {
		result = result[2:]

Since result is not used in the following execution, we can remove this line.


Comments from Reviewable

@zz-jason zz-jason added contribution This PR is from a community contributor. component/expression type/bugfix This PR fixes a bug. labels Jun 27, 2018
types/time.go Outdated
result := digitRegex.FindString(input) // 0..31
length := len(result)

if length > 2 {
Copy link
Contributor

Choose a reason for hiding this comment

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

is it better to add some comments here why do you only take the suffix after index 2?

@zz-jason
Copy link
Member

Review status: 0 of 2 files reviewed, 5 unresolved discussions (waiting on @mail2fish and @zhexuany)


types/time.go, line 2357 at r2 (raw file):

	v, ok := parseDigits(input, length)

	if !ok || v >= 32 {

I think we should keep the origin v > 31, this check form is consistent with the validation check of month, which is v > 12 at line 2458


types/time.go, line 2447 at r2 (raw file):

func monthNumeric(t *MysqlTime, input string, ctx map[string]int) (string, bool) {

can we remove this empty line?


Comments from Reviewable

types/time.go Outdated
"%Y": yearNumericFourDigits, // Year, numeric, four digits
"%b": abbreviatedMonth, // Abbreviated month name (Jan..Dec)
"%c": monthNumeric, // Month, numeric (0..12)
"%d": dayOfMonthNumeric, // Day of the month, numeric (00..31)
Copy link
Member

Choose a reason for hiding this comment

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

Please update the comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Which the comment be needed to update?

Copy link
Member

Choose a reason for hiding this comment

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

update "(00..31)" to "(0..31)"

"%k": hour24Numeric, // Hour (0..23)
"%l": hour12Numeric, // Hour (1..12)
"%M": fullNameMonth, // Month name (January..December)
"%m": monthNumeric, // Month, numeric (00..12)
Copy link
Member

Choose a reason for hiding this comment

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

ditto

Copy link
Member

Choose a reason for hiding this comment

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

Please update the comment.

types/time.go Outdated
v, rem := parseTwoNumeric(input)
if len(rem) == len(input) || v > 12 {
return rem, false

Copy link
Member

Choose a reason for hiding this comment

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

please remove this empty line.

@mail2fish
Copy link
Contributor Author

/run-all-tests

@mail2fish
Copy link
Contributor Author

/run-all-tests

@zz-jason
Copy link
Member

@mail2fish Please remove the empty line between the function declaration and the first code of that function, that empty line is meaningless and redundant.

"%k": hour24Numeric, // Hour (0..23)
"%l": hour12Numeric, // Hour (1..12)
"%M": fullNameMonth, // Month name (January..December)
"%m": monthNumeric, // Month, numeric (00..12)
Copy link
Member

Choose a reason for hiding this comment

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

Please update the comment.

types/time.go Outdated
return input[2:], true
}
// digitRegex: it was used to scan a variable-length monthly day or month in the string. Ex: "01" or "1" or "30"
var digitRegex = regexp.MustCompile("^[0-9]+")
Copy link
Member

Choose a reason for hiding this comment

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

^[0-9]{1,2} is suitable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, It's better

types/time.go Outdated
length = 2
}

v, ok := parseDigits(input, length)
Copy link
Member

Choose a reason for hiding this comment

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

For "20181120" the v would be 20?

return input, false
}
t.month = uint8(v)
return remain, true
t.day = uint8(v)
Copy link
Member

Choose a reason for hiding this comment

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

t.month = uint8(v) is a bug?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I think so.

@mail2fish
Copy link
Contributor Author

/run-all-tests

types/time.go Outdated
result := digitRegex.FindString(input) // 1..12
length := len(result)

// Some time the input is a consecutive digital string. Ex: 20181120
Copy link
Contributor

Choose a reason for hiding this comment

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

You want to say e.g.?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just forgot to remove those lines

@shenli
Copy link
Member

shenli commented Jun 28, 2018

/run-all-tests

@shenli
Copy link
Member

shenli commented Jun 28, 2018

LGTM

@shenli shenli added the status/LGT1 Indicates that a PR has LGTM 1. label Jun 28, 2018
Copy link
Member

@winoros winoros 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

"%T": time24Hour, // Time, 24-hour (hh:mm:ss)
"%Y": yearNumericFourDigits, // Year, numeric, four digits
"%b": abbreviatedMonth, // Abbreviated month name (Jan..Dec)
"%c": monthNumeric, // Month, numeric (0..12)
Copy link
Member

Choose a reason for hiding this comment

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

These 0 should be 00?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@winoros winoros added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Jun 28, 2018
@zz-jason zz-jason merged commit 39d00d3 into pingcap:master Jun 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/expression contribution This PR is from a community contributor. 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.

Behavior of str_to_date() is different from mysql
7 participants