sqltables

package
v1.142.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 9, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

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

View Source
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

func HasTopLevelOrderBy(sql string) bool

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

func StatementKind(sql string) string

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

func Summary(sql string) string

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.

func Extract

func Extract(sql string) []Ref

Extract returns every physical table a statement reads. Uses regex for Trino-specific functions and standard table patterns. Combines ES raw_query indices with regular table references (e.g., JOINs). Filters out CTE references to only return physical tables.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL