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

Added not reserved keyword. Works for both not in and not like #68

Merged
merged 8 commits into from
Oct 15, 2018

Conversation

frahman5
Copy link
Contributor

The basic update I made is to add a "Not" field to the NodeIn and NodeLike types and update their assertion methods accordingly. The Not field acts as a flag telling the program whether to query with a normal In/Like or with a Not In/Not Like. If "Not" is set to true, then the assertion method returns the opposite of what it would return otherwise.

All the other changes just support the above structural update. I updated lexical to be able to process a "not" reserved keyword. And I updated the parser to be able to correctly read in the "not" and create the appropriate NodeIn and NodeLike objects. I also added some tests to parser_test.go to make sure that was all working.

I chose this route over the other route of creating entirely new NodeNotIn and NodeNotLike objects because:

  • it seems simpler, requiring less overall new code.
  • it feels more appropriate, since the 'not' keyword is not really asking the program to create a whole different kind of where condition, but is just modifying the upcoming not or like expression. And so it seems appropriate to reflect that in the code, using the inclusion of a 'not' keyword to modify existing NodeIn or NodeLike objects, rather than create new negative versions of them.
  • it would extend pretty easily if we were to add new reserved keywords, like between. In this model, if you wanted to support 'not between', you would just add a 'Not' field to the NodeBetween object and update the getWhereConds() functions appropriately.

Examples

A query with no where condition

// ♥ go run gitql.go cmd.go autocomplete.go "select author, message from commits limit 5'"
+---------------------+--------------------------------+
|       author        |            message             |
+---------------------+--------------------------------+
| frahman5            | Added not reserved keyword.    |
|                     | Functions for both not in and  |
|                     | not like                       |
+---------------------+--------------------------------+
| Claudson Oliveira   | Update supported go version on |
|                     | travis CI                      |
+---------------------+--------------------------------+
| Claudson Oliveira   | Release a minor release        |
+---------------------+--------------------------------+
| ia                  | all: gofmt (#65)               |
+---------------------+--------------------------------+
| Arumugam Jeganathan | Add 'like' functionality in    |
|                     | where clause (#64)             |
+---------------------+--------------------------------+

A query with a where condition that excludes several of the authors you'd otherwise see

// ♥ go run gitql.go cmd.go autocomplete.go "select author, message from commits where 'Claudson' not in author AND 'Arumugam' not in author limit 5'"
+---------------------+---------------------------------+
|       author        |             message             |
+---------------------+---------------------------------+
| frahman5            | Added not reserved keyword.     |
|                     | Functions for both not in and   |
|                     | not like                        |
+---------------------+---------------------------------+
| ia                  | all: gofmt (#65)                |
+---------------------+---------------------------------+
| Luiz Fernando Peres | Merge pull request #62 from     |
|                     | jsixface/feature/WhereNotEquals |
+---------------------+---------------------------------+
| Luiz Fernando Peres | Merge pull request #61 from     |
|                     | jsixface/bug/NilStarSelect      |
+---------------------+---------------------------------+
| Luiz Fernando Peres | Merge pull request #56 from     |
|                     | jsixface/bug/NilStarSelect      |
+---------------------+---------------------------------+

Using a not like to exclude any commits where the message begins with Add

// ♥ go run gitql.go cmd.go autocomplete.go "select author, message from commits where message not like '%Add' limit 5"
+---------------------+---------------------------------+
|       author        |             message             |
+---------------------+---------------------------------+
| Claudson Oliveira   | Update supported go version on  |
|                     | travis CI                       |
+---------------------+---------------------------------+
| Claudson Oliveira   | Release a minor release         |
+---------------------+---------------------------------+
| ia                  | all: gofmt (#65)                |
+---------------------+---------------------------------+
| Luiz Fernando Peres | Merge pull request #62 from     |
|                     | jsixface/feature/WhereNotEquals |
+---------------------+---------------------------------+
| Arumugam J          | register walk type              |
+---------------------+---------------------------------+

@luizperes :)

Copy link
Owner

@filhodanuvem filhodanuvem left a comment

Choose a reason for hiding this comment

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

Awesome work @frahman5 🎉 .
I'm just waiting for @luizperes review and we can merge it.

@@ -26,6 +26,8 @@ const T_PARENTH_R = 23
const T_IN = 24
const T_ASC = 25
const T_LIKE = 26
const T_NOT = 27
const T_NOT_OR_T_LIKE = 28
Copy link
Owner

Choose a reason for hiding this comment

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

Did your Idea actually was T_IN_OR_T_LIKE, isn't? I'm not too comfortable seeing a token that is used just for error messages. I prefer to suggest just one of the options (T_NOT) and maybe we can discuss better in another thread how to improve the parser error to show more then one expected tokens. What do you think?

Copy link
Contributor Author

@frahman5 frahman5 Oct 12, 2018

Choose a reason for hiding this comment

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

Yeah I wasn't too happy about that either. I didn't want to create an entirely different SyntaxError function though, so I squeezed in that token instead. I think you're right though. I'll change it to just suggest T_NOT for now, and we can leave the issue of leaving better parser errors for another day.

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 letting you know I pushed another commit with this fix :)

@@ -230,6 +230,154 @@ func TestWhereWithNotEqualCompare(t *testing.T) {
}
}

func TestWhereWithIn(t *testing.T) {
Copy link
Owner

Choose a reason for hiding this comment

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

Wow, thanks a lot for that ❤️

Copy link
Contributor Author

Choose a reason for hiding this comment

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

:)

}

func TestWhereWithNotIn(t *testing.T) {
New("Select message from commits where 'react' not in message")
Copy link
Owner

Choose a reason for hiding this comment

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

Vue forever (?) 😆

Copy link
Contributor Author

Choose a reason for hiding this comment

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

lol

.idea/gitql.iml Outdated
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
Copy link
Owner

Choose a reason for hiding this comment

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

Thank you for the change but you commit some IDE files :/ . Can you remove them?

Copy link
Owner

@filhodanuvem filhodanuvem left a comment

Choose a reason for hiding this comment

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

Just because of the IDE files.

@@ -58,6 +59,7 @@ func allocMapTokenNames() {
T_IN: "T_IN",
T_EOF: "T_EOF",
T_ASC: "T_ASC",
T_NOT: "T_NOT",
Copy link
Collaborator

Choose a reason for hiding this comment

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

are these extra spaces only on github? otherwise, could you align them?

Copy link
Collaborator

@luizperes luizperes left a comment

Choose a reason for hiding this comment

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

LGTM (except for the extra non-needed files)

@filhodanuvem filhodanuvem changed the title Added not reserved keyword. Works for both not in and not like. Added not reserved keyword. Works for both not in and not like #49 Oct 12, 2018
@filhodanuvem filhodanuvem changed the title Added not reserved keyword. Works for both not in and not like #49 Added not reserved keyword. Works for both not in and not like Oct 12, 2018
@frahman5
Copy link
Contributor Author

@luizperes @cloudson I'll take care of those IDE files and space issues by tomorrow

@frahman5
Copy link
Contributor Author

@luizperes @cloudson requested changes made. I've removed the IDE files and fixed the spacing on tokens. go :)

Copy link
Collaborator

@luizperes luizperes left a comment

Choose a reason for hiding this comment

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

Thank you so much for this PR @frahman5! It looks neat!

@filhodanuvem filhodanuvem merged commit a3f1a73 into filhodanuvem:develop Oct 15, 2018
@filhodanuvem
Copy link
Owner

Thank you again 🤘

@frahman5
Copy link
Contributor Author

👍 😃

@jsixface
Copy link
Contributor

I think this would close #49

@filhodanuvem
Copy link
Owner

Totally right @jsixface , thank you for the suggestion.

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.

4 participants