elastic-esql 0.3.0 → 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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/elastic/esql.rb +14 -54
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ee4efdbcbcfd0ced3cc7d373b9fe58719f3434c995a75112ce5c2740509b8840
4
- data.tar.gz: 4c11d6fd4dfd95b27e34bd189904c83abf469ac06c06a3672d170bac1ae1e30f
3
+ metadata.gz: f7837c640aa915808d6c720d4cd53bdcfe3210fbff0a5e9b900a0c0adcc3ed7a
4
+ data.tar.gz: 6f3cc673984d2968b098a36137a44780e279be68c3ec04d37737044e29cf1af5
5
5
  SHA512:
6
- metadata.gz: 3fa05ddee1fceb1f300e3c16ca6b8ab32fead629bf20e50d6f406694cdc97400d8bef450e0ef050dd86a95bbd9c1bf69b2384ca641b0605e2048eb86e66b549d
7
- data.tar.gz: cb732b90ceb859d05872705bf777886d9b8a844bd82d7cbf5351203516b78e304f427ed727d1a8576966f87f999447fae9a880b6d7a5ea6d4b7efe3d60cd0cc5
6
+ metadata.gz: 90fbc7b576d768c0d2282d87e2ae0bcbd7c8f82ba19a910edfd084fa15cb5ef1b86423fe4eae5ddd07c0910ab0dcde4a6e67516147b54f5102a093c018d26237
7
+ data.tar.gz: a535a2fa6d19d8a5bb41ac4c70e27f66559699fe07073383ee7a3af295416d0df8a1f47e7a7ff0a1fbe20d0c6dbb315e6842e4fbf111351de2ee54d4bd774a56
data/lib/elastic/esql.rb CHANGED
@@ -15,6 +15,7 @@
15
15
  # specific language governing permissions and limitations
16
16
  # under the License.
17
17
 
18
+ require_relative 'branch'
18
19
  require_relative 'change_point'
19
20
  require_relative 'custom'
20
21
  require_relative 'dissect'
@@ -22,42 +23,29 @@ require_relative 'drop'
22
23
  require_relative 'enrich'
23
24
  require_relative 'eval'
24
25
  require_relative 'functions'
26
+ require_relative 'fork'
27
+ require_relative 'fuse'
25
28
  require_relative 'grok'
26
29
  require_relative 'keep'
27
- require_relative 'limit'
28
30
  require_relative 'lookup_join'
29
31
  require_relative 'metadata'
32
+ require_relative 'queryable'
30
33
  require_relative 'rename'
31
34
  require_relative 'row'
32
35
  require_relative 'show'
33
- require_relative 'sort'
34
36
  require_relative 'stats'
35
37
  require_relative 'ts'
36
- require_relative 'where'
38
+ require_relative 'util'
37
39
 
38
40
  module Elastic
39
41
  # @example
40
42
  # Elastic::ESQL.from('sample_data').sort_descending('@timestamp').limit(3).to_s
41
43
  # # => FROM 'sample_data' | SORT @timestamp desc | LIMIT 3
42
- # rubocop:disable Metrics/ClassLength
43
44
  class ESQL
44
- include ChangePoint
45
- include Custom
46
- include Dissect
47
- include Drop
48
- include Eval
49
- include Grok
50
- include Keep
51
- include Limit
52
- include LookupJoin
53
- include Metadata
54
- include Rename
55
- include Row
56
- include Show
57
- include Sort
58
- include Stats
59
- include TS
60
- include Where
45
+ [
46
+ ChangePoint, Custom, Dissect, Drop, Eval, Fork, Fuse, Grok, Keep, LookupJoin, Metadata,
47
+ Queryable, Rename, Row, Show, Stats, TS, Util
48
+ ].each { |m| include m }
61
49
 
62
50
  SOURCE_COMMANDS = [:from, :row, :show, :ts].freeze
63
51
 
@@ -65,7 +53,6 @@ module Elastic
65
53
  @query = {}
66
54
  @custom = []
67
55
  @metadata = []
68
- @lookup_joins = []
69
56
  end
70
57
 
71
58
  # Function to build the ES|QL formatted query and return it as a String.
@@ -74,9 +61,8 @@ module Elastic
74
61
  def query
75
62
  raise ArgumentError, 'No source command found' unless source_command_present?
76
63
 
77
- @query[:enrich] = @enriches.join('| ') if @enriches
64
+ @query[:enrich] = @enriches.map(&:to_query).join('| ') if @enriches
78
65
  string_query = build_string_query
79
- string_query.concat(build_lookup_joins) unless @lookup_joins.empty?
80
66
  string_query.concat(" #{@custom.join(' ')}") unless @custom.empty?
81
67
  string_query
82
68
  end
@@ -149,6 +135,10 @@ module Elastic
149
135
  end
150
136
  # rubocop:enable Naming/MethodName, Naming/BinaryOperatorParameterName
151
137
 
138
+ def self.branch
139
+ Branch.new
140
+ end
141
+
152
142
  private
153
143
 
154
144
  # Function for eval, row, and other functions that have one or more columns with values specified
@@ -179,35 +169,5 @@ module Elastic
179
169
 
180
170
  false
181
171
  end
182
-
183
- # Helper method to return a copy of the object when functions are called without `!`, so the
184
- # object is not mutated.
185
- def method_copy(name, *params)
186
- esql = clone
187
- esql.instance_variable_set('@query', esql.instance_variable_get('@query').clone)
188
- esql.send("#{name}!", *params)
189
- esql
190
- end
191
-
192
- # Helper to build the LOOKUP JOIN part of the query.
193
- def build_lookup_joins
194
- joins = @lookup_joins.map { |a| a.map { |k, v| "LOOKUP JOIN #{k} ON #{v}" } }.flatten.join(' | ')
195
- " | #{joins}"
196
- end
197
-
198
- # Helper to build the String for the simpler functions.
199
- # These are of the form 'key.upcase value' like 'DROP value'
200
- # If metadata has been set, it needs to be added to FROM. There's a possibility there'll be more
201
- # special cases like this in the future, they can be added here.
202
- def build_string_query
203
- @query.map do |k, v|
204
- if k == :from && !@metadata.empty?
205
- "#{k.upcase} #{v} METADATA #{@metadata.join(', ')}"
206
- else
207
- "#{k.upcase} #{v}"
208
- end
209
- end.join(' | ')
210
- end
211
172
  end
212
- # rubocop:enable Metrics/ClassLength
213
173
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elastic-esql
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fernando Briano