Skip to content

Commit e65d39c

Browse files
committed
Added rule engine. Compatible with all SQL now
1 parent 5208a48 commit e65d39c

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

crdb_sql_audit/audit.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ def generate_reports(seen_sql, issues, output_prefix):
5151
out.write(sql + "\n")
5252

5353
df = pd.DataFrame(issues)
54+
55+
# Rule-level summary
56+
rule_summary = df.groupby("Rule_ID").size().reset_index(name="Matches")
57+
rule_summary["% of Total"] = (rule_summary["Matches"] / len(seen_sql)) * 100
58+
5459
if df.empty or not {'SQL_Type', 'Issue'}.issubset(df.columns):
5560
logging.warning("⚠️ No compatibility issues found or rules failed to match.")
5661
return
@@ -70,7 +75,11 @@ def generate_reports(seen_sql, issues, output_prefix):
7075
f.write(f"**Total unique SQL/function statements analyzed:** {len(seen_sql)} \n")
7176
f.write(f"**Total compatibility issues detected:** {len(issues)}\n")
7277
f.write(f"**Issue rate:** {issue_pct:.2f}%\n\n")
73-
f.write("## Compatibility Issues Summary\n\n")
78+
f.write("## Rule Match Summary\n\n")
79+
f.write("| Rule ID | Matches | % of Total |\n|---------|---------|-------------|\n")
80+
for _, row in rule_summary.iterrows():
81+
f.write(f"| {row['Rule_ID']} | {row['Matches']} | {row['% of Total']:.2f}% |\n")
82+
f.write("\n## Compatibility Issues Summary\n\n")
7483
f.write("| SQL Type | Issue | Count |\n|----------|-------|-------|\n")
7584
for _, row in summary.iterrows():
7685
f.write(f"| {row['SQL_Type']} | {row['Issue']} | {row['Count']} |\n")
@@ -146,6 +155,8 @@ def generate_reports(seen_sql, issues, output_prefix):
146155
f"<p><strong>Total SQL/function statements:</strong> {len(seen_sql)}<br><strong>Total issues:</strong> {len(issues)}<br><strong>Issue rate:</strong> {issue_pct:.2f}%</p>"
147156
)
148157
f.write(summary.to_html(index=False))
158+
f.write("<h2>Rule Match Summary</h2>")
159+
f.write(rule_summary.to_html(index=False))
149160
f.write("<h2>Sample Issues</h2>")
150161
for i, row in enumerate(issues[:10]):
151162
f.write(f"<h3>{i+1}. {row['SQL_Type']}: {row['Issue']}</h3><pre>{row['Example']}</pre>")

crdb_sql_audit/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import logging
33
from crdb_sql_audit.audit import extract_sql, analyze_compatibility, generate_reports
44

5-
__version__ = "0.2.2"
5+
__version__ = "0.2.3"
66

77
logging.basicConfig(
88
level=logging.INFO,

pyproject.toml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,25 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "crdb-sql-audit"
7-
version = "0.2.2"
7+
version = "0.2.3"
88
description = "Analyze PostgreSQL SQL logs for CockroachDB compatibility"
99
authors = [
1010
{ name = "Virag Tripathi", email = "virag.tripathi@gmail.com" }
1111
]
1212
license = "MIT"
1313
readme = "README.md"
1414
requires-python = ">=3.7"
15+
classifiers = [
16+
"Development Status :: 4 - Beta",
17+
"Intended Audience :: Developers",
18+
"Topic :: Software Development :: Quality Assurance",
19+
"Programming Language :: Python :: 3",
20+
"Programming Language :: Python :: 3.7",
21+
"Programming Language :: Python :: 3.8",
22+
"Programming Language :: Python :: 3.9",
23+
"Programming Language :: Python :: 3.10",
24+
"Operating System :: OS Independent"
25+
]
1526
dependencies = [
1627
"pandas",
1728
"matplotlib",

0 commit comments

Comments
 (0)