Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Jan 28, 2021. It is now read-only.

Fix integer literals parsing #840

Merged
erizocosmico merged 16 commits into src-d:master from agarciamontoro:fix.parsing
Oct 15, 2019
Merged

Conversation

@agarciamontoro
Copy link
Contributor

@agarciamontoro agarciamontoro commented Oct 11, 2019
edited
Loading

This PR fixes #834 with some changes:

  • Modify convertInt so it returns the smallest representation allowed. See acb2bc0.
  • (削除) Add a rule to convert integer literals to the specified types in the schema in INSERT nodes. See 2eb11bb. (削除ここまで) After discussion with @erizocosmico (check Fix integer literals parsing #840 (comment) ), I've completely removed the integer conversion rule and moved its logic to Insert.Execute function. Much less code, which is always better. See instead 653fdde#diff-7e21a9fc108efea330a88d73d2a81023.
  • Adapt several parts of the code that broke after the above changes, namely:
    • getInt64Literal function was modified so it converts any integer to int64. See 10d13fc.
    • an explicit conversion to int64 was added in GROUP BY parsing, so any integer that fits is allowed. See 2320b07.
    • the ROUND and YEARWEEK functions were also modified so they can work with all types of integers. See 97a2315
    • most of the changes in this PR are in tests, as they were tailored to the previous int64-only design. These changes make the tests expect the right types. Review with care here, please 🙏 : 00a8833
    • some more boilerplate changes in pilosa code so it handles 8 and 16 bits signed and unsigned integers values as well. See 5c38a0d
    • I also needed to modify the conversion back to sqltypes.Value in numberT.SQL function, as it failed when 8 and 16 bits signed and unsigned integers values were passed, resulting in empty rows when doing, for example, SELECT 1. See ffae1d2

Maybe the most comfortable way to review this is:

This one is my first big contribution to go-mysql-server, so please review and test thoroughly. Comments and suggestions are more than welcome.

@agarciamontoro agarciamontoro requested a review from a team October 11, 2019 10:27

var errWrongNumberOfValues = errors.NewKind("the number of values to insert differ from the expected columns")

func convertIntegerLiteralsInsert(ctx *sql.Context, analyzer *Analyzer, originalNode sql.Node) (sql.Node, error) {
Copy link
Contributor

@erizocosmico erizocosmico Oct 11, 2019

Choose a reason for hiding this comment

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

I think we should let the table implementations handle this. When the literals are parsed, they are converted to the minimum type of int possible, then the table is in charge of converting it.

If we really want to make this transparent for table implementations, then I'd go for doing column.Type.Convert(theLiteralValue) inside the InsertInto execution method, but I would not add a new rule in the analyzer for this specific case.

WDYT @src-d/data-processing?

Copy link
Contributor Author

@agarciamontoro agarciamontoro Oct 11, 2019

Choose a reason for hiding this comment

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

I think that the conversion should be done by us. If we convert string literals to proper dates, we should do the same here. I'd argue that int8 is as different from uint64 as a date is different from a string.

But maybe it makes sense to do it inside InsertInto, not as a new rule. I'll wait for the rest of opinions.

Copy link
Contributor Author

@agarciamontoro agarciamontoro Oct 11, 2019

Choose a reason for hiding this comment

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

Solved in 653fdde.

@agarciamontoro agarciamontoro force-pushed the fix.parsing branch 2 times, most recently from 37761f9 to 3034d2d Compare October 11, 2019 10:55
Copy link
Contributor Author

I'm just noticing that I did not run gofmt over the new files. I'll fix the formatting in the next commit.

Copy link
Contributor Author

As per @erizocosmico's comment (check #840 (comment)), I've completely removed the integer conversion rule and moved its logic to Insert.Execute function. Much less code, which is always better.

I've added it as a new commit (653fdde) for if someone still prefers the other alternative, but I can rebase it before merging.

Copy link
Contributor Author

The latest four commits add missing cases to tests of modified functions. I think that CodeCoverage should be happy now.

Copy link
Contributor

erizocosmico commented Oct 14, 2019
edited
Loading

Can you rebase? there are some conflicts now

agarciamontoro reacted with thumbs up emoji

@erizocosmico erizocosmico requested a review from a team October 14, 2019 09:17
Signed-off-by: Alejandro García Montoro <alejandro.garciamontoro@gmail.com>
- The integer literals in INSERT expressions are now converted to the type of
their corresponding column in the schema.
- sql.IsInteger has been fixed so that it recognizes smaller types.
Signed-off-by: Alejandro García Montoro <alejandro.garciamontoro@gmail.com>
Signed-off-by: Alejandro García Montoro <alejandro.garciamontoro@gmail.com>
Copy link
Contributor Author

Rebased. Codecov is still complaining, though. I'll take a look.

Copy link
Contributor

We can live with a -0.05%, don't worry 😄

agarciamontoro reacted with eyes emoji

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.

Well done!

Signed-off-by: Alejandro García Montoro <alejandro.garciamontoro@gmail.com>
Signed-off-by: Alejandro García Montoro <alejandro.garciamontoro@gmail.com>
Signed-off-by: Alejandro García Montoro <alejandro.garciamontoro@gmail.com>
The tests now expect the correct types specified in the tables schema
Signed-off-by: Alejandro García Montoro <alejandro.garciamontoro@gmail.com>
Signed-off-by: Alejandro García Montoro <alejandro.garciamontoro@gmail.com>
Signed-off-by: Alejandro García Montoro <alejandro.garciamontoro@gmail.com>
Signed-off-by: Alejandro García Montoro <alejandro.garciamontoro@gmail.com>
Signed-off-by: Alejandro García Montoro <alejandro.garciamontoro@gmail.com>
Signed-off-by: Alejandro García Montoro <alejandro.garciamontoro@gmail.com>
Signed-off-by: Alejandro García Montoro <alejandro.garciamontoro@gmail.com>
Signed-off-by: Alejandro García Montoro <alejandro.garciamontoro@gmail.com>
Signed-off-by: Alejandro García Montoro <alejandro.garciamontoro@gmail.com>
Signed-off-by: Alejandro García Montoro <alejandro.garciamontoro@gmail.com>
Copy link
Contributor Author

agarciamontoro commented Oct 15, 2019
edited
Loading

Force pushed without changes in go.mod. Thanks for the catch, @carlosms!
I think it should be ready to merge now.

carlosms reacted with thumbs up emoji

@erizocosmico erizocosmico merged commit fb0e801 into src-d:master Oct 15, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Reviewers

4 more reviewers

@carlosms carlosms carlosms approved these changes

@juanjux juanjux juanjux approved these changes

@ajnavarro ajnavarro ajnavarro approved these changes

@erizocosmico erizocosmico erizocosmico approved these changes

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Returned types do not fit the schema

AltStyle によって変換されたページ (->オリジナル) /