Class: ClickHouse::SQL::Table
- Inherits:
-
Object
- Object
- ClickHouse::SQL::Table
- Includes:
- Part
- Defined in:
- lib/clickhouse/sql/table.rb
Overview
A validated table reference that qualifies column references.
A table handle renders as its table name in FROM/JOIN position, and
builds qualified column references via #[] so shared fragments stay
unambiguous when a query joins tables with overlapping column names.
Instance Attribute Summary collapse
-
#alias_name ⇒ String?
readonly
Validated table alias, if any.
-
#name ⇒ String
readonly
Validated table name.
Instance Method Summary collapse
-
#[](column) ⇒ ClickHouse::SQL::Raw
Builds a qualified column reference using the alias when present.
-
#columns(*names) ⇒ Array<ClickHouse::SQL::Raw>
Builds qualified column references for many columns at once.
-
#initialize(name, as: nil) ⇒ ClickHouse::SQL::Table
constructor
Builds a validated table handle.
-
#qualifier ⇒ String
Returns the name this table's columns are qualified with.
-
#to_redacted_sql(_bind_index_manager = ClickHouse::SQL::BindIndexManager.new) ⇒ String
Renders the table name for redacted logs.
-
#to_sql ⇒ String
Renders the table name for FROM/JOIN position.
Methods included from Part
#placeholder_types, #placeholders
Constructor Details
#initialize(name, as: nil) ⇒ ClickHouse::SQL::Table
Builds a validated table handle.
35 36 37 38 |
# File 'lib/clickhouse/sql/table.rb', line 35 def initialize(name, as: nil) @name = validate_identifier!(name) @alias_name = as.nil? ? nil : ClickHouse::SQL.validate_alias!(as) end |
Instance Attribute Details
#alias_name ⇒ String? (readonly)
Returns Validated table alias, if any.
28 29 30 |
# File 'lib/clickhouse/sql/table.rb', line 28 def alias_name @alias_name end |
#name ⇒ String (readonly)
Returns Validated table name.
25 26 27 |
# File 'lib/clickhouse/sql/table.rb', line 25 def name @name end |
Instance Method Details
#[](column) ⇒ ClickHouse::SQL::Raw
Builds a qualified column reference using the alias when present.
44 45 46 |
# File 'lib/clickhouse/sql/table.rb', line 44 def [](column) Raw.new("#{qualifier}.#{validate_identifier!(column)}") end |
#columns(*names) ⇒ Array<ClickHouse::SQL::Raw>
Builds qualified column references for many columns at once.
Accepts names as arguments or arrays (t.columns(%i[id timestamp])).
SelectQuery#select flattens arrays, so the result can be passed with or
without a splat.
56 57 58 |
# File 'lib/clickhouse/sql/table.rb', line 56 def columns(*names) names.flatten.map { |name| self[name] } end |
#qualifier ⇒ String
Returns the name this table's columns are qualified with.
63 64 65 |
# File 'lib/clickhouse/sql/table.rb', line 63 def qualifier @alias_name || @name end |
#to_redacted_sql(_bind_index_manager = ClickHouse::SQL::BindIndexManager.new) ⇒ String
Renders the table name for redacted logs.
78 79 80 |
# File 'lib/clickhouse/sql/table.rb', line 78 def to_redacted_sql(_bind_index_manager = ClickHouse::SQL::BindIndexManager.new) @name end |
#to_sql ⇒ String
Renders the table name for FROM/JOIN position.
70 71 72 |
# File 'lib/clickhouse/sql/table.rb', line 70 def to_sql @name end |