elastic-esql 0.1.0 → 0.2.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 +30 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 99e718442d20298997082926d68a0a81fb7fa4caca2469438b1661f21134ea9f
|
4
|
+
data.tar.gz: 6baf28b918cfead958e96b59dc2062e02d5702c20b232cfe7fdaf6bdb9aa5285
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e4dffbd00b997031a36c27a7edf0640e8f726e1d719ba35a98d37a3f15235b3c92a2a8e38ee5159557a97dc775177e0ba08ef4df35cfed1921cc53b682fe129e
|
7
|
+
data.tar.gz: e1d9bd655f5d34016da2caf6a976c74dc9f57244782cbfc6700a8993f8dbbce37722c1cafe978c99a60f5b88daa6e99e1ae9015ed3347ca65d59f362d15f5dcc
|
data/lib/elastic/esql.rb
CHANGED
@@ -22,8 +22,10 @@ require_relative 'drop'
|
|
22
22
|
require_relative 'enrich'
|
23
23
|
require_relative 'eval'
|
24
24
|
require_relative 'grok'
|
25
|
-
require_relative 'limit'
|
26
25
|
require_relative 'keep'
|
26
|
+
require_relative 'limit'
|
27
|
+
require_relative 'lookup_join'
|
28
|
+
require_relative 'metadata'
|
27
29
|
require_relative 'rename'
|
28
30
|
require_relative 'row'
|
29
31
|
require_relative 'show'
|
@@ -43,6 +45,8 @@ module Elastic
|
|
43
45
|
include Grok
|
44
46
|
include Keep
|
45
47
|
include Limit
|
48
|
+
include LookupJoin
|
49
|
+
include Metadata
|
46
50
|
include Rename
|
47
51
|
include Row
|
48
52
|
include Show
|
@@ -53,6 +57,8 @@ module Elastic
|
|
53
57
|
def initialize
|
54
58
|
@query = {}
|
55
59
|
@custom = []
|
60
|
+
@metadata = []
|
61
|
+
@lookup_joins = []
|
56
62
|
end
|
57
63
|
|
58
64
|
# Function to build the ES|QL formatted query and return it as a String.
|
@@ -62,10 +68,8 @@ module Elastic
|
|
62
68
|
raise ArgumentError, 'No source command found' unless source_command_present?
|
63
69
|
|
64
70
|
@query[:enrich] = @enriches.join('| ') if @enriches
|
65
|
-
string_query =
|
66
|
-
|
67
|
-
end.join(' | ')
|
68
|
-
|
71
|
+
string_query = build_string_query
|
72
|
+
string_query.concat(build_lookup_joins) unless @lookup_joins.empty?
|
69
73
|
string_query.concat(" #{@custom.join(' ')}") unless @custom.empty?
|
70
74
|
string_query
|
71
75
|
end
|
@@ -134,7 +138,7 @@ module Elastic
|
|
134
138
|
# Error raised when a function expects a Hash and something else is passed in, with explanation
|
135
139
|
def raise_hash_error(name)
|
136
140
|
raise ArgumentError, "#{name.to_s.upcase} needs a Hash as a parameter where the keys are the " \
|
137
|
-
|
141
|
+
'column names and the value is the function or expression to calculate.'
|
138
142
|
end
|
139
143
|
|
140
144
|
# Used when building the query from hash params function
|
@@ -157,5 +161,25 @@ module Elastic
|
|
157
161
|
esql.send("#{name}!", *params)
|
158
162
|
esql
|
159
163
|
end
|
164
|
+
|
165
|
+
# Helper to build the LOOKUP JOIN part of the query.
|
166
|
+
def build_lookup_joins
|
167
|
+
joins = @lookup_joins.map { |a| a.map { |k, v| "LOOKUP JOIN #{k} ON #{v}" } }.flatten.join(' | ')
|
168
|
+
" | #{joins}"
|
169
|
+
end
|
170
|
+
|
171
|
+
# Helper to build the String for the simpler functions.
|
172
|
+
# These are of the form 'key.upcase value' like 'DROP value'
|
173
|
+
# If metadata has been set, it needs to be added to FROM. There's a possibility there'll be more
|
174
|
+
# special cases like this in the future, they can be added here.
|
175
|
+
def build_string_query
|
176
|
+
@query.map do |k, v|
|
177
|
+
if k == :from && !@metadata.empty?
|
178
|
+
"#{k.upcase} #{v} METADATA #{@metadata.join(', ')}"
|
179
|
+
else
|
180
|
+
"#{k.upcase} #{v}"
|
181
|
+
end
|
182
|
+
end.join(' | ')
|
183
|
+
end
|
160
184
|
end
|
161
185
|
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.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fernando Briano
|
@@ -104,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
104
104
|
- !ruby/object:Gem::Version
|
105
105
|
version: '0'
|
106
106
|
requirements: []
|
107
|
-
rubygems_version: 3.
|
107
|
+
rubygems_version: 3.7.1
|
108
108
|
specification_version: 4
|
109
109
|
summary: Elastic ES|QL Query builder
|
110
110
|
test_files: []
|