|
| 1 | +# SQL Translation Model Benchmark Evaluation |
| 2 | + |
| 3 | +Evaluate and compare SQL translation models (Snowflake → Databricks) using MLflow and LLM-as-a-judge. |
| 4 | + |
| 5 | +## Prerequisites |
| 6 | + |
| 7 | +Before running the benchmark, ensure you have: |
| 8 | + |
| 9 | +1. **Databricks CLI configured** (or `.env` file with credentials): |
| 10 | + ```bash |
| 11 | + # Option A: Databricks CLI |
| 12 | + databricks configure --host https://your-workspace.cloud.databricks.com |
| 13 | + |
| 14 | + # Option B: .env file in project root |
| 15 | + DATABRICKS_HOST=https://your-workspace.cloud.databricks.com |
| 16 | + DATABRICKS_TOKEN=dapi... |
| 17 | + ``` |
| 18 | + |
| 19 | +2. **Dependencies installed**: |
| 20 | + ```bash |
| 21 | + pip install -r requirements.txt |
| 22 | + ``` |
| 23 | + |
| 24 | +3. **Input Data**: The benchmark expects input JSON files (Snowflake DDL metadata). By default, it looks in `src/artifact_translation_package/examples/`. |
| 25 | + |
| 26 | +## Quick Start (Running the Evaluation) |
| 27 | + |
| 28 | +### Option 1: Interactive Notebook |
| 29 | +The simplest way to run and visualize results. |
| 30 | + |
| 31 | +1. Open `src/artifact_translation_package/evaluation/benchmark_interactive.ipynb` |
| 32 | +2. **Configure models**: Set your endpoints in the Config cell. |
| 33 | + ```python |
| 34 | + TRANSLATION_MODELS = ["databricks-llama-4-maverick", "databricks-gemini-2-5-flash"] |
| 35 | + ARTIFACT_TYPE = "tables" # or "views", "procedures" |
| 36 | + ``` |
| 37 | +3. **Run all cells**: It will trigger `run_local_benchmark.py` and display comparison charts. |
| 38 | + |
| 39 | +### Option 2: Command Line (Fastest) |
| 40 | + |
| 41 | +Run the benchmark from the project root: |
| 42 | + |
| 43 | +```bash |
| 44 | +# 1. Basic: Run benchmark for tables using default models |
| 45 | +python3 run_local_benchmark.py --artifact-type tables |
| 46 | + |
| 47 | +# 2. Advanced: Specify custom models to compare |
| 48 | +python3 run_local_benchmark.py \ |
| 49 | + --artifact-type views \ |
| 50 | + --models databricks-llama-4-maverick databricks-meta-llama-3-1-70b-instruct |
| 51 | + |
| 52 | +# 3. Custom Data: Specify a custom input JSON file |
| 53 | +python3 run_local_benchmark.py \ |
| 54 | + --artifact-type tables \ |
| 55 | + --dataset-source /path/to/your/metadata.json |
| 56 | + |
| 57 | +# 4. Settings: Control batch size for judge execution |
| 58 | +python3 run_local_benchmark.py --batch-size 10 |
| 59 | +``` |
| 60 | + |
| 61 | +## How Evaluation Works |
| 62 | + |
| 63 | +We use a **Strict Deduction-Based Scoring System** (starting at 100) to evaluate two independent dimensions: |
| 64 | + |
| 65 | +### Dimension 1: Compliance Score (0-100) |
| 66 | +**Goal**: Functional correctness. Can this code actually run on Databricks? |
| 67 | +- **Invalid syntax**: Automatic score of **0**. |
| 68 | +- **Point Deductions**: |
| 69 | + - Missing `USING DELTA` (-20 pts) |
| 70 | + - Using legacy types like `VARCHAR` or `TEXT` instead of `STRING` (-10 pts) |
| 71 | + - Missing 3-level naming (`catalog.schema.table`) (-15 pts) |
| 72 | + |
| 73 | +### Dimension 2: Best Practices Score (0-100) |
| 74 | +**Goal**: Performance and Documentation. Is this production-grade code? |
| 75 | +- **Point Deductions**: |
| 76 | + - Missing `CLUSTER BY` (Liquid Clustering) (-30 pts) |
| 77 | + - Missing table properties like `autoOptimize` (-20 pts) |
| 78 | + - Missing table or column `COMMENT`s (-25 pts each) |
| 79 | + |
| 80 | +## MLflow Features |
| 81 | + |
| 82 | +The benchmark automatically logs rich data to Databricks MLflow: |
| 83 | + |
| 84 | +- **Experiment Name**: Defaults to `sql-translation-benchmark` or your username. |
| 85 | +- **Searchable Tags**: Every run is tagged with issue categories (e.g., `has_naming_issues: true`). |
| 86 | +- **Issues Table**: `issues_table.json` logs every single violation found for queryable analysis. |
| 87 | +- **Top Issues Summary**: `top_issues_summary.txt` provides an at-a-glance summary of the most common mistakes across all samples. |
| 88 | + |
| 89 | +## Metrics Reference |
| 90 | + |
| 91 | +| Metric | Threshold | Description | |
| 92 | +|--------|-----------|-------------| |
| 93 | +| `avg_compliance` | 0-100 | Mean functional correctness score. | |
| 94 | +| `avg_best_practices` | 0-100 | Mean optimization/docs score. | |
| 95 | +| `compliant_pct` | >= 70 | % of statements that are functional. | |
| 96 | +| `syntax_valid_pct` | 100% | % of statements with valid Databricks SQL syntax. | |
| 97 | + |
| 98 | +## Troubleshooting |
| 99 | + |
| 100 | +| Issue | Cause | Fix | |
| 101 | +|-------|-------|-----| |
| 102 | +| Authentication Error | Missing `DATABRICKS_TOKEN` | Check `.env` or run `databricks configure`. | |
| 103 | +| `File Not Found` | Custom JSON path is wrong | Verify `--dataset-source` path. | |
| 104 | +| Model not found | Incorrect endpoint name | Verify name in Databricks Model Serving UI. | |
| 105 | +| Low scores | Model performance | Check `top_issues_summary.txt` to find systemic errors. | |
| 106 | + |
| 107 | +## Deployment to Databricks |
| 108 | + |
| 109 | +To run this directly within a Databricks Job or Notebook: |
| 110 | +1. Ensure the `requirements.txt` libraries are installed on the cluster. |
| 111 | +2. The benchmark will automatically detect it is running in Databricks and create MLflow experiments in your User workspace folder. |
0 commit comments