clickhouse-native 0.3.1 → 0.4.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: cbf19153b9c176c74fb8f20afb63e729234e03d3c8603b68746c474cabd53fe4
4
- data.tar.gz: a8400e1c62470dce319fd655e4fa90a930848e1e76134cc2dec02c978b6fb011
3
+ metadata.gz: 84034f8663b9af177af04d904900a1ede1c2de7de03947133b58fa65a3029d25
4
+ data.tar.gz: a2cf65ae0192a802c5f15e81a2a3576bbd1ec91969cd01972164c8880fb09f98
5
5
  SHA512:
6
- metadata.gz: d48367dcae10c7921dfd2021a8e99af178e97708a314f15d3c30a38c33118ba027e47fc8eef2a5eaa60f3c257a2f6ecb6c2b48565cfa045d23f79da77691026d
7
- data.tar.gz: 7080239fb14c0b7e1a0787942ea1a000749d36732744253dd9d1c7705bafea055970efb0a7f0163b480282b92b9e6abe520a36f044db8cf609b0de4587b50930
6
+ metadata.gz: 6d4c2c608f0329b3da01af0b159cc9b3fb81d3b1d32045e93ac6b71b43843a9c1cc0c7ba977114d16511eed26c6e40ac9aede8a5072b7e19e089ba9d15b35a16
7
+ data.tar.gz: d5b0664013e9b0f52c3c0b880751f81aa4a6bcb5ab99cfba9b87e5cdbaa74c3b499ec0f5a0b3747a9c11d3d8febed1dae01c1c679054e74aa106dccb458d84e7
@@ -101,7 +101,22 @@ static int64_t pow10_i64(size_t n) {
101
101
  return r;
102
102
  }
103
103
 
104
- static VALUE value_at(const ColumnRef& col, size_t idx) {
104
+ static VALUE value_at(const ColumnRef& col, size_t idx, const std::string& declared_type = {}) {
105
+ // clickhouse-cpp normalises Bool -> UInt8 at column-construction time,
106
+ // so at the codec layer we see UInt8 and can't tell Bool apart without
107
+ // the declared type string that came over the wire. The patched vendor
108
+ // tree preserves it on Block; we consume it here for top-level columns.
109
+ // Nested occurrences (Array(Bool), Map(_, Bool)) are not handled — the
110
+ // declared type for nested children is not threaded through recursion.
111
+ if (declared_type == "Bool") {
112
+ return col->As<ColumnUInt8>()->At(idx) ? Qtrue : Qfalse;
113
+ }
114
+ if (declared_type == "Nullable(Bool)") {
115
+ auto n = col->As<ColumnNullable>();
116
+ if (n->IsNull(idx)) return Qnil;
117
+ return n->Nested()->As<ColumnUInt8>()->At(idx) ? Qtrue : Qfalse;
118
+ }
119
+
105
120
  auto type = col->Type();
106
121
  switch (type->GetCode()) {
107
122
  case Type::Int8: return INT2NUM(col->As<ColumnInt8>()->At(idx));
@@ -736,7 +751,8 @@ static VALUE ch_client_query(VALUE self, VALUE rb_sql) {
736
751
  for (size_t r = 0; r < nrows; r++) {
737
752
  VALUE h = rb_hash_new();
738
753
  for (size_t cc = 0; cc < ncols; cc++) {
739
- rb_hash_aset(h, ID2SYM(col_ids[cc]), value_at(block[cc], r));
754
+ rb_hash_aset(h, ID2SYM(col_ids[cc]),
755
+ value_at(block[cc], r, block.GetColumnType(cc)));
740
756
  }
741
757
  rb_ary_push(rows, h);
742
758
  }
@@ -765,7 +781,7 @@ static VALUE ch_client_query_value(VALUE self, VALUE rb_sql) {
765
781
  c->client->Select(sql, [&](const Block& block) {
766
782
  if (seen) return;
767
783
  if (block.GetRowCount() == 0 || block.GetColumnCount() == 0) return;
768
- out = value_at(block[0], 0);
784
+ out = value_at(block[0], 0, block.GetColumnType(0));
769
785
  seen = true;
770
786
  });
771
787
  return out;
@@ -914,7 +930,8 @@ static VALUE yield_rows_body(VALUE arg) {
914
930
  for (size_t r = 0; r < nrows; r++) {
915
931
  VALUE h = rb_hash_new();
916
932
  for (size_t cc = 0; cc < ncols; cc++) {
917
- rb_hash_aset(h, ID2SYM(state->col_ids[cc]), value_at(block[cc], r));
933
+ rb_hash_aset(h, ID2SYM(state->col_ids[cc]),
934
+ value_at(block[cc], r, block.GetColumnType(cc)));
918
935
  }
919
936
  rb_funcall(state->user_proc, rb_intern("call"), 1, h);
920
937
  }
@@ -35,6 +35,24 @@ unless File.exist?(File.join(VENDOR, "CMakeLists.txt"))
35
35
  MSG
36
36
  end
37
37
 
38
+ # Apply in-tree patches to the vendored clickhouse-cpp before CMake
39
+ # configures/builds it. Patches are idempotent: skip any that already
40
+ # apply in reverse (meaning they've been applied previously).
41
+ PATCHES_DIR = File.expand_path("patches", EXT_DIR)
42
+ if Dir.exist?(PATCHES_DIR)
43
+ Dir[File.join(PATCHES_DIR, "*.patch")].each do |patch|
44
+ # -R --check: does the patch apply in reverse? If yes, already applied.
45
+ already_applied = system(
46
+ "patch", "-R", "--dry-run", "-p1", "-s", "-f",
47
+ "-d", VENDOR, "-i", patch,
48
+ out: File::NULL, err: File::NULL
49
+ )
50
+ next if already_applied
51
+ system("patch", "-p1", "-s", "-f", "-d", VENDOR, "-i", patch) or
52
+ fatal("failed to apply patch: #{patch}")
53
+ end
54
+ end
55
+
38
56
  unless find_executable("cmake")
39
57
  fatal <<~MSG
40
58
  CMake is required to build the vendored clickhouse-cpp library
@@ -0,0 +1,74 @@
1
+ diff --git a/clickhouse/block.cpp b/clickhouse/block.cpp
2
+ index 519cfa4..15334c5 100644
3
+ --- a/clickhouse/block.cpp
4
+ +++ b/clickhouse/block.cpp
5
+ @@ -53,13 +53,17 @@ Block::Block(size_t cols, size_t rows)
6
+ Block::~Block() = default;
7
+
8
+ void Block::AppendColumn(const std::string& name, const ColumnRef& col) {
9
+ + AppendColumn(name, col, std::string());
10
+ +}
11
+ +
12
+ +void Block::AppendColumn(const std::string& name, const ColumnRef& col, const std::string& type) {
13
+ if (columns_.empty()) {
14
+ rows_ = col->Size();
15
+ } else if (col->Size() != rows_) {
16
+ throw ValidationError("all columns in block must have same count of rows. Name: ["+name+"], rows: ["+std::to_string(rows_)+"], columns: [" + std::to_string(col->Size())+"]");
17
+ }
18
+
19
+ - columns_.push_back(ColumnItem{name, col});
20
+ + columns_.push_back(ColumnItem{name, col, type});
21
+ }
22
+
23
+ /// Count of columns in the block.
24
+ diff --git a/clickhouse/block.h b/clickhouse/block.h
25
+ index a32cd02..d2263cb 100644
26
+ --- a/clickhouse/block.h
27
+ +++ b/clickhouse/block.h
28
+ @@ -67,6 +67,11 @@ public:
29
+
30
+ /// Append named column to the block.
31
+ void AppendColumn(const std::string& name, const ColumnRef& col);
32
+ + /// Same, but preserves the declared wire type string (e.g. "Bool",
33
+ + /// "Nullable(Bool)") alongside the column. clickhouse-cpp normalises
34
+ + /// some types at column construction (Bool -> UInt8, etc.), so keep the
35
+ + /// original for callers who need to recover the true declared type.
36
+ + void AppendColumn(const std::string& name, const ColumnRef& col, const std::string& type);
37
+
38
+ /// Count of columns in the block.
39
+ size_t GetColumnCount() const;
40
+ @@ -85,6 +90,13 @@ public:
41
+ return columns_.at(idx).name;
42
+ }
43
+
44
+ + /// Declared wire type string for the column at `idx` (e.g. "Bool",
45
+ + /// "Nullable(Bool)"). Empty for columns appended via the two-arg
46
+ + /// AppendColumn overload.
47
+ + const std::string& GetColumnType(size_t idx) const {
48
+ + return columns_.at(idx).type;
49
+ + }
50
+ +
51
+ /// Convenience method to wipe out all rows from all columns
52
+ void Clear();
53
+
54
+ @@ -103,6 +115,7 @@ private:
55
+ struct ColumnItem {
56
+ std::string name;
57
+ ColumnRef column;
58
+ + std::string type;
59
+ };
60
+
61
+ BlockInfo info_;
62
+ diff --git a/clickhouse/client.cpp b/clickhouse/client.cpp
63
+ index a8c8ea6..d81f636 100644
64
+ --- a/clickhouse/client.cpp
65
+ +++ b/clickhouse/client.cpp
66
+ @@ -784,7 +784,7 @@ bool Client::Impl::ReadBlock(InputStream& input, Block* block) {
67
+ throw ProtocolError("can't load column '" + name + "' of type " + type);
68
+ }
69
+
70
+ - block->AppendColumn(name, col);
71
+ + block->AppendColumn(name, col, type);
72
+ } else {
73
+ throw UnimplementedError(std::string("unsupported column type: ") + type);
74
+ }
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ClickhouseNative
4
- VERSION = "0.3.1"
4
+ VERSION = "0.4.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.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuri Smirnov
@@ -34,6 +34,7 @@ extra_rdoc_files: []
34
34
  files:
35
35
  - ext/clickhouse_native/client.cpp
36
36
  - ext/clickhouse_native/extconf.rb
37
+ - ext/clickhouse_native/patches/0001-preserve-declared-column-type.patch
37
38
  - ext/clickhouse_native/vendor/clickhouse-cpp/.clang-format
38
39
  - ext/clickhouse_native/vendor/clickhouse-cpp/.git
39
40
  - ext/clickhouse_native/vendor/clickhouse-cpp/.gitattributes