rillv1

package
v0.37.0 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2023 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const Version = "rillv1"

Version identifier for this compiler

Variables

This section is empty.

Functions

func EvaluateBoolExpression added in v0.33.0

func EvaluateBoolExpression(expr string) (bool, error)

func InitEmpty

func InitEmpty(ctx context.Context, repo drivers.RepoStore, instanceID, title string) error

InitEmpty initializes an empty project

func IsInit

func IsInit(ctx context.Context, repo drivers.RepoStore, instanceID string) bool

IsInit returns true if a Rill project exists in the repo

func ResolveTemplate

func ResolveTemplate(tmpl string, data TemplateData) (string, error)

ResolveTemplate resolves a template to a string using the given data.

Types

type Connector

type Connector struct {
	Driver          string
	Name            string
	Spec            drivers.Spec
	Resources       []*Resource
	AnonymousAccess bool
}

Connector contains metadata about a connector used in a Rill project

type ConnectorDef

type ConnectorDef struct {
	Type     string
	Name     string
	Defaults map[string]string
}

ConnectorDef is a subtype of RillYAML, defining connectors required by the project

type Diff

type Diff struct {
	Reloaded       bool
	Skipped        bool
	Added          []ResourceName
	Modified       []ResourceName
	ModifiedDotEnv bool
	Deleted        []ResourceName
}

Diff shows changes to Parser.Resources following an incremental reparse.

type MetricsViewYAML added in v0.37.0

type MetricsViewYAML struct {
	Title              string   `yaml:"title"`
	DisplayName        string   `yaml:"display_name"` // Backwards compatibility
	Description        string   `yaml:"description"`
	Model              string   `yaml:"model"`
	Table              string   `yaml:"table"`
	TimeDimension      string   `yaml:"timeseries"`
	SmallestTimeGrain  string   `yaml:"smallest_time_grain"`
	DefaultTimeRange   string   `yaml:"default_time_range"`
	AvailableTimeZones []string `yaml:"available_time_zones"`
	FirstDayOfWeek     uint32   `yaml:"first_day_of_week"`
	FirstMonthOfYear   uint32   `yaml:"first_month_of_year"`
	Dimensions         []*struct {
		Name        string
		Label       string
		Column      string
		Property    string // For backwards compatibility
		Description string
		Ignore      bool `yaml:"ignore"`
		Unnest      bool
	}
	Measures []*struct {
		Name                string
		Label               string
		Expression          string
		Description         string
		FormatPreset        string `yaml:"format_preset"`
		FormatD3            string `yaml:"format_d3"`
		Ignore              bool   `yaml:"ignore"`
		ValidPercentOfTotal bool   `yaml:"valid_percent_of_total"`
	}
	Security *struct {
		Access    string `yaml:"access"`
		RowFilter string `yaml:"row_filter"`
		Include   []*struct {
			Names     []string
			Condition string `yaml:"if"`
		}
		Exclude []*struct {
			Names     []string
			Condition string `yaml:"if"`
		}
	}
	DefaultComparison struct {
		Mode      string `yaml:"mode"`
		Dimension string `yaml:"dimension"`
	} `yaml:"default_comparison"`
	// contains filtered or unexported fields
}

MetricsViewYAML is the raw structure of a MetricsView resource defined in YAML

type MigrationYAML added in v0.37.0

type MigrationYAML struct {
	Version uint `yaml:"version" mapstructure:"version"`
}

MigrationYAML is the raw structure of a Migration resource defined in YAML (does not include common fields)

type ModelYAML added in v0.37.0

type ModelYAML struct {
	Materialize  *bool         `yaml:"materialize" mapstructure:"materialize"`
	Timeout      string        `yaml:"timeout" mapstructure:"timeout"`
	Refresh      *ScheduleYAML `yaml:"refresh" mapstructure:"refresh"`
	ParserConfig struct {
		DuckDB struct {
			InferRefs *bool `yaml:"infer_refs" mapstructure:"infer_refs"`
		} `yaml:"duckdb" mapstructure:"duckdb"`
	} `yaml:"parser"`
}

ModelYAML is the raw structure of a Model resource defined in YAML (does not include common fields)

type Node

type Node struct {
	Kind              ResourceKind
	Name              string
	Refs              []ResourceName
	Paths             []string
	YAML              *yaml.Node
	YAMLRaw           string
	YAMLPath          string
	Connector         string
	ConnectorInferred bool
	SQL               string
	SQLPath           string
	SQLAnnotations    map[string]any
	SQLUsesTemplating bool
}

Node represents one path stem in the project. It contains data derived from a YAML and/or SQL file (e.g. "/path/to/file.yaml" for "/path/to/file.sql").

type Parser

type Parser struct {
	// Options
	Repo             drivers.RepoStore
	InstanceID       string
	DefaultConnector string
	DuckDBConnectors []string

	// Output
	RillYAML  *RillYAML
	DotEnv    map[string]string
	Resources map[ResourceName]*Resource
	Errors    []*runtimev1.ParseError
	// contains filtered or unexported fields
}

Parser parses a Rill project directory into a set of resources. After the initial parse, the parser can be used to incrementally reparse a subset of files. Parser is not concurrency safe.

func Parse

func Parse(ctx context.Context, repo drivers.RepoStore, instanceID, defaultConnector string, duckDBConnectors []string) (*Parser, error)

Parse creates a new parser and parses the entire project.

Note on SQL parsing: For DuckDB SQL specifically, the parser can use a SQL parser to extract refs and annotations (instead of relying on templating or YAML). To enable SQL parsing for a connector, pass it in duckDBConnectors. If DuckDB SQL parsing should be used on files where no connector is specified, put the defaultConnector in duckDBConnectors.

func (*Parser) AnalyzeConnectors

func (p *Parser) AnalyzeConnectors(ctx context.Context) ([]*Connector, error)

AnalyzeConnectors extracts connector metadata from a Rill project

func (*Parser) Reparse

func (p *Parser) Reparse(ctx context.Context, paths []string) (*Diff, error)

Reparse re-parses the indicated file paths, updating the Parser's state. If rill.yaml has previously errored, or if rill.yaml is included in paths, it will reload the entire project. If a previous call to Reparse has returned an error, the Parser may not be accessed or called again.

type ReportYAML added in v0.37.0

type ReportYAML struct {
	Title   string        `yaml:"title"`
	Refresh *ScheduleYAML `yaml:"refresh"`
	Timeout string        `yaml:"timeout"`
	Query   struct {
		Name     string         `yaml:"name"`
		Args     map[string]any `yaml:"args"`
		ArgsJSON string         `yaml:"args_json"`
	} `yaml:"query"`
	Export struct {
		Format string `yaml:"format"`
		Limit  uint   `yaml:"limit"`
	} `yaml:"export"`
	Email struct {
		Recipients []string `yaml:"recipients"`
	} `yaml:"email"`
	Annotations map[string]string `yaml:"annotations"`
	// contains filtered or unexported fields
}

ReportYAML is the raw structure of a Report resource defined in YAML (does not include common fields)

type Resource

type Resource struct {
	// Metadata
	Name  ResourceName
	Paths []string
	Refs  []ResourceName // Derived from rawRefs after parsing (can't contain ResourceKindUnspecified). Always sorted.

	// Only one of these will be non-nil
	SourceSpec      *runtimev1.SourceSpec
	ModelSpec       *runtimev1.ModelSpec
	MetricsViewSpec *runtimev1.MetricsViewSpec
	MigrationSpec   *runtimev1.MigrationSpec
	ReportSpec      *runtimev1.ReportSpec
	// contains filtered or unexported fields
}

Resource parsed from code files. One file may output multiple resources and multiple files may contribute config to one resource.

type ResourceKind

type ResourceKind int

ResourceKind identifies a resource type supported by the parser

const (
	ResourceKindUnspecified ResourceKind = iota
	ResourceKindSource
	ResourceKindModel
	ResourceKindMetricsView
	ResourceKindMigration
	ResourceKindReport
)

func ParseResourceKind

func ParseResourceKind(kind string) (ResourceKind, error)

ParseResourceKind maps a string to a ResourceKind. Note: The empty string is considered a valid kind (unspecified).

func (ResourceKind) String

func (k ResourceKind) String() string

type ResourceName

type ResourceName struct {
	Kind ResourceKind
	Name string
}

ResourceName is a unique identifier for a resource

func (ResourceName) Normalized

func (n ResourceName) Normalized() ResourceName

func (ResourceName) String

func (n ResourceName) String() string

type RillYAML

type RillYAML struct {
	Title       string
	Description string
	Connectors  []*ConnectorDef
	Variables   []*VariableDef
	Defaults    RillYAMLDefaults
}

RillYAML is the parsed contents of rill.yaml

func ParseRillYAML

func ParseRillYAML(ctx context.Context, repo drivers.RepoStore, instanceID string) (*RillYAML, error)

ParseRillYAML parses only the project's rill.yaml (or rill.yml) file.

type RillYAMLDefaults added in v0.35.2

type RillYAMLDefaults struct {
	Sources      yaml.Node
	Models       yaml.Node
	MetricsViews yaml.Node
	Migrations   yaml.Node
}

RillYAMLDefaults contains project-wide default YAML properties for different resources

type ScheduleYAML added in v0.37.0

type ScheduleYAML struct {
	Cron     string `yaml:"cron" mapstructure:"cron"`
	Every    string `yaml:"every" mapstructure:"every"`
	TimeZone string `yaml:"time_zone" mapstructure:"time_zone"`
	Disable  bool   `yaml:"disable" mapstructure:"disable"`
}

ScheduleYAML is the raw structure of a refresh schedule clause defined in YAML. This does not represent a stand-alone YAML file, just a partial used in other structs.

type SourceYAML added in v0.37.0

type SourceYAML struct {
	Type       string         `yaml:"type"` // Backwards compatibility
	Timeout    string         `yaml:"timeout"`
	Refresh    *ScheduleYAML  `yaml:"refresh"`
	Properties map[string]any `yaml:",inline" mapstructure:",remain"`
	// contains filtered or unexported fields
}

SourceYAML is the raw structure of a Source resource defined in YAML (does not include common fields)

type TemplateData

type TemplateData struct {
	User       map[string]any
	Variables  map[string]string
	ExtraProps map[string]any
	Self       TemplateResource
	Resolve    func(ref ResourceName) (string, error)
	Lookup     func(name ResourceName) (TemplateResource, error)
}

TemplateData contains data for resolving a template.

type TemplateMetadata

type TemplateMetadata struct {
	Refs                     []ResourceName
	Config                   map[string]any
	UsesTemplating           bool
	ResolvedWithPlaceholders string
}

TemplateMetadata contains metadata extracted from a template.

func AnalyzeTemplate

func AnalyzeTemplate(tmpl string) (*TemplateMetadata, error)

AnalyzeTemplate parses a template and extracts metadata.

type TemplateResource

type TemplateResource struct {
	Meta  *runtimev1.ResourceMeta
	Spec  any
	State any
}

TemplateResource contains data for a resource for injection into a template.

type VariableDef

type VariableDef struct {
	Name    string
	Default string
}

VariableDef is a subtype of RillYAML, defining defaults for project variables

Jump to

Keyboard shortcuts

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