Class: ClickhouseNative::Client
- Inherits:
-
Object
- Object
- ClickhouseNative::Client
- Includes:
- Logging
- Defined in:
- lib/clickhouse_native/client.rb,
lib/clickhouse_native/logging.rb,
ext/clickhouse_native/client.cpp
Constant Summary
Constants included from Logging
Instance Attribute Summary collapse
-
#database ⇒ Object
readonly
Returns the value of attribute database.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
Instance Method Summary collapse
-
#clear_schema_cache(table = nil, db_name: nil) ⇒ Object
Drop the memoized schema for a table (or all tables).
- #describe_table(table, db_name: nil) ⇒ Object
-
#insert(table, rows, columns: nil, db_name: nil, types: nil) ⇒ Object
insert(table, rows, columns: nil, db_name: nil, types: nil).
- #inspect ⇒ Object
Methods included from Logging
#execute, #insert_block, #query, #query_each, #query_value
Instance Attribute Details
#database ⇒ Object (readonly)
Returns the value of attribute database.
5 6 7 |
# File 'lib/clickhouse_native/client.rb', line 5 def database @database end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
5 6 7 |
# File 'lib/clickhouse_native/client.rb', line 5 def host @host end |
#logger ⇒ Object
Returns the value of attribute logger.
60 61 62 |
# File 'lib/clickhouse_native/logging.rb', line 60 def logger @logger end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
5 6 7 |
# File 'lib/clickhouse_native/client.rb', line 5 def port @port end |
Instance Method Details
#clear_schema_cache(table = nil, db_name: nil) ⇒ Object
Drop the memoized schema for a table (or all tables). Needed after DDL that changes column set or types, since insert-time schema lookups are cached per (table, db_name).
43 44 45 46 |
# File 'lib/clickhouse_native/client.rb', line 43 def clear_schema_cache(table = nil, db_name: nil) return unless defined?(@schema_cache) && @schema_cache table.nil? ? @schema_cache.clear : @schema_cache.delete([db_name, table.to_s]) end |
#describe_table(table, db_name: nil) ⇒ Object
7 8 9 10 |
# File 'lib/clickhouse_native/client.rb', line 7 def describe_table(table, db_name: nil) fq = db_name ? "#{db_name}.#{table}" : table query("DESCRIBE TABLE #{fq}") end |
#insert(table, rows, columns: nil, db_name: nil, types: nil) ⇒ Object
insert(table, rows, columns: nil, db_name: nil, types: nil)
rows may be Array<Hash=> Object> or Array<Array>. columns defaults to the first hash’s keys (for Array<Hash>) or all table columns in DDL order (for Array<Array>). types may be supplied to skip the DESCRIBE lookup.
The schema lookup is memoized per ‘(table, db_name)` on the client, so repeated inserts into the same table don’t re-run DESCRIBE. Call ‘clear_schema_cache` after `ALTER TABLE` to invalidate.
Hash keys not present in the schema raise ArgumentError — if you need to insert a subset, pass ‘columns:` explicitly.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/clickhouse_native/client.rb', line 25 def insert(table, rows, columns: nil, db_name: nil, types: nil) return 0 if rows.empty? fq = db_name ? "#{db_name}.#{table}" : table col_pairs = if types && columns zip_columns_and_types(columns, types) else columns_from_schema(table, rows, columns, db_name, fq) end row_arrays = rows.first.is_a?(Hash) ? hash_rows_to_arrays(rows, col_pairs) : rows insert_block(fq, col_pairs, row_arrays) end |
#inspect ⇒ Object
48 49 50 |
# File 'lib/clickhouse_native/client.rb', line 48 def inspect "#<#{self.class} #{host}:#{port}/#{database}>" end |