Compiling dbt models into Lightdash explores with full warehouse integration.
Compiles Lightdash resources by executing dbt compile, parsing the manifest, and integrating with the data warehouse to enrich model metadata.
lightdash compile [options]dbt Configuration Options:
--project-dir <path> - dbt project directory (default: .)--profiles-dir <path> - dbt profiles directory (default: auto-detected from ~/.dbt/ or .)--profile <name> - Profile name (default: from dbt_project.yml)--target <name> - Target in profiles.yml (default: profile default target)--target-path <path> - Override dbt target path (overrides DBT_TARGET_PATH and dbt_project.yml)--vars <vars> - dbt variables as JSON string--threads <number> - Number of threads for dbt--no-version-check - Skip dbt version checkModel Selection Options:
-s, --select <models...> - Select models using dbt selection syntax (space-separated)-m, --models <models...> - Alias for --select--exclude <models...> - Exclude models (space-separated)--selector <selector_name> - Use dbt selector from selectors.yml--state <state> - State directory for dbt state-based selectionAdvanced Compilation Options:
--defer - Resolve unselected nodes by deferring to the manifest within the --state directory--no-defer - Don't resolve unselected nodes by deferring--full-refresh - Full refresh for dbt incremental models--skip-warehouse-catalog - Skip fetching warehouse catalog, use types from YML files (default: false)--skip-dbt-compile - Skip dbt compile and use existing ./target/manifest.json (default: false)--no-warehouse-credentials - Compile without warehouse credentials (implies skip-dbt-compile and skip-warehouse-catalog)--disable-timestamp-conversion [true|false] - Disable timestamp conversion to UTC for Snowflake warehouses (default: false)--verbose - Enable debug logging (default: false)Usage Examples:
# Basic compilation (all models)
lightdash compile
# Compile specific model
lightdash compile --select customers
# Compile multiple models
lightdash compile --select customers orders
# Compile models with tag
lightdash compile --select tag:sales
# Compile model and its parents
lightdash compile --select +orders
# Compile model and its children
lightdash compile --select customers+
# Compile with custom dbt directories
lightdash compile --project-dir ./dbt --profiles-dir ./profiles
# Compile with custom target
lightdash compile --target dev
# Compile with dbt variables
lightdash compile --vars '{"start_date": "2024-01-01"}'
# Skip warehouse catalog (faster, uses YML types only)
lightdash compile --skip-warehouse-catalog
# Use existing manifest.json (skip dbt compile)
lightdash compile --skip-dbt-compile
# Compile without warehouse credentials (CI/CD)
lightdash compile --no-warehouse-credentials
# Exclude specific models
lightdash compile --exclude staging_*
# Use dbt selector
lightdash compile --selector my_selector
# State-based selection with defer
lightdash compile --state ./prod-manifest --defer
# Disable Snowflake timestamp conversion
lightdash compile --disable-timestamp-conversion true
# Verbose output for debugging
lightdash compile --verboseThe compile command executes the following steps:
Validate Configuration
Execute dbt Compile (unless --skip-dbt-compile)
dbt compile with provided optionsParse dbt Manifest
Fetch Warehouse Catalog (unless --skip-warehouse-catalog)
Process Lightdash Configuration
Generate Explores
Output Results
The --select, --models, and --exclude options support dbt's selection syntax:
# Single model
lightdash compile --select model_name
# Multiple models (space-separated)
lightdash compile --select model1 model2 model3# All models with "sales" tag
lightdash compile --select tag:sales
# Multiple tags
lightdash compile --select tag:sales tag:finance# Model and all its parents (upstream dependencies)
lightdash compile --select +customers
# Model and all its children (downstream dependents)
lightdash compile --select customers+
# Model, parents, and children
lightdash compile --select +customers+
# Model with specific depth
lightdash compile --select 2+customers # 2 levels of parents# Models in specific directory
lightdash compile --select path:marts/finance
# Models in subdirectories
lightdash compile --select path:marts/*# Models from specific dbt package
lightdash compile --select package:dbt_utils# Compile all except staging models
lightdash compile --exclude staging_*
# Combine selection and exclusion
lightdash compile --select tag:sales --exclude +staging_*# Models that are both tagged and in a path
lightdash compile --select tag:sales,path:marts/Standard dbt project configuration:
name: my_project
version: '1.0.0'
profile: my_profile
model-paths: ["models"]
analysis-paths: ["analyses"]
test-paths: ["tests"]
seed-paths: ["seeds"]
macro-paths: ["macros"]
target-path: "target"
models:
my_project:
+materialized: tableWarehouse connection profiles (in ~/.dbt/ or custom location):
my_profile:
target: dev
outputs:
dev:
type: postgres
host: localhost
port: 5432
user: my_user
pass: my_password
dbname: my_database
schema: dbt_dev
prod:
type: postgres
host: prod.example.com
port: 5432
user: prod_user
pass: "{{ env_var('DBT_PASSWORD') }}"
dbname: prod_database
schema: dbt_prodLightdash-specific configuration (in dbt project directory):
warehouse:
type: postgres # or bigquery, snowflake, redshift, databricks, trino, clickhouse
parameters:
my_param: "value"
spotlight:
categories:
featured:
label: "Featured Metrics"
color: "#4A90E2"
default_visibility: "visible"By default, the compile command fetches the warehouse catalog to get accurate column types:
# Default behavior: fetch warehouse catalog
lightdash compile
# Skip warehouse catalog (faster, uses YML types)
lightdash compile --skip-warehouse-catalogWhen to skip warehouse catalog:
Trade-offs:
# Default: requires warehouse credentials
lightdash compile
# Skip dbt compile and warehouse catalog entirely
lightdash compile --no-warehouse-credentialsUse --no-warehouse-credentials when:
Limitations:
Snowflake timestamps are automatically converted to UTC by default:
# Default: convert timestamps to UTC
lightdash compile
# Disable conversion (if timestamps already in UTC)
lightdash compile --disable-timestamp-conversion trueWhen to disable:
Default behavior:
Use dbt state for efficient compilation:
# Compile only changed models since production
lightdash compile --state ./prod-state --select state:modified+
# Defer to production for unchanged models
lightdash compile --state ./prod-state --deferState directory structure:
prod-state/
manifest.json # Production manifestUse cases:
# Enable defer (resolve unselected nodes from state)
lightdash compile --state ./prod-state --defer
# Disable defer (compile everything from scratch)
lightdash compile --state ./prod-state --no-deferOverride default settings with environment variables:
# dbt directories
export DBT_PROJECT_DIR="./my-dbt-project"
export DBT_PROFILES_DIR="./my-profiles"
export DBT_TARGET_PATH="./custom-target"
# Warehouse credentials (accessible in profiles.yml)
export DBT_PASSWORD="secret"
export DBT_ENV_VARIABLE="value"
# Run compile (uses environment variables)
lightdash compile--skip-dbt-compile cannot be used with model selection options (--select, --exclude, --selector, --models)--defer and --no-defer (mutually exclusive)--models and --select (same functionality, use one)dbt Not Found:
Error: dbt command not foundSolution: Install dbt - pip install dbt-core dbt-postgres (or your warehouse adapter)
Invalid dbt Project:
Error: dbt_project.yml not foundSolution: Run from dbt project directory or use --project-dir
Invalid Profiles:
Error: Could not find profile named 'my_profile'Solution: Check profiles.yml or use --profile to specify correct profile
Warehouse Connection Error:
Error: Could not connect to warehouseSolution: Verify credentials in profiles.yml or use --no-warehouse-credentials
Compilation Errors:
Error: SQL compilation failedSolution: Check dbt model SQL, run dbt compile directly for detailed errors
# Fastest: Skip dbt and warehouse entirely
lightdash compile --skip-dbt-compile --skip-warehouse-catalog
# Fast: Skip warehouse catalog only
lightdash compile --skip-warehouse-catalog
# Fast: Select only changed models
lightdash compile --state ./prod-state --select state:modified+# Use more threads for faster dbt compilation
lightdash compile --threads 8# Compile only specific models during development
lightdash compile --select +my_model+
# Use state for incremental compilation
lightdash compile --state ./prod-state --select state:modified+ --defer# Enable verbose logging
lightdash compile --verboseShows:
# Validate dbt compilation separately
dbt compile
# Check manifest.json
cat target/manifest.json
# Test warehouse connection
dbt debugExit Code 0: Compilation succeeded Exit Code 1: Compilation failed
Success Output:
✓ Compiled N models
✓ Generated N exploresError Output:
✗ Compilation failed: [error message]