Skip to content
21 changes: 0 additions & 21 deletions packages/altimate-engine/src/altimate_engine/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@
# Phase 1 (P0)
guard_fix as guard_fix_sql,
guard_check_policy,
guard_complexity_score,
guard_check_semantics,
guard_generate_tests,
# Phase 2 (P1)
Expand All @@ -153,7 +152,6 @@
guard_rewrite as guard_rewrite_sql,
guard_correct,
guard_evaluate,
guard_estimate_cost,
# Phase 3 (P2)
guard_classify_pii,
guard_check_query_pii,
Expand All @@ -180,7 +178,6 @@
from altimate_engine.models import (
SqlGuardFixParams,
SqlGuardPolicyParams,
SqlGuardComplexityParams,
SqlGuardSemanticsParams,
SqlGuardTestgenParams,
# Phase 2 (P1)
Expand All @@ -190,7 +187,6 @@
SqlGuardGuardRewriteParams,
SqlGuardCorrectParams,
SqlGuardGradeParams,
SqlGuardCostParams,
# Phase 3 (P2)
SqlGuardClassifyPiiParams,
SqlGuardQueryPiiParams,
Expand Down Expand Up @@ -525,15 +521,6 @@ def dispatch(request: JsonRpcRequest) -> JsonRpcResponse:
pc_params = SqlPredictCostParams(**params)
store = _get_feedback_store()
prediction = store.predict(sql=pc_params.sql, dialect=pc_params.dialect)
# Merge sqlguard cost estimate if feedback store has no data
if prediction.get("method") == "no_data":
guard_cost = guard_estimate_cost(
pc_params.sql, dialect=pc_params.dialect
)
if guard_cost.get("bytes_scanned") or guard_cost.get("estimated_usd"):
prediction["predicted_bytes"] = guard_cost.get("bytes_scanned")
prediction["predicted_credits"] = guard_cost.get("estimated_usd")
prediction["method"] = "sqlguard_estimate"
result = SqlPredictCostResult(**prediction)
elif method == "sql.format":
fmt_params = SqlFormatParams(**params)
Expand Down Expand Up @@ -835,10 +822,6 @@ def dispatch(request: JsonRpcRequest) -> JsonRpcResponse:
result = SqlGuardResult(
success=raw.get("pass", True), data=raw, error=raw.get("error")
)
elif method == "sqlguard.complexity":
p = SqlGuardComplexityParams(**params)
raw = guard_complexity_score(p.sql, p.schema_path, p.schema_context)
result = SqlGuardResult(success=True, data=raw, error=raw.get("error"))
elif method == "sqlguard.semantics":
p = SqlGuardSemanticsParams(**params)
raw = guard_check_semantics(p.sql, p.schema_path, p.schema_context)

This comment was marked as outdated.

This comment was marked as outdated.

Expand Down Expand Up @@ -885,10 +868,6 @@ def dispatch(request: JsonRpcRequest) -> JsonRpcResponse:
p = SqlGuardGradeParams(**params)
raw = guard_evaluate(p.sql, p.schema_path, p.schema_context)
result = SqlGuardResult(success=True, data=raw, error=raw.get("error"))
elif method == "sqlguard.cost":
p = SqlGuardCostParams(**params)
raw = guard_estimate_cost(p.sql, p.schema_path, p.schema_context, p.dialect)
result = SqlGuardResult(success=True, data=raw, error=raw.get("error"))
# --- sqlguard Phase 3 (P2) ---
elif method == "sqlguard.classify_pii":
p = SqlGuardClassifyPiiParams(**params)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from pathlib import Path
from typing import Any

from altimate_engine.sql.guard import guard_extract_metadata, guard_complexity_score
from altimate_engine.sql.guard import guard_extract_metadata


_CREATE_TABLE_SQL = """
Expand Down Expand Up @@ -325,16 +325,12 @@ def _estimate_from_tables(self, sql: str, dialect: str) -> dict[str, Any] | None
}

def _static_heuristic(self, sql: str, dialect: str) -> dict[str, Any]:
"""Tier 4: Estimate cost based on query complexity analysis.
"""Tier 4: Estimate cost based on query length heuristic.

Uses sqlguard complexity scoring, falling back to length-based heuristic.
Base costs are dialect-dependent: Snowflake uses bytes-scanned and
credit metrics, while Postgres and DuckDB use execution-time only.
"""
complexity = guard_complexity_score(sql)
complexity_score = complexity.get("total", complexity.get("score"))
if not complexity_score:
complexity_score = max(1.0, len(sql) / 100.0)
complexity_score = max(1.0, len(sql) / 100.0)

# Select dialect-specific base costs
d = (dialect or "").lower()
Expand Down
31 changes: 0 additions & 31 deletions packages/altimate-engine/src/altimate_engine/sql/guard.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,21 +244,6 @@ def guard_check_policy(
return {"success": False, "error": str(e)}


def guard_complexity_score(
sql: str,
schema_path: str = "",
schema_context: dict[str, Any] | None = None,
) -> dict:
"""Score multi-dimensional complexity and estimated cloud cost."""
if not SQLGUARD_AVAILABLE:
return _not_installed_result()
try:
schema = _schema_or_empty(schema_path, schema_context)
return altimate_core.complexity_score(sql, schema)
except Exception as e:
return {"success": False, "error": str(e)}


def guard_check_semantics(
sql: str,
schema_path: str = "",
Expand Down Expand Up @@ -386,22 +371,6 @@ def guard_evaluate(
return {"success": False, "error": str(e)}


def guard_estimate_cost(
sql: str,
schema_path: str = "",
schema_context: dict[str, Any] | None = None,
dialect: str = "",
) -> dict:
"""Estimate per-dialect cloud cost (bytes scanned, USD)."""
if not SQLGUARD_AVAILABLE:
return _not_installed_result()
try:
schema = _schema_or_empty(schema_path, schema_context)
return altimate_core.estimate_cost(sql, schema, dialect or "generic")
except Exception as e:
return {"success": False, "error": str(e)}


# ---------------------------------------------------------------------------
# Phase 3 (P2): Complete coverage
# ---------------------------------------------------------------------------
Expand Down
54 changes: 0 additions & 54 deletions packages/altimate-engine/tests/test_guard_new.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
# Phase 1 (P0)
guard_fix,
guard_check_policy,
guard_complexity_score,
guard_check_semantics,
guard_generate_tests,
# Phase 2 (P1)
Expand All @@ -27,7 +26,6 @@
guard_rewrite,
guard_correct,
guard_evaluate,
guard_estimate_cost,
# Phase 3 (P2)
guard_classify_pii,
guard_check_query_pii,
Expand Down Expand Up @@ -133,26 +131,6 @@ def test_policy_with_schema_context(self):
assert isinstance(result, dict)


class TestGuardComplexityScore:
def test_simple_query(self):
result = guard_complexity_score("SELECT 1")
assert isinstance(result, dict)

def test_complex_query(self):
result = guard_complexity_score(
"SELECT u.id, o.total FROM users u JOIN orders o ON u.id = o.user_id "
"WHERE o.total > 100 GROUP BY u.id HAVING COUNT(*) > 5"
)
assert isinstance(result, dict)

def test_with_schema_context(self):
result = guard_complexity_score("SELECT 1", schema_context=SIMPLE_SCHEMA)
assert isinstance(result, dict)

def test_empty_sql(self):
result = guard_complexity_score("")
assert isinstance(result, dict)


class TestGuardCheckSemantics:
def test_basic_semantics(self):
Expand Down Expand Up @@ -318,26 +296,6 @@ def test_empty_sql(self):
assert isinstance(result, dict)


class TestGuardEstimateCost:
def test_basic_cost(self):
result = guard_estimate_cost("SELECT * FROM orders")
assert isinstance(result, dict)

def test_with_dialect(self):
result = guard_estimate_cost("SELECT * FROM orders", dialect="snowflake")
assert isinstance(result, dict)

def test_complex_query(self):
result = guard_estimate_cost(
"SELECT u.id, SUM(o.total) FROM users u JOIN orders o ON u.id = o.user_id GROUP BY u.id",
dialect="bigquery",
)
assert isinstance(result, dict)

def test_empty_sql(self):
result = guard_estimate_cost("")
assert isinstance(result, dict)


# ---------------------------------------------------------------------------
# Phase 3 (P2): Complete coverage
Expand Down Expand Up @@ -619,12 +577,6 @@ def test_check_policy_fallback(self):
assert result["success"] is False
assert "not installed" in result["error"]

def test_complexity_score_fallback(self):
with patch("altimate_engine.sql.guard.SQLGUARD_AVAILABLE", False):
result = guard_complexity_score("SELECT 1")
assert result["success"] is False
assert "not installed" in result["error"]

def test_check_semantics_fallback(self):
with patch("altimate_engine.sql.guard.SQLGUARD_AVAILABLE", False):
result = guard_check_semantics("SELECT 1")
Expand Down Expand Up @@ -675,12 +627,6 @@ def test_evaluate_fallback(self):
assert result["success"] is False
assert "not installed" in result["error"]

def test_estimate_cost_fallback(self):
with patch("altimate_engine.sql.guard.SQLGUARD_AVAILABLE", False):
result = guard_estimate_cost("SELECT 1")
assert result["success"] is False
assert "not installed" in result["error"]

# Phase 3 (P2)

def test_classify_pii_fallback(self):
Expand Down
Loading