tableau_server_client 0.0.13 → 0.0.14

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: ac40ff9b18e29df41bff878b7f3ba1f7c5a34ffa20690edb6d23784603afd617
4
- data.tar.gz: 5ed21cfe75080d06b2db42b0a383cfb167ef84fde19f877bb22a31fc4fe91621
3
+ metadata.gz: 3800d6fbbddcc281f1b0b39569bae2cc6f7793906da71503ab1050a9c540d9a2
4
+ data.tar.gz: 796b262cd13c5c963679d6f9595315588ddeddce27a60f38506f9132fe962b48
5
5
  SHA512:
6
- metadata.gz: 4677d14c34c02d7db0da58eaa14758047cd923764d4a8bcc74cc1450b7ea403fa06045251f297427c8a6d129904efe4db9c66eb0247cb1736663135490bb0c38
7
- data.tar.gz: 30fb765574a89f51f53d1824e12dd8376603607d8842e2956ffe183c726473878dbab4ce6e53e0ffea887ad321194f22c9dcd4fd954202ac0a8aabfe37a584e0
6
+ metadata.gz: f1f52ce310a55bef61171c488cfbe67b1029204e2309d64891861cdc2d3350a1778e7af3777dda2b99e0cde4928c2314b0af787f09099c734fa6778a4534604a
7
+ data.tar.gz: 33a497c59dfac303ca8a22953d7929d0212a141aafa60a55af8a1c613eaf3b9924feb4c35972fe8e83080dbaa163a8d9d4f457bd26f245ff629d02f14a2354ba
@@ -51,6 +51,79 @@ module TableauServerClient
51
51
  @client.update self
52
52
  end
53
53
 
54
+ def content
55
+ DatasourceContent.new(download.xpath('//datasource').first)
56
+ end
57
+
58
+ class DatasourceContent
59
+
60
+ def initialize(xml)
61
+ @xml = xml
62
+ end
63
+
64
+ attr_reader :xml
65
+
66
+ NamedConnection = Struct.new("NamedConnections", :class, :caption, :name)
67
+ def named_connections
68
+ xml.xpath('//named-connection').map do |c|
69
+ NamedConnection.new(c.first_element_child['class'], c['caption'], c['name'])
70
+ end
71
+ end
72
+
73
+ def custom_queries
74
+ relations.select {|r| r['type'] == 'text' }.map {|c| c.content }
75
+ end
76
+
77
+ def tables
78
+ tables = []
79
+ redshift_connections = named_connections.select {|c| c.class == 'redshift' }.map {|c| c.name }
80
+ relations.each do |rel|
81
+ next unless redshift_connections.include? rel['connection']
82
+ case rel['type']
83
+ when 'table'
84
+ tables << rel['table']
85
+ when 'text'
86
+ tables.concat extract_tables(rel.content)
87
+ else
88
+ next
89
+ end
90
+ end
91
+ tables.map {|t| t.gsub(/[\[\]")]/, '')}.uniq
92
+ end
93
+
94
+ private
95
+
96
+ def relations
97
+ xml.xpath('//relation')
98
+ end
99
+
100
+ def extract_tables(query)
101
+ q = query.dup
102
+ q.gsub!(/(\<\[Parameters\]\.\[.*?\]\>)/, "'\\1'")
103
+ q.gsub!(/(--[^\r\n]*)|(\/\*[\w\W]*?(?=\*\/)\*\/)/m, '')
104
+ q.gsub!(/[\t\r\n]/, ' ')
105
+ q.gsub!(/\s+/, ' ')
106
+
107
+ tables = []
108
+ may_be_table = false
109
+ q.split(' ').each do |t|
110
+ t.downcase!
111
+ if may_be_table
112
+ tables << t unless t =~ /(^select|^\(.*)/
113
+ may_be_table = false
114
+ end
115
+ if ['from', 'join'].include?(t)
116
+ may_be_table = true
117
+ end
118
+ end
119
+ tables
120
+ # ParseError with sub-query without alias name
121
+ #PgQuery.parse(no_parameter_query).tables.each do |t|
122
+ # yield t
123
+ #end
124
+ end
125
+ end
126
+
54
127
  end
55
128
  end
56
129
  end
@@ -2,6 +2,7 @@ require 'tableau_server_client/resources/resource'
2
2
  require 'tableau_server_client/resources/project'
3
3
  require 'tableau_server_client/resources/connection'
4
4
  require 'tableau_server_client/resources/downloadable'
5
+ require 'tableau_server_client/resources/datasource'
5
6
 
6
7
  module TableauServerClient
7
8
  module Resources
@@ -51,64 +52,10 @@ module TableauServerClient
51
52
  @client.update self
52
53
  end
53
54
 
54
- def custom_queries
55
- relations.select {|r| r['type'] == 'text' }.map {|c| c.content }
56
- end
57
-
58
- def tables
59
- tables = []
60
- redshift_connections = named_connections.select {|c| c.class == 'redshift' }.map {|c| c.name }
61
- relations.each do |rel|
62
- next unless redshift_connections.include? rel['connection']
63
- case rel['type']
64
- when 'table'
65
- tables << rel['table']
66
- when 'text'
67
- tables.concat extract_tables(rel.content)
68
- else
69
- next
70
- end
71
- end
72
- tables.map {|t| t.gsub(/[\[\]")]/, '')}.uniq
73
- end
74
-
75
- private
76
-
77
- NamedConnection = Struct.new("NamedConnections", :class, :caption, :name)
78
- def named_connections
79
- download.xpath('//named-connection').map do |c|
80
- NamedConnection.new(c.first_element_child['class'], c['caption'], c['name'])
81
- end
82
- end
83
-
84
- def relations
85
- download.xpath('//datasources//datasource//relation')
86
- end
87
-
88
- def extract_tables(query)
89
- q = query.dup
90
- q.gsub!(/(\<\[Parameters\]\.\[.*?\]\>)/, "'\\1'")
91
- q.gsub!(/(--[^\r\n]*)|(\/\*[\w\W]*?(?=\*\/)\*\/)/m, '')
92
- q.gsub!(/[\t\r\n]/, ' ')
93
- q.gsub!(/\s+/, ' ')
94
-
95
- tables = []
96
- may_be_table = false
97
- q.split(' ').each do |t|
98
- t.downcase!
99
- if may_be_table
100
- tables << t unless t =~ /(^select|^\(.*)/
101
- may_be_table = false
102
- end
103
- if ['from', 'join'].include?(t)
104
- may_be_table = true
105
- end
55
+ def embedded_datasources
56
+ download.xpath('//datasources//datasource').each do |ds|
57
+ Datasource::DatasourceContent.new(ds)
106
58
  end
107
- tables
108
- # ParseError with sub-query without alias name
109
- #PgQuery.parse(no_parameter_query).tables.each do |t|
110
- # yield t
111
- #end
112
59
  end
113
60
 
114
61
  end
@@ -1,3 +1,3 @@
1
1
  module TableauServerClient
2
- VERSION = "0.0.13"
2
+ VERSION = "0.0.14"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tableau_server_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.13
4
+ version: 0.0.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - shimpeko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-04-17 00:00:00.000000000 Z
11
+ date: 2019-04-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler