sneaql 0.0.8-java

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,95 @@
1
+ require 'git'
2
+ require 'open-uri'
3
+
4
+ require_relative 'base.rb'
5
+
6
+ module Sneaql
7
+ # Classes to manage repositories full of SneaQL code.
8
+ module RepoManagers
9
+
10
+ # tells you the repo type based upon the url
11
+ # either git or http
12
+ # @param [String] repo_url
13
+ def self.repo_type_from_url(repo_url)
14
+ return 'git' if repo_url.match(/\.*git.*/i)
15
+ return 'http' if repo_url.match(/\.*http.*/i)
16
+ end
17
+
18
+
19
+ # pulls a branch from a remote git repo
20
+ class GitRepoManager < Sneaql::Core::RepoDownloadManager
21
+ Sneaql::Core::RegisterMappedClass.new(
22
+ :repo_manager,
23
+ 'git',
24
+ Sneaql::RepoManagers::GitRepoManager
25
+ )
26
+
27
+ # Pulls down the repo and checks out the branch.
28
+ def manage_repo
29
+ drop_and_rebuild_directory(@repo_base_dir)
30
+ clone_repo(@params[:repo_url])
31
+ checkout_branch(@params[:git_branch])
32
+ end
33
+
34
+ # Clones a git repo to the local file system.
35
+ # @param [String] repo_uri
36
+ def clone_repo(repo_uri)
37
+ Dir.chdir(@repo_base_dir) do
38
+ @logger.info("cloning git repo #{repo_uri}")
39
+ @local_repo = Git.clone(repo_uri, @repo_base_dir)
40
+ end
41
+ end
42
+
43
+ # Checks out specified branch/commit from local repo.
44
+ # @param [String] branch
45
+ def checkout_branch(branch)
46
+ Dir.chdir(@repo_base_dir) do
47
+ @logger.info("checking out branch #{branch}")
48
+ @local_repo.checkout(branch.to_s)
49
+ end
50
+ end
51
+ end
52
+
53
+ # pulls single archive file from http/https source
54
+ class HttpStoreRepoManager < Sneaql::Core::RepoDownloadManager
55
+ Sneaql::Core::RegisterMappedClass.new(
56
+ :repo_manager,
57
+ 'http',
58
+ Sneaql::RepoManagers::HttpStoreRepoManager
59
+ )
60
+
61
+ # Pulls a zip file from an HTTP store down to local file system
62
+ # then unzips it for use in transform.
63
+ def manage_repo
64
+ drop_and_rebuild_directory(@repo_base_dir)
65
+ pull_transform_repo_from_http_store(@params[:repo_url])
66
+ if @params[:compression] == 'zip'
67
+ unzip_file("#{@repo_base_dir}/#{File.basename(@params[:repo_url])}", @repo_base_dir)
68
+ end
69
+ end
70
+
71
+ # Pulls the transfrom to local file system.
72
+ # @param [String] repo_url
73
+ def pull_transform_repo_from_http_store(repo_url)
74
+ @logger.info "repo #{repo_url} to #{@repo_base_dir}/#{File.basename(repo_url)}"
75
+ File.write("#{@repo_base_dir}/#{File.basename(repo_url)}", open(repo_url).read)
76
+ end
77
+ end
78
+
79
+ # refers to repo in local file system
80
+ class LocalFileSystemRepoManager < Sneaql::Core::RepoDownloadManager
81
+ Sneaql::Core::RegisterMappedClass.new(
82
+ :repo_manager,
83
+ 'local',
84
+ Sneaql::RepoManagers::LocalFileSystemRepoManager
85
+ )
86
+
87
+ # Repo is simply a local file system reference.
88
+ def manage_repo
89
+ # overrides the value created by the
90
+ # constructor with the directory provided
91
+ @repo_base_dir = @params[:repo_base_dir]
92
+ end
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,30 @@
1
+ module Sneaql
2
+ # Classes to manage DB objects for standard SneaQL deployment.
3
+ module Standard
4
+ # Manages execution of a standard transform
5
+ class StandardTransform
6
+
7
+ attr_accessor {
8
+ :jdbc_url,
9
+ :db_user,
10
+ :db_pass
11
+ }
12
+
13
+ def initialize()
14
+ # set parameters
15
+
16
+ # determine database type
17
+
18
+ end
19
+
20
+ def execute_all_transforms()
21
+
22
+ end
23
+
24
+ def execute_single_transform(transform_name)
25
+
26
+ end
27
+
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,232 @@
1
+ module Sneaql
2
+ # Classes to manage DB objects for standard SneaQL deployment.
3
+ module Standard
4
+ # Facilitate creation/recreation of database table objects
5
+ # for standard SneaQL deployment.
6
+ class DBObjectCreator
7
+ attr_accessor :jdbc_connection
8
+
9
+ # @param [Object] jdbc_connection
10
+ # @param [Sneaql::Core::DatabaseManager] database_manager
11
+ # @param [Logger] logger
12
+ def initialize(jdbc_connection, database_manager, logger = nil)
13
+ @logger = logger ? logger : Logger.new(STDOUT)
14
+ @jdbc_connection = jdbc_connection
15
+ @database_manager = database_manager
16
+ end
17
+
18
+ # Drops and recreates the primary transform table.
19
+ # @param [String] transform_table_name fully qualified name for this table
20
+ # @return [Boolean]
21
+ def recreate_transforms_table(transform_table_name)
22
+ JDBCHelpers::Execute.new(
23
+ @jdbc_connection,
24
+ "drop table if exists #{ transform_table_name };",
25
+ @logger
26
+ )
27
+ create_transforms_table(transform_table_name)
28
+ return true
29
+ end
30
+
31
+ # Creates the primary transform table.
32
+ # @param [String] transform_table_name fully qualified name for this table
33
+ # @return [Boolean]
34
+ def create_transforms_table(transform_table_name)
35
+ JDBCHelpers::Execute.new(
36
+ @jdbc_connection,
37
+ transforms_table_create_statement(transform_table_name),
38
+ @logger
39
+ )
40
+ return true
41
+ end
42
+
43
+ # Coerces a boolean to the appropriate value for the database type.
44
+ # May return a 0 or 1 in RDBMS where boolean is not supported.
45
+ # @param [Boolean] boolean_value
46
+ # @return [Boolean, Fixnum]
47
+ def coerce_boolean(boolean_value)
48
+ if @database_manager.has_boolean
49
+ boolean_value
50
+ else
51
+ boolean_value == true ? 1 : 0
52
+ end
53
+ end
54
+
55
+ # Create table statement for primary transform table.
56
+ # @param [String] transform_table_name fully qualified name for this table
57
+ # @return [String]
58
+ def transforms_table_create_statement(transform_table_name)
59
+ %{create table if not exists #{ transform_table_name }
60
+ (
61
+ transform_name varchar(255) not null
62
+ ,sql_repository varchar(255)
63
+ ,sql_repository_branch varchar(255)
64
+ ,is_active #{ if @database_manager.has_boolean then 'boolean' else 'smallint' end }
65
+ ,notify_on_success #{ if @database_manager.has_boolean then 'boolean' else 'smallint' end }
66
+ ,notify_on_non_precondition_failure #{ if @database_manager.has_boolean then 'boolean' else 'smallint' end }
67
+ ,notify_on_precondition_failure #{ if @database_manager.has_boolean then 'boolean' else 'smallint' end }
68
+ ,updated_ts timestamp
69
+ );}
70
+ end
71
+
72
+ # Creates a record in the transforms table.
73
+ # @param [String] transform_table_name
74
+ # @param [Hash] params Hash of parameters with symbols matching column names
75
+ def create_transform(transform_table_name, params)
76
+ JDBCHelpers::Execute.new(
77
+ @jdbc_connection,
78
+ create_transform_statement(transform_table_name, params),
79
+ @logger
80
+ )
81
+ end
82
+
83
+ # @param [String] transform_table_name
84
+ # @param [Hash] params Hash of parameters with symbols matching column names
85
+ def create_transform_statement(transform_table_name, params)
86
+ %{insert into #{transform_table_name}
87
+ (
88
+ transform_name
89
+ ,sql_repository
90
+ ,sql_repository_branch
91
+ ,is_active
92
+ ,notify_on_success
93
+ ,notify_on_non_precondition_failure
94
+ ,notify_on_precondition_failure
95
+ ,updated_ts
96
+ )
97
+ values
98
+ (
99
+ '#{params[:transform_name]}'
100
+ ,'#{params[:sql_repository]}'
101
+ ,'#{params[:sql_repository_branch]}'
102
+ ,#{coerce_boolean(params[:is_active])}
103
+ ,#{coerce_boolean(params[:notify_on_success])}
104
+ ,#{coerce_boolean(params[:notify_on_non_precondition_failure])}
105
+ ,#{coerce_boolean(params[:notify_on_precondition_failure])}
106
+ ,current_timestamp
107
+ );}
108
+ end
109
+
110
+ # Drops and recreates the transform steps table.
111
+ # @param [String] transform_steps_table_name fully qualified name for this table
112
+ # @return [Boolean]
113
+ def recreate_transform_steps_table(transform_steps_table_name)
114
+ JDBCHelpers::Execute.new(
115
+ @jdbc_connection,
116
+ "drop table if exists #{ transform_steps_table_name };",
117
+ @logger
118
+ )
119
+ create_transform_steps_table(transform_steps_table_name)
120
+ return true
121
+ end
122
+
123
+ # Creates the transform steps table.
124
+ # @param [String] transform_steps_table_name fully qualified name for this table
125
+ # @return [Boolean]
126
+ def create_transform_steps_table(transform_steps_table_name)
127
+ JDBCHelpers::Execute.new(
128
+ @jdbc_connection,
129
+ transform_steps_table_create_statement(transform_steps_table_name),
130
+ @logger
131
+ )
132
+ return true
133
+ end
134
+
135
+ # Create table statement for transform steps table.
136
+ # @param [String] transform_steps_table_name fully qualified name for this table
137
+ # @return [String]
138
+ def transform_steps_table_create_statement(transform_steps_table_name)
139
+ %{create table if not exists #{ transform_steps_table_name }
140
+ (
141
+ transform_name varchar(255) not null
142
+ ,transform_step integer not null
143
+ ,sql_file_path_in_repo varchar(1024)
144
+ ,is_active #{ if @database_manager.has_boolean then 'boolean' else 'smallint' end }
145
+ ,is_precondition #{ if @database_manager.has_boolean then 'boolean' else 'smallint' end }
146
+ ,updated_ts timestamp
147
+ );}
148
+ end
149
+
150
+ # Drops and recreates the transform lock table.
151
+ # @param [String] transform_lock_table_name fully qualified name for this table
152
+ # @return [Boolean]
153
+ def recreate_transform_lock_table(transform_lock_table_name)
154
+ JDBCHelpers::Execute.new(
155
+ @jdbc_connection,
156
+ "drop table if exists #{ transform_lock_table_name };",
157
+ @logger
158
+ )
159
+ create_transform_lock_table(transform_lock_table_name)
160
+ return true
161
+ end
162
+
163
+ # Creates the transform lock table.
164
+ # @param [String] transform_lock_table_name fully qualified name for this table
165
+ # @return [Boolean]
166
+ def create_transform_lock_table(transform_lock_table_name)
167
+ JDBCHelpers::Execute.new(
168
+ @jdbc_connection,
169
+ transform_lock_table_create_statement(transform_lock_table_name),
170
+ @logger
171
+ )
172
+ return true
173
+ end
174
+
175
+ # Create table statement for transform lock table.
176
+ # @param [String] transform_lock_table_name fully qualified name for this table
177
+ # @return [String]
178
+ def transform_lock_table_create_statement(transform_lock_table_name)
179
+ %{create table if not exists #{ transform_lock_table_name }
180
+ (
181
+ transform_lock_id bigint
182
+ ,transform_name varchar(255)
183
+ ,transform_lock_time timestamp
184
+ );}
185
+ end
186
+
187
+ # Drops and recreates the transform log table.
188
+ # @param [String] transform_log_table_name fully qualified name for this table
189
+ # @return [Boolean]
190
+ def recreate_transform_log_table(transform_log_table_name)
191
+ JDBCHelpers::Execute.new(
192
+ @jdbc_connection,
193
+ "drop table if exists #{ transform_log_table_name };",
194
+ @logger
195
+ )
196
+ create_transform_log_table(transform_log_table_name)
197
+ return true
198
+ end
199
+
200
+ # Creates the transform log table.
201
+ # @param [String] transform_log_table_name fully qualified name for this table
202
+ # @return [Boolean]
203
+ def create_transform_log_table(transform_log_table_name)
204
+ JDBCHelpers::Execute.new(
205
+ @jdbc_connection,
206
+ transform_log_table_create_statement(transform_log_table_name),
207
+ @logger
208
+ )
209
+ return true
210
+ end
211
+
212
+ # Create table statement for transform log table.
213
+ # @param [String] transform_log_table_name fully qualified name for this table
214
+ # @return [String]
215
+ def transform_log_table_create_statement(transform_log_table_name)
216
+ %{create table if not exists #{ transform_log_table_name }
217
+ (
218
+ transform_run_id bigint
219
+ ,transform_lock_id bigint
220
+ ,transform_name varchar(255)
221
+ ,transform_step integer
222
+ ,transform_statement integer
223
+ ,all_steps_complete #{ if @database_manager.has_boolean then 'boolean' else 'smallint' end }
224
+ ,failed_in_precondition #{ if @database_manager.has_boolean then 'boolean' else 'smallint' end }
225
+ ,message varchar(65000)
226
+ ,transform_start_time timestamp
227
+ ,transform_end_time timestamp
228
+ );}
229
+ end
230
+ end
231
+ end
232
+ end
@@ -0,0 +1,60 @@
1
+ require 'json'
2
+
3
+ module Sneaql
4
+ # Managers for transform steps
5
+ module StepManagers
6
+ # source step metadata from a json file
7
+ class JSONFileStepManager < Sneaql::Core::StepMetadataManager
8
+ Sneaql::Core::RegisterMappedClass.new(
9
+ :step_metadata_manager,
10
+ 'local_file',
11
+ Sneaql::StepManagers::JSONFileStepManager
12
+ )
13
+
14
+ # Manages steps from a local JSON file.
15
+ def manage_steps
16
+ @steps = JSON.parse(File.read(@params[:step_metadata_file_path])).sort_by! { |h| h['step_number'] }
17
+ @steps.map! { |j| { step_number: j['step_number'], step_file: j['step_file'] } }
18
+ end
19
+ end
20
+
21
+ # source step metadata from a standardized table in the target database
22
+ class TransformStepTableManager < Sneaql::Core::StepMetadataManager
23
+ Sneaql::Core::RegisterMappedClass.new(
24
+ :step_metadata_manager,
25
+ 'transform_steps_table',
26
+ Sneaql::StepManagers::TransformStepTableManager
27
+ )
28
+
29
+ # Manages steps based in a standardized table.
30
+ def manage_steps
31
+ jdbc_connection = JDBCHelpers::ConnectionFactory.new(
32
+ @params[:jdbc_url],
33
+ @params[:db_user],
34
+ @params[:db_pass]
35
+ ).connection
36
+
37
+ @steps = JDBCHelpers::QueryResultsToArray.new(
38
+ jdbc_connection,
39
+ %(select
40
+ transform_step
41
+ ,sql_file_path_in_repo
42
+ from
43
+ #{@params[:transform_steps_table]}
44
+ where
45
+ transform_name='#{@params[:transform_name]}'
46
+ and
47
+ is_active=#{ if @params[:database_manager].has_boolean then 'true' else 1 end }
48
+ order by
49
+ transform_step asc;)
50
+ ).results
51
+
52
+ @steps.map! do |s|
53
+ { step_number: s['transform_step'], step_file: s['sql_file_path_in_repo'] }
54
+ end
55
+
56
+ jdbc_connection.close
57
+ end
58
+ end
59
+ end
60
+ end
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sneaql
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.8
5
+ platform: java
6
+ authors:
7
+ - jeremy winters
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-03-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '1.2'
19
+ name: logger
20
+ prerelease: false
21
+ type: :runtime
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.2'
27
+ - !ruby/object:Gem::Dependency
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: '5.9'
33
+ name: minitest
34
+ prerelease: false
35
+ type: :development
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '5.9'
41
+ - !ruby/object:Gem::Dependency
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '1.3'
47
+ name: git
48
+ prerelease: false
49
+ type: :runtime
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.3'
55
+ - !ruby/object:Gem::Dependency
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - '='
59
+ - !ruby/object:Gem::Version
60
+ version: 0.0.4
61
+ name: jdbc_helpers
62
+ prerelease: false
63
+ type: :runtime
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '='
67
+ - !ruby/object:Gem::Version
68
+ version: 0.0.4
69
+ - !ruby/object:Gem::Dependency
70
+ requirement: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0.9'
75
+ name: zip
76
+ prerelease: false
77
+ type: :runtime
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0.9'
83
+ description: provides the base classes required to run and extend sneaql
84
+ email: jeremy.winters@full360.com
85
+ executables:
86
+ - sneaql
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - bin/sneaql
91
+ - lib/sneaql.rb
92
+ - lib/sneaql_lib/base.rb
93
+ - lib/sneaql_lib/core.rb
94
+ - lib/sneaql_lib/database_manager.rb
95
+ - lib/sneaql_lib/database_prefs/redshift.rb
96
+ - lib/sneaql_lib/database_prefs/sqlite.rb
97
+ - lib/sneaql_lib/database_prefs/vertica.rb
98
+ - lib/sneaql_lib/exceptions.rb
99
+ - lib/sneaql_lib/expressions.rb
100
+ - lib/sneaql_lib/lock_manager.rb
101
+ - lib/sneaql_lib/parser.rb
102
+ - lib/sneaql_lib/recordset.rb
103
+ - lib/sneaql_lib/repo_manager.rb
104
+ - lib/sneaql_lib/standard.rb
105
+ - lib/sneaql_lib/standard_db_objects.rb
106
+ - lib/sneaql_lib/step_manager.rb
107
+ homepage: https://www.full360.com
108
+ licenses:
109
+ - MIT
110
+ metadata: {}
111
+ post_install_message:
112
+ rdoc_options: []
113
+ require_paths:
114
+ - lib
115
+ required_ruby_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '2.0'
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ requirements: []
126
+ rubyforge_project:
127
+ rubygems_version: 2.6.6
128
+ signing_key:
129
+ specification_version: 4
130
+ summary: sneaql language core
131
+ test_files: []