Commit 0babd37c authored by mouadh's avatar mouadh

with xmlwitch

parent 81b1c0f5
...@@ -967,6 +967,18 @@ class XmlaDiscoverTools(): ...@@ -967,6 +967,18 @@ class XmlaDiscoverTools():
if request.Restrictions.RestrictionList.HIERARCHY_VISIBILITY == 3 or \ if request.Restrictions.RestrictionList.HIERARCHY_VISIBILITY == 3 or \
request.Restrictions.RestrictionList.CATALOG_NAME == self.selected_catalogue: request.Restrictions.RestrictionList.CATALOG_NAME == self.selected_catalogue:
rows = "" rows = ""
xml = xmlwitch.Builder()
with xml['return']:
with xml.root(
mdschema_hierarchies_xsd,
xmlns="urn:schemas-microsoft-com:xml-analysis:rowset",
**{
'xmlns:xsd': 'http://www.w3.org/2001/XMLSchema',
'xmlns:xsi':
'http://www.w3.org/2001/XMLSchema-instance'
}):
for table_name, df in self.executer.tables_loaded.items(): for table_name, df in self.executer.tables_loaded.items():
if table_name == self.executer.facts: if table_name == self.executer.facts:
continue continue
...@@ -979,65 +991,110 @@ class XmlaDiscoverTools(): ...@@ -979,65 +991,110 @@ class XmlaDiscoverTools():
else: else:
column_attribut = df.iloc[0][0] column_attribut = df.iloc[0][0]
rows += """ with xml.row:
<row> xml.CATALOG_NAME(self.selected_catalogue)
<CATALOG_NAME>{0}</CATALOG_NAME> xml.CUBE_NAME(self.selected_catalogue)
<CUBE_NAME>{0}</CUBE_NAME> xml.DIMENSION_UNIQUE_NAME('[' + table_name + ']')
<DIMENSION_UNIQUE_NAME>[{1}]</DIMENSION_UNIQUE_NAME> xml.HIERARCHY_NAME(table_name)
<HIERARCHY_NAME>{1}</HIERARCHY_NAME> xml.HIERARCHY_UNIQUE_NAME('[{0}].[{0}]'.format(self.selected_catalogue))
<HIERARCHY_UNIQUE_NAME>[{1}].[{1}]</HIERARCHY_UNIQUE_NAME> xml.HIERARCHY_CAPTION(table_name)
<HIERARCHY_CAPTION>{1}</HIERARCHY_CAPTION> xml.DIMENSION_TYPE('3')
<DIMENSION_TYPE>3</DIMENSION_TYPE> xml.HIERARCHY_CARDINALITY('6')
<HIERARCHY_CARDINALITY>6</HIERARCHY_CARDINALITY> xml.DEFAULT_MEMBER('[{0}].[{0}].[{1}].[{2}]'.format(table_name,
<DEFAULT_MEMBER>[{1}].[{1}].[{2}].[{3}]</DEFAULT_MEMBER> df.columns[0], column_attribut))
<STRUCTURE>0</STRUCTURE> xml.STRUCTURE('0')
<IS_VIRTUAL>false</IS_VIRTUAL> xml.IS_VIRTUAL('false')
<IS_READWRITE>false</IS_READWRITE> xml.IS_READWRITE('false')
<DIMENSION_UNIQUE_SETTINGS>1</DIMENSION_UNIQUE_SETTINGS> xml.DIMENSION_UNIQUE_SETTINGS('1')
<DIMENSION_IS_VISIBLE>true</DIMENSION_IS_VISIBLE> xml.DIMENSION_IS_VISIBLE('true')
<HIERARCHY_ORDINAL>1</HIERARCHY_ORDINAL> xml.HIERARCHY_ORDINAL('1')
<DIMENSION_IS_SHARED>true</DIMENSION_IS_SHARED> xml.DIMENSION_IS_SHARED('true')
<HIERARCHY_IS_VISIBLE>true</HIERARCHY_IS_VISIBLE> xml.HIERARCHY_IS_VISIBLE('true')
<HIERARCHY_ORIGIN>1</HIERARCHY_ORIGIN> xml.HIERARCHY_ORIGIN('1')
<INSTANCE_SELECTION>0</INSTANCE_SELECTION> xml.INSTANCE_SELECTION('0')
</row>
""".format(self.selected_catalogue, table_name,
df.columns[0], column_attribut)
rows += """ # rows += """
<row> # <row>
<CATALOG_NAME>{0}</CATALOG_NAME> # <CATALOG_NAME>{0}</CATALOG_NAME>
<CUBE_NAME>{0}</CUBE_NAME> # <CUBE_NAME>{0}</CUBE_NAME>
<DIMENSION_UNIQUE_NAME>[Measures]</DIMENSION_UNIQUE_NAME> # <DIMENSION_UNIQUE_NAME>[{1}]</DIMENSION_UNIQUE_NAME>
<HIERARCHY_NAME>Measures</HIERARCHY_NAME> # <HIERARCHY_NAME>{1}</HIERARCHY_NAME>
<HIERARCHY_UNIQUE_NAME>[Measures]</HIERARCHY_UNIQUE_NAME> # <HIERARCHY_UNIQUE_NAME>[{1}].[{1}]</HIERARCHY_UNIQUE_NAME>
<HIERARCHY_CAPTION>Measures</HIERARCHY_CAPTION> # <HIERARCHY_CAPTION>{1}</HIERARCHY_CAPTION>
<DIMENSION_TYPE>2</DIMENSION_TYPE> # <DIMENSION_TYPE>3</DIMENSION_TYPE>
<HIERARCHY_CARDINALITY>0</HIERARCHY_CARDINALITY> # <HIERARCHY_CARDINALITY>6</HIERARCHY_CARDINALITY>
<DEFAULT_MEMBER>[Measures].[{1}]</DEFAULT_MEMBER> # <DEFAULT_MEMBER>[{1}].[{1}].[{2}].[{3}]</DEFAULT_MEMBER>
<STRUCTURE>0</STRUCTURE> # <STRUCTURE>0</STRUCTURE>
<IS_VIRTUAL>false</IS_VIRTUAL> # <IS_VIRTUAL>false</IS_VIRTUAL>
<IS_READWRITE>false</IS_READWRITE> # <IS_READWRITE>false</IS_READWRITE>
<DIMENSION_UNIQUE_SETTINGS>1</DIMENSION_UNIQUE_SETTINGS> # <DIMENSION_UNIQUE_SETTINGS>1</DIMENSION_UNIQUE_SETTINGS>
<DIMENSION_IS_VISIBLE>true</DIMENSION_IS_VISIBLE> # <DIMENSION_IS_VISIBLE>true</DIMENSION_IS_VISIBLE>
<HIERARCHY_ORDINAL>1</HIERARCHY_ORDINAL> # <HIERARCHY_ORDINAL>1</HIERARCHY_ORDINAL>
<DIMENSION_IS_SHARED>true</DIMENSION_IS_SHARED> # <DIMENSION_IS_SHARED>true</DIMENSION_IS_SHARED>
<HIERARCHY_IS_VISIBLE>true</HIERARCHY_IS_VISIBLE> # <HIERARCHY_IS_VISIBLE>true</HIERARCHY_IS_VISIBLE>
<HIERARCHY_ORIGIN>1</HIERARCHY_ORIGIN> # <HIERARCHY_ORIGIN>1</HIERARCHY_ORIGIN>
<INSTANCE_SELECTION>0</INSTANCE_SELECTION> # <INSTANCE_SELECTION>0</INSTANCE_SELECTION>
</row> # </row>
""".format(self.selected_catalogue, self.executer.measures[0]) # """.format(self.selected_catalogue, table_name,
# df.columns[0], column_attribut)
return etree.fromstring(""" with xml.row:
<return>
<root xmlns="urn:schemas-microsoft-com:xml-analysis:rowset" xml.CATALOG_NAME(self.selected_catalogue)
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xml.CUBE_NAME(self.selected_catalogue)
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> xml.DIMENSION_UNIQUE_NAME('[Measures]')
""" + mdschema_hierarchies_xsd + """ xml.HIERARCHY_NAME('Measures')
{0} xml.HIERARCHY_UNIQUE_NAME('[Measures]')
</root> xml.HIERARCHY_CAPTION('Measures')
</return> xml.DIMENSION_TYPE('2')
""".format(rows)) xml.HIERARCHY_CARDINALITY('0')
xml.DEFAULT_MEMBER('[Measures].[{0}]'.format(self.executer.measures[0]))
xml.STRUCTURE('0')
xml.IS_VIRTUAL('false')
xml.IS_READWRITE('false')
xml.DIMENSION_UNIQUE_SETTINGS('1')
xml.DIMENSION_IS_VISIBLE('true')
xml.HIERARCHY_ORDINAL('1')
xml.DIMENSION_IS_SHARED('true')
xml.HIERARCHY_IS_VISIBLE('true')
xml.HIERARCHY_ORIGIN('1')
xml.INSTANCE_SELECTION('0')
# rows += """
# <row>
# <CATALOG_NAME>{0}</CATALOG_NAME>
# <CUBE_NAME>{0}</CUBE_NAME>
# <DIMENSION_UNIQUE_NAME>[Measures]</DIMENSION_UNIQUE_NAME>
# <HIERARCHY_NAME>Measures</HIERARCHY_NAME>
# <HIERARCHY_UNIQUE_NAME>[Measures]</HIERARCHY_UNIQUE_NAME>
# <HIERARCHY_CAPTION>Measures</HIERARCHY_CAPTION>
# <DIMENSION_TYPE>2</DIMENSION_TYPE>
# <HIERARCHY_CARDINALITY>0</HIERARCHY_CARDINALITY>
# <DEFAULT_MEMBER>[Measures].[{1}]</DEFAULT_MEMBER>
# <STRUCTURE>0</STRUCTURE>
# <IS_VIRTUAL>false</IS_VIRTUAL>
# <IS_READWRITE>false</IS_READWRITE>
# <DIMENSION_UNIQUE_SETTINGS>1</DIMENSION_UNIQUE_SETTINGS>
# <DIMENSION_IS_VISIBLE>true</DIMENSION_IS_VISIBLE>
# <HIERARCHY_ORDINAL>1</HIERARCHY_ORDINAL>
# <DIMENSION_IS_SHARED>true</DIMENSION_IS_SHARED>
# <HIERARCHY_IS_VISIBLE>true</HIERARCHY_IS_VISIBLE>
# <HIERARCHY_ORIGIN>1</HIERARCHY_ORIGIN>
# <INSTANCE_SELECTION>0</INSTANCE_SELECTION>
# </row>
# """.format(self.selected_catalogue, self.executer.measures[0])
html_parser = HTMLParser.HTMLParser()
xml = html_parser.unescape(str(xml))
return xml
# return etree.fromstring("""
# <return>
# <root xmlns="urn:schemas-microsoft-com:xml-analysis:rowset"
# xmlns:xsd="http://www.w3.org/2001/XMLSchema"
# xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
# """ + mdschema_hierarchies_xsd + """
# {0}
# </root>
# </return>
# """.format(rows))
# if request.Restrictions.RestrictionList.CATALOG_NAME == self.selected_catalogue: # if request.Restrictions.RestrictionList.CATALOG_NAME == self.selected_catalogue:
# rows = "" # rows = ""
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment