transformer

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package transformer wires the parser and rules together: the Engine applies rules to parsed statements, and DirProcessor runs the pipeline over directory trees in parallel.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TransformString added in v1.3.0

func TransformString(cfg *config.Config, sql string, report *compat.Reporter) (string, error)

TransformString runs the whole pipeline on a MariaDB script: preprocess and parse, apply the rules, write TiDB SQL, and check the output still has the input's tables, columns, keys and statements. Migration warnings go to report (may be nil). A nil cfg means the default configuration.

func VerifyOutput added in v1.3.0

func VerifyOutput(before Shape, output string) error

VerifyOutput re-parses output with the TiDB parser and checks it still has the shape recorded before the transformation, so a bug anywhere in the pipeline cannot silently drop a table, column, key, row or statement.

Types

type DirProcessor

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

DirProcessor transforms all SQL files in a directory tree.

func NewDirProcessor

func NewDirProcessor(cfg *config.Config) *DirProcessor

NewDirProcessor creates a directory processor. A nil cfg means the default configuration.

func (*DirProcessor) ProcessDirectory

func (p *DirProcessor) ProcessDirectory(ctx context.Context, inputDir, outputDir string, workers int) error

ProcessDirectory mirrors inputDir into outputDir: schema .sql files are transformed, Dumpling data chunks and all other files (metadata, CSV, compressed chunks) are copied byte for byte, so the output directory is a complete source for TiDB Lightning. Workers controls the maximum number of files processed in parallel.

func (*DirProcessor) Warnings added in v1.3.0

func (p *DirProcessor) Warnings() []string

Warnings returns the migration warnings of the last run, prefixed with the file they came from.

type Engine

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

Engine handles the transformation of SQL statements

func NewEngine

func NewEngine(cfg *config.Config) *Engine

NewEngine creates a new transformation engine

func NewEngineWithReporter added in v1.3.0

func NewEngineWithReporter(cfg *config.Config, r *compat.Reporter) *Engine

NewEngineWithReporter creates an engine whose rules record migration warnings in r.

func (*Engine) Transform

func (e *Engine) Transform(stmts []ast.StmtNode) ([]ast.StmtNode, error)

Transform applies all registered rules to the SQL statements

type Shape added in v1.3.0

type Shape []string

Shape is what no transformation may change, statement by statement and in order: tables with their columns, keys (including column-level ones, key order and DESC, foreign key targets and actions) and partitioning; views; INSERTs with their target, columns and row/value counts; ALTER TABLE specs; USE. Rules legitimately change types, defaults, options, key prefix lengths, clustering and CHECK constraints (MariaDB's JSON_VALID checks are dropped on purpose), so those are not part of it.

func ShapeOf added in v1.3.0

func ShapeOf(stmts []ast.StmtNode) Shape

ShapeOf records the shape of stmts. Take it before Transform: rules modify the AST in place.

Jump to

Keyboard shortcuts

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