clickhouse-native 0.4.1-aarch64-linux-gnu → 0.6.0-aarch64-linux-gnu
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/clickhouse_native/client.rb +19 -1
- data/lib/clickhouse_native/pool.rb +12 -20
- data/lib/clickhouse_native/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f32459e08170ad3d746a116a2d18e20248ad1c02111a444bbd73fe985854548e
|
|
4
|
+
data.tar.gz: 3ce9cee80d2b7730b51433c2ffb3b1b3ab8516e4b490d83388dc2d4453efad3d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6022e3a874dd4277764748154965fc7f1461f5f10a2d46b752db886337d0d9c1e4cf277dc5b456059a3ec65f81174568bcc5fb268507e845807539ac03f46423
|
|
7
|
+
data.tar.gz: b06d6ac4bb900bc0ab67b88f821a75604e5d34998d88b743302e81f481806d0e3435c70c700efc63dbde5d56902f70e680c0cf083d73f048d05f2a8df1bbe9a3
|
|
@@ -16,6 +16,10 @@ module ClickhouseNative
|
|
|
16
16
|
# columns in DDL order (for Array<Array>).
|
|
17
17
|
# types may be supplied to skip the DESCRIBE lookup.
|
|
18
18
|
#
|
|
19
|
+
# The schema lookup is memoized per `(table, db_name)` on the client, so
|
|
20
|
+
# repeated inserts into the same table don't re-run DESCRIBE. Call
|
|
21
|
+
# `clear_schema_cache` after `ALTER TABLE` to invalidate.
|
|
22
|
+
#
|
|
19
23
|
# Hash keys not present in the schema raise ArgumentError — if you need
|
|
20
24
|
# to insert a subset, pass `columns:` explicitly.
|
|
21
25
|
def insert(table, rows, columns: nil, db_name: nil, types: nil)
|
|
@@ -33,6 +37,14 @@ module ClickhouseNative
|
|
|
33
37
|
insert_block(fq, col_pairs, row_arrays)
|
|
34
38
|
end
|
|
35
39
|
|
|
40
|
+
# Drop the memoized schema for a table (or all tables). Needed after
|
|
41
|
+
# DDL that changes column set or types, since insert-time schema
|
|
42
|
+
# lookups are cached per (table, db_name).
|
|
43
|
+
def clear_schema_cache(table = nil, db_name: nil)
|
|
44
|
+
return unless defined?(@schema_cache) && @schema_cache
|
|
45
|
+
table.nil? ? @schema_cache.clear : @schema_cache.delete([db_name, table.to_s])
|
|
46
|
+
end
|
|
47
|
+
|
|
36
48
|
def inspect
|
|
37
49
|
"#<#{self.class} #{host}:#{port}/#{database}>"
|
|
38
50
|
end
|
|
@@ -47,7 +59,7 @@ module ClickhouseNative
|
|
|
47
59
|
end
|
|
48
60
|
|
|
49
61
|
def columns_from_schema(table, rows, columns, db_name, fqn)
|
|
50
|
-
schema =
|
|
62
|
+
schema = cached_schema(table, db_name: db_name)
|
|
51
63
|
type_by_name = schema.to_h { |c| [c[:name], c[:type]] }
|
|
52
64
|
columns ||= rows.first.is_a?(Hash) ? rows.first.keys.map(&:to_s) : schema.map { |c| c[:name] }
|
|
53
65
|
columns.map do |name|
|
|
@@ -58,6 +70,12 @@ module ClickhouseNative
|
|
|
58
70
|
end
|
|
59
71
|
end
|
|
60
72
|
|
|
73
|
+
def cached_schema(table, db_name:)
|
|
74
|
+
@schema_cache ||= {}
|
|
75
|
+
@schema_cache[[db_name, table.to_s]] ||=
|
|
76
|
+
describe_table(table, db_name: db_name).freeze
|
|
77
|
+
end
|
|
78
|
+
|
|
61
79
|
def hash_rows_to_arrays(rows, col_pairs)
|
|
62
80
|
lookup = col_pairs.map { |n, _| [n.to_sym, n] }
|
|
63
81
|
rows.map { |h| lookup.map { |sym, str| h.fetch(sym) { h[str] } } }
|
|
@@ -4,8 +4,6 @@ require "connection_pool"
|
|
|
4
4
|
|
|
5
5
|
module ClickhouseNative
|
|
6
6
|
class Pool
|
|
7
|
-
STALE_IVAR = :@clickhouse_native_settings_stale
|
|
8
|
-
|
|
9
7
|
attr_reader :host, :port, :database
|
|
10
8
|
|
|
11
9
|
def initialize(host:, port:, database: "default", user: "default", password: "",
|
|
@@ -23,19 +21,20 @@ module ClickhouseNative
|
|
|
23
21
|
end
|
|
24
22
|
end
|
|
25
23
|
|
|
26
|
-
#
|
|
27
|
-
#
|
|
28
|
-
#
|
|
29
|
-
#
|
|
24
|
+
# On exception, discard the client rather than reuse it: an error
|
|
25
|
+
# path leaves the socket in an unknown state. The C++ binding issues
|
|
26
|
+
# ResetConnection, but a subsequent send can still surface buffered
|
|
27
|
+
# protocol errors from the prior aborted operation — those get
|
|
28
|
+
# attributed to whatever SQL we tried next (e.g. the SET reapplying
|
|
29
|
+
# session settings), producing misleading log lines and re-raises in
|
|
30
|
+
# unrelated code. A fresh socket + handshake is cheap relative to
|
|
31
|
+
# debugging that.
|
|
30
32
|
def with
|
|
31
33
|
@pool.with do |client|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
client.instance_variable_set(STALE_IVAR, true)
|
|
37
|
-
raise
|
|
38
|
-
end
|
|
34
|
+
yield client
|
|
35
|
+
rescue
|
|
36
|
+
@pool.discard_current_connection(&:close)
|
|
37
|
+
raise
|
|
39
38
|
end
|
|
40
39
|
end
|
|
41
40
|
|
|
@@ -73,13 +72,6 @@ module ClickhouseNative
|
|
|
73
72
|
|
|
74
73
|
private
|
|
75
74
|
|
|
76
|
-
def reapply_settings_if_stale(client)
|
|
77
|
-
return unless @set_sql
|
|
78
|
-
return unless client.instance_variable_get(STALE_IVAR)
|
|
79
|
-
client.execute(@set_sql)
|
|
80
|
-
client.instance_variable_set(STALE_IVAR, false)
|
|
81
|
-
end
|
|
82
|
-
|
|
83
75
|
# Render a `SET key1 = val1, key2 = val2` statement once at pool setup
|
|
84
76
|
# so every checked-out connection starts with the same session
|
|
85
77
|
# settings. Matches how the HTTP driver injected global_params per
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: clickhouse-native
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.6.0
|
|
5
5
|
platform: aarch64-linux-gnu
|
|
6
6
|
authors:
|
|
7
7
|
- Yuri Smirnov
|
|
@@ -15,14 +15,14 @@ dependencies:
|
|
|
15
15
|
requirements:
|
|
16
16
|
- - ">="
|
|
17
17
|
- !ruby/object:Gem::Version
|
|
18
|
-
version:
|
|
18
|
+
version: 2.5.4
|
|
19
19
|
type: :runtime
|
|
20
20
|
prerelease: false
|
|
21
21
|
version_requirements: !ruby/object:Gem::Requirement
|
|
22
22
|
requirements:
|
|
23
23
|
- - ">="
|
|
24
24
|
- !ruby/object:Gem::Version
|
|
25
|
-
version:
|
|
25
|
+
version: 2.5.4
|
|
26
26
|
description: A high-performance Ruby client for ClickHouse using the native binary
|
|
27
27
|
protocol via a C++ extension wrapping clickhouse-cpp.
|
|
28
28
|
email:
|