Rifqi Hafizuddin Claude Opus 5.5 commited on
Commit
d20cd21
·
1 Parent(s): 5772bbc

[NOTICKET] fix(query): GROUP BY without an aggregate is DISTINCT on uploaded files (P0-10)

Browse files

The pandas compiler applied group_by only with an aggregate, so
`SELECT site_code GROUP BY site_code LIMIT 50` on a tabular source returned
50 raw rows. The scope value index for uploaded files therefore held only the
first rows' values (analysis da688944: site_code ['LAT','BIN','SDJ'] of 7;
section missing OB LOADER), marked complete, and the objective's site ADT was
never pinned — Sofhia's "ADT lost" turns. Now drop_duplicates() after the
select, matching SQL; the rendered query shows it. Same turn's value index now
loads all 7 sites and the objective resolves to site_code ADT + OB HAULER.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

src/query/compiler/pandas.py CHANGED
@@ -74,6 +74,15 @@ class PandasCompiler(BaseCompiler):
74
  if has_agg:
75
  df = _apply_agg(df, _select, _group_by, _cols)
76
  else:
 
 
 
 
 
 
 
 
 
77
  df = _apply_select(df, _select, _cols)
78
 
79
  if _order_by:
 
74
  if has_agg:
75
  df = _apply_agg(df, _select, _group_by, _cols)
76
  else:
77
+ # GROUP BY without an aggregate is one row per group-key combination in
78
+ # SQL; it was ignored here, so `SELECT site_code GROUP BY site_code LIMIT
79
+ # 50` on an uploaded file returned 50 raw rows. The scope value index read
80
+ # ['LAT', 'BIN', 'SDJ'] for a 7-site column and never pinned the
81
+ # objective's site ADT (analysis da688944, audit P0-10, 2026-11-03).
82
+ # Deduped on the group KEYS before the select, so `SELECT a GROUP BY a, b`
83
+ # keeps one row per (a, b) like SQL (review).
84
+ if _group_by:
85
+ df = df.drop_duplicates(subset=[_cols[g].name for g in _group_by])
86
  df = _apply_select(df, _select, _cols)
87
 
88
  if _order_by:
src/query/executor/tabular.py CHANGED
@@ -311,6 +311,9 @@ def _render_query(ir: QueryIR, cols_by_id: dict) -> str:
311
  parts.append(f'{col}.{fn_map.get(agg.fn, agg.fn + "()")}')
312
  elif cols:
313
  col_names = [cols_by_id[s.column_id].name for s in cols]
 
 
 
314
  parts.append(f'[{col_names}]')
315
  if ir.limit:
316
  parts.append(f'.head({ir.limit})')
 
311
  parts.append(f'{col}.{fn_map.get(agg.fn, agg.fn + "()")}')
312
  elif cols:
313
  col_names = [cols_by_id[s.column_id].name for s in cols]
314
+ if ir.group_by: # GROUP BY without an aggregate = one row per key (P0-10)
315
+ group_names = [cols_by_id[g].name for g in ir.group_by]
316
+ parts.append(f".drop_duplicates(subset={group_names})")
317
  parts.append(f'[{col_names}]')
318
  if ir.limit:
319
  parts.append(f'.head({ir.limit})')