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

fix column keys so that query grouping works #44

Merged
merged 8 commits into from
Aug 8, 2018
Merged

Conversation

snopoke
Copy link
Contributor

@snopoke snopoke commented Aug 8, 2018

Previously the following query would result in 2 SQL queries instead of 1 because the column key hash did not work:

vc = QueryContext("user_table", filters=filters, group_by=["user"])
vc.append_column(SumColumn("indicator_a", filters=[GT('date', 'enddate')]))
vc.append_column(SumColumn("indicator_b", filters=[GT('date', 'enddate')]))

self.table_name,
tuple(sorted(self.filters)) if self.filters else None,
tuple(self.group_by) if self.group_by else None
)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the main change along with the implementation of correct hashing and comparison for the filter classes

return hash((RawFilter, self.expression))

def __repr__(self):
return "SQL({})".format(self.expression)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

just for debugging

@orangejenny
Copy link
Contributor

For the __hash__ implementations, is there a reason that sometimes they use type(self) and sometimes they use the class name?

@snopoke
Copy link
Contributor Author

snopoke commented Aug 8, 2018

I used type(self) for base classes (though I see I copied that to the INFilter class as well.

@snopoke snopoke merged commit 1621e34 into master Aug 8, 2018
@snopoke snopoke deleted the sk/equality branch August 8, 2018 14:01
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.

None yet

2 participants