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

Add parenthesis for custom where and having #1337

Merged
merged 1 commit into from
Oct 20, 2016
Merged

Add parenthesis for custom where and having #1337

merged 1 commit into from
Oct 20, 2016

Conversation

yejianye
Copy link
Contributor

Currently, when there's a 'OR' in custom where, it may result an unexpected query.

For example, if a user explore a table having a main dttm field, and he sets custom where as cond1="xxx" or cond2="yyy". The query generated would be

select ... from table_name where
dttm > '[since]' and dttm < '[until]' and cond1="xxx" or cond2="yyy"

That means any records that met cond="yyy" would be counted, even those records are out of user-specified date range. That result might not be what user expected. It would be much more reasonable if the generated query is

select ... from table_name where
dttm > '[since]' and dttm < '[until]' and (cond1="xxx" or cond2="yyy")

Copy link
Member

@mistercrunch mistercrunch left a comment

Choose a reason for hiding this comment

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

I agree with the idea. Happy to merge once comments are addressed.

@@ -486,3 +486,15 @@ def __exit__(self, type, value, traceback):
except ValueError as e:
logging.warning("timeout can't be used in the current context")
logging.exception(e)

Copy link
Member

Choose a reason for hiding this comment

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

PEP8 says 2 blank lines before a module scoped function

@@ -55,7 +55,7 @@
from caravel import app, db, db_engine_specs, get_session, utils, sm
from caravel.source_registry import SourceRegistry
from caravel.viz import viz_types
from caravel.utils import flasher, MetricPermException, DimSelector
from caravel.utils import flasher, MetricPermException, DimSelector, wrap_clause
Copy link
Member

Choose a reason for hiding this comment

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

line is 1 char too long according to code climate...

@@ -486,3 +486,15 @@ def __exit__(self, type, value, traceback):
except ValueError as e:
logging.warning("timeout can't be used in the current context")
logging.exception(e)

def wrap_clause(sql):
Copy link
Member

Choose a reason for hiding this comment

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

the doctest fails because you return a sqlalchemy.text object.

I'd make this function more generic and call it wrap_in_parentheses(s) and wrap clauses systematically (regardless of the OR in there). Note that the 'OR' in currently would trigger on something like 'my_field_has_the_letter_or_in_it > 0', but that's fine, we should just always put parentheses around the user clause when provided

@yejianye
Copy link
Contributor Author

@mistercrunch I've updated the code according to your comments. Please review again.

travis-ci timed out when building javascript (that should have nothing to do with this pull request)

@yejianye
Copy link
Contributor Author

Just rebased from master. And this travis-ci doesn't timeout either.

@mistercrunch could you review this and merge? Thanks.

@mistercrunch
Copy link
Member

Thanks for the PR!

@mistercrunch mistercrunch merged commit 458651f into apache:master Oct 20, 2016
neevany pushed a commit to Kieraya/caravel that referenced this pull request Oct 24, 2016
zhaoyongjie pushed a commit to zhaoyongjie/incubator-superset that referenced this pull request Nov 17, 2021
zhaoyongjie pushed a commit to zhaoyongjie/incubator-superset that referenced this pull request Nov 24, 2021
zhaoyongjie pushed a commit to zhaoyongjie/incubator-superset that referenced this pull request Nov 25, 2021
zhaoyongjie pushed a commit to zhaoyongjie/incubator-superset that referenced this pull request Nov 26, 2021
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 0.12.0 labels Feb 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 0.12.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants