data_conduit 0.1.3 → 0.2.1
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
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4cc315eef32b269bfa6be1d883eeeecd3b4f33269528d1841213621b28717812
|
|
4
|
+
data.tar.gz: 4c78d834e731c3903dde4cad8461bc5b3e2bc1c7886e41dcc3064090712aa710
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 56bb80246966f918000373dfec41ea9429554a93e3c13c9a404064349bcccd8a7fd9915dc924d039e30e10511fee3469bb5373c6e102130648ad6b83834dc21e
|
|
7
|
+
data.tar.gz: '0759aecc053dcc9f81ce8b484e5d89fd8b84f26919fc7c8aba75ea18375462b02b9ef95846bb0ac3365882ee9d7f3342f24b0a5503e4270b4b03e84eb1d9143c'
|
|
@@ -25,16 +25,33 @@ module DataConduit
|
|
|
25
25
|
validate_config!
|
|
26
26
|
end
|
|
27
27
|
|
|
28
|
+
def self.tables(config)
|
|
29
|
+
repo = new(nil, nil, config)
|
|
30
|
+
response_data = repo.send(:response_to, "SHOW tables")
|
|
31
|
+
if response_data[:result_data].is_a?(Hash) && response_data[:result_data]["error"]
|
|
32
|
+
raise DataConduit::TrinoException, response_data[:result_data]["error"].to_s
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
response_data[:result_data]&.flatten&.sort
|
|
36
|
+
end
|
|
37
|
+
|
|
28
38
|
def query(sql_query = nil)
|
|
29
39
|
sql_query ||= build_query
|
|
30
40
|
execute(sql_query)
|
|
31
41
|
end
|
|
32
42
|
|
|
33
43
|
def execute(sql_query)
|
|
34
|
-
response_data =
|
|
44
|
+
response_data = response_to(sql_query)
|
|
35
45
|
transform_response(response_data[:result_data], response_data[:result_columns])
|
|
36
46
|
end
|
|
37
47
|
|
|
48
|
+
def last_updated
|
|
49
|
+
response_data = response_to("SELECT made_current_at FROM \"#{table_name}$history\" " \
|
|
50
|
+
"ORDER BY made_current_at DESC LIMIT 1")
|
|
51
|
+
datetime_string = response_data[:result_data]&.flatten&.first
|
|
52
|
+
datetime_string.nil? ? nil : DateTime.parse(datetime_string)
|
|
53
|
+
end
|
|
54
|
+
|
|
38
55
|
private
|
|
39
56
|
|
|
40
57
|
def default_config
|
|
@@ -78,16 +95,26 @@ module DataConduit
|
|
|
78
95
|
end
|
|
79
96
|
end
|
|
80
97
|
|
|
98
|
+
def response_to(sql)
|
|
99
|
+
process_response(send_query(sql))
|
|
100
|
+
end
|
|
101
|
+
|
|
81
102
|
def process_response(initial_response)
|
|
82
103
|
result_data = []
|
|
83
104
|
result_columns = nil
|
|
84
105
|
response_data = initial_response
|
|
85
106
|
|
|
86
107
|
while response_data
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
108
|
+
if response_data["error"]
|
|
109
|
+
result_data = { "error" => response_data["error"] }
|
|
110
|
+
result_columns = nil
|
|
111
|
+
response_data = nil
|
|
112
|
+
else
|
|
113
|
+
result_data.concat(response_data["data"]) if response_data["data"]
|
|
114
|
+
result_columns ||= response_data["columns"]
|
|
115
|
+
next_uri = response_data["nextUri"]
|
|
116
|
+
response_data = next_uri ? fetch_next(next_uri) : nil
|
|
117
|
+
end
|
|
91
118
|
end
|
|
92
119
|
|
|
93
120
|
{ result_data: result_data, result_columns: result_columns }
|
|
@@ -18,6 +18,10 @@ module DataConduit
|
|
|
18
18
|
raise NotImplementedError, "You must implement the initialize method"
|
|
19
19
|
end
|
|
20
20
|
|
|
21
|
+
def self.tables(_config = {})
|
|
22
|
+
raise NotImplementedError, "You must implement the tables method"
|
|
23
|
+
end
|
|
24
|
+
|
|
21
25
|
def query(_sql_query = nil)
|
|
22
26
|
raise NotImplementedError, "You must implement the query method"
|
|
23
27
|
end
|
|
@@ -26,12 +30,16 @@ module DataConduit
|
|
|
26
30
|
raise NotImplementedError, "You must implement the execute method"
|
|
27
31
|
end
|
|
28
32
|
|
|
33
|
+
def last_updated
|
|
34
|
+
raise NotImplementedError, "You must implement the last_updated method"
|
|
35
|
+
end
|
|
36
|
+
|
|
29
37
|
protected
|
|
30
38
|
|
|
31
39
|
def validate_table_name(table_name)
|
|
32
40
|
raise ArgumentError, "Table name cannot be blank" if table_name.nil? || table_name.empty?
|
|
33
41
|
|
|
34
|
-
return if table_name.to_s.match?(/^[a-zA-Z0-9_
|
|
42
|
+
return if table_name.to_s.match?(/^[a-zA-Z0-9_.]+$/)
|
|
35
43
|
|
|
36
44
|
raise ArgumentError, "Invalid table name format. Table name must contain only letters, " \
|
|
37
45
|
"numbers, underscores, and periods."
|
|
@@ -39,6 +47,7 @@ module DataConduit
|
|
|
39
47
|
|
|
40
48
|
def transform_response(result_data, result_columns)
|
|
41
49
|
return [] if result_data.nil? || result_data.empty?
|
|
50
|
+
return [result_data] if result_data.is_a?(Hash) && result_data["error"]
|
|
42
51
|
|
|
43
52
|
columns = extract_column_names(result_columns)
|
|
44
53
|
result_data.map do |row|
|
data/lib/data_conduit/version.rb
CHANGED
data/lib/data_conduit.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: data_conduit
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1
|
|
4
|
+
version: 0.2.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Vinicius Dittgen
|
|
@@ -200,7 +200,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
200
200
|
- !ruby/object:Gem::Version
|
|
201
201
|
version: '0'
|
|
202
202
|
requirements: []
|
|
203
|
-
rubygems_version: 3.6.
|
|
203
|
+
rubygems_version: 3.6.9
|
|
204
204
|
specification_version: 4
|
|
205
205
|
summary: A Ruby connector for data warehouses
|
|
206
206
|
test_files: []
|