import re
from collections import Counter

with open('test_db.magento_product_dimension_with_text_embedding.sql', encoding='utf-8', errors='ignore') as f:
    data = f.read()

# Find the column order from INSERT statement
col_match = re.search(r'INSERT INTO[^(]+\(([^)]+)\)', data, re.DOTALL)
if col_match:
    cols = [c.strip().strip('`') for c in col_match.group(1).split(',')]
    season_idx = cols.index('season') if 'season' in cols else -1
    print(f"Column order found. 'season' is at index: {season_idx}")
    print(f"Columns around season: {cols[max(0,season_idx-2):season_idx+3]}")
else:
    print("Could not find INSERT column list")
    season_idx = -1

# Extract VALUES rows - find all value tuples
# Look for patterns like ('...', '...', NULL, ...)
rows = re.findall(r'\(([^;]+?)\)(?:,|\s*;)', data, re.DOTALL)
print(f"\nTotal value rows found: {len(rows)}")

if season_idx >= 0 and rows:
    seasons = []
    for row in rows[:50]:  # sample first 50
        # Split by comma but respect quoted strings
        parts = re.split(r",(?=(?:[^']*'[^']*')*[^']*$)", row.strip())
        if len(parts) > season_idx:
            val = parts[season_idx].strip().strip("'")
            seasons.append(val)

    counts = Counter(seasons)
    print(f"\nSeason values (sample from first 50 rows):")
    print("-" * 40)
    for s, c in sorted(counts.items(), key=lambda x: -x[1]):
        print(f"{c:5d}  |  '{s}'")
