click_house 1.6.2 → 2.0.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 +4 -4
- data/.github/workflows/main.yml +16 -5
- data/.rubocop.yml +77 -1
- data/CHANGELOG.md +15 -0
- data/Gemfile.lock +41 -48
- data/Gemfile_faraday1 +11 -0
- data/Gemfile_faraday1.lock +111 -0
- data/Gemfile_faraday2 +1 -0
- data/Gemfile_faraday2.lock +88 -0
- data/Makefile +25 -0
- data/README.md +6 -20
- data/click_house.gemspec +4 -3
- data/docker-compose.yml +1 -1
- data/lib/click_house/ast/parser.rb +53 -0
- data/lib/click_house/ast/statement.rb +99 -0
- data/lib/click_house/ast/ticker.rb +42 -0
- data/lib/click_house/ast.rb +9 -0
- data/lib/click_house/config.rb +17 -1
- data/lib/click_house/connection.rb +3 -2
- data/lib/click_house/definition/column.rb +6 -3
- data/lib/click_house/definition/column_set.rb +3 -2
- data/lib/click_house/extend/configurable.rb +2 -0
- data/lib/click_house/extend/connection_inserting.rb +3 -3
- data/lib/click_house/extend/type_definition.rb +1 -10
- data/lib/click_house/middleware/logging.rb +1 -1
- data/lib/click_house/middleware/parse_csv.rb +5 -6
- data/lib/click_house/middleware/parse_json.rb +16 -0
- data/lib/click_house/middleware/parse_json_oj.rb +22 -0
- data/lib/click_house/middleware/raise_error.rb +8 -8
- data/lib/click_house/middleware/response_base.rb +45 -0
- data/lib/click_house/middleware.rb +3 -0
- data/lib/click_house/response/result_set.rb +58 -40
- data/lib/click_house/response.rb +1 -0
- data/lib/click_house/type/array_type.rb +6 -12
- data/lib/click_house/type/base_type.rb +25 -1
- data/lib/click_house/type/date_time64_type.rb +5 -1
- data/lib/click_house/type/date_time_type.rb +5 -1
- data/lib/click_house/type/decimal_type.rb +15 -1
- data/lib/click_house/type/low_cardinality_type.rb +15 -0
- data/lib/click_house/type/map_type.rb +15 -0
- data/lib/click_house/type/nullable_type.rb +6 -8
- data/lib/click_house/type/string_type.rb +1 -1
- data/lib/click_house/type/tuple_type.rb +15 -0
- data/lib/click_house/type.rb +3 -0
- data/lib/click_house/version.rb +1 -1
- data/lib/click_house.rb +10 -3
- metadata +38 -4
@@ -7,9 +7,33 @@ module ClickHouse
|
|
7
7
|
raise NotImplementedError, __method__
|
8
8
|
end
|
9
9
|
|
10
|
-
def
|
10
|
+
def cast_each(_value, *)
|
11
11
|
raise NotImplementedError, __method__
|
12
12
|
end
|
13
|
+
|
14
|
+
# @return [Boolean]
|
15
|
+
# true if type contains another type like Nullable(T) or Array(T)
|
16
|
+
def container?
|
17
|
+
false
|
18
|
+
end
|
19
|
+
|
20
|
+
# @return [Boolean]
|
21
|
+
# true if type is a Map
|
22
|
+
def map?
|
23
|
+
false
|
24
|
+
end
|
25
|
+
|
26
|
+
# @return [Boolean]
|
27
|
+
# true if type is a Tuple
|
28
|
+
def tuple?
|
29
|
+
false
|
30
|
+
end
|
31
|
+
|
32
|
+
# @return [Boolean]
|
33
|
+
# skip type from DDL statements
|
34
|
+
def ddl?
|
35
|
+
true
|
36
|
+
end
|
13
37
|
end
|
14
38
|
end
|
15
39
|
end
|
@@ -4,7 +4,11 @@ module ClickHouse
|
|
4
4
|
module Type
|
5
5
|
class DateTime64Type < BaseType
|
6
6
|
def cast(value, _precision = nil, tz = nil)
|
7
|
-
|
7
|
+
if tz
|
8
|
+
Time.find_zone(tz).parse(value)
|
9
|
+
else
|
10
|
+
Time.parse(value)
|
11
|
+
end
|
8
12
|
end
|
9
13
|
|
10
14
|
def serialize(value, precision = 3)
|
@@ -3,8 +3,22 @@
|
|
3
3
|
module ClickHouse
|
4
4
|
module Type
|
5
5
|
class DecimalType < BaseType
|
6
|
+
MAXIMUM = Float::DIG
|
7
|
+
|
8
|
+
# clickhouse:
|
9
|
+
# P - precision. Valid range: [ 1 : 76 ]. Determines how many decimal digits number can have (including fraction).
|
10
|
+
# S - scale. Valid range: [ 0 : P ]. Determines how many decimal digits fraction can have.
|
11
|
+
#
|
12
|
+
# when Oj parser @refs https://stackoverflow.com/questions/47885304/deserialise-json-numbers-as-bigdecimal
|
6
13
|
def cast(value, precision = Float::DIG, _scale = nil)
|
7
|
-
|
14
|
+
case value
|
15
|
+
when BigDecimal
|
16
|
+
value
|
17
|
+
when String
|
18
|
+
BigDecimal(value)
|
19
|
+
else
|
20
|
+
BigDecimal(value, precision > MAXIMUM ? MAXIMUM : precision)
|
21
|
+
end
|
8
22
|
end
|
9
23
|
|
10
24
|
def serialize(value, precision = Float::DIG, _scale = nil)
|
@@ -3,18 +3,16 @@
|
|
3
3
|
module ClickHouse
|
4
4
|
module Type
|
5
5
|
class NullableType < BaseType
|
6
|
-
|
7
|
-
|
8
|
-
def initialize(subtype)
|
9
|
-
@subtype = subtype
|
6
|
+
def cast_each(value, *_argv)
|
7
|
+
yield(value) unless value.nil?
|
10
8
|
end
|
11
9
|
|
12
|
-
def
|
13
|
-
|
10
|
+
def container?
|
11
|
+
true
|
14
12
|
end
|
15
13
|
|
16
|
-
def
|
17
|
-
|
14
|
+
def ddl?
|
15
|
+
false
|
18
16
|
end
|
19
17
|
end
|
20
18
|
end
|
data/lib/click_house/type.rb
CHANGED
@@ -14,7 +14,10 @@ module ClickHouse
|
|
14
14
|
autoload :DecimalType, 'click_house/type/decimal_type'
|
15
15
|
autoload :FixedStringType, 'click_house/type/fixed_string_type'
|
16
16
|
autoload :ArrayType, 'click_house/type/array_type'
|
17
|
+
autoload :TupleType, 'click_house/type/tuple_type'
|
18
|
+
autoload :MapType, 'click_house/type/map_type'
|
17
19
|
autoload :StringType, 'click_house/type/string_type'
|
18
20
|
autoload :IPType, 'click_house/type/ip_type'
|
21
|
+
autoload :LowCardinalityType, 'click_house/type/low_cardinality_type'
|
19
22
|
end
|
20
23
|
end
|
data/lib/click_house/version.rb
CHANGED
data/lib/click_house.rb
CHANGED
@@ -8,13 +8,14 @@ require 'logger'
|
|
8
8
|
require 'faraday'
|
9
9
|
require 'forwardable'
|
10
10
|
require 'bigdecimal'
|
11
|
-
require '
|
11
|
+
require 'active_support/core_ext/time/calculations'
|
12
12
|
require 'click_house/version'
|
13
13
|
require 'click_house/errors'
|
14
14
|
require 'click_house/response'
|
15
15
|
require 'click_house/type'
|
16
16
|
require 'click_house/middleware'
|
17
17
|
require 'click_house/extend'
|
18
|
+
require 'click_house/ast'
|
18
19
|
require 'click_house/util'
|
19
20
|
require 'click_house/definition'
|
20
21
|
|
@@ -26,6 +27,12 @@ module ClickHouse
|
|
26
27
|
autoload :Config, 'click_house/config'
|
27
28
|
autoload :Connection, 'click_house/connection'
|
28
29
|
|
30
|
+
add_type 'Array', Type::ArrayType.new
|
31
|
+
add_type 'Nullable', Type::NullableType.new
|
32
|
+
add_type 'Map', Type::MapType.new
|
33
|
+
add_type 'LowCardinality', Type::LowCardinalityType.new
|
34
|
+
add_type 'Tuple', Type::TupleType.new
|
35
|
+
|
29
36
|
%w[Date].each do |column|
|
30
37
|
add_type column, Type::DateType.new
|
31
38
|
end
|
@@ -38,11 +45,11 @@ module ClickHouse
|
|
38
45
|
add_type column, Type::DateTimeType.new
|
39
46
|
end
|
40
47
|
|
41
|
-
['DateTime64(%d, %s)'].each do |column|
|
48
|
+
['DateTime64(%d)', 'DateTime64(%d, %s)'].each do |column|
|
42
49
|
add_type column, Type::DateTime64Type.new
|
43
50
|
end
|
44
51
|
|
45
|
-
['Decimal(%d, %d)', 'Decimal32(%d)', 'Decimal64(%d)', 'Decimal128(%d)'].each do |column|
|
52
|
+
['Decimal(%d, %d)', 'Decimal32(%d)', 'Decimal64(%d)', 'Decimal128(%d)', 'Decimal256(%d)'].each do |column|
|
46
53
|
add_type column, Type::DecimalType.new
|
47
54
|
end
|
48
55
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: click_house
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aliaksandr Shylau
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-11-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -17,6 +17,9 @@ dependencies:
|
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.7'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '3'
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -24,8 +27,11 @@ dependencies:
|
|
24
27
|
- - ">="
|
25
28
|
- !ruby/object:Gem::Version
|
26
29
|
version: '1.7'
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '3'
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
34
|
+
name: activesupport
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
30
36
|
requirements:
|
31
37
|
- - ">="
|
@@ -66,6 +72,20 @@ dependencies:
|
|
66
72
|
- - ">="
|
67
73
|
- !ruby/object:Gem::Version
|
68
74
|
version: '0'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: oj
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
69
89
|
- !ruby/object:Gem::Dependency
|
70
90
|
name: rspec
|
71
91
|
requirement: !ruby/object:Gem::Requirement
|
@@ -136,6 +156,10 @@ files:
|
|
136
156
|
- CHANGELOG.md
|
137
157
|
- Gemfile
|
138
158
|
- Gemfile.lock
|
159
|
+
- Gemfile_faraday1
|
160
|
+
- Gemfile_faraday1.lock
|
161
|
+
- Gemfile_faraday2
|
162
|
+
- Gemfile_faraday2.lock
|
139
163
|
- LICENCE.txt
|
140
164
|
- Makefile
|
141
165
|
- README.md
|
@@ -147,6 +171,10 @@ files:
|
|
147
171
|
- doc/logo.svg
|
148
172
|
- docker-compose.yml
|
149
173
|
- lib/click_house.rb
|
174
|
+
- lib/click_house/ast.rb
|
175
|
+
- lib/click_house/ast/parser.rb
|
176
|
+
- lib/click_house/ast/statement.rb
|
177
|
+
- lib/click_house/ast/ticker.rb
|
150
178
|
- lib/click_house/config.rb
|
151
179
|
- lib/click_house/connection.rb
|
152
180
|
- lib/click_house/definition.rb
|
@@ -167,7 +195,10 @@ files:
|
|
167
195
|
- lib/click_house/middleware.rb
|
168
196
|
- lib/click_house/middleware/logging.rb
|
169
197
|
- lib/click_house/middleware/parse_csv.rb
|
198
|
+
- lib/click_house/middleware/parse_json.rb
|
199
|
+
- lib/click_house/middleware/parse_json_oj.rb
|
170
200
|
- lib/click_house/middleware/raise_error.rb
|
201
|
+
- lib/click_house/middleware/response_base.rb
|
171
202
|
- lib/click_house/response.rb
|
172
203
|
- lib/click_house/response/factory.rb
|
173
204
|
- lib/click_house/response/result_set.rb
|
@@ -183,8 +214,11 @@ files:
|
|
183
214
|
- lib/click_house/type/float_type.rb
|
184
215
|
- lib/click_house/type/integer_type.rb
|
185
216
|
- lib/click_house/type/ip_type.rb
|
217
|
+
- lib/click_house/type/low_cardinality_type.rb
|
218
|
+
- lib/click_house/type/map_type.rb
|
186
219
|
- lib/click_house/type/nullable_type.rb
|
187
220
|
- lib/click_house/type/string_type.rb
|
221
|
+
- lib/click_house/type/tuple_type.rb
|
188
222
|
- lib/click_house/type/undefined_type.rb
|
189
223
|
- lib/click_house/util.rb
|
190
224
|
- lib/click_house/util/pretty.rb
|
@@ -203,7 +237,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
203
237
|
requirements:
|
204
238
|
- - ">="
|
205
239
|
- !ruby/object:Gem::Version
|
206
|
-
version: 2.
|
240
|
+
version: 2.7.0
|
207
241
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
208
242
|
requirements:
|
209
243
|
- - ">="
|