-
Notifications
You must be signed in to change notification settings - Fork 112
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
fix: Custom query validation throwing error with sql files ending with semicolon(;) #591
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1f19c37
fix: Custom query validation throwing error with sql files ending wit…
924022d
fix: Custom query validation throwing error with sql files ending wit…
928d222
fix: Custom query validation throwing error with sql files ending wit…
af23cf4
fix: Custom query validation throwing error with sql files ending wit…
2160649
fix: Custom query validation throwing error with sql files ending wit…
546bd06
fix: Custom query validation throwing error with sql files ending wit…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couldn't we just do an
query = query.rstrip(';')
? Or would there be some functionality missing if we did thatThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both rfind and rstrip does the job. If we need to use it for including complex scenarios then rfind has that flexibility, as it gets the index values which can be used later. I don't foresee any such use case though.
Happy to have more thoughts on this and agree to Neha's point to make it simpler and flexible.
For E2E : We have used 'split' function which basically splits the input query and removes semicolon.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the second thought!
I tired
query = query.rstrip(';')
in the first place, but it still gives the error:google.api_core.exceptions.BadRequest: 400 Syntax error: Expected ")" but got ";" at [2:11]
The test query is:
When using a ValueError to print out the query after the
We can see in the error message, the semicolon is still there:
One assumption is that the query string has multiple lines, and the semicolon only appears at the last line, so that the rstrip(';') hasn't been able to detect or delete it in this case. But, I did test rstrip(';') on the query string alone, and it works. I am not sure if it is because there are other functions in DVT which may interfere the result.
So I switched to rfind(). rfind() can make sure to find the last meaningless semicolon, by checking if the right side of this semicolon are all just spaces and enters.
I didn't choose split() is because I wanted to save the semicolon which may be meaningful in a query string, such as
select * from table a where text = "abc;"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The python file.read() method automatically appends a newline at the end of the string returned. Therefore, we should expect a newline and trim the newline/whitespace and semicolon accordingly:
query = query.rstrip(';\n'))
Using rstrip will ensure we are only removing trailing semicolons and not those in the query