{"html_url": "https://github.com/simonw/datasette/issues/1080#issuecomment-1029695083", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/1080", "id": 1029695083, "node_id": "IC_kwDOBm6k_c49X-Zr", "user": {"value": 9599, "label": "simonw"}, "created_at": "2022-02-04T06:24:40Z", "updated_at": "2022-02-04T06:25:18Z", "author_association": "OWNER", "body": "An initial prototype of that in my local `group-count` branch quickly started running into problems:\r\n```diff\r\ndiff --git a/datasette/views/table.py b/datasette/views/table.py\r\nindex be9e9c3..d30efe1 100644\r\n--- a/datasette/views/table.py\r\n+++ b/datasette/views/table.py\r\n@@ -105,8 +105,12 @@ class RowTableShared(DataView):\r\n type_ = \"integer\"\r\n notnull = 0\r\n else:\r\n- type_ = column_details[r[0]].type\r\n- notnull = column_details[r[0]].notnull\r\n+ try:\r\n+ type_ = column_details[r[0]].type\r\n+ notnull = column_details[r[0]].notnull\r\n+ except KeyError: # Probably count(*)\r\n+ type_ = \"integer\"\r\n+ notnull = False\r\n columns.append(\r\n {\r\n \"name\": r[0],\r\n@@ -613,6 +617,15 @@ class TableView(RowTableShared):\r\n offset=offset,\r\n )\r\n \r\n+ # If ?_group_count we convert the SQL query here\r\n+ group_count = request.args.getlist(\"_group_count\")\r\n+ if group_count:\r\n+ wrapped_sql = \"select {cols}, count(*) from ({sql}) group by {cols}\".format(\r\n+ cols=\", \".join(group_count),\r\n+ sql=sql,\r\n+ )\r\n+ sql = wrapped_sql\r\n+\r\n if request.args.get(\"_timelimit\"):\r\n extra_args[\"custom_time_limit\"] = int(request.args.get(\"_timelimit\"))\r\n```\r\nResulted in errors like this one:\r\n```\r\n pk_path = path_from_row_pks(row, pks, not pks, False)\r\n File \"/Users/simon/Dropbox/Development/datasette/datasette/utils/__init__.py\", line 82, in path_from_row_pks\r\n bits = [\r\n File \"/Users/simon/Dropbox/Development/datasette/datasette/utils/__init__.py\", line 83, in \r\n row[pk][\"value\"] if isinstance(row[pk], dict) else row[pk] for pk in pks\r\nIndexError: No item with that key\r\n```", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 734777631, "label": "\"View all\" option for facets, to provide a (paginated) list of ALL of the facet counts plus a link to view them"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/datasette/issues/1080#issuecomment-1029691693", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/1080", "id": 1029691693, "node_id": "IC_kwDOBm6k_c49X9kt", "user": {"value": 9599, "label": "simonw"}, "created_at": "2022-02-04T06:16:45Z", "updated_at": "2022-02-04T06:16:45Z", "author_association": "OWNER", "body": "Had a new, different idea for how this could work: support a `?_group_count=colname` parameter to the table view, which turns the page into a `select colname, count(*) ... group by colname` query - but keeps things like the filter interface, facet selection, search box and so on.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 734777631, "label": "\"View all\" option for facets, to provide a (paginated) list of ALL of the facet counts plus a link to view them"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/datasette/issues/1080#issuecomment-720696827", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/1080", "id": 720696827, "node_id": "MDEyOklzc3VlQ29tbWVudDcyMDY5NjgyNw==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2020-11-02T20:08:49Z", "updated_at": "2020-11-02T20:13:56Z", "author_association": "OWNER", "body": "Implementing pagination for facets will be interesting. Would be easier if I had a nicer reusable internal pagination mechanism, which is also needed for #856 (pagination of canned queries).", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 734777631, "label": "\"View all\" option for facets, to provide a (paginated) list of ALL of the facet counts plus a link to view them"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/datasette/issues/1080#issuecomment-720699160", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/1080", "id": 720699160, "node_id": "MDEyOklzc3VlQ29tbWVudDcyMDY5OTE2MA==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2020-11-02T20:13:42Z", "updated_at": "2020-11-02T20:13:42Z", "author_association": "OWNER", "body": "Also relevant to this issue: #830 - redesigning the facet plugin hook in preparation for Datasette 1.0. And #972 supporting faceting against arbitrary queries.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 734777631, "label": "\"View all\" option for facets, to provide a (paginated) list of ALL of the facet counts plus a link to view them"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/datasette/issues/1080#issuecomment-720698577", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/1080", "id": 720698577, "node_id": "MDEyOklzc3VlQ29tbWVudDcyMDY5ODU3Nw==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2020-11-02T20:12:26Z", "updated_at": "2020-11-02T20:12:26Z", "author_association": "OWNER", "body": "For regular column faceting, here's the query that is used:\r\n\r\nhttps://github.com/simonw/datasette/blob/13d1228d80c91d382a05b1a9549ed02c300ef851/datasette/facets.py#L196-L204\r\n\r\nSince it uses `order by count desc, value` maybe those values could be used to implement cursor-based pagination.\r\n\r\nThat wouldn't be robust in the face of changing data, but I'm not sure it's possible to implement paginated faceting in a way that survives ongoing changes to the underlying data.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 734777631, "label": "\"View all\" option for facets, to provide a (paginated) list of ALL of the facet counts plus a link to view them"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/datasette/issues/1080#issuecomment-720697226", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/1080", "id": 720697226, "node_id": "MDEyOklzc3VlQ29tbWVudDcyMDY5NzIyNg==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2020-11-02T20:09:38Z", "updated_at": "2020-11-02T20:09:38Z", "author_association": "OWNER", "body": "Maybe this ends up being code that defers to a simulated canned query, rendered using the existing `query.html` template.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 734777631, "label": "\"View all\" option for facets, to provide a (paginated) list of ALL of the facet counts plus a link to view them"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/datasette/issues/1080#issuecomment-720695174", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/1080", "id": 720695174, "node_id": "MDEyOklzc3VlQ29tbWVudDcyMDY5NTE3NA==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2020-11-02T20:05:26Z", "updated_at": "2020-11-02T20:05:26Z", "author_association": "OWNER", "body": "URL design:\r\n\r\n`/database/table/-/facet/colname`\r\n\r\nAnd for other types of facet (to be supported later):\r\n\r\n`/database/table/-/facet/colname?_type=m2m`", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 734777631, "label": "\"View all\" option for facets, to provide a (paginated) list of ALL of the facet counts plus a link to view them"}, "performed_via_github_app": null}