clickhouse

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultSchemaRefreshInterval is the refresh interval for schema discovery.
	DefaultSchemaRefreshInterval = 15 * time.Minute

	// DefaultSchemaQueryTimeout is the timeout for individual schema queries.
	DefaultSchemaQueryTimeout = 60 * time.Second
)

Variables

This section is empty.

Functions

func RegisterSchemaResources

func RegisterSchemaResources(
	log logrus.FieldLogger,
	reg module.ResourceRegistry,
	client ClickHouseSchemaClient,
)

RegisterSchemaResources registers ClickHouse schema resources with the registry.

Types

type ClickHouseSchemaClient

type ClickHouseSchemaClient interface {
	// Start initializes the client and fetches initial schema data.
	Start(ctx context.Context) error
	// Stop stops background refresh.
	Stop() error
	// WaitForReady blocks until the initial schema fetch completes or ctx is cancelled.
	WaitForReady(ctx context.Context) error
	// GetAllTables returns all tables across all clusters.
	GetAllTables() map[string]*ClusterTables
	// GetTable returns schema for a specific table (searches all clusters).
	GetTable(tableName string) (*TableSchema, string, bool)
}

ClickHouseSchemaClient fetches and caches ClickHouse schema information.

func NewClickHouseSchemaClient

func NewClickHouseSchemaClient(
	log logrus.FieldLogger,
	cfg ClickHouseSchemaConfig,
	proxySvc proxy.Service,
) ClickHouseSchemaClient

NewClickHouseSchemaClient creates a new schema discovery client.

type ClickHouseSchemaConfig

type ClickHouseSchemaConfig struct {
	RefreshInterval time.Duration
	QueryTimeout    time.Duration
	Datasources     []SchemaDiscoveryDatasource
}

ClickHouseSchemaConfig holds configuration for schema discovery.

type ClusterTables

type ClusterTables struct {
	ClusterName string                  `json:"cluster_name"`
	Tables      map[string]*TableSchema `json:"tables"`
	LastUpdated time.Time               `json:"last_updated"`
}

ClusterTables represents tables available in a ClickHouse cluster.

type ClusterTablesSummary

type ClusterTablesSummary struct {
	Tables      []*TableSummary `json:"tables"`
	TableCount  int             `json:"table_count"`
	LastUpdated string          `json:"last_updated"`
}

ClusterTablesSummary is a compact summary of tables in a cluster.

type Config

type Config struct {
	SchemaDiscovery SchemaDiscoveryConfig `yaml:"schema_discovery"`
}

Config holds the ClickHouse module configuration.

type Module

type Module struct {
	// contains filtered or unexported fields
}

Module implements the module.Module interface for ClickHouse.

func New

func New() *Module

New creates a new ClickHouse module.

func (*Module) ApplyDefaults

func (p *Module) ApplyDefaults()

ApplyDefaults sets default values before validation.

func (*Module) DatasourceInfo

func (p *Module) DatasourceInfo() []types.DatasourceInfo

DatasourceInfo returns datasource metadata for datasources:// resources.

func (*Module) Examples

func (p *Module) Examples() map[string]types.ExampleCategory

Examples returns query examples for the ClickHouse module.

func (*Module) GettingStartedSnippet

func (p *Module) GettingStartedSnippet() string

GettingStartedSnippet returns ClickHouse-specific getting-started content.

func (*Module) Init

func (p *Module) Init(rawConfig []byte) error

Init parses the raw YAML config for this module.

func (*Module) InitFromDiscovery

func (p *Module) InitFromDiscovery(datasources []types.DatasourceInfo) error

InitFromDiscovery initializes the module from discovered datasources.

func (*Module) Name

func (p *Module) Name() string

func (*Module) PythonAPIDocs

func (p *Module) PythonAPIDocs() map[string]types.ModuleDoc

PythonAPIDocs returns the ClickHouse module documentation.

func (*Module) RegisterResources

func (p *Module) RegisterResources(log logrus.FieldLogger, reg module.ResourceRegistry) error

RegisterResources registers ClickHouse schema resources.

func (*Module) SandboxEnv

func (p *Module) SandboxEnv() (map[string]string, error)

SandboxEnv returns environment variables for the sandbox.

func (*Module) SchemaClient

func (p *Module) SchemaClient() ClickHouseSchemaClient

SchemaClient returns the schema discovery client, or nil if not initialized.

func (*Module) SetProxyClient

func (p *Module) SetProxyClient(client proxy.Service)

SetProxyClient injects the proxy service for schema discovery.

func (*Module) Start

func (p *Module) Start(ctx context.Context) error

Start performs async initialization (schema discovery).

func (*Module) Stop

func (p *Module) Stop(_ context.Context) error

Stop cleans up resources.

func (*Module) Validate

func (p *Module) Validate() error

Validate checks that the parsed config is valid.

type SchemaDiscoveryConfig

type SchemaDiscoveryConfig struct {
	// Enabled controls whether schema discovery is active. Defaults to true if datasources are configured.
	Enabled *bool `yaml:"enabled,omitempty"`

	// RefreshInterval is the duration between schema refresh cycles. Defaults to 15 minutes.
	RefreshInterval time.Duration `yaml:"refresh_interval,omitempty"`

	// Datasources lists the ClickHouse datasources to discover schemas from.
	// Each entry references a proxy-exposed datasource by name.
	// If empty, all proxy datasources are used.
	Datasources []SchemaDiscoveryDatasource `yaml:"datasources"`
}

SchemaDiscoveryConfig holds configuration for ClickHouse schema discovery.

func (*SchemaDiscoveryConfig) IsEnabled

func (c *SchemaDiscoveryConfig) IsEnabled() bool

IsEnabled returns whether schema discovery is enabled. Defaults to true; set enabled=false to disable explicitly.

type SchemaDiscoveryDatasource

type SchemaDiscoveryDatasource struct {
	// Name references a ClickHouse datasource by its proxy name.
	Name string `yaml:"name"`

	// Cluster is the logical cluster name used in schema resources (e.g., "xatu", "xatu-cbt").
	// Defaults to Name when empty.
	Cluster string `yaml:"cluster"`
}

SchemaDiscoveryDatasource maps a proxy datasource name to a logical cluster name for schema discovery.

type TableColumn

type TableColumn struct {
	Name         string `json:"name"`
	Type         string `json:"type"`
	Comment      string `json:"comment,omitempty"`
	DefaultType  string `json:"default_type,omitempty"`
	DefaultValue string `json:"default_value,omitempty"`
}

TableColumn represents a column in a ClickHouse table.

type TableDetailResponse

type TableDetailResponse struct {
	Table   *TableSchema `json:"table"`
	Cluster string       `json:"cluster"`
}

TableDetailResponse is the response for clickhouse://tables/{table_name}.

type TableSchema

type TableSchema struct {
	Name            string        `json:"name"`
	Engine          string        `json:"engine,omitempty"`
	Columns         []TableColumn `json:"columns"`
	Networks        []string      `json:"networks,omitempty"`
	HasNetworkCol   bool          `json:"has_network_column"`
	CreateStatement string        `json:"create_statement,omitempty"`
	Comment         string        `json:"comment,omitempty"`
}

TableSchema represents the full schema of a ClickHouse table.

type TableSummary

type TableSummary struct {
	Name          string `json:"name"`
	ColumnCount   int    `json:"column_count"`
	HasNetworkCol bool   `json:"has_network_column"`
}

TableSummary is a compact overview of a table for the list view. Use clickhouse://tables/{table_name} for detailed schema including networks.

type TablesListResponse

type TablesListResponse struct {
	Description string                           `json:"description"`
	Clusters    map[string]*ClusterTablesSummary `json:"clusters"`
	Usage       string                           `json:"usage"`
}

TablesListResponse is the response for clickhouse://tables.

Jump to

Keyboard shortcuts

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