sml

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2024 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TypeBool     = "bool"
	TypeDatetime = "datetime"
	TypeFloat    = "float"
	TypeInt      = "int"
	TypeString   = "string"
	TypeTime     = "time"
	TypeVerbatim = "verbatim"
)

define SML data types

View Source
const Debug = false
View Source
const (
	DialectDuckDB = "duckdb"
)

Datasource provider constants

Variables

View Source
var Assert = func() func(bool) {
	if Debug {
		return assert
	}
	return func(bool) {}
}()

DataTypes ...

View Source
var SQL_RESERVED_WORDS = makeReservedWords()
View Source
var UNIVERSAL_TYPE_TO_CLICKHOUSE = map[string]string{
	"TINYINT":     "Int16",
	"SMALLINT":    "Int32",
	"INT":         "Int64",
	"INTEGER":     "Int64",
	"BIGINT":      "Int64",
	"INT8":        "Int8",
	"INT16":       "Int16",
	"INT32":       "Int32",
	"INT64":       "Int64",
	"UINT8":       "UInt8",
	"UINT16":      "UInt16",
	"UINT32":      "UInt32",
	"UINT64":      "UInt64",
	"DECIMAL":     "Float64",
	"DOUBLE":      "Float64",
	"FLOAT":       "Float64",
	"FLOAT32":     "Float32",
	"FLOAT64":     "Float64",
	"NUMERIC":     "Float64",
	"REAL":        "Float64",
	"CHAR":        "String",
	"VARCHAR":     "String",
	"STRING":      "String",
	"TEXT":        "String",
	"FIXEDSTRING": "String",
	"TIME":        "DateTime",
	"TIMESTAMP":   "DateTime",
	"DATE":        "Date",
	"DATETIME":    "DateTime",
	"BOOL":        "Boolean",
	"BOOLEAN":     "Boolean",
}

Functions

func ConvertColumnName

func ConvertColumnName(uniqueNames map[string]bool, name string) string

func ConvertName

func ConvertName(name string) string

func CreateQualifiedNames

func CreateQualifiedNames(names []string, dialect string) (qName string, err error)

CreateQualifiedNames creates a qualified name using "names" by combining them based on the dialect.

func DiffJSON

func DiffJSON(a, b string) string

DiffJSON ...

func GetQuotes

func GetQuotes(dialect string) (startQuote string, endQuote string, err error)

GetQuotes returns the dialect specific quotes.

func IsAlpha

func IsAlpha(c byte) bool

func IsColumnExpressionAtomic

func IsColumnExpressionAtomic(expression string) bool

IsColumnExpressionAtomic takes an expression and returns true if the expression is atomic

func IsReservedWord

func IsReservedWord(w string) bool

func IsStringInSlice

func IsStringInSlice(str string, list []string) bool

IsStringInSlice returns true if the string is present in the slice

func IsValidID

func IsValidID(value string) bool

IsValidID checks if a name is a valid id id definition:

minimum length has to be 1
1st character can only be undersore or alphabets
2nd character onwards can be alphanumeric and undersores

func ParseSML

func ParseSML(input, projectName string) (project Project, parseErrors []ParseError)

API ParseSML ... given an SML model, returns a parsed project

func RandomString

func RandomString(n int) string

RandomString returns a random string of specified length

func RemoveExtraSpaces

func RemoveExtraSpaces(s string) string

RemoveExtraSpaces removes extra spaces in a given string. It trims spaces from left and right ends. It also replaces extra spaces from between words in a string.

Types

type Column

type Column struct {
	Name            string
	SQL             string
	Label           string
	Format          string
	Type            string
	Description     string
	Transformer     string
	TransformerName string
}

Column ...

type Comment

type Comment struct {
	Comment string
	Line    int
}

Comment is a lingling comment

type CriteriaCombinationTerm

type CriteriaCombinationTerm struct {
	LogicalOperator string
	Terms           []CriteriaTerm
}

type CriteriaSimpleTerm

type CriteriaSimpleTerm struct {
	Column      string
	Table       string
	Operator    string
	Granularity string
	Value       []interface{}
}

type CriteriaTerm

type CriteriaTerm struct {
	// A criteria can either have a combination term
	// Or a simple term
	Name            string
	SimpleTerm      *CriteriaSimpleTerm
	CombinationTerm *CriteriaCombinationTerm
}

type Dataset

type Dataset struct {
	Name       string
	Label      string
	TableNames []string
	Tables     map[string]Table
	Joins      []Join
}

Dataset ...

type JInGo

type JInGo struct {
	Type  JType
	Atom  string
	Map   map[string]*JInGo
	Array []JInGo
}

JInGo ...

func J2Go

func J2Go(j string) (g JInGo, e error)

J2Go ...

type JType

type JType int

JType ...

const (
	JTInt JType = iota
	JTFloat
	JTString
	JTBool
	JTMap
	JTArray
	JTNull
)

Jt constants...

type Join

type Join struct {
	OneTable   string   // != "" => oneToMany / manyToOne
	OneColumns []string // != nil => oneToMany / manyToOne
	OTS        []OperatorTableSQL
}

Join ...

type Namespace

type Namespace string

type OperatorTableSQL

type OperatorTableSQL struct {
	Operator string
	Table    string
	SQL      string
}

OperatorTableSQL ...

type ParseError

type ParseError struct {
	Msg     string
	LineNum int
}

ParseError stores datamodel parse errors and line number

type Project

type Project struct {
	Name       string
	TableNames []string
	Tables     map[string]Table
	Datasets   map[string]Dataset
	Schemes    map[string]Scheme
}

Project ...

func ParseSMLPieces

func ParseSMLPieces(inputs []string, filenames []string) (project Project, errorLine int, err error)

ParseSMLPieces ... given an SML model, returns a parsed project

type SQLToken

type SQLToken struct {
	Position int
	Type     SQLTokenType
	Value    string
	Value2   string
}

SQLToken ...

func TokenizeSQL

func TokenizeSQL(sql string) (tokens []SQLToken)

TokenizeSQL ...

type SQLTokenType

type SQLTokenType int

SQLTokenType ...

const (
	NumberSQLToken SQLTokenType = iota
	StringSQLToken
	NameSQLToken
	OpSQLToken
	ReservedSQLToken
	UnknownSQLToken
)

TokenTypes ...

type Scheme

type Scheme struct {
	Name          string
	Label         string
	Description   string
	Criteria      map[string]CriteriaTerm
	CriteriaNames []string
	Evaluation    string // similar to a filter string
}

type StringSet

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

func ArrayToSet

func ArrayToSet(values []string) StringSet

func NewStringSet

func NewStringSet() StringSet

func (StringSet) Exists

func (s StringSet) Exists(v string) bool

func (StringSet) Insert

func (s StringSet) Insert(v string)

func (StringSet) Remove

func (s StringSet) Remove(v string)

type Table

type Table struct {
	Name        string
	DataSource  string
	SQL         string
	ColumnNames []string
	Columns     map[string]Column
	Label       string
	Pk          []string
	Description string
}

TODO: Add example

Jump to

Keyboard shortcuts

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