MCPcopy Create free account
hub / github.com/bytebase/bytebase / TestGetQuerySpan

Function TestGetQuerySpan

backend/plugin/parser/snowflake/query_span_test.go:20–86  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

18)
19
20func TestGetQuerySpan(t *testing.T) {
21 type testCase struct {
22 Description string `yaml:"description,omitempty"`
23 Statement string `yaml:"statement,omitempty"`
24 DefaultDatabase string `yaml:"defaultDatabase,omitempty"`
25 IgnoreCaseSensitve bool `yaml:"ignoreCaseSensitive,omitempty"`
26 // Metadata is the protojson encoded storepb.DatabaseSchemaMetadata,
27 // if it's empty, we will use the defaultDatabaseMetadata.
28 Metadata string `yaml:"metadata,omitempty"`
29 QuerySpan *base.YamlQuerySpan `yaml:"querySpan,omitempty"`
30 }
31
32 var (
33 record = false
34 testDataPaths = []string{
35 "test-data/query-span/standard.yaml",
36 "test-data/query-span/subquery.yaml",
37 "test-data/query-span/set-operator.yaml",
38 // TODO: re-enable once pivot lineage is implemented on the omni AST.
39 // omni models PIVOT/UNPIVOT on ast.TableRef (Pivot/Unpivot/Nested), but
40 // this extractor does not compute the pivoted projection yet — it FAILS
41 // CLOSED instead (see extractTableSourceFromTableRef and
42 // TestGetQuerySpan_PivotFailsClosed): GetQuerySpan returns an explicit
43 // error for pivoted table sources rather than silently resolving the
44 // bare base table with wrong lineage. The expected lineage assertions
45 // are preserved in pivot.yaml for when pivot projection lands. Tracked
46 // in the migration ledger.
47 // "test-data/query-span/pivot.yaml",
48 "test-data/query-span/cte.yaml",
49 }
50 )
51
52 a := require.New(t)
53 for _, testDataPath := range testDataPaths {
54 testDataPath := testDataPath
55
56 yamlFile, err := os.Open(testDataPath)
57 a.NoError(err)
58
59 var testCases []testCase
60 byteValue, err := io.ReadAll(yamlFile)
61 a.NoError(err)
62 a.NoError(yamlFile.Close())
63 a.NoError(yaml.Unmarshal(byteValue, &testCases))
64
65 for i, tc := range testCases {
66 metadata := &storepb.DatabaseSchemaMetadata{}
67 a.NoErrorf(common.ProtojsonUnmarshaler.Unmarshal([]byte(tc.Metadata), metadata), "cases %d", i+1)
68 databaseMetadataGetter, databaseNameLister := buildMockDatabaseMetadataGetter([]*storepb.DatabaseSchemaMetadata{metadata})
69 result, err := GetQuerySpan(context.TODO(), base.GetQuerySpanContext{
70 GetDatabaseMetadataFunc: databaseMetadataGetter,
71 ListDatabaseNamesFunc: databaseNameLister,
72 }, base.Statement{Text: tc.Statement}, tc.DefaultDatabase, "PUBLIC", tc.IgnoreCaseSensitve)
73 a.NoErrorf(err, "statement: %s", tc.Statement)
74 resultYaml := result.ToYaml()
75 if record {
76 testCases[i].QuerySpan = resultYaml
77 } else {

Callers

nothing calls this directly

Calls 7

RecordFunction · 0.92
UnmarshalMethod · 0.80
ToYamlMethod · 0.80
GetQuerySpanFunction · 0.70
OpenMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected