Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

fix(tsql): resolve view parsing and cross-database reference issues (#17354)

h3n4l3375b7c7304b
diff --git a/backend/plugin/parser/tsql/query_span_extractor.go b/backend/plugin/parser/tsql/query_span_extractor.go
index 8cabbdabfb..5b96de71ab 100644
--- a/backend/plugin/parser/tsql/query_span_extractor.go
+++ b/backend/plugin/parser/tsql/query_span_extractor.go
@@ -33,7 +33,7 @@ type querySpanExtractor struct {
// outerTableSources is used to record the outer table sources in the query.
// It's used to resolve the column name in the correlated subquery.
- // outerTableSources []base.TableSource
+ outerTableSources []base.TableSource
// tableSourcesFrom is the list of table sources from the FROM clause.
tableSourcesFrom []base.TableSource
@@ -110,6 +110,7 @@ func (q *querySpanExtractor) getQuerySpan(ctx context.Context, statement string)
var resourceNotFound *parsererror.ResourceNotFoundError
if errors.As(err, &resourceNotFound) {
return &base.QuerySpan{
+ Type: queryTypeListener.result,
SourceColumns: accessTables,
Results: []base.QuerySpanResult{},
NotFoundError: resourceNotFound,
@@ -723,7 +724,7 @@ func (q *querySpanExtractor) tsqlFindTableSchema(fullTableName parser.IFull_tabl
continue
}
view := schemaSchema.GetView(viewName)
- columns, err := q.getColumnsForView(view.Definition)
+ columns, err := q.getColumnsFromCreateView(view.Definition, databaseName, schemaName)
if err != nil {
return nil, errors.Wrapf(err, "failed to get columns for view %s.%s.%s", databaseName, schemaName, viewName)
}
@@ -745,9 +746,20 @@ func (q *querySpanExtractor) tsqlFindTableSchema(fullTableName parser.IFull_tabl
}
}
-func (q *querySpanExtractor) getColumnsForView(definition string) ([]base.QuerySpanResult, error) {
- newQ := newQuerySpanExtractor(q.defaultDatabase, q.defaultSchema, q.gCtx, q.ignoreCaseSensitive)
- span, err := newQ.getQuerySpan(q.ctx, definition)
+func (q *querySpanExtractor) getColumnsFromCreateView(definition string, viewDatabaseName string, viewSchemaName string) ([]base.QuerySpanResult, error) {
+ // Extract the SELECT body from CREATE VIEW statement
+ selectBody, err := getSelectBodyFromCreateView(definition)
+ if err != nil {
+ return nil, errors.Wrapf(err, "failed to extract SELECT body from CREATE VIEW")
+ }
+ if selectBody == "" {
+ return nil, errors.Errorf("no SELECT body found in CREATE VIEW statement")
+ }
+
+ // Use the view's database and schema as the default context for parsing the SELECT statement
+ // This ensures that cross-database references in the view definition are resolved correctly
+ newQ := newQuerySpanExtractor(viewDatabaseName, viewSchemaName, q.gCtx, q.ignoreCaseSensitive)
+ span, err := newQ.getQuerySpan(q.ctx, selectBody)
if err != nil {
return nil, errors.Wrapf(err, "failed to get query span for view definition")
}
@@ -874,6 +886,25 @@ func (q *querySpanExtractor) tsqlIsFieldSensitive(normalizedDatabaseName string,
return column, nil
}
}
+
+ for i := len(q.outerTableSources) - 1; i >= 0; i-- {
+ tableSource := q.outerTableSources[i]
+ if mask&maskDatabaseName != 0 && !q.isIdentifierEqual(normalizedDatabaseName, tableSource.GetDatabaseName()) {
+ continue
+ }
+ if mask&maskSchemaName != 0 && !q.isIdentifierEqual(normalizedSchemaName, tableSource.GetSchemaName()) {
+ continue
+ }
+ if mask&maskTableName != 0 && !q.isIdentifierEqual(normalizedTableName, tableSource.GetTableName()) {
+ continue
+ }
+ for _, column := range tableSource.GetQuerySpanResult() {
+ if mask&maskColumnName != 0 && !q.isIdentifierEqual(normalizedColumnName, column.Name) {
+ continue
+ }
+ return column, nil
+ }
+ }
return base.QuerySpanResult{}, errors.Errorf(`no matching column %q.%q.%q.%q`, normalizedDatabaseName, normalizedSchemaName, normalizedTableName, normalizedColumnName)
}
@@ -1140,11 +1171,11 @@ func (q *querySpanExtractor) getQuerySpanResultFromExpr(ctx antlr.RuleContext) (
case *parser.SubqueryContext:
// For subquery, we clone the current extractor, reset the from list, but keep the cte, and then extract the sensitive fields from the subquery
cloneExtractor := &querySpanExtractor{
- defaultDatabase: q.defaultDatabase,
- defaultSchema: q.defaultSchema,
- gCtx: q.gCtx,
- ctx: q.ctx,
- // outerTableSources: extractor.outerTableSources,
+ defaultDatabase: q.defaultDatabase,
+ defaultSchema: q.defaultSchema,
+ gCtx: q.gCtx,
+ ctx: q.ctx,
+ outerTableSources: append(q.outerTableSources, q.tableSourcesFrom...),
ctes: q.ctes,
ignoreCaseSensitive: q.ignoreCaseSensitive,
}
@@ -3626,3 +3657,43 @@ func unquote(name string) string {
}
return name
}
+
+func getSelectBodyFromCreateView(createView string) (string, error) {
+ parseResult, err := ParseTSQL(createView)
+ if err != nil {
+ return "", err
+ }
+ if parseResult == nil {
+ return "", errors.Errorf("failed to parse CREATE VIEW statement")
+ }
+ tree := parseResult.Tree
+ if tree == nil {
+ return "", errors.Errorf("parse tree is nil")
+ }
+
+ extractor := &selectBodyExtractor{}
+ antlr.ParseTreeWalkerDefault.Walk(extractor, tree)
+
+ if extractor.selectBody == "" {
+ return "", errors.Errorf("no SELECT statement found in CREATE VIEW")
+ }
+
+ return extractor.selectBody, nil
+}
+
+type selectBodyExtractor struct {
+ *parser.BaseTSqlParserListener
+ selectBody string
+}
+
+func (e *selectBodyExtractor) EnterCreate_view(ctx *parser.Create_viewContext) {
+ // Get the SELECT statement part from CREATE VIEW
+ if selectStatement := ctx.Select_statement_standalone(); selectStatement != nil {
+ // Extract the text of the SELECT statement using GetTextFromInterval to preserve spaces
+ start := selectStatement.GetStart().GetStart()
+ stop := selectStatement.GetStop().GetStop()
+ input := selectStatement.GetStart().GetInputStream()
+ interval := antlr.NewInterval(start, stop)
+ e.selectBody = input.GetTextFromInterval(interval)
+ }
+}
diff --git a/backend/plugin/parser/tsql/query_span_test.go b/backend/plugin/parser/tsql/query_span_test.go
index edde4c1011..990c073d24 100644
--- a/backend/plugin/parser/tsql/query_span_test.go
+++ b/backend/plugin/parser/tsql/query_span_test.go
@@ -24,7 +24,7 @@ func TestGetQuerySpan(t *testing.T) {
IgnoreCaseSensitve bool `yaml:"ignoreCaseSensitive,omitempty"`
// Metadata is the protojson encoded storepb.DatabaseSchemaMetadata,
// if it's empty, we will use the defaultDatabaseMetadata.
- Metadata string `yaml:"metadata,omitempty"`
+ Metadata []string `yaml:"metadata,omitempty"`
QuerySpan *base.YamlQuerySpan `yaml:"querySpan,omitempty"`
}
@@ -36,13 +36,12 @@ func TestGetQuerySpan(t *testing.T) {
"test-data/query-span/case-sensitivity.yaml",
"test-data/query-span/query_type.yaml",
"test-data/query-span/predicate.yaml",
+ "test-data/query-span/regression.yaml",
}
)
a := require.New(t)
for _, testDataPath := range testDataPaths {
- testDataPath := testDataPath
-
yamlFile, err := os.Open(testDataPath)
a.NoError(err)
@@ -53,9 +52,13 @@ func TestGetQuerySpan(t *testing.T) {
a.NoError(yaml.Unmarshal(byteValue, &testCases))
for i, tc := range testCases {
- metadata := &storepb.DatabaseSchemaMetadata{}
- a.NoErrorf(common.ProtojsonUnmarshaler.Unmarshal([]byte(tc.Metadata), metadata), "cases %d", i+1)
- databaseMetadataGetter, databaseNameLister := buildMockDatabaseMetadataGetter([]*storepb.DatabaseSchemaMetadata{metadata})
+ var ms []*storepb.DatabaseSchemaMetadata
+ for _, metadata := range tc.Metadata {
+ storepbMetadata := &storepb.DatabaseSchemaMetadata{}
+ a.NoErrorf(common.ProtojsonUnmarshaler.Unmarshal([]byte(metadata), storepbMetadata), "cases %d", i+1)
+ ms = append(ms, storepbMetadata)
+ }
+ databaseMetadataGetter, databaseNameLister := buildMockDatabaseMetadataGetter(ms)
result, err := GetQuerySpan(context.TODO(), base.GetQuerySpanContext{
GetDatabaseMetadataFunc: databaseMetadataGetter,
ListDatabaseNamesFunc: databaseNameLister,
diff --git a/backend/plugin/parser/tsql/test-data/query-span/case-sensitivity.yaml b/backend/plugin/parser/tsql/test-data/query-span/case-sensitivity.yaml
index dd8e94b274..8ff39a9b4f 100644
--- a/backend/plugin/parser/tsql/test-data/query-span/case-sensitivity.yaml
+++ b/backend/plugin/parser/tsql/test-data/query-span/case-sensitivity.yaml
@@ -2,28 +2,29 @@
statement: SELECT dbo.mytable1.a FROM dbo.[mytable1] ;
defaultDatabase: db
ignoreCaseSensitive: true
- metadata: |-
- {
- "name": "db",
- "schemas": [
- {
- "name": "dbo",
- "tables": [
- {
- "name": "MyTable1",
- "columns": [
- {
- "name": "a"
- },
- {
- "name": "b"
- }
- ]
- }
- ]
- }
- ]
- }
+ metadata:
+ - |-
+ {
+ "name": "db",
+ "schemas": [
+ {
+ "name": "dbo",
+ "tables": [
+ {
+ "name": "MyTable1",
+ "columns": [
+ {
+ "name": "a"
+ },
+ {
+ "name": "b"
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ }
querySpan:
type: 1
results:
diff --git a/backend/plugin/parser/tsql/test-data/query-span/join.yaml b/backend/plugin/parser/tsql/test-data/query-span/join.yaml
index 3409630be7..a236409161 100644
--- a/backend/plugin/parser/tsql/test-data/query-span/join.yaml
+++ b/backend/plugin/parser/tsql/test-data/query-span/join.yaml
@@ -2,39 +2,40 @@
statement: SELECT t.* FROM MyTable1 t JOIN MyTable2 u ON t.a = u.id;
defaultDatabase: db
ignoreCaseSensitive: true
- metadata: |-
- {
- "name": "db",
- "schemas": [
- {
- "name": "dbo",
- "tables": [
- {
- "name": "MyTable1",
- "columns": [
- {
- "name": "a"
- },
- {
- "name": "b"
- }
- ]
- },
- {
- "name": "MyTable2",
- "columns": [
- {
- "name": "c"
- },
- {
- "name": "d"
- }
- ]
- }
- ]
- }
- ]
- }
+ metadata:
+ - |-
+ {
+ "name": "db",
+ "schemas": [
+ {
+ "name": "dbo",
+ "tables": [
+ {
+ "name": "MyTable1",
+ "columns": [
+ {
+ "name": "a"
+ },
+ {
+ "name": "b"
+ }
+ ]
+ },
+ {
+ "name": "MyTable2",
+ "columns": [
+ {
+ "name": "c"
+ },
+ {
+ "name": "d"
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ }
querySpan:
type: 1
results:
@@ -74,39 +75,40 @@
statement: SELECT t.a, t.b FROM MyTable1 t JOIN MyTable2 u ON t.a = u.id;
defaultDatabase: db
ignoreCaseSensitive: true
- metadata: |-
- {
- "name": "db",
- "schemas": [
- {
- "name": "dbo",
- "tables": [
- {
- "name": "MyTable1",
- "columns": [
- {
- "name": "a"
- },
- {
- "name": "b"
- }
- ]
- },
- {
- "name": "MyTable2",
- "columns": [
- {
- "name": "c"
- },
- {
- "name": "d"
- }
- ]
- }
- ]
- }
- ]
- }
+ metadata:
+ - |-
+ {
+ "name": "db",
+ "schemas": [
+ {
+ "name": "dbo",
+ "tables": [
+ {
+ "name": "MyTable1",
+ "columns": [
+ {
+ "name": "a"
+ },
+ {
+ "name": "b"
+ }
+ ]
+ },
+ {
+ "name": "MyTable2",
+ "columns": [
+ {
+ "name": "c"
+ },
+ {
+ "name": "d"
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ }
querySpan:
type: 1
results:
diff --git a/backend/plugin/parser/tsql/test-data/query-span/predicate.yaml b/backend/plugin/parser/tsql/test-data/query-span/predicate.yaml
index 0d06ee059c..a49e9d91d5 100644
--- a/backend/plugin/parser/tsql/test-data/query-span/predicate.yaml
+++ b/backend/plugin/parser/tsql/test-data/query-span/predicate.yaml
@@ -1,42 +1,43 @@
- statement: SELECT * FROM t WHERE a in (SELECT c FROM t1 WHERE CONTAINS(b, 'foo'))
defaultDatabase: db
ignoreCaseSensitive: true
- metadata: |-
- {
- "name": "db",
- "schemas": [
- {
- "name": "dbo",
- "tables": [
- {
- "name": "t",
- "columns": [
- {
- "name": "a"
- },
- {
- "name": "b"
- }
- ]
- },
- {
- "name": "t1",
- "columns": [
- {
- "name": "a"
- },
- {
- "name": "b"
- },
- {
- "name": "c"
- }
- ]
- }
- ]
- }
- ]
- }
+ metadata:
+ - |-
+ {
+ "name": "db",
+ "schemas": [
+ {
+ "name": "dbo",
+ "tables": [
+ {
+ "name": "t",
+ "columns": [
+ {
+ "name": "a"
+ },
+ {
+ "name": "b"
+ }
+ ]
+ },
+ {
+ "name": "t1",
+ "columns": [
+ {
+ "name": "a"
+ },
+ {
+ "name": "b"
+ },
+ {
+ "name": "c"
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ }
querySpan:
type: 1
results:
@@ -90,28 +91,29 @@
- statement: SELECT * FROM t WHERE a = 1
defaultDatabase: db
ignoreCaseSensitive: true
- metadata: |-
- {
- "name": "db",
- "schemas": [
- {
- "name": "dbo",
- "tables": [
- {
- "name": "t",
- "columns": [
- {
- "name": "a"
- },
- {
- "name": "b"
- }
- ]
- }
- ]
- }
- ]
- }
+ metadata:
+ - |-
+ {
+ "name": "db",
+ "schemas": [
+ {
+ "name": "dbo",
+ "tables": [
+ {
+ "name": "t",
+ "columns": [
+ {
+ "name": "a"
+ },
+ {
+ "name": "b"
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ }
querySpan:
type: 1
results:
diff --git a/backend/plugin/parser/tsql/test-data/query-span/query_type.yaml b/backend/plugin/parser/tsql/test-data/query-span/query_type.yaml
index e4261ff816..6d287bd88d 100644
--- a/backend/plugin/parser/tsql/test-data/query-span/query_type.yaml
+++ b/backend/plugin/parser/tsql/test-data/query-span/query_type.yaml
@@ -1,10 +1,11 @@
- description: Go
statement: GO
defaultDatabase: db
- metadata: |-
- {
- "name": "db"
- }
+ metadata:
+ - |-
+ {
+ "name": "db"
+ }
querySpan:
type: 1
results: []
@@ -13,10 +14,11 @@
- description: Declare variable
statement: DECLARE @a INT = 1;
defaultDatabase: db
- metadata: |-
- {
- "name": "db"
- }
+ metadata:
+ - |-
+ {
+ "name": "db"
+ }
querySpan:
type: 1
results: []
@@ -25,10 +27,11 @@
- description: Treat set statement as select
statement: SET DATEFIRST 7;
defaultDatabase: db
- metadata: |-
- {
- "name": "db"
- }
+ metadata:
+ - |-
+ {
+ "name": "db"
+ }
querySpan:
type: 1
results: []
@@ -37,10 +40,11 @@
- description: DML
statement: INSERT INTO dbo.t VALUES (1);
defaultDatabase: db
- metadata: |-
- {
- "name": "db"
- }
+ metadata:
+ - |-
+ {
+ "name": "db"
+ }
querySpan:
type: 5
results: []
@@ -49,10 +53,11 @@
- description: DDL
statement: ALTER TABLE dbo.doc_exa ADD column_b VARCHAR(20) NULL, column_c INT NULL;
defaultDatabase: db
- metadata: |-
- {
- "name": "db"
- }
+ metadata:
+ - |-
+ {
+ "name": "db"
+ }
querySpan:
type: 4
results: []
@@ -61,10 +66,11 @@
- description: system query
statement: SELECT * FROM INFORMATION_SCHEMA.TABLES;
defaultDatabase: db
- metadata: |-
- {
- "name": "db"
- }
+ metadata:
+ - |-
+ {
+ "name": "db"
+ }
querySpan:
type: 3
results: []
diff --git a/backend/plugin/parser/tsql/test-data/query-span/regression.yaml b/backend/plugin/parser/tsql/test-data/query-span/regression.yaml
new file mode 100644
index 0000000000..d5d4eaacef
--- /dev/null
+++ b/backend/plugin/parser/tsql/test-data/query-span/regression.yaml
@@ -0,0 +1,209 @@
+# Regression tests for T-SQL query span extraction fixes
+# These tests ensure that fixes for specific user-reported issues continue to work
+
+- description: Test VIEW with table alias - fix for BYT-7974 column resolution issue
+ statement: |-
+ SELECT a.ProductID FROM v_CMS_HMNUM_FUll a WHERE a.ProductID = 1
+ defaultDatabase: byt7974
+ ignoreCaseSensitive: true
+ metadata:
+ - |-
+ {
+ "name": "byt7974",
+ "schemas": [
+ {
+ "name": "dbo",
+ "views": [
+ {
+ "name": "v_CMS_HMNUM_FUll",
+ "definition": "CREATE VIEW [dbo].[v_CMS_HMNUM_FUll] AS SELECT ProductID, HMNUM FROM CMS_HMNUM"
+ }
+ ],
+ "tables": [
+ {
+ "name": "CMS_HMNUM",
+ "columns": [
+ {
+ "name": "ProductID"
+ },
+ {
+ "name": "HMNUM"
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ }
+ querySpan:
+ type: 1
+ results:
+ - name: ProductID
+ sourcecolumns:
+ - server: ""
+ database: byt7974
+ schema: dbo
+ table: CMS_HMNUM
+ column: ProductID
+ isplainfield: true
+ sourcefieldpaths: []
+ selectasterisk: false
+ sourcecolumns:
+ - server: ""
+ database: byt7974
+ schema: dbo
+ table: v_CMS_HMNUM_FUll
+ column: ""
+ predicatecolumns:
+ - server: ""
+ database: byt7974
+ schema: dbo
+ table: CMS_HMNUM
+ column: ProductID
+
+- description: Test VIEW with cross-database references - fix for database context switching
+ statement: |-
+ SELECT * FROM SecondDB..v_CrossDB_View JOIN TableA ON 1=1 WHERE IDA=IDB;
+ defaultDatabase: MainDB
+ ignoreCaseSensitive: true
+ metadata:
+ - |-
+ {
+ "name": "MainDB",
+ "schemas": [
+ {
+ "name": "dbo",
+ "tables": [
+ {
+ "name": "TableA",
+ "columns": [
+ {
+ "name": "IDA"
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ }
+ - |-
+ {
+ "name": "SecondDB",
+ "schemas": [
+ {
+ "name": "dbo",
+ "views": [
+ {
+ "name": "v_CrossDB_View",
+ "definition": "CREATE VIEW [dbo].[v_CrossDB_View] AS SELECT IDB FROM TableB"
+ }
+ ],
+ "tables": [
+ {
+ "name": "TableB",
+ "columns": [
+ {
+ "name": "IDB"
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ }
+ querySpan:
+ type: 1
+ results:
+ - name: IDB
+ sourcecolumns:
+ - server: ""
+ database: SecondDB
+ schema: dbo
+ table: TableB
+ column: IDB
+ isplainfield: true
+ sourcefieldpaths: []
+ selectasterisk: false
+ - name: IDA
+ sourcecolumns:
+ - server: ""
+ database: MainDB
+ schema: dbo
+ table: TableA
+ column: IDA
+ isplainfield: true
+ sourcefieldpaths: []
+ selectasterisk: false
+ sourcecolumns:
+ - server: ""
+ database: MainDB
+ schema: dbo
+ table: TableA
+ column: ""
+ - server: ""
+ database: SecondDB
+ schema: dbo
+ table: v_CrossDB_View
+ column: ""
+ predicatecolumns:
+ - server: ""
+ database: MainDB
+ schema: dbo
+ table: TableA
+ column: IDA
+ - server: ""
+ database: SecondDB
+ schema: dbo
+ table: TableB
+ column: IDB
+
+- description: Test simple correlated subquery - fix for outer table sources
+ statement: |-
+ SELECT HMNum FROM TableA WHERE HMNum = 'test'
+ defaultDatabase: WebPO
+ ignoreCaseSensitive: true
+ metadata:
+ - |-
+ {
+ "name": "WebPO",
+ "schemas": [
+ {
+ "name": "dbo",
+ "tables": [
+ {
+ "name": "TableA",
+ "columns": [
+ {
+ "name": "HMNum"
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ }
+ querySpan:
+ type: 1
+ results:
+ - name: HMNum
+ sourcecolumns:
+ - server: ""
+ database: WebPO
+ schema: dbo
+ table: TableA
+ column: HMNum
+ isplainfield: true
+ sourcefieldpaths: []
+ selectasterisk: false
+ sourcecolumns:
+ - server: ""
+ database: WebPO
+ schema: dbo
+ table: TableA
+ column: ""
+ predicatecolumns:
+ - server: ""
+ database: WebPO
+ schema: dbo
+ table: TableA
+ column: HMNum
\ No newline at end of file
diff --git a/backend/plugin/parser/tsql/test-data/query-span/standard.yaml b/backend/plugin/parser/tsql/test-data/query-span/standard.yaml
index 4e254813c4..5f59aa4a3d 100644
--- a/backend/plugin/parser/tsql/test-data/query-span/standard.yaml
+++ b/backend/plugin/parser/tsql/test-data/query-span/standard.yaml
@@ -5,34 +5,35 @@
select * from @temp where 1=1;
defaultDatabase: db
ignoreCaseSensitive: true
- metadata: |-
- {
- "name": "db",
- "schemas": [
- {
- "name": "dbo",
- "tables": [
- {
- "name": "MyTable1",
- "columns": [
- {
- "name": "a"
- },
- {
- "name": "b"
- }
- ]
- }
- ],
- "views": [
- {
- "name": "MyView1",
- "definition": "SELECT * FROM MyTable1"
- }
- ]
- }
- ]
- }
+ metadata:
+ - |-
+ {
+ "name": "db",
+ "schemas": [
+ {
+ "name": "dbo",
+ "tables": [
+ {
+ "name": "MyTable1",
+ "columns": [
+ {
+ "name": "a"
+ },
+ {
+ "name": "b"
+ }
+ ]
+ }
+ ],
+ "views": [
+ {
+ "name": "MyView1",
+ "definition": "CREATE VIEW [dbo].[MyView1] AS SELECT * FROM MyTable1"
+ }
+ ]
+ }
+ ]
+ }
querySpan:
type: 1
results:
@@ -52,34 +53,35 @@
statement: SELECT NEWID() as uuid;
defaultDatabase: db
ignoreCaseSensitive: true
- metadata: |-
- {
- "name": "db",
- "schemas": [
- {
- "name": "dbo",
- "tables": [
- {
- "name": "MyTable1",
- "columns": [
- {
- "name": "a"
- },
- {
- "name": "b"
- }
- ]
- }
- ],
- "views": [
- {
- "name": "MyView1",
- "definition": "SELECT * FROM MyTable1"
- }
- ]
- }
- ]
- }
+ metadata:
+ - |-
+ {
+ "name": "db",
+ "schemas": [
+ {
+ "name": "dbo",
+ "tables": [
+ {
+ "name": "MyTable1",
+ "columns": [
+ {
+ "name": "a"
+ },
+ {
+ "name": "b"
+ }
+ ]
+ }
+ ],
+ "views": [
+ {
+ "name": "MyView1",
+ "definition": "CREATE VIEW [dbo].[MyView1] AS SELECT * FROM MyTable1"
+ }
+ ]
+ }
+ ]
+ }
querySpan:
type: 1
results:
@@ -94,34 +96,35 @@
statement: SELECT * FROM MyView1;
defaultDatabase: db
ignoreCaseSensitive: true
- metadata: |-
- {
- "name": "db",
- "schemas": [
- {
- "name": "dbo",
- "tables": [
- {
- "name": "MyTable1",
- "columns": [
- {
- "name": "a"
- },
- {
- "name": "b"
- }
- ]
- }
- ],
- "views": [
- {
- "name": "MyView1",
- "definition": "SELECT * FROM MyTable1"
- }
- ]
- }
- ]
- }
+ metadata:
+ - |-
+ {
+ "name": "db",
+ "schemas": [
+ {
+ "name": "dbo",
+ "tables": [
+ {
+ "name": "MyTable1",
+ "columns": [
+ {
+ "name": "a"
+ },
+ {
+ "name": "b"
+ }
+ ]
+ }
+ ],
+ "views": [
+ {
+ "name": "MyView1",
+ "definition": "CREATE VIEW [dbo].[MyView1] AS SELECT * FROM MyTable1"
+ }
+ ]
+ }
+ ]
+ }
querySpan:
type: 1
results:
@@ -156,28 +159,29 @@
statement: SELECT * FROM MyTable1;
defaultDatabase: db
ignoreCaseSensitive: true
- metadata: |-
- {
- "name": "db",
- "schemas": [
- {
- "name": "dbo",
- "tables": [
- {
- "name": "MyTable1",
- "columns": [
- {
- "name": "a"
- },
- {
- "name": "b"
- }
- ]
- }
- ]
- }
- ]
- }
+ metadata:
+ - |-
+ {
+ "name": "db",
+ "schemas": [
+ {
+ "name": "dbo",
+ "tables": [
+ {
+ "name": "MyTable1",
+ "columns": [
+ {
+ "name": "a"
+ },
+ {
+ "name": "b"
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ }
querySpan:
type: 1
results:
@@ -212,28 +216,29 @@
statement: SELECT T1.* FROM MyTable1 AS T1;
defaultDatabase: db
ignoreCaseSensitive: true
- metadata: |-
- {
- "name": "db",
- "schemas": [
- {
- "name": "dbo",
- "tables": [
- {
- "name": "MyTable1",
- "columns": [
- {
- "name": "a"
- },
- {
- "name": "b"
- }
- ]
- }
- ]
- }
- ]
- }
+ metadata:
+ - |-
+ {
+ "name": "db",
+ "schemas": [
+ {
+ "name": "dbo",
+ "tables": [
+ {
+ "name": "MyTable1",
+ "columns": [
+ {
+ "name": "a"
+ },
+ {
+ "name": "b"
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ }
querySpan:
type: 1
results:
@@ -268,39 +273,40 @@
statement: SELECT (SELECT MAX(d) FROM MyTable2) FROM MyTable1;
defaultDatabase: db
ignoreCaseSensitive: true
- metadata: |-
- {
- "name": "db",
- "schemas": [
- {
- "name": "dbo",
- "tables": [
- {
- "name": "MyTable1",
- "columns": [
- {
- "name": "a"
- },
- {
- "name": "b"
- }
- ]
- },
- {
- "name": "MyTable2",
- "columns": [
- {
- "name": "c"
- },
- {
- "name": "d"
- }
- ]
- }
- ]
- }
- ]
- }
+ metadata:
+ - |-
+ {
+ "name": "db",
+ "schemas": [
+ {
+ "name": "dbo",
+ "tables": [
+ {
+ "name": "MyTable1",
+ "columns": [
+ {
+ "name": "a"
+ },
+ {
+ "name": "b"
+ }
+ ]
+ },
+ {
+ "name": "MyTable2",
+ "columns": [
+ {
+ "name": "c"
+ },
+ {
+ "name": "d"
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ }
querySpan:
type: 1
results:
@@ -330,39 +336,40 @@
statement: SELECT a FROM MyTable1 UNION SELECT c FROM MyTable2;
defaultDatabase: db
ignoreCaseSensitive: true
- metadata: |-
- {
- "name": "db",
- "schemas": [
- {
- "name": "dbo",
- "tables": [
- {
- "name": "MyTable1",
- "columns": [
- {
- "name": "a"
- },
- {
- "name": "b"
- }
- ]
- },
- {
- "name": "MyTable2",
- "columns": [
- {
- "name": "c"
- },
- {
- "name": "d"
- }
- ]
- }
- ]
- }
- ]
- }
+ metadata:
+ - |-
+ {
+ "name": "db",
+ "schemas": [
+ {
+ "name": "dbo",
+ "tables": [
+ {
+ "name": "MyTable1",
+ "columns": [
+ {
+ "name": "a"
+ },
+ {
+ "name": "b"
+ }
+ ]
+ },
+ {
+ "name": "MyTable2",
+ "columns": [
+ {
+ "name": "c"
+ },
+ {
+ "name": "d"
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ }
querySpan:
type: 1
results:
@@ -397,39 +404,40 @@
statement: SELECT a, b, c, d FROM MyTable1 JOIN MyTable2 ON MyTable1.a = MyTable2.d;
defaultDatabase: db
ignoreCaseSensitive: true
- metadata: |-
- {
- "name": "db",
- "schemas": [
- {
- "name": "dbo",
- "tables": [
- {
- "name": "MyTable1",
- "columns": [
- {
- "name": "a"
- },
- {
- "name": "b"
- }
- ]
- },
- {
- "name": "MyTable2",
- "columns": [
- {
- "name": "c"
- },
- {
- "name": "d"
- }
- ]
- }
- ]
- }
- ]
- }
+ metadata:
+ - |-
+ {
+ "name": "db",
+ "schemas": [
+ {
+ "name": "dbo",
+ "tables": [
+ {
+ "name": "MyTable1",
+ "columns": [
+ {
+ "name": "a"
+ },
+ {
+ "name": "b"
+ }
+ ]
+ },
+ {
+ "name": "MyTable2",
+ "columns": [
+ {
+ "name": "c"
+ },
+ {
+ "name": "d"
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ }
querySpan:
type: 1
results:
@@ -489,39 +497,40 @@
statement: SELECT a, b, c, d FROM MyTable1, MyTable2;
defaultDatabase: db
ignoreCaseSensitive: true
- metadata: |-
- {
- "name": "db",
- "schemas": [
- {
- "name": "dbo",
- "tables": [
- {
- "name": "MyTable1",
- "columns": [
- {
- "name": "a"
- },
- {
- "name": "b"
- }
- ]
- },
- {
- "name": "MyTable2",
- "columns": [
- {
- "name": "c"
- },
- {
- "name": "d"
- }
- ]
- }
- ]
- }
- ]
- }
+ metadata:
+ - |-
+ {
+ "name": "db",
+ "schemas": [
+ {
+ "name": "dbo",
+ "tables": [
+ {
+ "name": "MyTable1",
+ "columns": [
+ {
+ "name": "a"
+ },
+ {
+ "name": "b"
+ }
+ ]
+ },
+ {
+ "name": "MyTable2",
+ "columns": [
+ {
+ "name": "c"
+ },
+ {
+ "name": "d"
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ }
querySpan:
type: 1
results:
@@ -581,39 +590,40 @@
statement: SELECT tt.a, b FROM (SELECT * FROM MyTable1) AS tt;
defaultDatabase: db
ignoreCaseSensitive: true
- metadata: |-
- {
- "name": "db",
- "schemas": [
- {
- "name": "dbo",
- "tables": [
- {
- "name": "MyTable1",
- "columns": [
- {
- "name": "a"
- },
- {
- "name": "b"
- }
- ]
- },
- {
- "name": "MyTable2",
- "columns": [
- {
- "name": "c"
- },
- {
- "name": "d"
- }
- ]
- }
- ]
- }
- ]
- }
+ metadata:
+ - |-
+ {
+ "name": "db",
+ "schemas": [
+ {
+ "name": "dbo",
+ "tables": [
+ {
+ "name": "MyTable1",
+ "columns": [
+ {
+ "name": "a"
+ },
+ {
+ "name": "b"
+ }
+ ]
+ },
+ {
+ "name": "MyTable2",
+ "columns": [
+ {
+ "name": "c"
+ },
+ {
+ "name": "d"
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ }
querySpan:
type: 1
results:
@@ -648,39 +658,40 @@
statement: WITH tt1(aa, bb) AS ( SELECT a, b FROM MyTable1 ) SELECT tt1.aa, bb FROM tt1;
defaultDatabase: db
ignoreCaseSensitive: true
- metadata: |-
- {
- "name": "db",
- "schemas": [
- {
- "name": "dbo",
- "tables": [
- {
- "name": "MyTable1",
- "columns": [
- {
- "name": "a"
- },
- {
- "name": "b"
- }
- ]
- },
- {
- "name": "MyTable2",
- "columns": [
- {
- "name": "c"
- },
- {
- "name": "d"
- }
- ]
- }
- ]
- }
- ]
- }
+ metadata:
+ - |-
+ {
+ "name": "db",
+ "schemas": [
+ {
+ "name": "dbo",
+ "tables": [
+ {
+ "name": "MyTable1",
+ "columns": [
+ {
+ "name": "a"
+ },
+ {
+ "name": "b"
+ }
+ ]
+ },
+ {
+ "name": "MyTable2",
+ "columns": [
+ {
+ "name": "c"
+ },
+ {
+ "name": "d"
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ }
querySpan:
type: 1
results:
@@ -727,39 +738,40 @@
SELECT * FROM tt1 JOIN tt2 ON tt1.aa = tt2.cc;
defaultDatabase: db
ignoreCaseSensitive: true
- metadata: |-
- {
- "name": "db",
- "schemas": [
- {
- "name": "dbo",
- "tables": [
- {
- "name": "MyTable1",
- "columns": [
- {
- "name": "a"
- },
- {
- "name": "b"
- }
- ]
- },
- {
- "name": "MyTable2",
- "columns": [
- {
- "name": "c"
- },
- {
- "name": "d"
- }
- ]
- }
- ]
- }
- ]
- }
+ metadata:
+ - |-
+ {
+ "name": "db",
+ "schemas": [
+ {
+ "name": "dbo",
+ "tables": [
+ {
+ "name": "MyTable1",
+ "columns": [
+ {
+ "name": "a"
+ },
+ {
+ "name": "b"
+ }
+ ]
+ },
+ {
+ "name": "MyTable2",
+ "columns": [
+ {
+ "name": "c"
+ },
+ {
+ "name": "d"
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ }
querySpan:
type: 1
results:
@@ -825,31 +837,32 @@
SELECT * FROM cte_01;
defaultDatabase: db
ignoreCaseSensitive: true
- metadata: |-
- {
- "name": "db",
- "schemas": [
- {
- "name": "dbo",
- "tables": [
- {
- "name": "MyTable1",
- "columns": [
- {
- "name": "a"
- },
- {
- "name": "b"
- },
- {
- "name": "c"
- }
- ]
- }
- ]
- }
- ]
- }
+ metadata:
+ - |-
+ {
+ "name": "db",
+ "schemas": [
+ {
+ "name": "dbo",
+ "tables": [
+ {
+ "name": "MyTable1",
+ "columns": [
+ {
+ "name": "a"
+ },
+ {
+ "name": "b"
+ },
+ {
+ "name": "c"
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ }
querySpan:
type: 1
results: