egis 1.4.0 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4fa3323e3c02d8537df83f33799f580fb196c255315c9923eb70c0e87bd1f50e
4
- data.tar.gz: 9b4054a2201d98f501603cc137c1c7df93fccf105c448b6d4261515c3f53d959
3
+ metadata.gz: 924727f52ac809df7ab4457a6a0c05469cd6c128adaff339018e964dc9ff4ea0
4
+ data.tar.gz: c8ba9d090641c899e832b73b062314bd76fa4fb39041fb175d7e3a717e943856
5
5
  SHA512:
6
- metadata.gz: 3da9b098de6948b584244db63eda8ef4ba3d26ff29806be0e1a3b3469a321bb72d0761bc4bcb415759646a2397c71d32221477cc2dabeb9233dd8cad22300cef
7
- data.tar.gz: 5c50463ef9585563b3aa6fefbb89b4df101f93693b7e5d5f423e98fa803e614d7541639db9afe06fc1a4544205d6e3b0cbf3c166112f556f58b8c798b528571d
6
+ metadata.gz: fa429f550a68475a75f9dd9c0610b0d41c9a8017f0e46c0f9e467cfaeddfb7d6587d6e7df5b4440bbd75e4d4d9a12d5966f40e4ce72cb8abf70e5dc2897f91d8
7
+ data.tar.gz: 3beac29ce82c267bfc2621e730a8b631f76a94f7426ac7d7901b31d204cda3320d1ab934e9c3e156ee52e5fca315728412ffd5a007bf4623dd2ac077d85399ba
data/lib/egis.rb CHANGED
@@ -50,8 +50,8 @@ require 'egis/s3_location_parser'
50
50
  #
51
51
  module Egis
52
52
  class << self
53
- def configure
54
- yield(configuration)
53
+ def configure(&block)
54
+ configuration.configure(&block)
55
55
  end
56
56
 
57
57
  # @!visibility private
@@ -6,25 +6,23 @@ require 'aws-sdk-athena'
6
6
  module Egis
7
7
  # @!visibility private
8
8
  class AwsClientProvider
9
- def s3_client
10
- Aws::S3::Client.new(client_config)
9
+ def s3_client(configuration)
10
+ Aws::S3::Client.new(client_config(configuration))
11
11
  end
12
12
 
13
- def athena_client
14
- Aws::Athena::Client.new(client_config)
13
+ def athena_client(configuration)
14
+ Aws::Athena::Client.new(client_config(configuration))
15
15
  end
16
16
 
17
17
  private
18
18
 
19
- def client_config
20
- configuration = Egis.configuration
21
-
22
- config = {}
23
- config[:region] = configuration.aws_region if configuration.aws_region
24
- config[:access_key_id] = configuration.aws_access_key_id if configuration.aws_access_key_id
25
- config[:secret_access_key] = configuration.aws_secret_access_key if configuration.aws_secret_access_key
26
- config[:profile] = configuration.aws_profile if configuration.aws_profile
27
- config
19
+ def client_config(configuration)
20
+ {
21
+ region: configuration.aws_region,
22
+ access_key_id: configuration.aws_access_key_id,
23
+ secret_access_key: configuration.aws_secret_access_key,
24
+ profile: configuration.aws_profile
25
+ }.compact
28
26
  end
29
27
  end
30
28
  end
data/lib/egis/client.rb CHANGED
@@ -4,6 +4,9 @@ module Egis
4
4
  ##
5
5
  # The most fundamental {Egis} class. Provides an interface for executing Athena queries.
6
6
  #
7
+ # @yieldparam config [Egis::Configuration] Egis configuration block, if missing Egis will use global configuration
8
+ # provided by {Egis.configure}
9
+ #
7
10
  # See configuration instructions {Egis.configure}.
8
11
  #
9
12
  # @see Egis.configure
@@ -33,14 +36,17 @@ module Egis
33
36
  'CANCELLED' => Egis::QueryStatus::CANCELLED
34
37
  }.freeze
35
38
 
36
- DEFAULT_QUERY_STATUS_BACKOFF = ->(attempt) { 1.5**attempt - 1 }
39
+ private_constant :QUERY_STATUS_MAPPING
37
40
 
38
- private_constant :QUERY_STATUS_MAPPING, :DEFAULT_QUERY_STATUS_BACKOFF
41
+ attr_reader :aws_s3_client
39
42
 
40
- def initialize(aws_client_provider: Egis::AwsClientProvider.new, s3_location_parser: Egis::S3LocationParser.new)
41
- @aws_athena_client = aws_client_provider.athena_client
43
+ def initialize(aws_client_provider: Egis::AwsClientProvider.new,
44
+ s3_location_parser: Egis::S3LocationParser.new,
45
+ &block)
46
+ @configuration = block_given? ? Egis.configuration.dup.configure(&block) : Egis.configuration
47
+ @aws_athena_client = aws_client_provider.athena_client(configuration)
48
+ @aws_s3_client = aws_client_provider.s3_client(configuration)
42
49
  @s3_location_parser = s3_location_parser
43
- @query_status_backoff = Egis.configuration.query_status_backoff || DEFAULT_QUERY_STATUS_BACKOFF
44
50
  end
45
51
 
46
52
  ##
@@ -99,16 +105,17 @@ module Egis
99
105
  query_execution.query_execution_id,
100
106
  QUERY_STATUS_MAPPING.fetch(query_status),
101
107
  query_execution.status.state_change_reason,
102
- parse_output_location(query_execution)
108
+ parse_output_location(query_execution),
109
+ client: self
103
110
  )
104
111
  end
105
112
 
106
113
  private
107
114
 
108
- attr_reader :aws_athena_client, :s3_location_parser, :query_status_backoff
115
+ attr_reader :configuration, :aws_athena_client, :s3_location_parser
109
116
 
110
117
  def query_execution_params(query, work_group, database, output_location)
111
- work_group_params = work_group || Egis.configuration.work_group
118
+ work_group_params = work_group || configuration.work_group
112
119
 
113
120
  params = {query_string: query}
114
121
  params[:work_group] = work_group_params if work_group_params
@@ -128,7 +135,7 @@ module Egis
128
135
  def wait_for_query_to_finish(query_id)
129
136
  attempt = 1
130
137
  loop do
131
- sleep(query_status_backoff.call(attempt))
138
+ sleep(configuration.query_status_backoff.call(attempt))
132
139
  status = query_status(query_id)
133
140
 
134
141
  return status unless status.queued? || status.running?
@@ -8,6 +8,12 @@ module Egis
8
8
 
9
9
  def initialize
10
10
  @logger = Logger.new(STDOUT, level: :info)
11
+ @query_status_backoff = ->(attempt) { 1.5**attempt - 1 }
12
+ end
13
+
14
+ def configure
15
+ yield(self)
16
+ self
11
17
  end
12
18
  end
13
19
  end
data/lib/egis/database.rb CHANGED
@@ -14,10 +14,10 @@ module Egis
14
14
  # @return [String] Athena database name
15
15
  #
16
16
  class Database
17
- def initialize(name, client: Egis::Client.new, output_downloader: Egis::OutputDownloader.new)
17
+ def initialize(name, client: Egis::Client.new, output_downloader: Egis::OutputDownloader.new(client.aws_s3_client))
18
18
  @client = client
19
- @name = name
20
19
  @output_downloader = output_downloader
20
+ @name = name
21
21
  end
22
22
 
23
23
  attr_reader :name
@@ -33,7 +33,7 @@ module Egis
33
33
  # @return [Egis::Table]
34
34
 
35
35
  def table(table_name, table_schema, table_location, **options)
36
- Table.new(self, table_name, table_schema, table_location, options: options)
36
+ Table.new(self, table_name, table_schema, table_location, client: client, options: options)
37
37
  end
38
38
 
39
39
  ##
@@ -5,8 +5,8 @@ require 'csv'
5
5
  module Egis
6
6
  # @!visibility private
7
7
  class OutputDownloader
8
- def initialize(aws_client_provider: Egis::AwsClientProvider.new)
9
- @s3_client = aws_client_provider.s3_client
8
+ def initialize(aws_s3_client)
9
+ @s3_client = aws_s3_client
10
10
  end
11
11
 
12
12
  def download(output_location)
@@ -23,7 +23,8 @@ module Egis
23
23
  attr_reader :id, :status, :message, :output_location
24
24
 
25
25
  def initialize(id, status, message, output_location,
26
- output_downloader: Egis::OutputDownloader.new,
26
+ client: Egis::Client.new,
27
+ output_downloader: Egis::OutputDownloader.new(client.aws_s3_client),
27
28
  output_parser: Egis::OutputParser.new)
28
29
  raise ArgumentError, "Unsupported status #{status}" unless STATUSES.include?(status)
29
30
 
@@ -51,6 +52,10 @@ module Egis
51
52
  status == RUNNING
52
53
  end
53
54
 
55
+ def cancelled?
56
+ status == CANCELLED
57
+ end
58
+
54
59
  def in_progress?
55
60
  [RUNNING, QUEUED].include?(status)
56
61
  end
@@ -3,8 +3,8 @@
3
3
  module Egis
4
4
  # @!visibility private
5
5
  class S3Cleaner
6
- def initialize(aws_client_provider: Egis::AwsClientProvider.new)
7
- @s3_client = aws_client_provider.s3_client
6
+ def initialize(aws_s3_client)
7
+ @s3_client = aws_s3_client
8
8
  end
9
9
 
10
10
  def delete(bucket, prefix)
data/lib/egis/table.rb CHANGED
@@ -17,11 +17,13 @@ module Egis
17
17
  DEFAULT_OPTIONS = {format: :tsv}.freeze
18
18
 
19
19
  def initialize(database, name, schema, location, options: {},
20
+ client: Egis::Client.new,
20
21
  partitions_generator: Egis::PartitionsGenerator.new,
21
22
  table_ddl_generator: Egis::TableDDLGenerator.new,
22
- output_downloader: Egis::OutputDownloader.new,
23
+ output_downloader: Egis::OutputDownloader.new(client.aws_s3_client),
23
24
  output_parser: Egis::OutputParser.new,
24
- table_data_wiper: Egis::TableDataWiper.new)
25
+ s3_cleaner: Egis::S3Cleaner.new(client.aws_s3_client),
26
+ table_data_wiper: Egis::TableDataWiper.new(s3_cleaner: s3_cleaner))
25
27
  @database = database
26
28
  @name = name
27
29
  @schema = schema
@@ -6,7 +6,7 @@ module Egis
6
6
  class TestingMode
7
7
  def initialize(test_id, s3_bucket,
8
8
  client: Egis::Client.new,
9
- output_downloader: Egis::OutputDownloader.new,
9
+ output_downloader: Egis::OutputDownloader.new(client.aws_s3_client),
10
10
  s3_location_parser: Egis::S3LocationParser.new)
11
11
  @test_id = test_id
12
12
  @s3_bucket = s3_bucket
data/lib/egis/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Egis
4
- VERSION = '1.4.0'
4
+ VERSION = '1.5.0'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: egis
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Agnieszka Czereba
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2021-03-12 00:00:00.000000000 Z
12
+ date: 2021-05-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: aws-sdk-athena
@@ -99,7 +99,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
99
99
  - !ruby/object:Gem::Version
100
100
  version: '0'
101
101
  requirements: []
102
- rubygems_version: 3.1.4
102
+ rubygems_version: 3.1.6
103
103
  signing_key:
104
104
  specification_version: 4
105
105
  summary: A handy wrapper for AWS Athena Ruby SDK.