sql-writer
SKILL.md
Prerequisites
Environment variables: DATABRICKS_HOST, DATABRICKS_TOKEN
For log spec lookup: Google Cloud auth via gcloud auth application-default login
Scripts
Run from skill directory.
log_spec.py - Log Specification Lookup
uv run scripts/log_spec.py --list-games # List available games
uv run scripts/log_spec.py --game litemeta --list-sheets # List spec sheets
uv run scripts/log_spec.py --game litemeta --event stageClose # Get event spec
uv run scripts/log_spec.py --game litemeta --field playId # Search field
uv run scripts/log_spec.py --game litemeta --event login --cache # Use cache
schema.py - Table Metadata
uv run scripts/schema.py <table> # Get schema
uv run scripts/schema.py --list-databases # List databases
uv run scripts/schema.py --list-tables <database> # List tables
validate.py - Query Validation
uv run scripts/validate.py -q "<sql>" # Validate query
uv run scripts/validate.py -f query.sql --check-tables # Check tables exist
sample.py - Execute Query
Requires partition filter (dt, log_date) to prevent full table scans.
uv run scripts/sample.py -q "SELECT * FROM table WHERE dt = '2024-01-01' LIMIT 10"
uv run scripts/sample.py -f query.sql --limit 100 --output results.csv
uv run scripts/sample.py -q "..." --no-filter-check # Skip filter check (caution)
References
references/index.md- Database overview and common schemareferences/log-specs.md- Log specification sources and event documentationreferences/{game}_production.md- Table catalogs per game
Database catalogs:
litemeta_production.md- 46 tableslinkpang_production.md- 39 tablespkpkg_production.md- 36 tablesmatchflavor_production.md- 10 tablesmatchwitch_production.md- 4 tablestraincf_production.md- 4 tables
Workflow
Standard Query Writing
- Understand - Parse request: project, metrics, date range
- Research - Look up log specs for unfamiliar events (see below)
- Search - Check catalog for relevant tables
- Validate - Run
schema.pyto confirm columns - Sample - Test query with
sample.py(use partition filter) - Deliver - Provide query + tables used + assumptions
When to Research Log Specs
Use log_spec.py when:
- Event type is unfamiliar or undocumented
- Need to understand
propertiesfield contents - Need to know when/why an event fires
- Cross-referencing spec vs actual data
- Building queries involving
gameDataextraction
Example research flow:
# 1. Check what sheets exist
uv run scripts/log_spec.py --game litemeta --list-sheets
# 2. Get event specification
uv run scripts/log_spec.py --game litemeta --event stageClose
# 3. Search for specific field
uv run scripts/log_spec.py --game litemeta --field playId
Complex Research Tasks
For multi-topic investigation (log specs + codebase + existing queries), use the log-data-researcher agent:
Agent: ~/.claude/agents/log-data-researcher.md
Capabilities:
- Read log specs from Google Sheets
- Cross-reference with codebase implementations
- Document field definitions and data types
- Check production table schemas
Launch via Task tool with subagent_type=general-purpose:
Prompt: Research log specifications for {game}.
Include agent instructions from ~/.claude/agents/log-data-researcher.md
Focus on: {specific events or fields}
Safety
- Read-only: SELECT, EXPLAIN, DESCRIBE, SHOW only
- Partition filter required by default
- 60s timeout, 10000 row limit
Common Patterns
Properties Field Extraction
SELECT
properties:playId::string as play_id,
properties:stage::int as stage,
properties:result::string as result
FROM litemeta_production.stageclose
WHERE dt = '2024-01-01'
Session Calculation
-- 10-minute session timeout
CASE
WHEN next_timestamp IS NULL
OR (next_timestamp - timestamp) / 1000 > 600
THEN 1 ELSE 0
END as is_session_end
Retention Query Pattern
See templates/retention.sql for D1/D3/D7 retention template.
Funnel Analysis Pattern
See templates/funnel.sql for conversion funnel template.
Weekly Installs
2
Repository
treenod-idq/tre…d-marketFirst Seen
Jan 28, 2026
Security Audits
Installed on
trae2
kilo2
antigravity2
claude-code2
windsurf2
github-copilot2