MCPcopy Index your code
hub / github.com/bytebase/bytebase / GetQuerySpan

Function GetQuerySpan

backend/plugin/parser/mongodb/query_span.go:18–42  ·  view source on GitHub ↗

GetQuerySpan returns a QuerySpan for a MongoDB shell statement. It classifies the statement type and populates PredicatePaths from predicate fields extracted by masking analysis.

(_ context.Context, _ base.GetQuerySpanContext, stmt base.Statement, _ string, _ string, _ bool)

Source from the content-addressed store, hash-verified

16// It classifies the statement type and populates PredicatePaths from
17// predicate fields extracted by masking analysis.
18func GetQuerySpan(_ context.Context, _ base.GetQuerySpanContext, stmt base.Statement, _ string, _ string, _ bool) (*base.QuerySpan, error) {
19 queryType := GetQueryType(stmt.Text)
20 span := &base.QuerySpan{
21 Type: queryType,
22 }
23
24 analysis, err := AnalyzeMaskingStatement(stmt.Text)
25 if err != nil {
26 return span, err
27 }
28 if analysis == nil {
29 return span, nil
30 }
31
32 span.MongoDBAnalysis = analysis
33
34 if len(analysis.PredicateFields) > 0 {
35 span.PredicatePaths = make(map[string]*base.PathAST, len(analysis.PredicateFields))
36 for _, field := range analysis.PredicateFields {
37 span.PredicatePaths[field] = dotPathToPathAST(field)
38 }
39 }
40
41 return span, nil
42}
43
44// dotPathToPathAST converts a dot-delimited field path (e.g. "contact.phone")
45// into a PathAST with ItemSelector nodes.

Callers 2

TestGetQuerySpanFunction · 0.70

Calls 3

GetQueryTypeFunction · 0.85
AnalyzeMaskingStatementFunction · 0.85
dotPathToPathASTFunction · 0.85

Tested by 2

TestGetQuerySpanFunction · 0.56