Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions backend/plugin/lineage/mariadb/analyze_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package mariadb

import (
"testing"

"github.com/Ranxy/metaxisdata/backend/plugin/lineage/testutil"
)

// knownParserGaps lists shared-corpus cases omni's MariaDB parser cannot parse
// yet: a join tree nested in three or more parentheses, e.g.
// `FROM (((a JOIN b ON ...)))`, which is what mysqldump emits for views. omni's
// MySQL parser accepts any depth; the MariaDB parser stops at two. These
// statements hard-fail in production too, so the gap is recorded here rather
// than hidden. Remove an entry once the parser accepts the statement.
var knownParserGaps = map[string]bool{
"select with parenthesized join tree": true,
"INSERT SELECT with parenthesized join tree": true,
"CREATE TABLE AS SELECT with parenthesized join tree": true,
"CREATE VIEW with deeply nested parenthesized join tree": true,
}

// TestAnalyzeYAML runs the shared MySQL-family golden corpus through the MariaDB
// analyzer, minus statements the MariaDB parser cannot parse yet.
func TestAnalyzeYAML(t *testing.T) {
testutil.RunLineageTestSuitesFromYAMLDirSkipping(t, sharedCorpusDir(), analyzeSQL, knownParserGaps)
testutil.RunLineageTestSuitesFromYAMLDir(t, dialectCorpusDir(), analyzeSQL)
}
29 changes: 29 additions & 0 deletions backend/plugin/lineage/mariadb/analyze_test_helper.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package mariadb

import (
"context"
"path/filepath"
"runtime"

"github.com/Ranxy/metaxisdata/backend/plugin/lineage/catalog"
"github.com/Ranxy/metaxisdata/backend/plugin/lineage/model"
)

// analyzeSQL adapts the analyzer to the shared lineage test harness.
func analyzeSQL(sql string, cat catalog.Provide) ([]model.ColumnRelation, error) {
return NewAnalyzer(context.TODO(), sql, cat).AnalyzeRelations()
}

// dialectCorpusDir locates this dialect's own golden corpus.
func dialectCorpusDir() string {
_, filename, _, _ := runtime.Caller(0)
return filepath.Join(filepath.Dir(filename), "testdata", "analyze")
}

// sharedCorpusDir locates the MySQL golden corpus. Its statements are
// dialect-neutral SQL that every MySQL-family analyzer must resolve identically,
// so reusing it keeps the dialects behaviorally in sync.
func sharedCorpusDir() string {
_, filename, _, _ := runtime.Caller(0)
return filepath.Join(filepath.Dir(filename), "..", "mysql", "testdata", "analyze")
}
Loading
Loading