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

Type value changes & row type assertions #1044

Merged
merged 2 commits into from
Jun 12, 2022
Merged

Conversation

Hydrocharged
Copy link
Contributor

@Hydrocharged Hydrocharged commented Jun 7, 2022

This PR has two primary goals:

  1. All types now pass their values around in a form most suitable to that type.
  2. Enforce that the aforementioned types are always passed to integrators, such that integrators do not need to do type validation on their end.

To elaborate on these points, some types already passed around values that were sensible and a best fit for that type, such as MEDIUMINT returning an int32. Other types, such as DECIMAL, passed around strings, which necessitated conversions for integrators to be able to properly persist the values. Not only that, there is currently no guarantee that a row's values each have their best fit type (a BIGINT can work with an int8, but it should be able to always expect int64). To make these guarantees, I'm adding a check at all GMS-integrator junctions that pass a sql.Row and verifying that the value types are exactly what that column expects.

This may have the side effect of changing the output of a SELECT statement for integrators. As a SELECT statement simply returns a sql.RowIter, additional logic will be needed to convert all values to their canonical MySQL representation. This can easily be achieved by passing all values through Type.SQL() before display.

@Hydrocharged Hydrocharged requested a review from zachmu June 7, 2022 15:10
@Hydrocharged Hydrocharged marked this pull request as draft June 7, 2022 15:10
Copy link
Member

@zachmu zachmu left a comment

Choose a reason for hiding this comment

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

LGTM

My only real concern is places that are doing type assertions that could panic if they get a bad value from an integrator. I think I only saw this in Compare methods where the values being type asserted already passed through a Convert() call so should be safe, but be cautious about that.

sql/arraytype.go Show resolved Hide resolved
@Hydrocharged Hydrocharged force-pushed the daylon/type-changes branch 3 times, most recently from 78fc86a to f015b1c Compare June 10, 2022 16:11
@Hydrocharged Hydrocharged marked this pull request as ready for review June 10, 2022 16:12
@Hydrocharged Hydrocharged merged commit de8461d into main Jun 12, 2022
@Hydrocharged Hydrocharged deleted the daylon/type-changes branch June 21, 2022 10:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants