anitnilay20 / anitnilay20/thoth

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

Đang mở
#55 1 bình luận 0 reaction 0 người được giao Xem trên GitHub
enhancement feature performance priority:medium size:large
Ngôn ngữ chính
Rust
Star
70
Fork
5
Merge trung bình
10 giờ 33 phút
Pull request đã merge (30 ngày)
2

Mô tả

## 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

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.