Documentation
¶
Overview ¶
Package polyglot is the official Go SDK for Polyglot SQL.
The SDK loads the polyglot-sql-ffi shared library at runtime through PureGo, so callers can keep CGO_ENABLED=0. It does not download or bundle native libraries; provide the shared library path with Open or POLYGLOT_SQL_FFI_PATH.
Index ¶
- Constants
- Variables
- func AnnotateTypes(sql, dialect string, schema *ValidationSchema) (json.RawMessage, error)
- func ClearDefaultClient()
- func DialectCount() (int, error)
- func Dialects() ([]string, error)
- func Diff(sql1, sql2, dialect string) (json.RawMessage, error)
- func Format(sql, dialect string, options ...FormatOptions) ([]string, error)
- func Generate(ast json.RawMessage, dialect string, options ...GenerateOptions) ([]string, error)
- func GenerateDataType(dataType json.RawMessage, dialect string) (string, error)
- func Optimize(sql, dialect string, options ...OptimizeOptions) ([]string, error)
- func Parse(sql, dialect string) (json.RawMessage, error)
- func ParseDataType(sql, dialect string) (json.RawMessage, error)
- func ParseOne(sql, dialect string) (json.RawMessage, error)
- func QualifyTables(ast json.RawMessage, options QualifyTablesOptions) (json.RawMessage, error)
- func RenameTables(ast json.RawMessage, mapping map[string]string, options RenameTablesOptions) (json.RawMessage, error)
- func RuntimeVersion() (string, error)
- func SetDefaultClient(client *Client)
- func SetLimit(ast json.RawMessage, limit int) (json.RawMessage, error)
- func SetOffset(ast json.RawMessage, offset int) (json.RawMessage, error)
- func SetOrderBy(ast json.RawMessage, orderBy json.RawMessage) (json.RawMessage, error)
- func SourceTables(column, sql, dialect string) ([]string, error)
- func Tokenize(sql, dialect string) (json.RawMessage, error)
- func Transpile(sql, fromDialect, toDialect string, options ...TranspileOptions) ([]string, error)
- func Version() string
- type AnalyzeQueryOptions
- type CTEFact
- type Client
- func (c *Client) AnalyzeQuery(sql string, options AnalyzeQueryOptions) (QueryAnalysis, error)
- func (c *Client) AnnotateTypes(sql, dialect string, schema *ValidationSchema) (json.RawMessage, error)
- func (c *Client) Close() error
- func (c *Client) DialectCount() (int, error)
- func (c *Client) Dialects() ([]string, error)
- func (c *Client) Diff(sql1, sql2, dialect string) (json.RawMessage, error)
- func (c *Client) Format(sql, dialect string, options ...FormatOptions) ([]string, error)
- func (c *Client) Generate(ast json.RawMessage, dialect string, options ...GenerateOptions) ([]string, error)
- func (c *Client) GenerateDataType(dataType json.RawMessage, dialect string) (string, error)
- func (c *Client) Lineage(column, sql, dialect string) (LineageNode, error)
- func (c *Client) LineageWithSchema(column, sql string, schema ValidationSchema, dialect string) (LineageNode, error)
- func (c *Client) OpenLineageColumnLineage(sql string, options OpenLineageOptions) (OpenLineageColumnLineageResult, error)
- func (c *Client) OpenLineageJobEvent(sql string, options OpenLineageOptions) (OpenLineageEventResult, error)
- func (c *Client) OpenLineageRunEvent(sql string, options OpenLineageOptions) (OpenLineageEventResult, error)
- func (c *Client) Optimize(sql, dialect string, options ...OptimizeOptions) ([]string, error)
- func (c *Client) Parse(sql, dialect string) (json.RawMessage, error)
- func (c *Client) ParseDataType(sql, dialect string) (json.RawMessage, error)
- func (c *Client) ParseOne(sql, dialect string) (json.RawMessage, error)
- func (c *Client) QualifyTables(ast json.RawMessage, options QualifyTablesOptions) (json.RawMessage, error)
- func (c *Client) RenameTables(ast json.RawMessage, mapping map[string]string, options RenameTablesOptions) (json.RawMessage, error)
- func (c *Client) RuntimeVersion() (string, error)
- func (c *Client) SetLimit(ast json.RawMessage, limit int) (json.RawMessage, error)
- func (c *Client) SetOffset(ast json.RawMessage, offset int) (json.RawMessage, error)
- func (c *Client) SetOrderBy(ast json.RawMessage, orderBy json.RawMessage) (json.RawMessage, error)
- func (c *Client) SourceTables(column, sql, dialect string) ([]string, error)
- func (c *Client) Tokenize(sql, dialect string) (json.RawMessage, error)
- func (c *Client) Transpile(sql, fromDialect, toDialect string, options ...TranspileOptions) ([]string, error)
- func (c *Client) Validate(sql, dialect string) (ValidationResult, error)
- func (c *Client) Version() string
- type ColumnReferenceFact
- type Error
- type FormatOptions
- type GenerateOptions
- type LineageNode
- type OpenLineageColumnLineageFacet
- type OpenLineageColumnLineageField
- type OpenLineageColumnLineageResult
- type OpenLineageDataset
- type OpenLineageDatasetID
- type OpenLineageEventResult
- type OpenLineageInputField
- type OpenLineageOptions
- type OpenLineageRunEventType
- type OpenLineageTransformation
- type OpenLineageWarning
- type OptimizeOptions
- type ProjectionFact
- type QualifyTablesOptions
- type QueryAnalysis
- type RelationFact
- type RenameTablesOptions
- type SchemaColumn
- type SchemaColumnReference
- type SchemaForeignKey
- type SchemaTable
- type SchemaTableReference
- type SetOperationBranchFact
- type SetOperationFact
- type StarProjectionFact
- type TransformFunctionFact
- type TranspileOptions
- type UnsupportedLevel
- type ValidationError
- type ValidationResult
- type ValidationSchema
Constants ¶
View Source
const LibraryPathEnv = "POLYGLOT_SQL_FFI_PATH"
Variables ¶
View Source
var ( ErrClosed = errors.New("polyglot: client is closed") ErrNoDefaultClient = errors.New("polyglot: default client is not configured") )
Functions ¶
func AnnotateTypes ¶
func AnnotateTypes(sql, dialect string, schema *ValidationSchema) (json.RawMessage, error)
func ClearDefaultClient ¶
func ClearDefaultClient()
func DialectCount ¶
func Generate ¶
func Generate(ast json.RawMessage, dialect string, options ...GenerateOptions) ([]string, error)
func GenerateDataType ¶ added in v0.5.1
func GenerateDataType(dataType json.RawMessage, dialect string) (string, error)
func ParseDataType ¶ added in v0.5.1
func ParseDataType(sql, dialect string) (json.RawMessage, error)
func QualifyTables ¶
func QualifyTables(ast json.RawMessage, options QualifyTablesOptions) (json.RawMessage, error)
func RenameTables ¶
func RenameTables(ast json.RawMessage, mapping map[string]string, options RenameTablesOptions) (json.RawMessage, error)
func RuntimeVersion ¶
func SetDefaultClient ¶
func SetDefaultClient(client *Client)
func SetLimit ¶ added in v0.5.4
func SetLimit(ast json.RawMessage, limit int) (json.RawMessage, error)
func SetOffset ¶ added in v0.5.4
func SetOffset(ast json.RawMessage, offset int) (json.RawMessage, error)
func SetOrderBy ¶ added in v0.5.4
func SetOrderBy(ast json.RawMessage, orderBy json.RawMessage) (json.RawMessage, error)
func SourceTables ¶
Types ¶
type AnalyzeQueryOptions ¶ added in v0.5.1
type AnalyzeQueryOptions struct {
Dialect string `json:"dialect,omitempty"`
Schema *ValidationSchema `json:"schema,omitempty"`
}
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func DefaultClient ¶
func OpenDefault ¶
func (*Client) AnalyzeQuery ¶ added in v0.5.1
func (c *Client) AnalyzeQuery(sql string, options AnalyzeQueryOptions) (QueryAnalysis, error)
func (*Client) AnnotateTypes ¶
func (c *Client) AnnotateTypes(sql, dialect string, schema *ValidationSchema) (json.RawMessage, error)
func (*Client) DialectCount ¶
func (*Client) Format ¶
func (c *Client) Format(sql, dialect string, options ...FormatOptions) ([]string, error)
func (*Client) Generate ¶
func (c *Client) Generate(ast json.RawMessage, dialect string, options ...GenerateOptions) ([]string, error)
func (*Client) GenerateDataType ¶ added in v0.5.1
func (*Client) LineageWithSchema ¶
func (c *Client) LineageWithSchema(column, sql string, schema ValidationSchema, dialect string) (LineageNode, error)
func (*Client) OpenLineageColumnLineage ¶
func (c *Client) OpenLineageColumnLineage(sql string, options OpenLineageOptions) (OpenLineageColumnLineageResult, error)
func (*Client) OpenLineageJobEvent ¶
func (c *Client) OpenLineageJobEvent(sql string, options OpenLineageOptions) (OpenLineageEventResult, error)
func (*Client) OpenLineageRunEvent ¶
func (c *Client) OpenLineageRunEvent(sql string, options OpenLineageOptions) (OpenLineageEventResult, error)
func (*Client) Optimize ¶
func (c *Client) Optimize(sql, dialect string, options ...OptimizeOptions) ([]string, error)
func (*Client) ParseDataType ¶ added in v0.5.1
func (c *Client) ParseDataType(sql, dialect string) (json.RawMessage, error)
func (*Client) QualifyTables ¶
func (c *Client) QualifyTables(ast json.RawMessage, options QualifyTablesOptions) (json.RawMessage, error)
func (*Client) RenameTables ¶
func (c *Client) RenameTables(ast json.RawMessage, mapping map[string]string, options RenameTablesOptions) (json.RawMessage, error)
func (*Client) RuntimeVersion ¶
func (*Client) SetLimit ¶ added in v0.5.4
func (c *Client) SetLimit(ast json.RawMessage, limit int) (json.RawMessage, error)
func (*Client) SetOffset ¶ added in v0.5.4
func (c *Client) SetOffset(ast json.RawMessage, offset int) (json.RawMessage, error)
func (*Client) SetOrderBy ¶ added in v0.5.4
func (c *Client) SetOrderBy(ast json.RawMessage, orderBy json.RawMessage) (json.RawMessage, error)
func (*Client) SourceTables ¶
type ColumnReferenceFact ¶ added in v0.5.1
type FormatOptions ¶
type GenerateOptions ¶
type GenerateOptions struct{}
type LineageNode ¶
type LineageNode struct {
Name string `json:"name"`
Expression json.RawMessage `json:"expression"`
Source json.RawMessage `json:"source"`
Downstream []LineageNode `json:"downstream"`
SourceName string `json:"source_name"`
SourceKind string `json:"source_kind"`
SourceAlias *string `json:"source_alias,omitempty"`
ReferenceNodeName string `json:"reference_node_name"`
}
func Lineage ¶
func Lineage(column, sql, dialect string) (LineageNode, error)
func LineageWithSchema ¶
func LineageWithSchema(column, sql string, schema ValidationSchema, dialect string) (LineageNode, error)
type OpenLineageColumnLineageFacet ¶
type OpenLineageColumnLineageFacet struct {
Producer string `json:"_producer"`
SchemaURL string `json:"_schemaURL"`
Fields map[string]OpenLineageColumnLineageField `json:"fields"`
}
type OpenLineageColumnLineageField ¶
type OpenLineageColumnLineageField struct {
InputFields []OpenLineageInputField `json:"inputFields"`
}
type OpenLineageColumnLineageResult ¶
type OpenLineageColumnLineageResult struct {
Facet OpenLineageColumnLineageFacet `json:"facet"`
Inputs []OpenLineageDataset `json:"inputs"`
Outputs []OpenLineageDataset `json:"outputs"`
Warnings []OpenLineageWarning `json:"warnings"`
}
func OpenLineageColumnLineage ¶
func OpenLineageColumnLineage(sql string, options OpenLineageOptions) (OpenLineageColumnLineageResult, error)
type OpenLineageDataset ¶
type OpenLineageDataset struct {
Namespace string `json:"namespace"`
Name string `json:"name"`
Facets map[string]json.RawMessage `json:"facets,omitempty"`
}
type OpenLineageDatasetID ¶
type OpenLineageEventResult ¶
type OpenLineageEventResult struct {
Event json.RawMessage `json:"event"`
Warnings []OpenLineageWarning `json:"warnings"`
}
func OpenLineageJobEvent ¶
func OpenLineageJobEvent(sql string, options OpenLineageOptions) (OpenLineageEventResult, error)
func OpenLineageRunEvent ¶
func OpenLineageRunEvent(sql string, options OpenLineageOptions) (OpenLineageEventResult, error)
type OpenLineageInputField ¶
type OpenLineageInputField struct {
Namespace string `json:"namespace"`
Name string `json:"name"`
Field string `json:"field"`
Transformations []OpenLineageTransformation `json:"transformations,omitempty"`
}
type OpenLineageOptions ¶
type OpenLineageOptions struct {
Dialect string `json:"dialect,omitempty"`
Producer string `json:"producer"`
DatasetNamespace string `json:"datasetNamespace,omitempty"`
DatasetMappings map[string]OpenLineageDatasetID `json:"datasetMappings"`
OutputDataset *OpenLineageDatasetID `json:"outputDataset,omitempty"`
Schema *ValidationSchema `json:"schema,omitempty"`
JobNamespace string `json:"jobNamespace,omitempty"`
JobName string `json:"jobName,omitempty"`
EventTime string `json:"eventTime,omitempty"`
RunID string `json:"runId,omitempty"`
EventType OpenLineageRunEventType `json:"eventType,omitempty"`
}
type OpenLineageRunEventType ¶
type OpenLineageRunEventType string
const ( OpenLineageRunEventStart OpenLineageRunEventType = "START" OpenLineageRunEventRunning OpenLineageRunEventType = "RUNNING" OpenLineageRunEventComplete OpenLineageRunEventType = "COMPLETE" OpenLineageRunEventAbort OpenLineageRunEventType = "ABORT" OpenLineageRunEventFail OpenLineageRunEventType = "FAIL" OpenLineageRunEventOther OpenLineageRunEventType = "OTHER" )
type OpenLineageWarning ¶
type OptimizeOptions ¶
type OptimizeOptions struct{}
type ProjectionFact ¶ added in v0.5.1
type ProjectionFact struct {
Index int `json:"index"`
Name *string `json:"name"`
IsStar bool `json:"isStar"`
StarTable *string `json:"starTable"`
TransformKind string `json:"transformKind"`
TransformFunction *TransformFunctionFact `json:"transformFunction,omitempty"`
CastType *string `json:"castType"`
TypeHint *string `json:"typeHint"`
Nullability string `json:"nullability"`
Upstream []ColumnReferenceFact `json:"upstream"`
}
type QualifyTablesOptions ¶
type QualifyTablesOptions struct {
DB string `json:"db,omitempty"`
Catalog string `json:"catalog,omitempty"`
Dialect string `json:"dialect,omitempty"`
CanonicalizeTableAliases *bool `json:"canonicalizeTableAliases,omitempty"`
AliasUnaliasedTables *bool `json:"aliasUnaliasedTables,omitempty"`
AliasUnaliasedSubqueries *bool `json:"aliasUnaliasedSubqueries,omitempty"`
AliasPrefix string `json:"aliasPrefix,omitempty"`
NormalizeSetOperationSubqueries *bool `json:"normalizeSetOperationSubqueries,omitempty"`
}
type QueryAnalysis ¶ added in v0.5.1
type QueryAnalysis struct {
Shape string `json:"shape"`
CTEs []string `json:"ctes"`
CTEFacts []CTEFact `json:"cteFacts"`
Projections []ProjectionFact `json:"projections"`
Relations []RelationFact `json:"relations"`
BaseTables []RelationFact `json:"baseTables"`
StarProjections []StarProjectionFact `json:"starProjections"`
SetOperations []SetOperationFact `json:"setOperations"`
}
func AnalyzeQuery ¶ added in v0.5.1
func AnalyzeQuery(sql string, options AnalyzeQueryOptions) (QueryAnalysis, error)
type RelationFact ¶ added in v0.5.1
type RenameTablesOptions ¶
type SchemaColumn ¶
type SchemaColumnReference ¶
type SchemaForeignKey ¶
type SchemaForeignKey struct {
Name string `json:"name,omitempty"`
Columns []string `json:"columns"`
References SchemaTableReference `json:"references"`
}
type SchemaTable ¶
type SchemaTable struct {
Name string `json:"name"`
Schema string `json:"schema,omitempty"`
Columns []SchemaColumn `json:"columns"`
Aliases []string `json:"aliases,omitempty"`
PrimaryKey []string `json:"primaryKey,omitempty"`
UniqueKeys [][]string `json:"uniqueKeys,omitempty"`
ForeignKeys []SchemaForeignKey `json:"foreignKeys,omitempty"`
}
type SchemaTableReference ¶
type SetOperationBranchFact ¶ added in v0.5.1
type SetOperationBranchFact struct {
Index int `json:"index"`
Projections []ProjectionFact `json:"projections"`
}
type SetOperationFact ¶ added in v0.5.1
type SetOperationFact struct {
Kind string `json:"kind"`
All bool `json:"all"`
Distinct bool `json:"distinct"`
OutputColumns []string `json:"outputColumns"`
Branches []SetOperationBranchFact `json:"branches"`
}
type StarProjectionFact ¶ added in v0.5.3
type TransformFunctionFact ¶ added in v0.5.4
type TransformFunctionFact struct {
Name string `json:"name"`
LiteralArgs []string `json:"literalArgs"`
ColumnArgs []ColumnReferenceFact `json:"columnArgs"`
}
type TranspileOptions ¶
type TranspileOptions struct {
Pretty bool `json:"pretty,omitempty"`
UnsupportedLevel UnsupportedLevel `json:"unsupportedLevel,omitempty"`
MaxUnsupported int `json:"maxUnsupported,omitempty"`
}
type UnsupportedLevel ¶ added in v0.5.0
type UnsupportedLevel string
const ( UnsupportedIgnore UnsupportedLevel = "ignore" UnsupportedWarn UnsupportedLevel = "warn" UnsupportedRaise UnsupportedLevel = "raise" UnsupportedImmediate UnsupportedLevel = "immediate" )
type ValidationError ¶
type ValidationResult ¶
type ValidationResult struct {
Valid bool `json:"valid"`
Errors []ValidationError `json:"errors"`
}
func Validate ¶
func Validate(sql, dialect string) (ValidationResult, error)
type ValidationSchema ¶
type ValidationSchema struct {
Tables []SchemaTable `json:"tables"`
Strict *bool `json:"strict,omitempty"`
}
Click to show internal directories.
Click to hide internal directories.