anitnilay20 / anitnilay20/thoth

File query: aggregation (GROUP BY + aggregate functions via DuckDB)

Aperta
#55 1 commento 0 reazioni 0 assegnatari Vedi su GitHub
enhancement feature performance priority:medium size:large
Lingua principale
Rust
Stelle
70
Fork
5
Merge medio
10h 33m
PR unite (30g)
2

Descrizione

## Context

Part of the DuckDB file query engine epic (#147). Depends on #148 (FileQueryEngine) and #149 (query editor UI). The original plan proposed a custom `GroupByConfig` + Rayon parallel grouping — with DuckDB this is standard SQL `GROUP BY`.

## What this covers

Full SQL aggregation over open files via DuckDB — `GROUP BY`, aggregate functions, `HAVING`, `ORDER BY` on aggregate results.

### Examples (typed into the query editor)

```sql
-- Count by status
SELECT status, COUNT(*) as total FROM data GROUP BY status ORDER BY total DESC

-- Revenue summary
SELECT country, COUNT(*) as orders, SUM(total) as revenue, AVG(total) as avg_order
FROM data GROUP BY country ORDER BY revenue DESC

-- Error breakdown
SELECT error_type, COUNT(*) as count, MAX(response_time) as worst_ms
FROM data WHERE level = 'error' GROUP BY error_type HAVING count > 10

-- Count distinct
SELECT COUNT(DISTINCT user_id) as unique_users FROM data

-- Min/max per category
SELECT category, MIN(price) as cheapest, MAX(price) as most_expensive
FROM data GROUP BY category

-- Percentile (DuckDB built-in)
SELECT PERCENTILE_CONT(0.95) WITHIN GROUP (ORDER BY response_time) as p95 FROM data

-- Time bucketing
SELECT DATE_TRUNC('hour', timestamp) as hour, COUNT(*) as events
FROM data GROUP BY hour ORDER BY hour
```

DuckDB provides: all standard aggregate functions (`COUNT`, `SUM`, `AVG`, `MIN`, `MAX`), `COUNT(DISTINCT)`, percentiles, `HAVING`, window functions, `DATE_TRUNC`, `STRING_AGG`, approximate aggregates (`APPROX_COUNT_DISTINCT`). No custom implementation needed.

## What needs building

This ticket is focused on result display and UX for aggregate queries:

- Aggregate results are tabular — they route through the existing `dataset-bus` → `data-view` path exactly like filter/sort results
- Result row count differs from file row count — status line should show "N groups" not "N rows" when a `GROUP BY` is detected
- Export of aggregate results to CSV/JSON (use DuckDB's `COPY (SELECT …) TO 'file' (FORMAT CSV)`)

## Acceptance criteria

- [ ] `GROUP BY` + `COUNT`, `SUM`, `AVG`, `MIN`, `MAX` work end-to-end in the query editor
- [ ] `HAVING` clause filters groups correctly
- [ ] `COUNT(DISTINCT field)` works
- [ ] Results display in data-view table with correct column names/aliases
- [ ] Export aggregate results to CSV
- [ ] Date/time bucketing via `DATE_TRUNC` works on timestamp columns
- [ ] Status line shows group count for `GROUP BY` queries

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.