-
-
Notifications
You must be signed in to change notification settings - Fork 0
feat(sql): Phase 3 procedural SQL metrics #257
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 12 commits
7f833a7
d5f66dc
9c19900
82a0439
657058b
cb7dcff
082963c
3acb3aa
6bb92c6
f42eb80
e88fafe
83608fa
8762bb9
2f90fc5
ea051a5
f3f9eed
0f44cfb
0ea450f
6e3d0cb
687a166
af92c43
d8a602d
5d38d7d
863d487
1d38867
220e9d4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,31 +15,6 @@ use crate::dialect::{DialectResolution, dialect_label}; | |
| use crate::facts::{SqlFileFacts, StatementKind}; | ||
| use crate::loc::SqlLoc; | ||
|
|
||
| /// All distinct statement kinds, so `kind_count.<kind>` keys are emitted with | ||
| /// an explicit `0` when absent (grepability over silent omission). | ||
| const ALL_STATEMENT_KINDS: &[StatementKind] = &[ | ||
| StatementKind::Select, | ||
| StatementKind::WithSelect, | ||
| StatementKind::Insert, | ||
| StatementKind::Update, | ||
| StatementKind::Delete, | ||
| StatementKind::Merge, | ||
| StatementKind::CreateView, | ||
| StatementKind::CreateTable, | ||
| StatementKind::CreateTableAsSelect, | ||
| StatementKind::CreateOther, | ||
| StatementKind::AlterTable, | ||
| StatementKind::Drop, | ||
| StatementKind::Truncate, | ||
| StatementKind::Grant, | ||
| StatementKind::Revoke, | ||
| StatementKind::TransactionControl, | ||
| StatementKind::Explain, | ||
| StatementKind::Procedural, | ||
| StatementKind::SetOperation, | ||
| StatementKind::Unknown, | ||
| ]; | ||
|
|
||
| const JOIN_KINDS: &[&str] = &[ | ||
| "inner", "left", "right", "full", "cross", "natural", "lateral", | ||
| ]; | ||
|
|
@@ -66,6 +41,7 @@ pub(crate) fn publish( | |
| publish_expressions(facts, target); | ||
| publish_output(facts, target); | ||
| publish_objects(facts, target); | ||
| publish_procedural(facts, target); | ||
| publish_dialect(facts, loc, dialect, target); | ||
| publish_parser(facts, loc, target); | ||
| publish_halstead(facts, target); | ||
|
|
@@ -97,8 +73,9 @@ fn publish_loc(loc: &SqlLoc, target: &mut MetricSet) { | |
|
|
||
| fn publish_statements(facts: &SqlFileFacts, target: &mut MetricSet) { | ||
| set(target, "sql.statement.count", facts.statements.len()); | ||
| // kind_count.<kind> | ||
| for kind in ALL_STATEMENT_KINDS { | ||
| // kind_count.<kind> — every kind gets an explicit `0` when absent | ||
| // (grepability over silent omission). | ||
| for kind in StatementKind::ALL { | ||
| let n = facts.statements.iter().filter(|s| s.kind == *kind).count(); | ||
| set( | ||
| target, | ||
|
Comment on lines
+78
to
81
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When a file contains an anonymous procedural block, iterating over the expanded AGENTS.md reference: AGENTS.md:L9-L11 Useful? React with 👍 / 👎.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ✅ Addressed in 1d38867. Thanks @chatgpt-codex-connector!
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Outcome
Testing
|
||
|
|
@@ -377,6 +354,55 @@ fn publish_objects(facts: &SqlFileFacts, target: &mut MetricSet) { | |
| ); | ||
| } | ||
|
|
||
| /// Procedural-SQL metrics (research foundation §6.17, Phase 3). Published | ||
| /// unconditionally — a purely declarative file reports explicit zeros, the | ||
| /// same contract as every other family. | ||
| fn publish_procedural(facts: &SqlFileFacts, target: &mut MetricSet) { | ||
| let p = &facts.procedural; | ||
| set(target, "sql.procedural.block_count", p.block_count); | ||
| set(target, "sql.procedural.routine_count", p.routine_count); | ||
| set( | ||
| target, | ||
| "sql.procedural.cyclomatic_complexity", | ||
| p.cyclomatic_complexity, | ||
| ); | ||
| set( | ||
| target, | ||
| "sql.procedural.cognitive_complexity", | ||
| p.cognitive_complexity, | ||
| ); | ||
| set(target, "sql.procedural.max_block_depth", p.max_block_depth); | ||
| set(target, "sql.procedural.loop_count", p.loop_count); | ||
| set(target, "sql.procedural.if_count", p.if_count); | ||
| set( | ||
| target, | ||
| "sql.procedural.case_statement_count", | ||
| p.case_statement_count, | ||
| ); | ||
| set( | ||
| target, | ||
| "sql.procedural.exception_handler_count", | ||
| p.exception_handler_count, | ||
| ); | ||
| set(target, "sql.procedural.return_count", p.return_count); | ||
| set( | ||
| target, | ||
| "sql.procedural.raise_throw_count", | ||
| p.raise_throw_count, | ||
| ); | ||
| set( | ||
| target, | ||
| "sql.procedural.dynamic_sql_count", | ||
| p.dynamic_sql_count, | ||
| ); | ||
| // §9.3: the worst embedded query inside any single routine. | ||
| set( | ||
| target, | ||
| "sql.structural_complexity.max_embedded_query", | ||
| p.max_embedded_query_structural, | ||
|
Comment on lines
+401
to
+402
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When contributions are enabled, a routine containing an embedded query publishes a nonzero AGENTS.md reference: AGENTS.md:L11-L11 Useful? React with 👍 / 👎.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ✅ Addressed in cb7dcff. Thanks @chatgpt-codex-connector!
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Summary
Testing
|
||
| ); | ||
| } | ||
|
|
||
| fn publish_dialect( | ||
| facts: &SqlFileFacts, | ||
| _loc: &SqlLoc, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When contribution output is enabled, this mapping exposes evidence only for the three procedural composites; every newly published raw metric—including
if_count,loop_count,block_count,return_count, anddynamic_sql_count—has noMetricEvidenceunder its own key. For example, a file can publishsql.procedural.if_count = 1while providing no span or reason explaining that value, so these new metrics do not satisfy the repository's explainability requirement. Add evidence variants and collector mappings for each raw procedural increment.AGENTS.md reference: AGENTS.md:L9-L11
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅ Addressed in 2f90fc5. Thanks @chatgpt-codex-connector!
Every raw
sql.procedural.*_countis now evidence-backed under its own key: the machine routes increments through araw_counthelper pairing each with span + stable reason code (block_count,loop_count,if_count,case_statement_count,exception_handler_count,return_count,raise_throw_count,dynamic_sql_count), androutine_countemits one entry per unit with its (continuation-extended) span. Thecontributions.rsinvariant test now assertsmetric == Σ evidencefor all eleven procedural keys across all four fixtures. One documented exemption:max_block_depth— a high-water mark has no meaningful sum decomposition.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Outcome
2f90fc5already addressed the raw procedural evidence finding.max_block_depthexplicitly exempted because a high-water mark is not sum-decomposable. crates/mehen-sql/src/procedural.rsL65-L86raw_countupdates the metric and emits span- and reason-coded evidence for block, loop, branch, case, exception, return, raise/throw, and dynamic-SQL increments. crates/mehen-sql/src/procedural.rsL583-L610routine_countemits one contribution per routine using its continuation-extended source span. crates/mehen-sql/src/procedural.rsL1639-L1653npm/mehen/node_modules/directory was left untouched.Testing
cargo test -p mehen-sql --test contributions procedural -- --nocapture— 2 passed, 0 failed.git diff --checkrg -n "raw_count|block_count|loop_count|if_count|case_statement_count|exception_handler_count|return_count|raise_throw_count|dynamic_sql_count|routine_count|max_block_depth" crates/mehen-sql/src/procedural.rs crates/mehen-sql/src/lib.rs crates/mehen-sql/tests/contributions.rsgit status --short --branch— confirmed no tracked working-tree changes.View task →