8000 Fix #87 by working around non-federated sqlproxy connections (#89) · mmithil/document-api-python@a440256 · GitHub
[go: up one dir, main page]

Skip to content

Commit a440256

Browse files
t8y8Russell Hay
authored and
Russell Hay
committed
Fix tableau#87 by working around non-federated sqlproxy connections (tableau#89)
When Cross Database Joins were introduced in 10 all connections became "federated" by default, even if they weren't actually joined to anything else. In the file format that means they get represented as named-connection/connection elements. Expressed under one top-level connection element with a class of 'federated'. Except for 'sqlproxy' connections (Published Data Sources) -- they stay in the old connection style as a top level connection element. We need to, when in a 10.0 or greater workbook, get all federated connections (named-connection) plus go back and find any sqlproxy connections as well.
1 parent cfcebde commit a440256

File tree

3 files changed

+61
-1
lines changed

3 files changed

+61
-1
lines changed

tableaudocumentapi/datasource.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,9 @@ def __init__(self, datasource_xml, version):
101101
self._dsversion = version
102102

103103
def _extract_federated_connections(self):
104-
return list(map(Connection, self._dsxml.findall('.//named-connections/named-connection/*')))
104+
connections = list(map(Connection, self._dsxml.findall('.//named-connections/named-connection/*')))
105+
connections.extend(map(Connection, self._dsxml.findall("./connection[@class='sqlproxy']")))
106+
return connections
105107

106108
def _extract_legacy_connection(self):
107109
return list(map(Connection, self._dsxml.findall('connection')))

test/assets/multiple_connections.twb

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?xml version='1.0' encoding='utf-8' ?>
2+
3+
<!-- build main.16.0928.1300 -->
4+
<workbook source-build='0.0.0 (0000.16.0928.1300)' source-platform='mac' version='10.1' xmlns:user='http://www.tableausoftware.com/xml/user'>
5+
<datasources>
6+
<datasource caption='xy (TestV1)' inline='true' name='sqlproxy.0uczajf02b02kv16u6atd08pslj5' version='10.1'>
7+
<repository-location id='xyTestV1' path='/datasources' revision='1.0' />
8+
<connection channel='http' class='sqlproxy' dbname='xyTestV1' directory='/dataserver' port='80' server='awesomeserver' username=''>
9+
<relation name='sqlproxy' table='[sqlproxy]' type='table' />
10+
</connection>
11+
</datasource>
12+
<datasource caption='xy+ (Multiple Connections)' inline='true' name='federated.1bw8gel1hkm5ms1c8jgrm0zixmde' version='10.1'>
13+
<connection class='federated'>
14+
<named-connections>
15+
<named-connection caption='mysql55' name='mysql.0unbi0i1tfh602155zoou04tacme'>
16+
<connection class='mysql' dbname='testv1' odbc-native-protocol='' port='' server='mysql55' source-charset='' username='test' />
17+
</named-connection>
18+
<named-connection caption='mssql2012.test' name='sqlserver.15j0kvj16xdjas1bs191w1ji441w'>
19+
<connection authentication='sqlserver' class='sqlserver' dbname='TestV1' odbc-native-protocol='yes' one-time-sql='' server='mssql2012' username='test' />
20+
</named-connection>
21+
</named-connections>
22+
<relation join='inner' type='join'>
23+
<clause type='join'>
24+
<expression op='='>
25+
<expression op='[xy].[a]' />
26+
<expression op='[xy1].[a]' />
27+
</expression>
28+
</clause>
29+
<relation connection='mysql.0unbi0i1tfh602155zoou04tacme' name='xy' table='[xy]' type='table' />
30+
<relation connection='sqlserver.15j0kvj16xdjas1bs191w1ji441w' name='xy1' table='[dbo].[xy]' type='table' />
31+
</relation>
32+
</connection>
33+
</datasource>
34+
</datasources>
35+
</workbook>

test/bvt.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727

2828
EMPTY_WORKBOOK = os.path.join(TEST_DIR, 'assets', 'empty_workbook.twb')
2929

30+
MULTI_CONNECTION_10 = os.path.join(
31+
TEST_DIR, 'assets', 'multiple_connections.twb')
32+
3033

3134
class ConnectionParserTests(unittest.TestCase):
3235

@@ -94,6 +97,26 @@ def test_can_create_datasource_from_connections(self):
9497
self.assertEqual(ds.connections[1].server, '1')
9598

9699

100+
class ConnectionParserInComplicatedWorkbooks(unittest.TestCase):
101+
102+
def setUp(self):
103+
with open(MULTI_CONNECTION_10, 'rb') as in_file, open('test.twb', 'wb') as out_file:
104+
out_file.write(in_file.read())
105+
self.twb_file = out_file
106+
107+
def tearDown(self):
108+
self.twb_file.close()
109+
os.unlink(self.twb_file.name)
110+
111+
def test_can_mixed_connections_workbook(self):
112+
wb = Workbook(self.twb_file.name)
113+
self.assertTrue(len(wb.datasources), 2)
114+
self.assertTrue(len(wb.datasources[1].connections), 2)
115+
self.assertEqual(wb.datasources[0].connections[0].dbclass, 'sqlproxy')
116+
self.assertEqual(wb.datasources[1].connections[0].dbclass, 'mysql')
117+
self.assertEqual(wb.datasources[1].connections[1].dbclass, 'sqlserver')
118+
119+
97120
class DatasourceModelTests(unittest.TestCase):
98121

99122
def setUp(self):

0 commit comments

Comments
 (0)
0