Skip to content

Commit

Permalink
More reliable tie-break ordering for facet results
Browse files Browse the repository at this point in the history
I was seeing a weird bug where the order of results running tests
on my laptop was inconsistent, causing pytest failures even though
the order of tests in Travis CI was fine.

I think the fix is to explicitly state how facet ordering ties on
the count should be resolved.
  • Loading branch information
simonw committed Feb 13, 2020
1 parent 298a899 commit 0091dfe
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions datasette/facets.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ async def facet_results(self):
{sql}
)
where {col} is not null
group by {col} order by count desc limit {limit}
group by {col} order by count desc, value limit {limit}
""".format(
col=escape_sqlite(column), sql=self.sql, limit=facet_size + 1
)
Expand Down Expand Up @@ -344,7 +344,7 @@ async def facet_results(self):
select j.value as value, count(*) as count from (
{sql}
) join json_each({col}) j
group by j.value order by count desc limit {limit}
group by j.value order by count desc, value limit {limit}
""".format(
col=escape_sqlite(column), sql=self.sql, limit=facet_size + 1
)
Expand Down Expand Up @@ -457,7 +457,7 @@ async def facet_results(self):
{sql}
)
where date({col}) is not null
group by date({col}) order by count desc limit {limit}
group by date({col}) order by count desc, value limit {limit}
""".format(
col=escape_sqlite(column), sql=self.sql, limit=facet_size + 1
)
Expand Down

0 comments on commit 0091dfe

Please sign in to comment.