Skip to content
This repository has been archived by the owner on Jan 28, 2021. It is now read-only.

sql: use custom boolean coercion logic in condition evaluation #768

Merged
merged 1 commit into from
Jun 24, 2019

Conversation

erizocosmico
Copy link
Contributor

Part of the fix for src-d/gitbase#902

The idea is to use EvaluateCondition as a common logic for filtering in both gitbase squashed tables and go-mysql-server.

Right now, in go-mysql-server we just check the result == true, which not only is not correct but is not consistent with how gitbase does it.
In gitbase we use sql.Boolean.Convert, but by definition the convert method of boolean can't handle some types.

That's why I added some helper function for this with the type coercion logic that we can also reuse on gitbase.

@erizocosmico erizocosmico requested a review from a team June 24, 2019 13:05
Signed-off-by: Miguel Molina <miguel@erizocosmi.co>
Copy link
Contributor

@ajnavarro ajnavarro left a comment

Choose a reason for hiding this comment

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

Nice catch.

@ajnavarro ajnavarro requested a review from a team June 24, 2019 13:28
return b, nil
case int, int64, int32, int16, int8, uint, uint64, uint32, uint16, uint8:
return b != 0, nil
case time.Duration:
Copy link
Contributor

Choose a reason for hiding this comment

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

Should a Duration or time really ever evaluate to false?

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 it's 0, i guess

Copy link
Contributor

Choose a reason for hiding this comment

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

But those are valid dates/durations. Anyway it's very minor; we should probably just do whatever MySQL do in these cases.

@ajnavarro ajnavarro merged commit d9b20c8 into src-d:master Jun 24, 2019
case float32, float64:
return int(math.Round(v.(float64))) != 0, nil
default:
return 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.

how about the string:
select 1 from dual where "1";
basically it false, but for above string it's true for mysql.

@erizocosmico erizocosmico deleted the fix/bool-coercion branch June 24, 2019 14:02
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants