-
Notifications
You must be signed in to change notification settings - Fork 62
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 mysql case in cleaner #220
Conversation
eval/api_runner.py
Outdated
# remove extra spaces around brackets especially for MySQL | ||
query = query.replace(" ( ", "(").replace(" )", ")") | ||
query = query.replace(" (", "(").replace(") ", ")") | ||
query = query.replace("( ", "(").replace(" )", ")") |
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.
Hello! Could we use regex here for cleaner code that handles edge cases better? The code above would fail in some cases. For example, if the query generated is
query = "SELECT SUM ( a ) from table;"
The the code above would fail.
However, the code below would work fine.
query = re.sub(r'\s*\(\s*', '(', query) # Remove spaces before and after '('
query = re.sub(r'\s*\)\s*', ') ', query) # Remove spaces before and after ')', and only leaves a single space for syntactic correctness
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, fixed- also realized we do not want to remove space after a closing brace because that is valid- eg: COUNT(t.sbTxStatus) , 0) AS success_rate
. So, its this now:
# remove extra spaces around brackets especially for MySQL
query = re.sub(r"\s*\(\s*", "(", query) # Remove spaces before and after '('
query = re.sub(r"\s*\)", ")", query) # Remove spaces before ')'
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.
Cool, looks good to to me!
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.
looks good to me too! thanks for this change
The eval I ran earlier had a lot of errors because of this space before and after
(
and)
.This is something that is completely fine with postgres but erroneous in mysql. We do some post cleaning of the query to make sure we get rid of any such spaces. A case with spaces both before and after a bracket was handled but a more popular case is when there is a space after the bracket. Including this in the
clean_generated_query
for clarity.