Releases: BurntSushi/nfldb
Materialized view for `play`. `Query` demolition.
This is a new release of nfldb that brings major changes to the
implementation and one small change that could break your code:
ATTN: This introduces a breaking change. The team field can no longer
be used in the play method. Instead, you should use the new
play_player method to select individual player statistics belonging to
a specific team.
Once you update, the next time you connect to nfldb, your database will be
migrated to include the agg_play table. You should see some messages printed
to your terminal. You should not have to do anything other than wait a few
moments while the operation completes.
Otherwise, there are very few public facing changes, but the entire
guts of nfldb.Query have been ripped out and replaced with more
robust SQL generation code. Moreover, several idiosyncracies have been
fixed and some unit tests have finally been added.
-
Previously, the
Queryclass was doing some very clever things to do
parts of a JOIN in Python code. The general flow was that filtering
was applied to find primary keys---never using any JOINs---and once
all criteria had been applied, those ids were used in a simple SELECT
to fetch the actual rows.Now all of that cruft has been removed and replaced with intelligent
SQL generation that constructs one query with all the proper JOINs.
For whatever reason, I thought this was slower when experimenting
with it when I first started nfldb. Perhaps my indexes weren't
configured properly then. In any case, I can't really see much
performance difference. -
The SQL generation code is very smart. Although it is not part of
nfldb's public API, I imagine it would be very useful if you had some
special needs. See the unexported but documentednfldb.sqlmodule. -
Many idiosyncracies resulting from doing a join in Python are now
completely gone. For example, if you tried to apply asortwith a
limitwith complex search criteria, you were bound to get wrong
answers. For example, if you tried sorting by both a column on the
weektable (likedown) and a column onplay_player(like
passing_tds) and applied a limit to it, the results would be
completely wonky because the pure Python join can't cope with it
performantly. A regular SQL join? Piece of cake. -
I have added a materialized view
agg_play. This is a fancy word for
"a table that automatically updates itself." In essence, whenever a
new row is added toplay_player, aggregate statistics for that play
are re-computed. This makes adding data slower (which doesn't happen
very frequently), but it makes querying data much faster and easier.
For example, plays can be queried forpassing_ydswithout ever
joining withplay_player. (Which is wonky because of the
one-to-many relationship.)
To reflect this clearer separation of concerns, theQuery.play
method will no longer add criteria that hits theplay_playertable.
Instead, if you really want theplay_playertable, then you can use
the newplay_playermethod. The only field that was accepted in the
playthat is no longer allowed is theteamandplayer_id
fields. This is because there is no sensible way to aggregate these
values into a single play.To the best of my knowledge, that is the only possible breaking
change here.