-
Notifications
You must be signed in to change notification settings - Fork 22
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
Nibrs agency api #521
Nibrs agency api #521
Conversation
@harrisj - I can't seem to tag you as the reviewer on this for some reason. When you get a chance, can you take a look at this? Thanks! |
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.
Have a few questions so I can understand what is going on, but looking good. Given the performance issues, I think I will merge it, but I'd like to understand why the 2012 tables are being used.
@@ -1015,7 +1015,7 @@ def get_field_table(self, field): | |||
return ('ref_race','race_code') | |||
|
|||
if field in ['sex_code']: | |||
return ('nibrs_victim_denorm_2012','sex_code') | |||
return ('victim_counts_2012','sex_code') |
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.
Is there a reason why this is pegged to a single year of materialized data?
@@ -1083,9 +1083,9 @@ def base_query(self, field): | |||
join_table,join_field = self.get_field_table(field) | |||
if join_field: | |||
if self.year: | |||
query_gap_fill = ' RIGHT JOIN (SELECT DISTINCT ' + join_table + '.' + join_field + ' AS :field, c.year from ' + join_table + ' RIGHT JOIN (SELECT year::text, :view_name.:field from :view_name ' + inner_where_query + ' GROUP BY year,:view_name.:field ORDER BY year DESC) c ON (c.:field = ' + join_table +'.' + join_field + ')) b ON (a.:field = b.:field)' | |||
query_gap_fill = ' RIGHT JOIN (SELECT DISTINCT ' + join_table + '.' + join_field + ' AS :field, c.year from ' + join_table + ' CROSS JOIN (SELECT year::text from nibrs_years WHERE year::int = :year) c) b ON (a.:field = b.:field)' |
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.
Sing to the tune of Trogdor: "CROSS JOIN! CROSS JOIN! Combinating the tables! Combinating the fields!"
Seriously, this is interesting, but I think I would like if you could use SqlAlchemy's interpolation (I think there are some cases where you can say "Unescape this field") since I worry this would trip off SQL injection alerts?
This fixes some major performance issues in production with the NIBRS API's. The indexes and such are already live.