tablename

package
v0.11.643 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package tablename centralizes how Bruin parses and validates multi-component asset/table names (e.g. `table`, `schema.table`, `catalog.schema.table`).

Historically every platform package re-implemented its own `strings.Split(name, ".")` switch with subtly different rules, which led to the database component of three-part names being silently dropped. This package replaces those ad-hoc switches with a single capability-driven parser.

It is intentionally a leaf package: it must not import pkg/pipeline (which owns AssetTypeConnectionMapping and would create an import cycle). Callers pass the platform string produced by pipeline.AssetTypeConnectionMapping.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContainerToCreate

func ContainerToCreate(name string, transform func(string) string) (string, bool)

ContainerToCreate returns the catalog/database component (the first segment) that should be ensured to exist for a three-part name (catalog.schema.table), with transform applied. ok is false for names with fewer than three components — there is no parent container to create — or for names with empty components.

This is the parent of the schema returned by SchemaToCreate, and is only meaningful for platforms whose top-level container can be created with SQL (e.g. Snowflake `CREATE DATABASE`, Databricks `CREATE CATALOG`).

func SchemaToCreate

func SchemaToCreate(name string, transform func(string) string) (string, bool)

SchemaToCreate returns the schema identifier that should be ensured to exist for an asset materialized as name, qualified by its catalog/database when the name is three-part (catalog.schema.table) so the schema is created in the named container rather than the connection's default. It returns ok=false when there is no schema to create (a single-component name) or the name has more components than a three-level identifier.

transform is applied to each component (e.g. strings.ToUpper for Snowflake, strings.ToLower for DuckDB) so the result — used both as the CREATE SCHEMA target and the dedup cache key — matches how the platform stores identifiers.

Types

type Capability

type Capability struct {
	// Platform is the connection/platform key, matching the values in
	// pipeline.AssetTypeConnectionMapping (e.g. "snowflake", "mssql").
	Platform string

	// MinComponents and MaxComponents bound how many dot-separated components a
	// name may have. A three-level platform sets MaxComponents to 3.
	MinComponents int
	MaxComponents int

	// Labels names each level for the widest supported form, used in error
	// messages and to document intent: [catalog-ish, schema-ish, table].
	// e.g. Snowflake -> {"database", "schema", "table"};
	//      BigQuery  -> {"project", "dataset", "table"}.
	Labels [3]string

	// Unbounded marks platforms (e.g. Dremio) that accept arbitrary-depth paths.
	// Component-count validation is skipped for them and they are not parsed into
	// the fixed catalog/schema/table shape.
	Unbounded bool

	// FormatDesc is the human-readable description of accepted formats, surfaced
	// in lint messages (e.g. "`schema.table` or `database.schema.table`").
	FormatDesc string
}

Capability describes how a single platform interprets multi-component table names. It is the single source of truth for both runtime parsing and lint validation.

func For

func For(platform string) (Capability, bool)

For returns the table-name capability for a platform string (as produced by pipeline.AssetTypeConnectionMapping). The boolean is false for platforms that do not have table-name semantics (e.g. non-SQL targets), in which case callers must skip component-count validation entirely.

func (Capability) CheckName

func (c Capability) CheckName(raw string) error

CheckName validates the component count and shape of raw without resolving it. It rejects empty components and counts outside the platform's [Min,Max] range. Unbounded platforms (e.g. Dremio) only get the empty-component check.

func (Capability) Parse

func (c Capability) Parse(raw string, d Defaults) (TableName, error)

Parse splits raw into components and right-aligns them: the last component is always the table, the next is the schema, and (only when the platform allows three components) the first is the catalog. Missing leading components are filled from d. It returns an error when CheckName fails.

Parse is not meaningful for Unbounded platforms (Dremio) and should not be used for them; their runtime code keeps its own path handling.

type Defaults

type Defaults struct {
	Catalog string
	Schema  string
}

Defaults supplies the leading components to fall back on when the raw name omits them. They come from the platform's connection config (e.g. Snowflake's configured Database and Schema).

type TableName

type TableName struct {
	Catalog string // database / catalog / project
	Schema  string // schema / dataset
	Table   string
}

TableName is a parsed, component-resolved table identifier. Absent components are the empty string (e.g. Catalog == "" for a two-component name with no catalog supplied or defaulted).

func (TableName) QualifiedSchema

func (t TableName) QualifiedSchema(sep string) string

QualifiedSchema returns the schema qualified by the catalog when present, e.g. "db" + "." + "schema" => "db.schema", or just "schema". Returns "" when there is no schema component.

func (TableName) String

func (t TableName) String(sep string) string

String renders the full qualified name, joining the present components with sep (e.g. "db.schema.table").

func (TableName) Upper

func (t TableName) Upper() TableName

Upper returns a copy with every present component upper-cased. Snowflake and MSSQL information_schema lookups compare against upper-cased identifiers.

Jump to

Keyboard shortcuts

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