elastic-esql 0.3.0 → 0.5.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/lib/elastic/esql.rb +26 -54
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d816aedd477416a9edcf948d7e19c89212aeca77b79e78cbc20eaf9ccbfc8f07
|
|
4
|
+
data.tar.gz: 7a59bd4340bc1aaac08b12cc54e2da359f67a0604331c29896096452b021086c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2c7e3459562b9a4a8d27144b65d63ddd93455b20556f34763381a1a85f776857b4cefa03eb6102276451b71d256ec1221eba6f3265a0ba8bd5ebd018a6bb8225
|
|
7
|
+
data.tar.gz: 0a7073741cc71c28183a9afa9c3ab311bd034bc8c762d58bf530d1ac86f3e0763d0294bdd54e9f93b28eb6817f1115d357892ef88b3eb6bcf9fd8c8789a47b0d
|
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,32 @@ 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 'mv_expand'
|
|
33
|
+
require_relative 'queryable'
|
|
30
34
|
require_relative 'rename'
|
|
35
|
+
require_relative 'rerank'
|
|
31
36
|
require_relative 'row'
|
|
37
|
+
require_relative 'sample'
|
|
32
38
|
require_relative 'show'
|
|
33
|
-
require_relative 'sort'
|
|
34
39
|
require_relative 'stats'
|
|
35
40
|
require_relative 'ts'
|
|
36
|
-
require_relative '
|
|
41
|
+
require_relative 'util'
|
|
37
42
|
|
|
38
43
|
module Elastic
|
|
39
44
|
# @example
|
|
40
45
|
# Elastic::ESQL.from('sample_data').sort_descending('@timestamp').limit(3).to_s
|
|
41
46
|
# # => FROM 'sample_data' | SORT @timestamp desc | LIMIT 3
|
|
42
|
-
# rubocop:disable Metrics/ClassLength
|
|
43
47
|
class ESQL
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
include
|
|
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
|
|
48
|
+
[
|
|
49
|
+
ChangePoint, Custom, Dissect, Drop, Eval, Fork, Fuse, Grok, Keep, LookupJoin, Metadata,
|
|
50
|
+
MvExpand, Queryable, Rename, Row, Sample, Show, Stats, TS, Util
|
|
51
|
+
].each { |m| include m }
|
|
61
52
|
|
|
62
53
|
SOURCE_COMMANDS = [:from, :row, :show, :ts].freeze
|
|
63
54
|
|
|
@@ -65,7 +56,6 @@ module Elastic
|
|
|
65
56
|
@query = {}
|
|
66
57
|
@custom = []
|
|
67
58
|
@metadata = []
|
|
68
|
-
@lookup_joins = []
|
|
69
59
|
end
|
|
70
60
|
|
|
71
61
|
# Function to build the ES|QL formatted query and return it as a String.
|
|
@@ -74,9 +64,9 @@ module Elastic
|
|
|
74
64
|
def query
|
|
75
65
|
raise ArgumentError, 'No source command found' unless source_command_present?
|
|
76
66
|
|
|
77
|
-
@query[:enrich] = @enriches.join('| ') if @enriches
|
|
67
|
+
@query[:enrich] = @enriches.map(&:to_query).join('| ') if @enriches
|
|
68
|
+
@query[:rerank] = @rerank.to_query if @rerank
|
|
78
69
|
string_query = build_string_query
|
|
79
|
-
string_query.concat(build_lookup_joins) unless @lookup_joins.empty?
|
|
80
70
|
string_query.concat(" #{@custom.join(' ')}") unless @custom.empty?
|
|
81
71
|
string_query
|
|
82
72
|
end
|
|
@@ -91,6 +81,14 @@ module Elastic
|
|
|
91
81
|
enrich
|
|
92
82
|
end
|
|
93
83
|
|
|
84
|
+
# Creates a new Rerank object to chain with +on+ and +with+. If other method is chained to the
|
|
85
|
+
# Rerank object, it calls it upon the ESQL object that instantiated it, and returns it.
|
|
86
|
+
# @return [Elastic::Rerank]
|
|
87
|
+
def rerank(column: nil, query: '')
|
|
88
|
+
@rerank = Rerank.new(self, column: column, query: query)
|
|
89
|
+
@rerank
|
|
90
|
+
end
|
|
91
|
+
|
|
94
92
|
# Class method to allow static instantiation.
|
|
95
93
|
# @param [String] index_pattern A list of indices, data streams or aliases. Supports wildcards and date math.
|
|
96
94
|
# @example
|
|
@@ -149,6 +147,10 @@ module Elastic
|
|
|
149
147
|
end
|
|
150
148
|
# rubocop:enable Naming/MethodName, Naming/BinaryOperatorParameterName
|
|
151
149
|
|
|
150
|
+
def self.branch
|
|
151
|
+
Branch.new
|
|
152
|
+
end
|
|
153
|
+
|
|
152
154
|
private
|
|
153
155
|
|
|
154
156
|
# Function for eval, row, and other functions that have one or more columns with values specified
|
|
@@ -179,35 +181,5 @@ module Elastic
|
|
|
179
181
|
|
|
180
182
|
false
|
|
181
183
|
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
184
|
end
|
|
212
|
-
# rubocop:enable Metrics/ClassLength
|
|
213
185
|
end
|