elastic-esql 0.5.0 → 0.6.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 +43 -62
  3. metadata +4 -73
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d816aedd477416a9edcf948d7e19c89212aeca77b79e78cbc20eaf9ccbfc8f07
4
- data.tar.gz: 7a59bd4340bc1aaac08b12cc54e2da359f67a0604331c29896096452b021086c
3
+ metadata.gz: f78cf59762700445a9241150e555c8b77cae9b5f6fde95540a83ef4420cb3f57
4
+ data.tar.gz: 0bd367ff0a9228bf14284446c6bf0c7013b580b101506e4eeeba5537fbf6acf1
5
5
  SHA512:
6
- metadata.gz: 2c7e3459562b9a4a8d27144b65d63ddd93455b20556f34763381a1a85f776857b4cefa03eb6102276451b71d256ec1221eba6f3265a0ba8bd5ebd018a6bb8225
7
- data.tar.gz: 0a7073741cc71c28183a9afa9c3ab311bd034bc8c762d58bf530d1ac86f3e0763d0294bdd54e9f93b28eb6817f1115d357892ef88b3eb6bcf9fd8c8789a47b0d
6
+ metadata.gz: ca8b8a9b1d45a7fcf36e7a82232d6d4e56cca5ca268a78da9f97a0077c3f27630644f1e91b4e728a402bd888a184082ea9582adc7bae42c41de10eab46f769e6
7
+ data.tar.gz: 74911524b52175a7e524b6924a14b1090c3c9ff906ea7e4bd3e0d7c2372fda21abbf31240363c9c8bcae856df31d9b47e12534e0a502fe8b76d26a14e662a44f
data/lib/elastic/esql.rb CHANGED
@@ -26,18 +26,26 @@ require_relative 'functions'
26
26
  require_relative 'fork'
27
27
  require_relative 'fuse'
28
28
  require_relative 'grok'
29
+ require_relative 'inline_stats'
29
30
  require_relative 'keep'
30
31
  require_relative 'lookup_join'
31
32
  require_relative 'metadata'
33
+ require_relative 'metrics_info'
32
34
  require_relative 'mv_expand'
35
+ require_relative 'promql'
33
36
  require_relative 'queryable'
37
+ require_relative 'registered_domain'
34
38
  require_relative 'rename'
35
39
  require_relative 'rerank'
36
40
  require_relative 'row'
37
41
  require_relative 'sample'
42
+ require_relative 'set'
38
43
  require_relative 'show'
39
44
  require_relative 'stats'
45
+ require_relative 'stats_mixin'
40
46
  require_relative 'ts'
47
+ require_relative 'user_agent'
48
+ require_relative 'uri_parts'
41
49
  require_relative 'util'
42
50
 
43
51
  module Elastic
@@ -46,11 +54,12 @@ module Elastic
46
54
  # # => FROM 'sample_data' | SORT @timestamp desc | LIMIT 3
47
55
  class ESQL
48
56
  [
49
- ChangePoint, Custom, Dissect, Drop, Eval, Fork, Fuse, Grok, Keep, LookupJoin, Metadata,
50
- MvExpand, Queryable, Rename, Row, Sample, Show, Stats, TS, Util
57
+ ChangePoint, Custom, Dissect, Drop, Eval, Fork, Fuse, Grok, InlineStats, Keep, LookupJoin,
58
+ Metadata, MetricsInfo, MvExpand, PromQL, Queryable, RegisteredDomain, Rename, Row, Sample,
59
+ SetDirective, Show, Stats, StatsMixin, TS, URIParts, Util
51
60
  ].each { |m| include m }
52
61
 
53
- SOURCE_COMMANDS = [:from, :row, :show, :ts].freeze
62
+ SOURCE_COMMANDS = [:from, :promql, :row, :show, :ts].freeze
54
63
 
55
64
  def initialize
56
65
  @query = {}
@@ -58,15 +67,33 @@ module Elastic
58
67
  @metadata = []
59
68
  end
60
69
 
70
+ # Dinamically define Class methods to allow static instantiation with Source Commands:
71
+ # @see ESQL#from
72
+ # @see PromQL#promql
73
+ # @see Row#row
74
+ # @see Show#show
75
+ # @see TS#ts
76
+ # @example
77
+ # Elastic::ESQL.from('sample_data')
78
+ # Elastic::ESQL.row({ a: 1, b: 'two' })
79
+ class << self
80
+ SOURCE_COMMANDS.each do |command|
81
+ define_method(command) do |*params|
82
+ new.send(command, *params)
83
+ end
84
+ end
85
+ end
86
+
61
87
  # Function to build the ES|QL formatted query and return it as a String.
62
88
  # @raise [ArgumentError] if the query has no source command
63
89
  # @return [String] The ES|QL query in ES|QL format.
64
90
  def query
65
91
  raise ArgumentError, 'No source command found' unless source_command_present?
66
92
 
93
+ string_query = @set ? "SET #{@set};\n" : ''
67
94
  @query[:enrich] = @enriches.map(&:to_query).join('| ') if @enriches
68
95
  @query[:rerank] = @rerank.to_query if @rerank
69
- string_query = build_string_query
96
+ string_query.concat(build_string_query)
70
97
  string_query.concat(" #{@custom.join(' ')}") unless @custom.empty?
71
98
  string_query
72
99
  end
@@ -89,35 +116,6 @@ module Elastic
89
116
  @rerank
90
117
  end
91
118
 
92
- # Class method to allow static instantiation.
93
- # @param [String] index_pattern A list of indices, data streams or aliases. Supports wildcards and date math.
94
- # @example
95
- # Elastic::ESQL.from('sample_data')
96
- # @see https://www.elastic.co/docs/reference/query-languages/esql/commands/source-commands#esql-from
97
- def self.from(index_pattern)
98
- new.from(index_pattern)
99
- end
100
-
101
- # The SHOW source command returns information about the deployment and its capabilities.
102
- # @return [String] 'SHOW INFO'
103
- # @see https://www.elastic.co/docs/reference/query-languages/esql/commands/source-commands#esql-show
104
- def self.show
105
- new.show
106
- end
107
-
108
- # Class method to allow static instantiation.
109
- # @param [Hash] params Receives a Hash<column, value>
110
- # @option params [String] column_name The column name. In case of duplicate column names, only the
111
- # rightmost duplicate creates a column.
112
- # @option params [String] value The value for the column. Can be a literal, an expression, or a function.
113
- def self.row(*params)
114
- new.row(*params)
115
- end
116
-
117
- def self.ts(*params)
118
- new.ts(*params)
119
- end
120
-
121
119
  # Instance method to allow to update +from+ with +esql.from('different_source')+.
122
120
  # @param [String] index_pattern A list of indices, data streams or aliases. Supports wildcards and date math.
123
121
  def from(index_pattern)
@@ -132,50 +130,33 @@ module Elastic
132
130
  end
133
131
 
134
132
  # rubocop:disable Naming/MethodName, Naming/BinaryOperatorParameterName
135
- def self.🐔(message)
136
- "ROW CHICKEN(\"#{message}\")"
133
+ class << self
134
+ def 🐔(message)
135
+ "ROW CHICKEN(\"#{message}\")"
136
+ end
137
+ alias chicken 🐔
137
138
  end
138
139
 
139
140
  def 🐔(message)
140
141
  self.class.🐔(message)
141
142
  end
142
-
143
143
  alias chicken 🐔
144
-
145
- class << self
146
- alias chicken 🐔
147
- end
148
144
  # rubocop:enable Naming/MethodName, Naming/BinaryOperatorParameterName
149
145
 
150
146
  def self.branch
151
147
  Branch.new
152
148
  end
153
149
 
154
- private
155
-
156
- # Function for eval, row, and other functions that have one or more columns with values specified
157
- # as parameters. The hash_or_string function is called with the caller name since it's the same
158
- # logic to use these parameters.
159
- # TODO: Refactor to accept other types when not a Hash
160
- def hash_param(name, params)
161
- raise_hash_error(name) unless params.is_a?(Hash)
162
-
163
- @query[symbolize(name)] = params.map { |k, v| "#{k} = #{v}" }.join(', ')
164
- self
150
+ # Creates a new UserAgent object to chain with +with+. If other method is chained to the
151
+ # UserAgent object, it calls it upon the ESQL object that instantiated it, and returns it.
152
+ # @return [Elastic::UserAgent]
153
+ def user_agent(params)
154
+ UserAgent.new(params, self)
165
155
  end
166
156
 
167
- # Error raised when a function expects a Hash and something else is passed in, with explanation
168
- def raise_hash_error(name)
169
- raise ArgumentError, "#{name.to_s.upcase} needs a Hash as a parameter where the keys are the " \
170
- 'column names and the value is the function or expression to calculate.'
171
- end
172
-
173
- # Used when building the query from hash params function
174
- def symbolize(name)
175
- name.is_a?(Symbol) ? name : name.to_sym
176
- end
157
+ private
177
158
 
178
- # Check if we have a source command
159
+ # Check if there's a source command present in the query
179
160
  def source_command_present?
180
161
  SOURCE_COMMANDS.map { |c| @query.each_key { |k| return true if k == c } }
181
162
 
metadata CHANGED
@@ -1,84 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elastic-esql
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fernando Briano
8
8
  bindir: bin
9
9
  cert_chain: []
10
10
  date: 1980-01-02 00:00:00.000000000 Z
11
- dependencies:
12
- - !ruby/object:Gem::Dependency
13
- name: debug
14
- requirement: !ruby/object:Gem::Requirement
15
- requirements:
16
- - - "~>"
17
- - !ruby/object:Gem::Version
18
- version: '1'
19
- type: :development
20
- prerelease: false
21
- version_requirements: !ruby/object:Gem::Requirement
22
- requirements:
23
- - - "~>"
24
- - !ruby/object:Gem::Version
25
- version: '1'
26
- - !ruby/object:Gem::Dependency
27
- name: rake
28
- requirement: !ruby/object:Gem::Requirement
29
- requirements:
30
- - - "~>"
31
- - !ruby/object:Gem::Version
32
- version: '13'
33
- type: :development
34
- prerelease: false
35
- version_requirements: !ruby/object:Gem::Requirement
36
- requirements:
37
- - - "~>"
38
- - !ruby/object:Gem::Version
39
- version: '13'
40
- - !ruby/object:Gem::Dependency
41
- name: rspec
42
- requirement: !ruby/object:Gem::Requirement
43
- requirements:
44
- - - "~>"
45
- - !ruby/object:Gem::Version
46
- version: '3'
47
- type: :development
48
- prerelease: false
49
- version_requirements: !ruby/object:Gem::Requirement
50
- requirements:
51
- - - "~>"
52
- - !ruby/object:Gem::Version
53
- version: '3'
54
- - !ruby/object:Gem::Dependency
55
- name: rubocop
56
- requirement: !ruby/object:Gem::Requirement
57
- requirements:
58
- - - "~>"
59
- - !ruby/object:Gem::Version
60
- version: '1.75'
61
- type: :development
62
- prerelease: false
63
- version_requirements: !ruby/object:Gem::Requirement
64
- requirements:
65
- - - "~>"
66
- - !ruby/object:Gem::Version
67
- version: '1.75'
68
- - !ruby/object:Gem::Dependency
69
- name: yard
70
- requirement: !ruby/object:Gem::Requirement
71
- requirements:
72
- - - "~>"
73
- - !ruby/object:Gem::Version
74
- version: '0.9'
75
- type: :development
76
- prerelease: false
77
- version_requirements: !ruby/object:Gem::Requirement
78
- requirements:
79
- - - "~>"
80
- - !ruby/object:Gem::Version
81
- version: '0.9'
11
+ dependencies: []
82
12
  executables: []
83
13
  extensions: []
84
14
  extra_rdoc_files: []
@@ -90,6 +20,7 @@ metadata:
90
20
  changelog_uri: https://github.com/elastic/esql-ruby/blob/main/CHANGELOG.md
91
21
  source_code_uri: https://github.com/elastic/esql-ruby/tree/main
92
22
  bug_tracker_uri: https://github.com/elastic/esql-ruby/issues
23
+ rubygems_mfa_required: 'true'
93
24
  rdoc_options: []
94
25
  require_paths:
95
26
  - lib
@@ -104,7 +35,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
104
35
  - !ruby/object:Gem::Version
105
36
  version: '0'
106
37
  requirements: []
107
- rubygems_version: 4.0.3
38
+ rubygems_version: 4.0.6
108
39
  specification_version: 4
109
40
  summary: Elastic ES|QL Query builder
110
41
  test_files: []