MATIH Platform is in active MVP development. Documentation reflects current implementation status.
12. AI Service
Query Execution

Query Execution

Production - SQL execution via Query Engine with result formatting and caching

The Query Execution component sends validated SQL to the MATIH Query Engine and formats the results for display. It handles timeout management, result pagination, and response caching.


12.3.4.1Execution Architecture

# Query Engine connection from settings
query_engine_url: str = "http://query-engine.matih-data-plane.svc.cluster.local:8080"
query_timeout_seconds: int = 300

Execution Flow

# Execute SQL via the AI Service
curl -X POST http://localhost:8000/api/v1/text-to-sql/execute \
  -H "Content-Type: application/json" \
  -H "X-Tenant-ID: acme-corp" \
  -d '{
    "sql": "SELECT customer_name, SUM(revenue) as total FROM orders GROUP BY customer_name ORDER BY total DESC LIMIT 10",
    "dialect": "trino",
    "timeout_seconds": 60,
    "max_rows": 1000
  }'

Response:

{
  "success": true,
  "columns": [
    {"name": "customer_name", "type": "VARCHAR"},
    {"name": "total", "type": "DECIMAL(18,2)"}
  ],
  "rows": [
    ["Acme Corp", 1250000.00],
    ["TechStart Inc", 980000.00],
    ["Global Retail", 875000.00]
  ],
  "row_count": 10,
  "execution_time_ms": 342,
  "truncated": false
}