influxdb-client 1.2.0.pre.503 → 1.2.0.pre.529

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: 369c8281b3985a0757703f1c68a95d25793508a8c1c3c6dd458646ae01c768d8
4
- data.tar.gz: 82c4dae23afd29ccb574a6314443ef53fc4fe3ff17f9f952d435c7522441d7e3
3
+ metadata.gz: '0350846a0e09c3e3aeb2cb139b9dd6e0ff29b2ecf8ec77f8cc99c571db645261'
4
+ data.tar.gz: e2c2e114b352b4e2334efc31516ab34648270ebc9af0b2a923367e6cc9b98f00
5
5
  SHA512:
6
- metadata.gz: 17c810f5d87978b3c7359031b52fa86d39c06d70bb118a15e4f686f5f0b515de2001bc77cae24bce50a1dec6d4f3b366b104997e657d61219586e266c67b3d4b
7
- data.tar.gz: 5255b4b24ffd03b9895c624a501e765881a944368cd31d41eb02c421b29344955ad941532df9d02b416acb0ab9a7ff389142c432fca974ecf301ef88ba3f7c88
6
+ metadata.gz: 526e08ed0e716028379040714ed54a995856c2517d646b3cb6aecc4ead0f182ca5aeaefd14c864fb871af50677db07877e058b47b83a385a91bf4d16d2aadd9a
7
+ data.tar.gz: eedc0d2bffb13eab86e8b42064f99543e37dd128a4bbcd43977c65ab444f45dba433cb25c1f9cd4fb28d2ec475bb4ce11ce3bfaf3632a8cf0963da61e140c796
data/.rubocop.yml CHANGED
@@ -31,7 +31,7 @@ Metrics/MethodLength:
31
31
  Metrics/ClassLength:
32
32
  Max: 200
33
33
  Metrics/AbcSize:
34
- Max: 30
34
+ Max: 40
35
35
  Metrics/CyclomaticComplexity:
36
36
  Max: 15
37
37
  Metrics/PerceivedComplexity:
data/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  ## 1.2.0 [unreleased]
2
2
 
3
+ ### Features
4
+ 1. [#23](https://github.com/influxdata/influxdb-client-ruby/issues/23): Added DeleteApi to delete time series data from InfluxDB.
5
+
3
6
  ### Bugs
4
7
  1. [#22](https://github.com/influxdata/influxdb-client-ruby/pull/22): Fixed batch write
5
8
 
data/README.md CHANGED
@@ -208,6 +208,27 @@ write_api = client.create_write_api
208
208
  write_api.write(data: ['h2o,location=west value=33i 15', point, hash])
209
209
  ```
210
210
 
211
+ ### Delete data
212
+
213
+ The [DeleteApi](https://github.com/influxdata/influxdb-client-ruby/blob/master/lib/influxdb2/client/delete_api.rb) supports deletes [points](https://v2.docs.influxdata.com/v2.0/reference/glossary/#point) from an InfluxDB bucket.
214
+
215
+ ```ruby
216
+ client = InfluxDB2::Client.new('http://localhost:9999', 'my-token',
217
+ bucket: 'my-bucket',
218
+ org: 'my-org',
219
+ precision: InfluxDB2::WritePrecision::NANOSECOND)
220
+
221
+ client.create_delete_api.delete(DateTime.rfc3339('2019-02-03T04:05:06+07:00'),
222
+ DateTime.rfc3339('2019-03-03T04:05:06+07:00'),
223
+ predicate: 'key1="value1" AND key2="value"')
224
+ ```
225
+
226
+ The time range could be specified as:
227
+
228
+ 1. String - `"2019-02-03T04:05:06+07:00"`
229
+ 1. DateTime - `DateTime.rfc3339('2019-03-03T04:05:06+07:00')`
230
+ 1. Time - `Time.utc(2015, 10, 16, 8, 20, 15)`
231
+
211
232
  ## Local tests
212
233
 
213
234
  ```
@@ -4,12 +4,7 @@
4
4
 
5
5
  SCRIPT_PATH="$( cd "$(dirname "$0")" || exit ; pwd -P )"
6
6
 
7
- # Generate OpenAPI generator
8
- #cd "${SCRIPT_PATH}"/../openapi-generator/ || exit
9
- #mvn clean install -DskipTests
10
-
11
7
  # delete old sources
12
- #rm "${SCRIPT_PATH}"/../influxdb_client/domain/*.py
13
8
  rm "${SCRIPT_PATH}"/../lib/influxdb2/client/models/*
14
9
 
15
10
  # Generate client
@@ -21,10 +16,8 @@ mkdir -p "${SCRIPT_PATH}"/../lib/influxdb2/client/models
21
16
  mv "${SCRIPT_PATH}"/../lib/influx_db2/models/* "${SCRIPT_PATH}"/../lib/influxdb2/client/models
22
17
 
23
18
  cd "${SCRIPT_PATH}"/../lib/influxdb2/client/models || exit
24
- rm -r $(ls | grep -v "\<query.rb\>\|\<dialect.rb\>")
19
+ rm -r $(ls | grep -v "\<dialect.rb\>\|\<query.rb\>\|\<delete_predicate_request.rb\>")
25
20
 
26
21
  # Clean
27
22
  rmdir "${SCRIPT_PATH}"/../lib/influx_db2/models
28
23
  rmdir "${SCRIPT_PATH}"/../lib/influx_db2/
29
-
30
- #rm -r $(ls | grep -v "\<query.rb\>\|\<dialect.rb\>")
@@ -24,5 +24,6 @@ require 'influxdb2/client/client'
24
24
  require 'influxdb2/client/influx_error'
25
25
  require 'influxdb2/client/write_api'
26
26
  require 'influxdb2/client/query_api'
27
+ require 'influxdb2/client/delete_api'
27
28
  require 'influxdb2/client/point'
28
29
  require 'influxdb2/client/flux_table'
@@ -70,6 +70,13 @@ module InfluxDB2
70
70
  QueryApi.new(options: @options)
71
71
  end
72
72
 
73
+ # Get the Delete API to delete time series data from InfluxDB.
74
+ #
75
+ # @return [DeleteApi] New instance of DeleteApi.
76
+ def create_delete_api
77
+ DeleteApi.new(options: @options)
78
+ end
79
+
73
80
  # Close all connections into InfluxDB 2.
74
81
  #
75
82
  # @return [ true ] Always true.
@@ -0,0 +1,80 @@
1
+ # The MIT License
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the "Software"), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in
11
+ # all copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ # THE SOFTWARE.
20
+
21
+ require_relative 'models/delete_predicate_request'
22
+
23
+ module InfluxDB2
24
+ # Delete time series data from InfluxDB
25
+ #
26
+ class DeleteApi < DefaultApi
27
+ # @param [Hash] options The options to be used by the client.
28
+ def initialize(options:)
29
+ super(options: options)
30
+ end
31
+
32
+ # Delete time series data from InfluxDB.
33
+ #
34
+ # @example
35
+ # delete('2019-02-03T04:05:06+07:00', '2019-04-03T04:05:06+07:00',
36
+ # predicate: 'key1="value1" AND key2="value"', bucket: 'my-bucket', org: 'my-org')
37
+ #
38
+ # @example
39
+ # delete(DateTime.rfc3339('2019-02-03T04:05:06+07:00'), DateTime.rfc3339('2019-03-03T04:05:06+07:00'),
40
+ # predicate: 'key1="value1" AND key2="value"', bucket: 'my-bucket', org: 'my-org')
41
+ #
42
+ # @param [Object] start Start time of interval to delete data.
43
+ # The start could be represent by [Time], [DateTime] or [String] formatted as RFC3339.
44
+ # @param [Object] stop Stop time of interval to delete data
45
+ # The stop could be represent by [Time], [DateTime] or [String] formatted as RFC3339.
46
+ # @param [String] predicate InfluxQL-like predicate Stop time of interval to delete data
47
+ # @param [String] bucket specifies the bucket to remove data from
48
+ # @param [String] org specifies the organization to remove data from
49
+ def delete(start, stop, predicate: nil, bucket: nil, org: nil)
50
+ delete_request = InfluxDB2::DeletePredicateRequest.new(start: _to_rfc3339(start), stop: _to_rfc3339(stop),
51
+ predicate: predicate)
52
+
53
+ _delete(delete_request, bucket: bucket, org: org)
54
+ end
55
+
56
+ private
57
+
58
+ def _delete(delete_request, bucket: nil, org: nil)
59
+ bucket_param = bucket || @options[:bucket]
60
+ org_param = org || @options[:org]
61
+ _check('bucket', bucket_param)
62
+ _check('org', org_param)
63
+
64
+ uri = URI.parse(File.join(@options[:url], '/api/v2/delete'))
65
+ uri.query = URI.encode_www_form(org: org_param, bucket: bucket_param)
66
+
67
+ _post(delete_request.to_body.to_json, uri)
68
+ end
69
+
70
+ def _to_rfc3339(time)
71
+ if time.is_a?(String)
72
+ time
73
+ elsif time.is_a?(Time)
74
+ _to_rfc3339(time.to_datetime)
75
+ elsif time.is_a?(DateTime)
76
+ _to_rfc3339(time.rfc3339)
77
+ end
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,215 @@
1
+ =begin
2
+ #Influx API Service
3
+
4
+ #No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
5
+
6
+ OpenAPI spec version: 0.1.0
7
+
8
+ Generated by: https://openapi-generator.tech
9
+ OpenAPI Generator version: 3.3.4
10
+
11
+ =end
12
+
13
+ require 'date'
14
+
15
+ module InfluxDB2
16
+ # The delete predicate request.
17
+ class DeletePredicateRequest
18
+ # RFC3339Nano
19
+ attr_accessor :start
20
+
21
+ # RFC3339Nano
22
+ attr_accessor :stop
23
+
24
+ # InfluxQL-like delete statement
25
+ attr_accessor :predicate
26
+
27
+ # Attribute mapping from ruby-style variable name to JSON key.
28
+ def self.attribute_map
29
+ {
30
+ :'start' => :'start',
31
+ :'stop' => :'stop',
32
+ :'predicate' => :'predicate'
33
+ }
34
+ end
35
+
36
+ # Attribute type mapping.
37
+ def self.openapi_types
38
+ {
39
+ :'start' => :'DateTime',
40
+ :'stop' => :'DateTime',
41
+ :'predicate' => :'String'
42
+ }
43
+ end
44
+
45
+ # Initializes the object
46
+ # @param [Hash] attributes Model attributes in the form of hash
47
+ def initialize(attributes = {})
48
+ return unless attributes.is_a?(Hash)
49
+
50
+ # convert string to symbol for hash key
51
+ attributes = attributes.each_with_object({}) { |(k, v), h| h[k.to_sym] = v }
52
+
53
+ if attributes.has_key?(:'start')
54
+ self.start = attributes[:'start']
55
+ end
56
+
57
+ if attributes.has_key?(:'stop')
58
+ self.stop = attributes[:'stop']
59
+ end
60
+
61
+ if attributes.has_key?(:'predicate')
62
+ self.predicate = attributes[:'predicate']
63
+ end
64
+ end
65
+
66
+ # Show invalid properties with the reasons. Usually used together with valid?
67
+ # @return Array for valid properties with the reasons
68
+ def list_invalid_properties
69
+ invalid_properties = Array.new
70
+ if @start.nil?
71
+ invalid_properties.push('invalid value for "start", start cannot be nil.')
72
+ end
73
+
74
+ if @stop.nil?
75
+ invalid_properties.push('invalid value for "stop", stop cannot be nil.')
76
+ end
77
+
78
+ invalid_properties
79
+ end
80
+
81
+ # Check to see if the all the properties in the model are valid
82
+ # @return true if the model is valid
83
+ def valid?
84
+ return false if @start.nil?
85
+ return false if @stop.nil?
86
+ true
87
+ end
88
+
89
+ # Checks equality by comparing each attribute.
90
+ # @param [Object] Object to be compared
91
+ def ==(o)
92
+ return true if self.equal?(o)
93
+ self.class == o.class &&
94
+ start == o.start &&
95
+ stop == o.stop &&
96
+ predicate == o.predicate
97
+ end
98
+
99
+ # @see the `==` method
100
+ # @param [Object] Object to be compared
101
+ def eql?(o)
102
+ self == o
103
+ end
104
+
105
+ # Calculates hash code according to all attributes.
106
+ # @return [Fixnum] Hash code
107
+ def hash
108
+ [start, stop, predicate].hash
109
+ end
110
+
111
+ # Builds the object from hash
112
+ # @param [Hash] attributes Model attributes in the form of hash
113
+ # @return [Object] Returns the model itself
114
+ def build_from_hash(attributes)
115
+ return nil unless attributes.is_a?(Hash)
116
+ self.class.openapi_types.each_pair do |key, type|
117
+ if type =~ /\AArray<(.*)>/i
118
+ # check to ensure the input is an array given that the the attribute
119
+ # is documented as an array but the input is not
120
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
121
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
122
+ end
123
+ elsif !attributes[self.class.attribute_map[key]].nil?
124
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
125
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
126
+ end
127
+
128
+ self
129
+ end
130
+
131
+ # Deserializes the data based on type
132
+ # @param string type Data type
133
+ # @param string value Value to be deserialized
134
+ # @return [Object] Deserialized data
135
+ def _deserialize(type, value)
136
+ case type.to_sym
137
+ when :DateTime
138
+ DateTime.parse(value)
139
+ when :Date
140
+ Date.parse(value)
141
+ when :String
142
+ value.to_s
143
+ when :Integer
144
+ value.to_i
145
+ when :Float
146
+ value.to_f
147
+ when :BOOLEAN
148
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
149
+ true
150
+ else
151
+ false
152
+ end
153
+ when :Object
154
+ # generic object (usually a Hash), return directly
155
+ value
156
+ when /\AArray<(?<inner_type>.+)>\z/
157
+ inner_type = Regexp.last_match[:inner_type]
158
+ value.map { |v| _deserialize(inner_type, v) }
159
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
160
+ k_type = Regexp.last_match[:k_type]
161
+ v_type = Regexp.last_match[:v_type]
162
+ {}.tap do |hash|
163
+ value.each do |k, v|
164
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
165
+ end
166
+ end
167
+ else # model
168
+ temp_model = InfluxDB2.const_get(type).new
169
+ temp_model.build_from_hash(value)
170
+ end
171
+ end
172
+
173
+ # Returns the string representation of the object
174
+ # @return [String] String presentation of the object
175
+ def to_s
176
+ to_hash.to_s
177
+ end
178
+
179
+ # to_body is an alias to to_hash (backward compatibility)
180
+ # @return [Hash] Returns the object in the form of hash
181
+ def to_body
182
+ to_hash
183
+ end
184
+
185
+ # Returns the object in the form of hash
186
+ # @return [Hash] Returns the object in the form of hash
187
+ def to_hash
188
+ hash = {}
189
+ self.class.attribute_map.each_pair do |attr, param|
190
+ value = self.send(attr)
191
+ next if value.nil?
192
+ hash[param] = _to_hash(value)
193
+ end
194
+ hash
195
+ end
196
+
197
+ # Outputs non-array value in the form of hash
198
+ # For object, use to_hash. Otherwise, just return the value
199
+ # @param [Object] value Any valid value
200
+ # @return [Hash] Returns the value in the form of hash
201
+ def _to_hash(value)
202
+ if value.is_a?(Array)
203
+ value.compact.map { |v| _to_hash(v) }
204
+ elsif value.is_a?(Hash)
205
+ {}.tap do |hash|
206
+ value.each { |k, v| hash[k] = _to_hash(v) }
207
+ end
208
+ elsif value.respond_to? :to_hash
209
+ value.to_hash
210
+ else
211
+ value
212
+ end
213
+ end
214
+ end
215
+ end
@@ -0,0 +1,100 @@
1
+ # The MIT License
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the "Software"), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in
11
+ # all copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ # THE SOFTWARE.
20
+
21
+ require 'test_helper'
22
+
23
+ class DeleteApiIntegrationTest < MiniTest::Test
24
+ def setup
25
+ WebMock.allow_net_connect!
26
+
27
+ @client = InfluxDB2::Client.new('http://localhost:9999', 'my-token',
28
+ bucket: 'my-bucket',
29
+ org: 'my-org',
30
+ precision: InfluxDB2::WritePrecision::NANOSECOND,
31
+ use_ssl: false)
32
+
33
+ now = Time.now.utc
34
+ @measurement = 'h2o_delete_' + now.to_i.to_s + +now.nsec.to_s
35
+
36
+ data = [InfluxDB2::Point.new(name: @measurement)
37
+ .add_tag('location', 'europe')
38
+ .add_field('level', 2)
39
+ .time(Time.utc(2015, 10, 15, 8, 20, 15), InfluxDB2::WritePrecision::MILLISECOND),
40
+ InfluxDB2::Point.new(name: @measurement)
41
+ .add_tag('location', 'us')
42
+ .add_field('level', 2)
43
+ .time(Time.utc(2016, 10, 15, 8, 20, 15), InfluxDB2::WritePrecision::MILLISECOND),
44
+ InfluxDB2::Point.new(name: @measurement)
45
+ .add_tag('location', 'india')
46
+ .add_field('level', 2)
47
+ .time(Time.utc(2017, 10, 15, 8, 20, 15), InfluxDB2::WritePrecision::MILLISECOND),
48
+ InfluxDB2::Point.new(name: @measurement)
49
+ .add_tag('location', 'europe')
50
+ .add_field('level', 2)
51
+ .time(Time.utc(2018, 10, 15, 8, 20, 15), InfluxDB2::WritePrecision::MILLISECOND)]
52
+
53
+ @client.create_write_api.write(data: data, precision: InfluxDB2::WritePrecision::MILLISECOND)
54
+
55
+ assert_equal 4, _query_count
56
+ end
57
+
58
+ def test_delete
59
+ @client.create_delete_api.delete(Time.utc(2015, 10, 16, 8, 20, 15), Time.utc(2020, 10, 16, 8, 20, 15),
60
+ predicate: 'location="europe"')
61
+
62
+ assert_equal 3, _query_count
63
+ end
64
+
65
+ def test_delete_without_predicate
66
+ @client.create_delete_api.delete(Time.utc(2016, 10, 15, 7, 20, 15), Time.utc(2018, 10, 14, 8, 20, 15))
67
+
68
+ assert_equal 2, _query_count
69
+ end
70
+
71
+ def test_delete_all
72
+ @client.create_delete_api.delete(Time.utc(2010, 10, 15, 7, 20, 15), Time.utc(2020, 10, 14, 8, 20, 15))
73
+
74
+ assert_equal 0, _query_count
75
+ end
76
+
77
+ def test_delete_without_interval
78
+ error = assert_raises InfluxDB2::InfluxError do
79
+ @client.create_delete_api.delete(nil, nil)
80
+ end
81
+
82
+ assert error.message.include?('invalid request'),
83
+ "Error message: '#{error.message}' doesn't contains 'invalid request'"
84
+ end
85
+
86
+ private
87
+
88
+ def _query_count
89
+ query = 'from(bucket: "my-bucket") |> range(start: 0) |> ' \
90
+ "filter(fn: (r) => r._measurement == \"#{@measurement}\") " \
91
+ '|> drop(columns: ["location"]) |> count()'
92
+
93
+ table = @client.create_query_api.query(query: InfluxDB2::Query.new(query: query,
94
+ dialect: InfluxDB2::QueryApi::DEFAULT_DIALECT,
95
+ type: nil))[0]
96
+ return 0 if table.nil?
97
+
98
+ table.records[0].value
99
+ end
100
+ end
@@ -0,0 +1,99 @@
1
+ # The MIT License
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the "Software"), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in
11
+ # all copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ # THE SOFTWARE.
20
+
21
+ require 'test_helper'
22
+
23
+ class DeleteApiTest < MiniTest::Test
24
+ def setup
25
+ WebMock.disable_net_connect!
26
+ end
27
+
28
+ def test_delete
29
+ stub_request(:any, 'http://localhost:9999/api/v2/delete?bucket=my-bucket&org=my-org')
30
+ .to_return(status: 204)
31
+ client = InfluxDB2::Client.new('http://localhost:9999', 'my-token',
32
+ bucket: 'my-bucket',
33
+ org: 'my-org',
34
+ precision: InfluxDB2::WritePrecision::NANOSECOND,
35
+ use_ssl: false)
36
+
37
+ client.create_delete_api.delete(Time.utc(2019, 10, 15, 8, 20, 15), Time.utc(2019, 11, 15, 8, 20, 15),
38
+ predicate: 'key1="value1" AND key2="value"', bucket: 'my-bucket', org: 'my-org')
39
+
40
+ body = '{"start":"2019-10-15T08:20:15+00:00","stop":"2019-11-15T08:20:15+00:00","predicate":"key1=\"value1\" ' \
41
+ 'AND key2=\"value\""}'
42
+
43
+ assert_requested(:post, 'http://localhost:9999/api/v2/delete?bucket=my-bucket&org=my-org', times: 1, body: body)
44
+ end
45
+
46
+ def test_delete_time_as_date_time
47
+ stub_request(:any, 'http://localhost:9999/api/v2/delete?bucket=my-bucket&org=my-org')
48
+ .to_return(status: 204)
49
+ client = InfluxDB2::Client.new('http://localhost:9999', 'my-token',
50
+ bucket: 'my-bucket',
51
+ org: 'my-org',
52
+ precision: InfluxDB2::WritePrecision::NANOSECOND,
53
+ use_ssl: false)
54
+
55
+ client.create_delete_api.delete(DateTime.rfc3339('2019-02-03T04:05:06+07:00'),
56
+ DateTime.rfc3339('2019-03-03T04:05:06+07:00'),
57
+ predicate: 'key1="value1" AND key2="value"', bucket: 'my-bucket', org: 'my-org')
58
+
59
+ body = '{"start":"2019-02-03T04:05:06+07:00","stop":"2019-03-03T04:05:06+07:00","predicate":"key1=\"value1\" ' \
60
+ 'AND key2=\"value\""}'
61
+
62
+ assert_requested(:post, 'http://localhost:9999/api/v2/delete?bucket=my-bucket&org=my-org', times: 1, body: body)
63
+ end
64
+
65
+ def test_delete_time_as_string
66
+ stub_request(:any, 'http://localhost:9999/api/v2/delete?bucket=my-bucket&org=my-org')
67
+ .to_return(status: 204)
68
+ client = InfluxDB2::Client.new('http://localhost:9999', 'my-token',
69
+ bucket: 'my-bucket',
70
+ org: 'my-org',
71
+ precision: InfluxDB2::WritePrecision::NANOSECOND,
72
+ use_ssl: false)
73
+
74
+ client.create_delete_api.delete('2019-02-03T04:05:06+07:00', '2019-04-03T04:05:06+07:00',
75
+ predicate: 'key1="value1" AND key2="value"', bucket: 'my-bucket', org: 'my-org')
76
+
77
+ body = '{"start":"2019-02-03T04:05:06+07:00","stop":"2019-04-03T04:05:06+07:00","predicate":"key1=\"value1\" ' \
78
+ 'AND key2=\"value\""}'
79
+
80
+ assert_requested(:post, 'http://localhost:9999/api/v2/delete?bucket=my-bucket&org=my-org', times: 1, body: body)
81
+ end
82
+
83
+ def test_without_predicate
84
+ stub_request(:any, 'http://localhost:9999/api/v2/delete?bucket=my-bucket&org=my-org')
85
+ .to_return(status: 204)
86
+ client = InfluxDB2::Client.new('http://localhost:9999', 'my-token',
87
+ bucket: 'my-bucket',
88
+ org: 'my-org',
89
+ precision: InfluxDB2::WritePrecision::NANOSECOND,
90
+ use_ssl: false)
91
+
92
+ client.create_delete_api.delete('2019-02-03T04:05:06+07:00', '2019-04-03T04:05:06+07:00',
93
+ bucket: 'my-bucket', org: 'my-org')
94
+
95
+ body = '{"start":"2019-02-03T04:05:06+07:00","stop":"2019-04-03T04:05:06+07:00"}'
96
+
97
+ assert_requested(:post, 'http://localhost:9999/api/v2/delete?bucket=my-bucket&org=my-org', times: 1, body: body)
98
+ end
99
+ end
@@ -33,7 +33,7 @@ class QueryApiIntegrationTest < MiniTest::Test
33
33
 
34
34
  def test_query
35
35
  now = Time.now.utc
36
- measurement = 'h2o_query_' + now.to_i.to_s
36
+ measurement = 'h2o_query_' + now.to_i.to_s + now.nsec.to_s
37
37
 
38
38
  @client.create_write_api.write(data: InfluxDB2::Point.new(name: measurement)
39
39
  .add_tag('location', 'europe')
@@ -35,7 +35,7 @@ class WriteApiIntegrationTest < MiniTest::Test
35
35
 
36
36
  now = Time.now.utc
37
37
 
38
- measurement = 'h2o_' + now.to_i.to_s
38
+ measurement = 'h2o_' + now.to_i.to_s + now.nsec.to_s
39
39
  point = InfluxDB2::Point.new(name: measurement)
40
40
  .add_tag('location', 'europe')
41
41
  .add_field('level', 2)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: influxdb-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0.pre.503
4
+ version: 1.2.0.pre.529
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jakub Bednar
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-02-20 00:00:00.000000000 Z
11
+ date: 2020-02-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -149,9 +149,11 @@ files:
149
149
  - lib/influxdb2/client.rb
150
150
  - lib/influxdb2/client/client.rb
151
151
  - lib/influxdb2/client/default_api.rb
152
+ - lib/influxdb2/client/delete_api.rb
152
153
  - lib/influxdb2/client/flux_csv_parser.rb
153
154
  - lib/influxdb2/client/flux_table.rb
154
155
  - lib/influxdb2/client/influx_error.rb
156
+ - lib/influxdb2/client/models/delete_predicate_request.rb
155
157
  - lib/influxdb2/client/models/dialect.rb
156
158
  - lib/influxdb2/client/models/query.rb
157
159
  - lib/influxdb2/client/point.rb
@@ -160,6 +162,8 @@ files:
160
162
  - lib/influxdb2/client/worker.rb
161
163
  - lib/influxdb2/client/write_api.rb
162
164
  - test/influxdb/client_test.rb
165
+ - test/influxdb/delete_api_integration_test.rb
166
+ - test/influxdb/delete_api_test.rb
163
167
  - test/influxdb/flux_csv_parser_test.rb
164
168
  - test/influxdb/point_test.rb
165
169
  - test/influxdb/query_api_integration_test.rb
@@ -197,6 +201,8 @@ specification_version: 4
197
201
  summary: Ruby library for InfluxDB 2.
198
202
  test_files:
199
203
  - test/influxdb/client_test.rb
204
+ - test/influxdb/delete_api_integration_test.rb
205
+ - test/influxdb/delete_api_test.rb
200
206
  - test/influxdb/flux_csv_parser_test.rb
201
207
  - test/influxdb/point_test.rb
202
208
  - test/influxdb/query_api_integration_test.rb