Documentation
¶
Overview ¶
Package sqltables extracts the physical tables a SQL statement reads.
It is one extractor, not one per caller: semantic enrichment names the tables it must fetch context for, and the call catalog names the datasets a recorded query addressed (#1321). Both are answering the same question, and a second implementation of it would mean an enriched table and a cataloged target disagreeing about what a query touched.
The extraction is lexical (regular expressions over FROM and JOIN clauses, plus Trino's Elasticsearch raw_query table function), not a parser: it names what a statement plainly reads, drops common table expressions, and makes no claim about a statement it cannot parse.
Index ¶
Constants ¶
const KindOther = "other"
KindOther is the statement kind of anything StatementKind does not recognize, including an empty statement.
Variables ¶
This section is empty.
Functions ¶
func HasTopLevelOrderBy ¶ added in v1.142.0
HasTopLevelOrderBy reports whether a statement orders its own result: an ORDER BY outside every parenthesis, so not a subquery's, a CTE's or a window function's, none of which fix the order of the rows the statement returns. String literals, quoted identifiers and comments are skipped. A statement without one returns its rows in whatever order the engine produced them, which is what makes a limited subset of it arbitrary (#2057).
func StatementKind ¶ added in v1.141.0
StatementKind is the lowercased leading keyword of a SQL statement, after any leading comments and opening parentheses, when it is one of the keywords this package knows; KindOther otherwise. It reads no further than that word, so it never carries a literal, an identifier or the text.
func Summary ¶ added in v1.141.0
Summary is a low-cardinality description of a statement without its literals, in the shape the OpenTelemetry database conventions give db.query.summary: the statement's keyword in upper case followed by the tables it reads, at most three of them ("SELECT hive.sales.orders"). A statement this package does not recognize summarizes as its kind alone.
Types ¶
type Ref ¶
type Ref struct {
Catalog string
Schema string
Table string
FullPath string
Source string // "FROM", "JOIN", "TABLE_FUNCTION"
}
Ref is one table a statement reads.