humlab-sead / sead_query_api

.NET Core port of Query SEAD API
Other
2 stars 0 forks source link

Analysis entity ages facet breaks when using very small spans #145

Open johanvonboer opened 1 month ago

johanvonboer commented 1 month ago

This request against /facets/load:

{
  "requestId": 5,
  "requestType": "populate",
  "targetCode": "analysis_entity_ages",
  "triggerCode": "analysis_entity_ages",
  "domainCode": "",
  "facetConfigs": [
    {
      "facetCode": "analysis_entity_ages",
      "position": 1,
      "picks": [
        {
          "pickType": 2,
          "pickValue": 166,
          "text": 166
        },
        {
          "pickType": 3,
          "pickValue": 173,
          "text": 173
        }
      ],
      "textFilter": ""
    }
  ]
}

Results in: "ERROR: step size cannot equal zero".

With this being the generated SQL:

WITH categories(category, category_range) AS (
    SELECT n::text || ' to ' || (n + 0.1000::integer)::text, int4range(n, (n + 0.1000::integer)), n as lower, (n + 0.1000::integer) as upper
    FROM generate_series(166.0000::integer, 173.0000::integer, 0.1000::integer) as a(n)
    WHERE n < 173.0000
)
SELECT c.category, lower(c.category_range)::integer, upper(c.category_range)::integer, COALESCE(r.count_column, 0) as count_column
FROM categories c
LEFT JOIN (
    SELECT category, COUNT(DISTINCT tbl_analysis_entities.analysis_entity_id) AS count_column
    FROM tbl_analysis_entity_ages
    JOIN categories
      ON categories.category_range && age_range::int4range
    INNER JOIN tbl_analysis_entities 
      ON tbl_analysis_entities."analysis_entity_id" = tbl_analysis_entity_ages."analysis_entity_id"
    WHERE TRUE
      AND int4range(166, 173, '[]') && age_range
    GROUP BY category
) AS r
ON r.category = c.category
ORDER BY c.category_range;

I intend to use the analysis entity ages facet as the basis of the general purpose timeline, and for that we need to be able to select small timespans.