elastic-esql 0.4.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 +53 -60
  3. metadata +4 -73
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f7837c640aa915808d6c720d4cd53bdcfe3210fbff0a5e9b900a0c0adcc3ed7a
4
- data.tar.gz: 6f3cc673984d2968b098a36137a44780e279be68c3ec04d37737044e29cf1af5
3
+ metadata.gz: f78cf59762700445a9241150e555c8b77cae9b5f6fde95540a83ef4420cb3f57
4
+ data.tar.gz: 0bd367ff0a9228bf14284446c6bf0c7013b580b101506e4eeeba5537fbf6acf1
5
5
  SHA512:
6
- metadata.gz: 90fbc7b576d768c0d2282d87e2ae0bcbd7c8f82ba19a910edfd084fa15cb5ef1b86423fe4eae5ddd07c0910ab0dcde4a6e67516147b54f5102a093c018d26237
7
- data.tar.gz: a535a2fa6d19d8a5bb41ac4c70e27f66559699fe07073383ee7a3af295416d0df8a1f47e7a7ff0a1fbe20d0c6dbb315e6842e4fbf111351de2ee54d4bd774a56
6
+ metadata.gz: ca8b8a9b1d45a7fcf36e7a82232d6d4e56cca5ca268a78da9f97a0077c3f27630644f1e91b4e728a402bd888a184082ea9582adc7bae42c41de10eab46f769e6
7
+ data.tar.gz: 74911524b52175a7e524b6924a14b1090c3c9ff906ea7e4bd3e0d7c2372fda21abbf31240363c9c8bcae856df31d9b47e12534e0a502fe8b76d26a14e662a44f
data/lib/elastic/esql.rb CHANGED
@@ -26,15 +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'
34
+ require_relative 'mv_expand'
35
+ require_relative 'promql'
32
36
  require_relative 'queryable'
37
+ require_relative 'registered_domain'
33
38
  require_relative 'rename'
39
+ require_relative 'rerank'
34
40
  require_relative 'row'
41
+ require_relative 'sample'
42
+ require_relative 'set'
35
43
  require_relative 'show'
36
44
  require_relative 'stats'
45
+ require_relative 'stats_mixin'
37
46
  require_relative 'ts'
47
+ require_relative 'user_agent'
48
+ require_relative 'uri_parts'
38
49
  require_relative 'util'
39
50
 
40
51
  module Elastic
@@ -43,11 +54,12 @@ module Elastic
43
54
  # # => FROM 'sample_data' | SORT @timestamp desc | LIMIT 3
44
55
  class ESQL
45
56
  [
46
- ChangePoint, Custom, Dissect, Drop, Eval, Fork, Fuse, Grok, Keep, LookupJoin, Metadata,
47
- Queryable, Rename, Row, 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
48
60
  ].each { |m| include m }
49
61
 
50
- SOURCE_COMMANDS = [:from, :row, :show, :ts].freeze
62
+ SOURCE_COMMANDS = [:from, :promql, :row, :show, :ts].freeze
51
63
 
52
64
  def initialize
53
65
  @query = {}
@@ -55,14 +67,33 @@ module Elastic
55
67
  @metadata = []
56
68
  end
57
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
+
58
87
  # Function to build the ES|QL formatted query and return it as a String.
59
88
  # @raise [ArgumentError] if the query has no source command
60
89
  # @return [String] The ES|QL query in ES|QL format.
61
90
  def query
62
91
  raise ArgumentError, 'No source command found' unless source_command_present?
63
92
 
93
+ string_query = @set ? "SET #{@set};\n" : ''
64
94
  @query[:enrich] = @enriches.map(&:to_query).join('| ') if @enriches
65
- string_query = build_string_query
95
+ @query[:rerank] = @rerank.to_query if @rerank
96
+ string_query.concat(build_string_query)
66
97
  string_query.concat(" #{@custom.join(' ')}") unless @custom.empty?
67
98
  string_query
68
99
  end
@@ -77,33 +108,12 @@ module Elastic
77
108
  enrich
78
109
  end
79
110
 
80
- # Class method to allow static instantiation.
81
- # @param [String] index_pattern A list of indices, data streams or aliases. Supports wildcards and date math.
82
- # @example
83
- # Elastic::ESQL.from('sample_data')
84
- # @see https://www.elastic.co/docs/reference/query-languages/esql/commands/source-commands#esql-from
85
- def self.from(index_pattern)
86
- new.from(index_pattern)
87
- end
88
-
89
- # The SHOW source command returns information about the deployment and its capabilities.
90
- # @return [String] 'SHOW INFO'
91
- # @see https://www.elastic.co/docs/reference/query-languages/esql/commands/source-commands#esql-show
92
- def self.show
93
- new.show
94
- end
95
-
96
- # Class method to allow static instantiation.
97
- # @param [Hash] params Receives a Hash<column, value>
98
- # @option params [String] column_name The column name. In case of duplicate column names, only the
99
- # rightmost duplicate creates a column.
100
- # @option params [String] value The value for the column. Can be a literal, an expression, or a function.
101
- def self.row(*params)
102
- new.row(*params)
103
- end
104
-
105
- def self.ts(*params)
106
- new.ts(*params)
111
+ # Creates a new Rerank object to chain with +on+ and +with+. If other method is chained to the
112
+ # Rerank object, it calls it upon the ESQL object that instantiated it, and returns it.
113
+ # @return [Elastic::Rerank]
114
+ def rerank(column: nil, query: '')
115
+ @rerank = Rerank.new(self, column: column, query: query)
116
+ @rerank
107
117
  end
108
118
 
109
119
  # Instance method to allow to update +from+ with +esql.from('different_source')+.
@@ -120,50 +130,33 @@ module Elastic
120
130
  end
121
131
 
122
132
  # rubocop:disable Naming/MethodName, Naming/BinaryOperatorParameterName
123
- def self.🐔(message)
124
- "ROW CHICKEN(\"#{message}\")"
133
+ class << self
134
+ def 🐔(message)
135
+ "ROW CHICKEN(\"#{message}\")"
136
+ end
137
+ alias chicken 🐔
125
138
  end
126
139
 
127
140
  def 🐔(message)
128
141
  self.class.🐔(message)
129
142
  end
130
-
131
143
  alias chicken 🐔
132
-
133
- class << self
134
- alias chicken 🐔
135
- end
136
144
  # rubocop:enable Naming/MethodName, Naming/BinaryOperatorParameterName
137
145
 
138
146
  def self.branch
139
147
  Branch.new
140
148
  end
141
149
 
142
- private
143
-
144
- # Function for eval, row, and other functions that have one or more columns with values specified
145
- # as parameters. The hash_or_string function is called with the caller name since it's the same
146
- # logic to use these parameters.
147
- # TODO: Refactor to accept other types when not a Hash
148
- def hash_param(name, params)
149
- raise_hash_error(name) unless params.is_a?(Hash)
150
-
151
- @query[symbolize(name)] = params.map { |k, v| "#{k} = #{v}" }.join(', ')
152
- self
153
- end
154
-
155
- # Error raised when a function expects a Hash and something else is passed in, with explanation
156
- def raise_hash_error(name)
157
- raise ArgumentError, "#{name.to_s.upcase} needs a Hash as a parameter where the keys are the " \
158
- 'column names and the value is the function or expression to calculate.'
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)
159
155
  end
160
156
 
161
- # Used when building the query from hash params function
162
- def symbolize(name)
163
- name.is_a?(Symbol) ? name : name.to_sym
164
- end
157
+ private
165
158
 
166
- # Check if we have a source command
159
+ # Check if there's a source command present in the query
167
160
  def source_command_present?
168
161
  SOURCE_COMMANDS.map { |c| @query.each_key { |k| return true if k == c } }
169
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.4.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: []