generators#
import "github.com/magnus-ffcg/go-dbt2lookml/pkg/generators"
Package generators provides LookML generation functionality from dbt models.
This package contains the core logic for transforming dbt catalog and manifest data into LookML view files. It handles dimension generation, measure creation, explore definitions, and nested view structures.
Key components:
- LookMLGenerator: Main coordinator for generating all LookML files
- ViewGenerator: Generates LookML views from dbt models
- DimensionGenerator: Creates dimensions and dimension groups
- MeasureGenerator: Generates measures from metadata
- ExploreGenerator: Creates explores with join relationships
The package supports:
- BigQuery nested/repeated columns (STRUCT/ARRAY)
- Custom LookML metadata via dbt meta tags
- Dimension groups for date/timestamp fields
- Automatic and custom measure generation
- Context-aware cancellation for long operations
Example usage:
cfg := &config.Config{
OutputDir: "./output",
UseTableName: false,
}
generator := NewLookMLGenerator(cfg)
Index#
- type DimensionGenerator
- func NewDimensionGenerator(cfg *config.Config) *DimensionGenerator
- func (g *DimensionGenerator) GenerateDimension(model *models.DbtModel, column *models.DbtModelColumn) (*models.LookMLDimension, error)
- func (g *DimensionGenerator) GenerateDimensionGroup(model *models.DbtModel, column *models.DbtModelColumn) (*models.LookMLDimensionGroup, error)
- func (g *DimensionGenerator) GetDimensionGroupLabel(column *models.DbtModelColumn) *string
- func (g *DimensionGenerator) GetDimensionName(column *models.DbtModelColumn) string
- type DimensionGeneratorInterface
- type ErrorStrategy
- type ExploreGenerator
- func NewExploreGenerator(cfg *config.Config) *ExploreGenerator
- func (g *ExploreGenerator) GenerateExplore(model *models.DbtModel) (*models.LookMLExplore, error)
- func (g *ExploreGenerator) GenerateExploreWithJoins(model *models.DbtModel, relatedModels []*models.DbtModel) (*models.LookMLExplore, error)
- func (g *ExploreGenerator) ValidateExplore(explore *models.LookMLExplore) []string
- type ExploreGeneratorInterface
- type GenerationOptions
- type GenerationResult
- type LookMLGenerator
- func NewLookMLGenerator(cfg *config.Config) *LookMLGenerator
- func (g *LookMLGenerator) GenerateAll(models []*models.DbtModel) (int, error)
- func (g *LookMLGenerator) GenerateAllWithContext(ctx context.Context, models []*models.DbtModel) (int, error)
- func (g *LookMLGenerator) GenerateAllWithOptions(ctx context.Context, models []*models.DbtModel, opts GenerationOptions) (*GenerationResult, error)
- type LookMLGeneratorInterface
- type MeasureGenerator
- func NewMeasureGenerator(cfg *config.Config) *MeasureGenerator
- func (g *MeasureGenerator) GenerateDefaultCountMeasure(model *models.DbtModel) *models.LookMLMeasure
- func (g *MeasureGenerator) GenerateMeasure(model *models.DbtModel, measureMeta *models.DbtMetaLookerMeasure) (*models.LookMLMeasure, error)
- func (g *MeasureGenerator) GenerateNumericMeasures(model *models.DbtModel, column *models.DbtModelColumn) []*models.LookMLMeasure
- func (g *MeasureGenerator) GeneratePrimaryKeyMeasure(model *models.DbtModel, pkColumn *models.DbtModelColumn) *models.LookMLMeasure
- type MeasureGeneratorInterface
- type ModelError
- type ViewGenerator
- type ViewGeneratorInterface
type DimensionGenerator#
DimensionGenerator handles generation of LookML dimensions and dimension groups
type DimensionGenerator struct {
// contains filtered or unexported fields
}
func NewDimensionGenerator#
func NewDimensionGenerator(cfg *config.Config) *DimensionGenerator
NewDimensionGenerator creates a new DimensionGenerator instance
func (*DimensionGenerator) GenerateDimension#
func (g *DimensionGenerator) GenerateDimension(model *models.DbtModel, column *models.DbtModelColumn) (*models.LookMLDimension, error)
GenerateDimension generates a LookML dimension from a model column
func (*DimensionGenerator) GenerateDimensionGroup#
func (g *DimensionGenerator) GenerateDimensionGroup(model *models.DbtModel, column *models.DbtModelColumn) (*models.LookMLDimensionGroup, error)
GenerateDimensionGroup generates a LookML dimension group from a model column
func (*DimensionGenerator) GetDimensionGroupLabel#
func (g *DimensionGenerator) GetDimensionGroupLabel(column *models.DbtModelColumn) *string
GetDimensionGroupLabel gets the group label for the dimension
func (*DimensionGenerator) GetDimensionName#
func (g *DimensionGenerator) GetDimensionName(column *models.DbtModelColumn) string
GetDimensionName gets the dimension name from the column
type DimensionGeneratorInterface#
DimensionGeneratorInterface defines the interface for generating LookML dimensions
type DimensionGeneratorInterface interface {
// GenerateDimension generates a LookML dimension from a model column
GenerateDimension(model *models.DbtModel, column *models.DbtModelColumn) (*models.LookMLDimension, error)
// GenerateDimensionGroup generates a LookML dimension group from a model column
GenerateDimensionGroup(model *models.DbtModel, column *models.DbtModelColumn) (*models.LookMLDimensionGroup, error)
// GetDimensionName gets the dimension name from the column
GetDimensionName(column *models.DbtModelColumn) string
// GetDimensionGroupLabel gets the group label for the dimension
GetDimensionGroupLabel(column *models.DbtModelColumn) *string
}
type ErrorStrategy#
ErrorStrategy defines how the generator should handle errors during generation.
type ErrorStrategy int
const (
// FailFast stops generation immediately on the first error.
// This is the safest strategy for production use.
FailFast ErrorStrategy = iota
// FailAtEnd collects all errors and continues processing all models.
// Returns an error at the end if any models failed.
// Useful for seeing all problems at once.
FailAtEnd
// ContinueOnError logs errors but does not fail the generation.
// Returns success even if some models failed.
// Use with caution - only for non-critical generation tasks.
ContinueOnError
)
func (ErrorStrategy) String#
func (e ErrorStrategy) String() string
String returns a human-readable name for the error strategy.
type ExploreGenerator#
ExploreGenerator handles generation of LookML explores
type ExploreGenerator struct {
// contains filtered or unexported fields
}
func NewExploreGenerator#
func NewExploreGenerator(cfg *config.Config) *ExploreGenerator
NewExploreGenerator creates a new ExploreGenerator instance
func (*ExploreGenerator) GenerateExplore#
func (g *ExploreGenerator) GenerateExplore(model *models.DbtModel) (*models.LookMLExplore, error)
GenerateExplore generates a LookML explore from a dbt model
func (*ExploreGenerator) GenerateExploreWithJoins#
func (g *ExploreGenerator) GenerateExploreWithJoins(model *models.DbtModel, relatedModels []*models.DbtModel) (*models.LookMLExplore, error)
GenerateExploreWithJoins generates an explore with automatic joins based on foreign keys
func (*ExploreGenerator) ValidateExplore#
func (g *ExploreGenerator) ValidateExplore(explore *models.LookMLExplore) []string
ValidateExplore validates that an explore is properly configured
type ExploreGeneratorInterface#
ExploreGeneratorInterface defines the interface for generating LookML explores
type ExploreGeneratorInterface interface {
// GenerateExplore generates a LookML explore from a dbt model
GenerateExplore(model *models.DbtModel) (*models.LookMLExplore, error)
// GenerateExploreWithJoins generates an explore with automatic joins based on foreign keys
GenerateExploreWithJoins(model *models.DbtModel, relatedModels []*models.DbtModel) (*models.LookMLExplore, error)
// ValidateExplore validates that an explore is properly configured
ValidateExplore(explore *models.LookMLExplore) []string
}
type GenerationOptions#
GenerationOptions configures the behavior of the generation process.
type GenerationOptions struct {
// ErrorStrategy determines how errors are handled
ErrorStrategy ErrorStrategy
// MaxErrors limits the number of errors before stopping (0 = unlimited)
// Only applies when ErrorStrategy is FailAtEnd
MaxErrors int
}
func DefaultGenerationOptions#
func DefaultGenerationOptions() GenerationOptions
DefaultGenerationOptions returns the default options (FailFast).
type GenerationResult#
GenerationResult contains the results of a generation operation.
type GenerationResult struct {
// FilesGenerated is the number of files successfully generated
FilesGenerated int
// Errors contains all errors that occurred during generation
Errors []ModelError
// ModelsProcessed is the total number of models attempted
ModelsProcessed int
}
func (*GenerationResult) ErrorSummary#
func (r *GenerationResult) ErrorSummary() string
ErrorSummary returns a summary of the errors.
func (*GenerationResult) HasErrors#
func (r *GenerationResult) HasErrors() bool
HasErrors returns true if any errors occurred during generation.
func (*GenerationResult) Success#
func (r *GenerationResult) Success() bool
Success returns true if generation completed successfully according to the strategy.
type LookMLGenerator#
LookMLGenerator is the main generator that coordinates all LookML generation
type LookMLGenerator struct {
// contains filtered or unexported fields
}
func NewLookMLGenerator#
func NewLookMLGenerator(cfg *config.Config) *LookMLGenerator
NewLookMLGenerator creates a new LookMLGenerator instance
func (*LookMLGenerator) GenerateAll#
func (g *LookMLGenerator) GenerateAll(models []*models.DbtModel) (int, error)
GenerateAll generates all LookML files for the given models. Uses the legacy error handling behavior (respects config.ContinueOnError).
func (*LookMLGenerator) GenerateAllWithContext#
func (g *LookMLGenerator) GenerateAllWithContext(ctx context.Context, models []*models.DbtModel) (int, error)
GenerateAllWithContext generates all LookML files for the given models with cancellation support
func (*LookMLGenerator) GenerateAllWithOptions#
func (g *LookMLGenerator) GenerateAllWithOptions(ctx context.Context, models []*models.DbtModel, opts GenerationOptions) (*GenerationResult, error)
GenerateAllWithOptions generates all LookML files with configurable error handling. This is the recommended method for new code as it provides better error control.
type LookMLGeneratorInterface#
LookMLGeneratorInterface defines the interface for the main LookML generator
type LookMLGeneratorInterface interface {
// GenerateAll generates all LookML files for the given models
GenerateAll(models []*models.DbtModel) (int, error)
// GenerateAllWithContext generates all LookML files with cancellation support
GenerateAllWithContext(ctx context.Context, models []*models.DbtModel) (int, error)
}
type MeasureGenerator#
MeasureGenerator handles generation of LookML measures
type MeasureGenerator struct {
// contains filtered or unexported fields
}
func NewMeasureGenerator#
func NewMeasureGenerator(cfg *config.Config) *MeasureGenerator
NewMeasureGenerator creates a new MeasureGenerator instance
func (*MeasureGenerator) GenerateDefaultCountMeasure#
func (g *MeasureGenerator) GenerateDefaultCountMeasure(model *models.DbtModel) *models.LookMLMeasure
GenerateDefaultCountMeasure generates a default count measure for a model
func (*MeasureGenerator) GenerateMeasure#
func (g *MeasureGenerator) GenerateMeasure(model *models.DbtModel, measureMeta *models.DbtMetaLookerMeasure) (*models.LookMLMeasure, error)
GenerateMeasure generates a LookML measure from measure metadata
func (*MeasureGenerator) GenerateNumericMeasures#
func (g *MeasureGenerator) GenerateNumericMeasures(model *models.DbtModel, column *models.DbtModelColumn) []*models.LookMLMeasure
GenerateNumericMeasures generates sum/average measures for numeric columns
func (*MeasureGenerator) GeneratePrimaryKeyMeasure#
func (g *MeasureGenerator) GeneratePrimaryKeyMeasure(model *models.DbtModel, pkColumn *models.DbtModelColumn) *models.LookMLMeasure
GeneratePrimaryKeyMeasure generates a count distinct measure for primary key columns
type MeasureGeneratorInterface#
MeasureGeneratorInterface defines the interface for generating LookML measures
type MeasureGeneratorInterface interface {
// GenerateMeasure generates a LookML measure from measure metadata
GenerateMeasure(model *models.DbtModel, measureMeta *models.DbtMetaLookerMeasure) (*models.LookMLMeasure, error)
// GenerateDefaultCountMeasure generates a default count measure for a model
GenerateDefaultCountMeasure(model *models.DbtModel) *models.LookMLMeasure
// GeneratePrimaryKeyMeasure generates a count distinct measure for primary key columns
GeneratePrimaryKeyMeasure(model *models.DbtModel, pkColumn *models.DbtModelColumn) *models.LookMLMeasure
// GenerateNumericMeasures generates sum/average measures for numeric columns
GenerateNumericMeasures(model *models.DbtModel, column *models.DbtModelColumn) []*models.LookMLMeasure
}
type ModelError#
ModelError represents an error that occurred while generating a specific model.
type ModelError struct {
ModelName string
Error error
}
func (ModelError) String#
func (e ModelError) String() string
String returns a formatted error message.
type ViewGenerator#
ViewGenerator handles generation of LookML views
type ViewGenerator struct {
// contains filtered or unexported fields
}
func NewViewGenerator#
func NewViewGenerator(cfg *config.Config) *ViewGenerator
NewViewGenerator creates a new ViewGenerator instance
func (*ViewGenerator) GenerateNestedView#
func (g *ViewGenerator) GenerateNestedView(model *models.DbtModel, arrayColumn *models.DbtModelColumn) (*models.LookMLView, error)
GenerateNestedView generates a nested view for array/struct columns
func (*ViewGenerator) GenerateView#
func (g *ViewGenerator) GenerateView(model *models.DbtModel) (*models.LookMLView, error)
GenerateView generates a LookML view from a dbt model
type ViewGeneratorInterface#
ViewGeneratorInterface defines the interface for generating LookML views
type ViewGeneratorInterface interface {
// GenerateView generates a LookML view from a dbt model
GenerateView(model *models.DbtModel) (*models.LookMLView, error)
// GenerateNestedView generates a nested view for array/struct columns
GenerateNestedView(model *models.DbtModel, arrayColumn *models.DbtModelColumn) (*models.LookMLView, error)
}
Generated by gomarkdoc