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

Function catalogNeeded

backend/plugin/parser/trino/completion.go:147–164  ·  view source on GitHub ↗

catalogNeeded reports whether the current completion statement needs this catalog's full schema/table/column metadata loaded: true for the session default catalog and for any catalog whose name appears in the statement text (a qualified reference such as catalog.schema.table). The reference check is

(normName, defaultDB, lowerStmt string)

Source from the content-addressed store, hash-verified

145// case-insensitive substring, which errs toward loading an occasional extra
146// catalog rather than missing a referenced one.
147func catalogNeeded(normName, defaultDB, lowerStmt string) bool {
148 if normName == "" {
149 return false
150 }
151 if defaultDB != "" && normName == defaultDB {
152 return true
153 }
154 // A catalog name containing a double quote is rewritten inside a quoted
155 // reference (each " is escaped as ""), so its normalized form is not a literal
156 // substring of the statement and the check below would miss it. Such names are
157 // vanishingly rare; load them unconditionally rather than drop completion. A
158 // double quote is the only identifier character Trino re-spells when quoting —
159 // every other character appears verbatim, so the substring check is reliable.
160 if strings.Contains(normName, `"`) {
161 return true
162 }
163 return strings.Contains(lowerStmt, strings.ToLower(normName))
164}
165
166// columnsOf converts storepb columns into omni catalog columns (names
167// normalized).

Callers 2

buildCompletionCatalogFunction · 0.85
buildSpanCatalogMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected