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

BUG: Fix subqueries with parameters #1303

Closed
wants to merge 1 commit into from

Conversation

cpcloud
Copy link
Member

@cpcloud cpcloud commented Jan 25, 2018

closes #1300
closes #1331

This was a somewhat invasive change, but nets a lot fewer places where the params argument has to be used outside of the compile and execute functions and methods on clients. Now, params are part of the context and context is never None so it's easier to reason about where parameters are coming from.

@cpcloud cpcloud self-assigned this Jan 25, 2018
@cpcloud cpcloud requested a review from wesm January 25, 2018 21:31
@cpcloud cpcloud added the bug Incorrect behavior inside of ibis label Jan 25, 2018
@cpcloud cpcloud added this to the 0.13 milestone Jan 25, 2018
@cpcloud cpcloud force-pushed the fix-scalar-params branch 3 times, most recently from b607536 to 94bb3e2 Compare January 27, 2018 20:34
@cpcloud cpcloud changed the title BUG: Fix subqueries with parameters WIP/BUG: Fix subqueries with parameters Jan 27, 2018
@cpcloud cpcloud force-pushed the fix-scalar-params branch 2 times, most recently from 3909737 to 6c4aee3 Compare January 28, 2018 16:51
@cpcloud
Copy link
Member Author

cpcloud commented Jan 30, 2018

@wesm @kszucs can you review when you get a chance?

Copy link
Member

@kszucs kszucs left a comment

Choose a reason for hiding this comment

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

A short summary on top of ibis/sql/compiler.py would be great, a general overview of the classes and the relationships between them.

It was pretty hard to understand the abstractions here when I wrote the clickhouse backend.

@@ -46,14 +55,30 @@ def __exit__(self, exc_type, exc_value, traceback):

class BigQuery(Query):

def __init__(self, *args, **kwargs):
Copy link
Member

Choose a reason for hiding this comment

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

How about explicit args?

def __init__(self, client, ddl, params=None):
    super(BigQuery, self).__init__(client, ddl)
    self.query_parameters = params or []

Copy link
Member Author

Choose a reason for hiding this comment

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

Good idea, will change. This originally was just so that I could do the default initialization and be robust to signature changes in the parent.

def __init__(self, *args, **kwargs):
query_parameters = kwargs.pop('query_parameters', [])
super(BigQuery, self).__init__(*args, **kwargs)
self.query_parameters = query_parameters
Copy link
Member

@kszucs kszucs Jan 30, 2018

Choose a reason for hiding this comment

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

I might just hate typing but ibis.bigquery.BigQuery.query_parameters is a bit verbose to me.

Copy link
Member Author

Choose a reason for hiding this comment

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

Users don't interact with ibis at this level, and this is an instance variable anyway so the most you'd ever type is self.query_parameters

@@ -260,6 +245,13 @@ class BigQueryExprTranslator(impala_compiler.ImpalaExprTranslator):
_registry = _operation_registry
_rewrites = impala_compiler.ImpalaExprTranslator._rewrites.copy()

context_class = BigQueryContext
Copy link
Member

Choose a reason for hiding this comment

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

This is inconsistent with the BigQuerySelect.translator which is not postfixed with _class

Copy link
Member Author

Choose a reason for hiding this comment

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

There's context_class which is a class variable, and context which is an instance of context_class, so they are consistent, unless I'm misunderstanding you here.

Copy link
Member

@kszucs kszucs Feb 7, 2018

Choose a reason for hiding this comment

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

I mean BigQuerySelect.translator is holding a class too: BigQueryExprTranslator.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll make a follow up issue to fix the inconsistency. In the meantime, I'm going to merge this next.

Copy link
Member

Choose a reason for hiding this comment

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

Great! :) You might check #1315 next

@@ -243,7 +234,8 @@ def execute(self, expr, params=None, limit='default', async=False):

def _execute_query(self, ddl, async=False):
klass = self.async_query if async else self.sync_query
return klass(self, ddl).execute()
inst = klass(self, ddl)
return inst.execute()
Copy link
Member

Choose a reason for hiding this comment

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

The previous one was nicer :)

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, but this is +epsilon easier to debug.

context = self.context
@property
def translator(self):
return self.context.dialect.translator
Copy link
Member

@kszucs kszucs Jan 30, 2018

Choose a reason for hiding this comment

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

It's quite hard to distinguish between Context, Dialect and Translator. Too many indirections for me.
What is the relationship between them?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll add some documentation for this in ibis/sql/compiler.py.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks :)

@cpcloud cpcloud force-pushed the fix-scalar-params branch 4 times, most recently from ff16f0b to 0d5247e Compare February 4, 2018 22:08
param = ibis.param('int64')
expr = alltypes[alltypes.string_col.cast('int64') == param]

string_value = 0
Copy link
Member Author

Choose a reason for hiding this comment

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

I need to change these names to reflect the actual values.

@cpcloud cpcloud force-pushed the fix-scalar-params branch 4 times, most recently from f8c7261 to 3330226 Compare February 6, 2018 16:41
@@ -57,6 +57,14 @@ def batting(self):
def awards_players(self):
return self.connection.database().awards_players

@classmethod
def make_context(cls, params=None):
module_name = cls.module
Copy link
Member

Choose a reason for hiding this comment

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

There is a property for getting the module's name: self.name
We should use either explicit module variables or a method which converts the classname.

Copy link
Member Author

Choose a reason for hiding this comment

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

We should use either explicit module variables or a method which converts the classname.

I'm not sure I follow this. Isn't self.name enough?

@cpcloud cpcloud changed the title WIP/BUG: Fix subqueries with parameters BUG: Fix subqueries with parameters Feb 7, 2018
@cpcloud
Copy link
Member Author

cpcloud commented Feb 7, 2018

merging on green

@cpcloud cpcloud closed this in 780084d Feb 7, 2018
@cpcloud cpcloud deleted the fix-scalar-params branch February 7, 2018 23:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Incorrect behavior inside of ibis
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: Unable to add column based on a scalar parameter ScalarParameters are not passed to subqueries
2 participants