semantic

package
v0.11.595 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 25, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadDir

func LoadDir(dir string) (map[string]*Model, error)

LoadDir loads every *.yml/*.yaml semantic model from a directory tree.

func LoadDirFS

func LoadDirFS(fs afero.Fs, dir string) (map[string]*Model, error)

LoadDirFS loads every *.yml/*.yaml semantic model from a directory tree using the given filesystem.

func LoadDirPartial

func LoadDirPartial(dir string) (map[string]*Model, map[string]error, error)

LoadDirPartial loads valid semantic models while keeping track of invalid named models so callers can fail only dashboards that reference them.

func LoadDirPartialFS

func LoadDirPartialFS(fs afero.Fs, dir string) (map[string]*Model, map[string]error, error)

LoadDirPartialFS loads valid semantic models using the given filesystem while keeping track of invalid named models so callers can fail only dashboards that reference them.

func Names

func Names(models map[string]*Model) []string

Types

type Dimension

type Dimension struct {
	Name          string            `yaml:"name" json:"name"`
	Label         string            `yaml:"label,omitempty" json:"label,omitempty"`
	Description   string            `yaml:"description,omitempty" json:"description,omitempty"`
	Type          string            `yaml:"type,omitempty" json:"type,omitempty"` // string, number, boolean, time
	Expression    string            `yaml:"expression,omitempty" json:"expression,omitempty"`
	Granularities map[string]string `yaml:"granularities,omitempty" json:"granularities,omitempty"`
	Hidden        bool              `yaml:"hidden,omitempty" json:"hidden,omitempty"`
	Group         string            `yaml:"group,omitempty" json:"group,omitempty"`
}

type DimensionRef

type DimensionRef struct {
	Name        string `json:"name"`
	Granularity string `json:"granularity,omitempty"`
}

type Engine

type Engine struct {
	// contains filtered or unexported fields
}

Engine generates SQL from a Model and a Query.

func NewEngine

func NewEngine(m *Model) (*Engine, error)

func NewEngineWithModels

func NewEngineWithModels(m *Model, models map[string]*Model) (*Engine, error)

func (*Engine) GenerateSQL

func (e *Engine) GenerateSQL(q *Query) (string, error)

GenerateSQL produces a SQL query string for the given Query.

type Filter

type Filter struct {
	Dimension  string      `json:"dimension,omitempty"`
	Operator   string      `json:"operator,omitempty"` // equals, not_equals, gt, gte, lt, lte, in, not_in, between, is_null, is_not_null
	Value      interface{} `json:"value,omitempty"`
	Expression string      `json:"expression,omitempty"`
}

type Format

type Format struct {
	Type     string `yaml:"type,omitempty" json:"type,omitempty"` // number, currency, percentage, decimal
	Currency string `yaml:"currency,omitempty" json:"currency,omitempty"`
	Decimals int    `yaml:"decimals,omitempty" json:"decimals,omitempty"`
}

type Join

type Join struct {
	Name         string `yaml:"name" json:"name"`
	Model        string `yaml:"model,omitempty" json:"model,omitempty"`
	Relationship string `yaml:"relationship" json:"relationship"` // one_to_one, many_to_one, one_to_many, many_to_many
	ForeignKey   string `yaml:"foreign_key,omitempty" json:"foreign_key,omitempty"`
	TargetKey    string `yaml:"target_key,omitempty" json:"target_key,omitempty"`
	SQL          string `yaml:"sql,omitempty" json:"sql,omitempty"`
}

type Metric

type Metric struct {
	Name        string  `yaml:"name" json:"name"`
	Label       string  `yaml:"label,omitempty" json:"label,omitempty"`
	Description string  `yaml:"description,omitempty" json:"description,omitempty"`
	Expression  string  `yaml:"expression" json:"expression"`
	Filter      string  `yaml:"filter,omitempty" json:"filter,omitempty"`
	Hidden      bool    `yaml:"hidden,omitempty" json:"hidden,omitempty"`
	Group       string  `yaml:"group,omitempty" json:"group,omitempty"`
	Format      *Format `yaml:"format,omitempty" json:"format,omitempty"`
	Window      *Window `yaml:"window,omitempty" json:"window,omitempty"`
}

type Model

type Model struct {
	Schema      string      `yaml:"schema,omitempty" json:"schema,omitempty"`
	Name        string      `yaml:"name" json:"name"`
	Label       string      `yaml:"label,omitempty" json:"label,omitempty"`
	Description string      `yaml:"description,omitempty" json:"description,omitempty"`
	Source      Source      `yaml:"source" json:"source"`
	PrimaryKey  string      `yaml:"primary_key,omitempty" json:"primary_key,omitempty"`
	Joins       []Join      `yaml:"joins,omitempty" json:"joins,omitempty"`
	Dimensions  []Dimension `yaml:"dimensions,omitempty" json:"dimensions,omitempty"`
	Metrics     []Metric    `yaml:"metrics,omitempty" json:"metrics,omitempty"`
	Segments    []Segment   `yaml:"segments,omitempty" json:"segments,omitempty"`
}

Model describes a single semantic model with dimensions, metrics, and segments.

func LoadFile

func LoadFile(path string) (*Model, error)

LoadFile loads and validates a semantic model from a YAML file.

func LoadFileFS

func LoadFileFS(fs afero.Fs, path string) (*Model, error)

LoadFileFS loads and validates a semantic model from a YAML file using the given filesystem.

type Query

type Query struct {
	Dimensions []DimensionRef `json:"dimensions,omitempty"`
	Metrics    []string       `json:"metrics,omitempty"`
	Filters    []Filter       `json:"filters,omitempty"`
	Segments   []string       `json:"segments,omitempty"`
	Sort       []SortSpec     `json:"sort,omitempty"`
	Limit      int            `json:"limit,omitempty"`
}

Query specifies what to retrieve from a model.

type Segment

type Segment struct {
	Name        string `yaml:"name" json:"name"`
	Label       string `yaml:"label,omitempty" json:"label,omitempty"`
	Description string `yaml:"description,omitempty" json:"description,omitempty"`
	Filter      string `yaml:"filter" json:"filter"`
}

type SortSpec

type SortSpec struct {
	Name      string `json:"name"`
	Direction string `json:"direction,omitempty"` // asc, desc
}

type Source

type Source struct {
	Table string `yaml:"table" json:"table"`
}

type Window

type Window struct {
	Type        string   `yaml:"type,omitempty" json:"type,omitempty"` // running_total, lag, lead, rank, percent_of_total
	OrderBy     string   `yaml:"order_by,omitempty" json:"order_by,omitempty"`
	PartitionBy []string `yaml:"partition_by,omitempty" json:"partition_by,omitempty"`
	Offset      int      `yaml:"offset,omitempty" json:"offset,omitempty"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL