engine

package
v0.2.5 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2024 License: LGPL-3.0 Imports: 39 Imported by: 0

Documentation

Index

Constants

View Source
const Version = "v0.2.4"

Variables

This section is empty.

Functions

func BuildMetadata

func BuildMetadata(sc *SourceConfig, mc *ModelConfig) error

BuildMetadata builds any required metadata for the sources in the sources.yaml config. Postgres and MySQL sources require an information schema to be built. S3 sources require duckDB secrets to be stored.

func BuildModels

func BuildModels(sc *SourceConfig, mc *ModelConfig) error

This is the main entry point for building models. The CLI commands call this function.

func ConfirmInsert

func ConfirmInsert(modelName string, dc chan []int64, rowsExpected int64)

func Debug

func Debug(args ...interface{})

func Debugf

func Debugf(format string, args ...interface{})

func Error

func Error(args ...interface{})

func Errorf

func Errorf(format string, args ...interface{})

func Fatal

func Fatal(args ...interface{})

func Fatalf

func Fatalf(format string, args ...interface{})

func GetConfig

func GetConfig(modelTarget string) (*SourceConfig, *ModelConfig, error)

func GetMysqlPoolFromSource

func GetMysqlPoolFromSource(source Source) (*sql.DB, error)

func Info

func Info(args ...interface{})

func Infof

func Infof(format string, args ...interface{})

func Initialize

func Initialize(logLevels ...string) error

func Insert

func Insert(modelName ModelName, ic <-chan []driver.Value, dc chan<- []int64)

func IsValidLogLevel

func IsValidLogLevel(logLevel string) error

func ParseModelColumns

func ParseModelColumns(mc *ModelConfig, columnMetadata ColumnMetadata) error

func ParseModelTables

func ParseModelTables(mc *ModelConfig) error

func PrintPrettyJSON

func PrintPrettyJSON(data []map[string]interface{}) error

PrintPrettyJSON prints the pretty JSON to the console.

func PrintPrettyStruct

func PrintPrettyStruct(v interface{}) error

func ReadRows

func ReadRows(rows *sql.Rows, c chan map[string]any) error

func Retrieve

func Retrieve(sc *SourceConfig, mc *ModelConfig) error

Retrieve data from sources and insert into the duckDB database. Database sources are inserted via the Insert function. File sources are inserted via the native duckDB integrations.

func ValidateConfigs

func ValidateConfigs(sc *SourceConfig, mc *ModelConfig) error

func Warn

func Warn(args ...interface{})

func Warnf

func Warnf(format string, args ...interface{})

func WithError

func WithError(err error) *logrus.Entry

func WithFields

func WithFields(fields logrus.Fields) *logrus.Entry

func WriteToTable

func WriteToTable(rows []map[string]any, columns []string, outputFormat string) error

Types

type Column

type Column struct {
	TableName *TableName
	ModelName ModelName
	FuncName  FuncName
	IsJoin    bool
	Position  int
	Alias     string
}

type ColumnMetadata

type ColumnMetadata map[TableName]map[ColumnName]ColumnType

func BuildColumnMetadata

func BuildColumnMetadata() (ColumnMetadata, error)

BuildColumnMetadata does 2 things: 1) Acts as the interface between information schema data stored in DuckDB and the parts of the application that will need to consume that data, in particular the model builder 2) Performs type validation against each column pulled from the source databases, via the Boyer-Moore majority voting algorithm. This majority type is then packaged into the ColumnMetadata and return to the caller. This is important for typing the model tables created in DuckDB

type ColumnName

type ColumnName string

type ColumnType

type ColumnType struct {
	// Types is a slice of every data type found for a column from its sources
	Types        []string     `json:"types"`
	MajorityType MajorityType `json:"majority_type"`
}

type Connection

type Connection struct {
	Host       string `yaml:"host"`
	Port       int    `yaml:"port"`
	Database   string `yaml:"database"`
	Username   string `yaml:"username"`
	Password   string `yaml:"password"`
	AuthSource string `yaml:"auth_source"`
	BucketName string `yaml:"bucket_name"`
	Region     string `yaml:"region"`
	Schema     string `yaml:"schema"`
	Warehouse  string `yaml:"warehouse"`
	Role       string `yaml:"role"`
	Account    string `yaml:"account"`
}

type Env

type Env struct {
	PreenConfigPath string
	PreenModelsPath string
	LicenseKey      string
}

func EnvInit

func EnvInit() (*Env, error)

type Fields

type Fields = logrus.Fields

type FuncName

type FuncName string

type MajorityType

type MajorityType string

type Model

type Model struct {
	Name         ModelName `yaml:"name"`
	Type         string    `yaml:"type"`
	Format       string    `yaml:"format"`
	Options      Options   `yaml:"options"`
	Query        string    `yaml:"query"`
	FilePatterns *[]string `yaml:"file_patterns"`
	Collection   string    `yaml:"collection"`
	Parsed       sqlparser.Statement
	DDLString    string
	Columns      map[TableName]map[ColumnName]Column
	TableMap     TableMap
	TableSet     TableSet
}

type ModelConfig

type ModelConfig struct {
	Models []*Model `yaml:"models"`
	Env    *Env     `yaml:"-"`
}

func GetModelConfigs

func GetModelConfigs(modelTarget string) (*ModelConfig, error)

type ModelName

type ModelName string

type Options

type Options struct {
	AllVarchar         *bool     `default:"false" yaml:"all_varchar"`
	AllowQuotedNulls   *bool     `default:"true" yaml:"allow_quoted_nulls"`
	AutoDetect         *bool     `default:"true" yaml:"auto_detect"`
	AutoTypeCandidates *[]string `default:"-" yaml:"auto_type_candidates"`
	Columns            *[]Type   `default:"-" yaml:"columns"`
	Compression        *string   `default:"auto" yaml:"compression"`
	DateFormat         *string   `default:"-" yaml:"date_format"`
	DecimalSeparator   *string   `default:"." yaml:"decimal_separator"`
	Delim              *string   `default:"," yaml:"delim"`
	Escape             *string   `default:"\"" yaml:"escape"`
	FileName           *bool     `default:"false" yaml:"filename"`
	ForceNotNull       *[]string `default:"[]" yaml:"force_not_null"`
	Header             *bool     `default:"false" yaml:"header"`
	HivePartitioning   *bool     `default:"false" yaml:"hive_partitioning"`
	IgnoreErrors       *bool     `default:"false" yaml:"ignore_errors"`
	MaxLineSize        *int64    `default:"2097152" yaml:"max_line_size"`
	Names              *[]string `default:"-" yaml:"names"`
	NewLine            *string   `default:"-" yaml:"new_line"`
	NormalizeNames     *bool     `default:"false" yaml:"normalize_names"`
	NullPadding        *bool     `default:"false" yaml:"null_padding"`
	NullString         *[]string `default:"-" yaml:"null_string"`
	Parallel           *bool     `default:"true" yaml:"parallel"`
	Quote              *string   `default:"\"" yaml:"quote"`
	SampleSize         *int64    `default:"20480" yaml:"sample_size"`
	Skip               *int64    `default:"0" yaml:"skip"`
	TimestampFormat    *string   `default:"-" yaml:"timestamp_format"`
	Types              *[]Type   `default:"-" yaml:"types"`
	UnionByName        *bool     `default:"false" yaml:"union_by_name"`
}

type QueryResult

type QueryResult struct {
	Rows    []map[string]any
	Columns []string
}

type QueryResults

type QueryResults struct {
	Rows        []map[string]any
	Columns     []string
	ResultsChan chan map[string]any
}

func Execute

func Execute(statement string) (*QueryResults, error)

type Retriever

type Retriever struct {
	ModelName    string
	TableName    string
	Query        string
	Source       Source
	Options      Options
	Format       string
	FilePatterns *[]string
	Collection   string
}

type Source

type Source struct {
	Name       string     `yaml:"name"`
	Engine     string     `yaml:"engine"`
	Connection Connection `yaml:"connection"`
	Models     []string   `yaml:"models"`
}

type SourceConfig

type SourceConfig struct {
	Sources []Source `yaml:"sources"`
	Env     *Env     `yaml:"-"` // not in yaml
}

func GetSourceConfig

func GetSourceConfig() (*SourceConfig, error)

type TableAlias

type TableAlias string

type TableMap

type TableMap map[TableAlias]TableName

type TableName

type TableName string

type TableSet

type TableSet []TableName

type Type

type Type struct {
	Name string `yaml:"name"`
	Type string `yaml:"type"`
}

Jump to

Keyboard shortcuts

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