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

Fix integer literals parsing #840

Merged
merged 16 commits into from
Oct 15, 2019
Merged

Conversation

agarciamontoro
Copy link
Contributor

@agarciamontoro agarciamontoro commented Oct 11, 2019

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

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

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

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
@agarciamontoro
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.

@agarciamontoro
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.

@agarciamontoro
Copy link
Contributor Author

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

@erizocosmico
Copy link
Contributor

erizocosmico commented Oct 14, 2019

Can you rebase? there are some conflicts now

@erizocosmico erizocosmico requested a review from a team October 14, 2019 09:17
- 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 <[email protected]>
@agarciamontoro
Copy link
Contributor Author

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

@erizocosmico
Copy link
Contributor

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

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!

The tests now expect the correct types specified in the tables schema

Signed-off-by: Alejandro García Montoro <[email protected]>
Signed-off-by: Alejandro García Montoro <[email protected]>
Signed-off-by: Alejandro García Montoro <[email protected]>
Signed-off-by: Alejandro García Montoro <[email protected]>
Signed-off-by: Alejandro García Montoro <[email protected]>
Signed-off-by: Alejandro García Montoro <[email protected]>
Signed-off-by: Alejandro García Montoro <[email protected]>
@agarciamontoro
Copy link
Contributor Author

agarciamontoro commented Oct 15, 2019

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

@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.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Returned types do not fit the schema
5 participants