-
Notifications
You must be signed in to change notification settings - Fork 0
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
SQL Backend #54
SQL Backend #54
Conversation
For now I think it's valid to treat this as SQL-specific. Use-cases where that degree of normalization isn't required won't need it.
This is a bit silly, since the sinks are just stumps for these tests, but it's good form.
# Conflicts: # onix-env2.yaml # onix-env3.yaml
If ability isn't sanitized, get_all_formes won't work
I'm not sure that SQL isn't smart enough to not repeat the calculation, but this works regardless.
In case anyone's interested, this is the compiled SQL query for SELECT anon_1.species, sum(anon_1.weight) AS sum
FROM (SELECT anon_2.bid AS bid, anon_2.side AS side, anon_2.weight AS weight, count(anon_2.slot) AS count, anon_2.species AS species
FROM (SELECT anon_3.bid AS bid, anon_3.side AS side, anon_3.weight AS weight, teams.idx AS slot, teams.sid AS sid, CASE group_concat(formes.species) WHEN ? THEN ? WHEN ? THEN ? WHEN ? THEN ? WHEN ? THEN ? ELSE ? || group_concat(formes.species) END AS species
FROM (SELECT anon_4.bid AS bid, anon_4.side AS side, anon_4.pid AS pid, anon_4.tid AS tid, CASE WHEN (ifnull(anon_4.rprd, ?) > ?) THEN ? ELSE weight(ifnull(anon_4.rpr, ?), ifnull(anon_4.rprd, ?), ?) END AS weight
FROM (SELECT anon_5.id AS bid, battle_players.side AS side, battle_players.pid AS pid, battle_players.tid AS tid, battle_players.w AS w, battle_players.l AS l, battle_players.t AS t, battle_players.elo AS elo, battle_players.r AS r, battle_players.rd AS rd, battle_players.rpr AS rpr, battle_players.rprd AS rprd
FROM (SELECT battle_infos.id AS id
FROM battle_infos
WHERE battle_infos.format = ? AND battle_infos.date BETWEEN ? AND ? AND battle_infos.turns >= ?) AS anon_5 JOIN battle_players ON anon_5.id = battle_players.bid) AS anon_4) AS anon_3 JOIN teams ON anon_3.tid = teams.tid JOIN moveset_forme ON teams.sid = moveset_forme.sid JOIN formes ON moveset_forme.fid = formes.id GROUP BY anon_3.bid, anon_3.side, teams.idx) AS anon_2 GROUP BY anon_2.bid, anon_2.side, anon_2.species) AS anon_1 GROUP BY anon_1.species ORDER BY sum DESC |
Crud. This structure doesn't support ordering ('camerupt,cameruptmegax' is just a matter of alphabetical sorting, but how can we do 'charizardmegay,charizardmegax'?) |
I can handle this the same way it's handled for team members (in fact, it looks like there's a way to handle this more cleanly), but I honestly think this might be the impetus I need to tackle #48. |
LOL. I've been doing this kind of ordering all over the place (see: battle_players), but w/e--I feel like the core approach is cleaner |
The new compiled SQLite query: SELECT anon_1.species, sum(anon_1.weight) AS sum
FROM (SELECT anon_2.bid AS bid, anon_2.side AS side, anon_2.weight AS weight, count(anon_2.slot) AS count, anon_2.species AS species
FROM (SELECT anon_3.bid AS bid, anon_3.side AS side, anon_3.weight AS weight, anon_3.slot AS slot, anon_3.sid AS sid, CASE group_concat(anon_3.species) ELSE ? || group_concat(anon_3.species) END AS species
FROM (SELECT anon_4.bid AS bid, anon_4.side AS side, anon_4.weight AS weight, teams.idx AS slot, teams.sid AS sid, formes.species AS species, moveset_forme.prime AS prime
FROM (SELECT anon_5.bid AS bid, anon_5.side AS side, anon_5.pid AS pid, anon_5.tid AS tid, CASE WHEN (ifnull(anon_5.rprd, ?) > ?) THEN ? ELSE weight(ifnull(anon_5.rpr, ?), ifnull(anon_5.rprd, ?), ?) END AS weight
FROM (SELECT anon_6.id AS bid, battle_players.side AS side, battle_players.pid AS pid, battle_players.tid AS tid, battle_players.w AS w, battle_players.l AS l, battle_players.t AS t, battle_players.elo AS elo, battle_players.r AS r, battle_players.rd AS rd, battle_players.rpr AS rpr, battle_players.rprd AS rprd
FROM (SELECT battle_infos.id AS id
FROM battle_infos
WHERE battle_infos.format = ? AND battle_infos.date BETWEEN ? AND ? AND battle_infos.turns >= ?) AS anon_6 JOIN battle_players ON anon_6.id = battle_players.bid) AS anon_5) AS anon_4 JOIN teams ON anon_4.tid = teams.tid JOIN moveset_forme ON teams.sid = moveset_forme.sid JOIN formes ON moveset_forme.fid = formes.id ORDER BY formes.species, moveset_forme.prime DESC) AS anon_3 GROUP BY anon_3.bid, anon_3.side, anon_3.slot) AS anon_2 GROUP BY anon_2.bid, anon_2.side, anon_2.species) AS anon_1 GROUP BY anon_1.species ORDER BY sum DESC |
Resolves #18
SQLite implementation of a backend for Onix.
Before merging I might want to add some "pipeline" tests that verify expected operation from start to finish