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

Removing unnecessary if statement #236

Merged
merged 2 commits into from
Jan 31, 2025
Merged

Removing unnecessary if statement #236

merged 2 commits into from
Jan 31, 2025

Conversation

NourOM02
Copy link
Contributor

In the eval.py file, the get_all_minimal_queries function contains an unnecessary if statement, when trying to replace the inside of the brackets when there is a GROUP BY statement, and it does look the same as saying if True:.

Lines of code:

# change group by size dynamically if necessary
if right.find("GROUP BY {}"):
    right = right.replace("GROUP BY {}", f"GROUP BY {column_str}")

The find method documentation:

Return the lowest index in the string where substring sub is found within the slice s[start:end]. Optional arguments start and end are interpreted as in slice notation. Return -1 if sub is not found.

Note : The find() method should be used only if you need to know the position of sub. To check if sub is a substring or not, use the in operator:

Description of the problem:

The find method is used to determine the presence of the string (not advised as per the python documentation). In addition to that, if GROUP BY {} is not in the string it will return -1 (which is not considered as False only 0 is). Furthermore, the replace method used in the inside will check the presence of the string anyway before replacing it. So why adding to the complexity of the code !?

Proposed edit:

# change group by size dynamically if necessary
right = right.replace("GROUP BY {}", f"GROUP BY {column_str}")

@rishsriv rishsriv self-requested a review January 31, 2025 20:15
Copy link
Member

@rishsriv rishsriv left a comment

Choose a reason for hiding this comment

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

Thanks!

@rishsriv rishsriv merged commit d89d0e0 into defog-ai:main Jan 31, 2025
2 checks passed
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.

2 participants