Class: ClickHouse::SQL::Join

Inherits:
Object
  • Object
show all
Includes:
Part
Defined in:
lib/clickhouse/sql/join.rb

Instance Method Summary collapse

Constructor Details

#initialize(table, type:, as: nil, final: false, on:) ⇒ ClickHouse::SQL::Join

Builds a rendered JOIN clause.

Parameters:

  • table (String, Symbol, ClickHouse::SQL::Part)

    Trusted table expression.

  • type (String)

    JOIN type, for example INNER or LEFT.

  • as (String, Symbol, nil) (defaults to: nil)

    Optional table alias; only valid for string/symbol table names — a ClickHouse::SQL::Table handle owns its alias.

  • final (Boolean) (defaults to: false)

    Whether to append ClickHouse FINAL.

  • on (String, ClickHouse::SQL::Part, Array)

    ON conditions.

Raises:



17
18
19
20
21
22
23
24
# File 'lib/clickhouse/sql/join.rb', line 17

def initialize(table, type:, as: nil, final: false, on:)
  @table = ClickHouse::SQL.coerce_raw_expression(table)
  @type = type
  @alias_name = ClickHouse::SQL.resolve_table_alias(table, as)
  @final = final
  @on = Array(on).flatten.compact.map { |condition| ClickHouse::SQL.coerce_expression(condition) }
  raise Error, "JOIN requires at least one ON condition" if @on.empty?
end

Instance Method Details

#placeholder_typesHash{Symbol=>String}

Returns ClickHouse placeholder types used by the JOIN.

Returns:

  • (Hash{Symbol=>String})

    Placeholder types keyed by name.



51
52
53
# File 'lib/clickhouse/sql/join.rb', line 51

def placeholder_types
  ClickHouse::SQL.collect_placeholder_types([@table, *@on])
end

#placeholdersHash{Symbol=>Object}

Returns typed placeholder values used by the JOIN.

Returns:

  • (Hash{Symbol=>Object})

    Placeholder values keyed by name.



44
45
46
# File 'lib/clickhouse/sql/join.rb', line 44

def placeholders
  ClickHouse::SQL.collect_placeholders([@table, *@on])
end

#to_redacted_sql(bind_index_manager) ⇒ String

Renders the JOIN with typed placeholders replaced by bind markers.

Parameters:

Returns:

  • (String)

    Redacted SQL JOIN clause.



37
38
39
# File 'lib/clickhouse/sql/join.rb', line 37

def to_redacted_sql(bind_index_manager)
  render(redacted: true, bind_index_manager:)
end

#to_sqlString

Renders the JOIN with ClickHouse typed placeholders intact.

Returns:

  • (String)

    SQL JOIN clause.



29
30
31
# File 'lib/clickhouse/sql/join.rb', line 29

def to_sql
  render(redacted: false)
end