clickhouse-native 0.5.0 → 0.7.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b77997a63f9cfed092a0c26eccaeb63e34aad3072d52aff9f20f0bfaeaaeffa7
4
- data.tar.gz: ebdf9129e7e6bea78bc12dfe0b04246a14d7a03024bf49feb67dc43f3bf6435b
3
+ metadata.gz: 2f3cc163e6a966e97acca8801841c4512293870eaf1461d04cd3050a4aa4fd73
4
+ data.tar.gz: 0abc84555ec48af61ac6d56e526a22e1bb17ddf87ad417cba63bcfbf844a08ef
5
5
  SHA512:
6
- metadata.gz: db47e0695db8a4e7d448372fafb0aaa3c6483909d787cf970d6cd5386199df779c68247eb638f6a83ea3e18e12f2a45c505121351459abe65ce9b08ce01f0653
7
- data.tar.gz: f2c7c53106b186021a587e2b6a85991500cc322886b32392b6a32cc5da35e043914da6c43009804df8571496ce65f3e4e46c8497baf0b85ba2ecaaf4bde6ab9a
6
+ metadata.gz: fbf92ccd73e237a8855f158477c54c6a12b1a630e2cf2a145386b2d624bbc2080747c06e2a247c0e58a159b26c7192981309e1a769c9e6cf66d4badf82a7639c
7
+ data.tar.gz: ce7dc8ae0256db019528ae9d50b43710230a2f70939e82367a34d2c643a04a420199a689eec79dd11f845f6ea1b103ee7a8aba724881fe6432d57aa0aa4803e2
@@ -296,6 +296,20 @@ static VALUE value_at(const ColumnRef& col, size_t idx, const std::string& decla
296
296
 
297
297
  static void append_value(const ColumnRef& col, VALUE value);
298
298
 
299
+ // rb_hash_foreach callback: appends each key/value pair into the columns
300
+ // passed via the context pointer. Used by the Map encoder.
301
+ struct MapInsertCtx {
302
+ ColumnRef key_col;
303
+ ColumnRef val_col;
304
+ };
305
+
306
+ static int append_map_pair(VALUE key, VALUE val, VALUE arg) {
307
+ auto* ctx = reinterpret_cast<MapInsertCtx*>(arg);
308
+ append_value(ctx->key_col, key);
309
+ append_value(ctx->val_col, val);
310
+ return ST_CONTINUE;
311
+ }
312
+
299
313
  // Append a zero/default value; used for the nested column of Nullable when
300
314
  // the flag is set to null. We never expose these bytes to the caller.
301
315
  static void append_default(const ColumnRef& col) {
@@ -539,8 +553,8 @@ static void append_value(const ColumnRef& col, VALUE value) {
539
553
 
540
554
  case Type::LowCardinality: {
541
555
  // Only LowCardinality(String) and LowCardinality(Nullable(String))
542
- // are supported for insert in v1 this covers the profile-service
543
- // use case. Numeric LC dictionaries are rare and can wait.
556
+ // are supported for insert. Numeric LC dictionaries are rare and
557
+ // can wait.
544
558
  auto nested_type = type->As<LowCardinalityType>()->GetNestedType();
545
559
  bool nullable = nested_type->GetCode() == Type::Nullable;
546
560
  auto inner_type = nullable
@@ -576,6 +590,43 @@ static void append_value(const ColumnRef& col, VALUE value) {
576
590
  return;
577
591
  }
578
592
 
593
+ case Type::Map: {
594
+ // CH's wire format for Map(K, V) is Array(Tuple(K, V)). We build
595
+ // a one-row Map column holding all of this row's pairs and
596
+ // Append it to the target — ColumnMap exposes only Append(map),
597
+ // its underlying ColumnArray is private. Nil is treated as an
598
+ // empty map.
599
+ if (NIL_P(value)) value = rb_hash_new();
600
+ Check_Type(value, T_HASH);
601
+ auto map_type = type->As<MapType>();
602
+ auto key_type = map_type->GetKeyType();
603
+ auto val_type = map_type->GetValueType();
604
+
605
+ auto key_col = CreateColumnByType(key_type->GetName());
606
+ auto val_col = CreateColumnByType(val_type->GetName());
607
+ if (!key_col || !val_col) {
608
+ throw chn::EncoderFailure(
609
+ "cannot create columns for Map(" + key_type->GetName() +
610
+ ", " + val_type->GetName() + ")");
611
+ }
612
+
613
+ MapInsertCtx ctx{key_col, val_col};
614
+ rb_hash_foreach(value, append_map_pair, reinterpret_cast<VALUE>(&ctx));
615
+
616
+ auto src_tuple = std::make_shared<ColumnTuple>(
617
+ std::vector<ColumnRef>{key_col, val_col});
618
+
619
+ auto seed_tuple = std::make_shared<ColumnTuple>(std::vector<ColumnRef>{
620
+ CreateColumnByType(key_type->GetName()),
621
+ CreateColumnByType(val_type->GetName()),
622
+ });
623
+ auto seed_array = std::make_shared<ColumnArray>(seed_tuple);
624
+ seed_array->AppendAsColumn(src_tuple);
625
+
626
+ col->As<ColumnMap>()->Append(std::make_shared<ColumnMap>(seed_array));
627
+ return;
628
+ }
629
+
579
630
  default:
580
631
  throw chn::EncoderFailure(
581
632
  "cannot insert into column of type " + type->GetName());
@@ -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
- # Yields a client with the pool's session settings applied. If the
27
- # previous checkout raised (which, in this gem's C++ bindings, always
28
- # triggers a ResetConnection that wipes the session), re-apply the SET
29
- # before yielding. Exceptions re-raise after marking the client stale.
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
- reapply_settings_if_stale(client)
33
- begin
34
- yield client
35
- rescue
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ClickhouseNative
4
- VERSION = "0.5.0"
4
+ VERSION = "0.7.0"
5
5
  end
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.5.0
4
+ version: 0.7.0
5
5
  platform: ruby
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: '2.4'
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: '2.4'
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: