Take a query-history definition draft's tables and columns from the query log

Aperta
#1,755 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
48/100
Tipo di issue
Funzionalità
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
clickhouse, python
Ambito
backend, databases

Direzione di ricerca

Start with group_sql in server/knowledge/store/query_history_remote.py, then trace how query-history data reaches the prompt and rests_on through server/memory/app/definition_drafts.py and server/memory/domain/definition_drafts.py. Add the acceptance fixture in tests/integration/test_query_history_drafts.py and check the query-log arrays, capped lists, gap drafts, and one model call per draft.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

enhancement
Company

ClickHouse

Component

Knowledge (documents)

Use case

A definition drafted from query history records the tables and columns it rests on in rests_on. Today the model writes both lists. The draft prompt asks for tables and columns, and the reply is stored after a size check only (server/memory/app/definition_drafts.py, server/memory/domain/definition_drafts.py). The source already knows the answer: system.query_log holds the tables and columns each query read, and the query-history read does not select them (group_sql in server/knowledge/store/query_history_remote.py).

An admin reviewing the draft, or a later check of the definition against its source, reads a list that can name a table the query never touched or omit one it did. rests_on holds the source's normalized SQL beside the model's two lists and does not mark which is which; only the documentation says so (docs/architecture/definition-drafts.md).

Describe the solution you'd like

Read the lists from the source and stop asking the model for them. This is a proposal; nothing is implemented or measured.

  • group_sql also selects the tables and columns arrays of the query whose text it keeps, each cut to the draft's existing list limits. A cut list is reported as capped, not passed off as complete. The registration probe runs the same statement, so it also verifies that the credential can read the two arrays.
  • For a query-history draft, rests_on.tables and rests_on.columns come from that read. rests_on records where the lists came from, so a reader can tell a source-read list from one written before this change.
  • The prompt and DefinitionDraft drop tables and columns. The model still returns the term, aliases and body.
  • A draft from a knowledge gap has no SQL and no source to read, so it carries no table or column list.
  • The read stays inside the registration's database allowlist, which the existing filter on the log's databases array already applies. The lists keep the visibility rests_on has today.
  • The change adds no model call, no table and no statement on the source beyond the existing bounded query-log read.

Acceptance fixture, added to tests/integration/test_query_history_drafts.py:

  1. A query group over one table yields a draft whose rests_on lists equal the log's arrays, whatever the model returns.
  2. The model input and the expected reply contain no table or column list.
  3. A group whose arrays exceed the limits yields cut lists marked capped.
  4. A query through a view records what the log records for it.
  5. A gap draft has no lists.
  6. The model-call count per draft stays at one.

Evidence still needed before this is called a gain:

  • A read-only count, on a deployment that has query-history drafts, of the share whose model-written lists differ from the log's arrays for the same query.
  • Whether the drafted term, aliases and body change when the prompt stops asking for the two lists. This needs a paired run on fixed query groups, and a paid run only on request.
  • What the log's arrays contain for views, SELECT * and joins on the supported server versions, confirmed in the fixture.
Describe alternatives you've considered
  • Parse the normalized SQL in the server. The server imports no SQL parser; sqlglot is in the extractor's dependency group only. A parser also cannot resolve a view or SELECT * the way the source does.
  • Keep the model's lists and verify them against system.columns. That adds a metadata read on the data tables, and registration verifies the query-log read only, not that the credential can see those tables' columns.
  • Leave it as documented. The lists then stay unusable as evidence for any later check.
Where the need comes from

An AI tool suggested this feature

Additional context

Found by source review; no draft was generated and no source was queried.

Related: #1176 checks maintained guidance against a registered tracker source, with objects a maintainer declares. This change is separate and smaller. It gives query-history definitions a source-read list that a later extension of that check could use. Part of the roadmap in #1232.

Lingua principale
Python
Stelle
263
Fork
47
Merge medio
14h 21m
PR unite (30g)
873

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di ClickHouse/loom

Tutte le issue di ClickHouse/loom

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.