| name | query |
| description | Compile a semantic query to SQL using airlayer. Use when the user wants to generate SQL from .view.yml schemas, test a query against their semantic layer, or translate dimensions/measures/filters into dialect-specific SQL. |
| allowed-tools | ["Bash","Read","Glob","Grep"] |
| argument-hint | [--dimension view.dim --measure view.measure --filter view.dim:operator:value] |
airlayer Query — Compile Semantic Queries to SQL
You are compiling a semantic layer query to SQL using the airlayer CLI.
Prerequisites
Ensure airlayer is installed:
which airlayer || cargo install --git https://github.com/oxy-hq/airlayer
Locate the semantic layer
- Find
.view.yml files in the project. They are typically under a views/ or semantics/views/ directory.
- Identify the base directory (parent of
views/).
find . -name "*.view.yml" -not -path "*/node_modules/*" -not -path "*/cube/*" 2>/dev/null | head -20
Inspect available members
Before building a query, inspect what's available:
airlayer inspect```
This lists all views, dimensions, measures, and entities.
Use CLI flags (preferred for LLM tool use):
```bash
airlayer query -d <dialect> \
--dimension <view.dimension> \
--measure <view.measure> \
--filter <view.dimension>:<operator>:<value> \
--order <view.member>:desc \
--limit 100
Or JSON input for complex queries:
airlayer query -d <dialect> -q '{
"dimensions": ["view.dimension"],
"measures": ["view.measure"],
"filters": [{"member": "view.dim", "operator": "equals", "values": ["val"]}],
"order": [{"id": "view.measure", "desc": true}],
"limit": 100
}'
Arguments from user
$ARGUMENTS
Dialect selection
Pick the dialect based on the project's database:
postgres (default), mysql, bigquery, snowflake, duckdb, clickhouse, databricks, redshift, sqlite, domo
If the project has a config.yml with database definitions, use -c config.yml instead of -d.
Filter operators
equals, notEquals, contains, notContains, startsWith, notStartsWith, endsWith, notEndsWith, gt, gte, lt, lte, set, notSet, inDateRange, notInDateRange, beforeDate, beforeOrOnDate, afterDate, afterOrOnDate, onTheDate
Advanced features
- Segments:
--segments view.segment_name (predefined filter conditions)
- Join hints:
--through entity_name (disambiguate multi-path joins)
- Time dimensions (JSON only):
"time_dimensions": [{"dimension": "view.date_col", "granularity": "month", "date_range": ["2024-01-01", "2024-12-31"]}]
- Relative dates (JSON only):
"date_range": ["last 7 days"] or ["this month"]
- Ungrouped mode (JSON only):
"ungrouped": true for raw rows without aggregation
Output
airlayer prints the generated SQL to stdout and params to stderr. Show the SQL to the user.