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

Function GetQuerySpan

backend/plugin/parser/base/interface.go:209–243  ·  view source on GitHub ↗

GetQuerySpan gets the span of a query from pre-split statements. The interface will return the query spans with non-critical errors, or return an error if the query is invalid. Callers should split the SQL first using SplitMultiSQL and pass the resulting []Statement.

(ctx context.Context, gCtx GetQuerySpanContext, engine storepb.Engine, statements []Statement, database, schema string, ignoreCaseSensitive bool)

Source from the content-addressed store, hash-verified

207// The interface will return the query spans with non-critical errors, or return an error if the query is invalid.
208// Callers should split the SQL first using SplitMultiSQL and pass the resulting []Statement.
209func GetQuerySpan(ctx context.Context, gCtx GetQuerySpanContext, engine storepb.Engine, statements []Statement, database, schema string, ignoreCaseSensitive bool) ([]*QuerySpan, error) {
210 f, ok := spans[engine]
211 if !ok {
212 return nil, nil
213 }
214 gCtx.Engine = engine
215 gCtx.TempTables = make(map[string]*PhysicalTable)
216 var results []*QuerySpan
217 var nonEmptyStatements []Statement
218 for _, stmt := range statements {
219 if stmt.Empty {
220 continue
221 }
222 nonEmptyStatements = append(nonEmptyStatements, stmt)
223 result, err := f(ctx, gCtx, stmt, database, schema, ignoreCaseSensitive)
224 if err != nil {
225 // Try to unwrap the error to see if it's a ResourceNotFoundError to decrease the error noise.
226 // TODO(d): remove resource not found error checks.
227 var resourceNotFound *ResourceNotFoundError
228 if errors.As(err, &resourceNotFound) {
229 return nil, resourceNotFound
230 }
231 var typeNotSupported *TypeNotSupportedError
232 if errors.As(err, &typeNotSupported) {
233 return nil, typeNotSupported
234 }
235 return nil, err
236 }
237 results = append(results, result)
238 }
239 if engine == storepb.Engine_MSSQL {
240 tsqlRecognizeExplainType(results, nonEmptyStatements)
241 }
242 return results, nil
243}
244
245// RegisterTransformDMLToSelect registers the transformDMLToSelect function for the engine.
246func RegisterTransformDMLToSelect(engine storepb.Engine, f TransformDMLToSelectFunc) {

Callers 3

getResourcesForMySQLFunction · 0.92
getResourcesForPostgresFunction · 0.92
getResourcesForRedshiftFunction · 0.92

Calls 2

fFunction · 0.85
tsqlRecognizeExplainTypeFunction · 0.85

Tested by

no test coverage detected