Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
olapy
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
2
Merge Requests
2
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
olapy
Commits
d699346b
Commit
d699346b
authored
Mar 20, 2017
by
mouadh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix bugs
parent
07891711
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
64 additions
and
54 deletions
+64
-54
olapy/core/mdx/executor/execute.py
olapy/core/mdx/executor/execute.py
+14
-8
olapy/core/services/xmla_execute_tools.py
olapy/core/services/xmla_execute_tools.py
+50
-46
No files found.
olapy/core/mdx/executor/execute.py
View file @
d699346b
...
@@ -41,7 +41,10 @@ class MdxEngine:
...
@@ -41,7 +41,10 @@ class MdxEngine:
cube_name
)
cube_name
)
self
.
tables_loaded
=
self
.
_load_tables
()
self
.
tables_loaded
=
self
.
_load_tables
()
self
.
tables_names
=
self
.
_get_tables_name
()
self
.
tables_names
=
self
.
_get_tables_name
()
# all measures
self
.
measures
=
self
.
_get_measures
()
self
.
measures
=
self
.
_get_measures
()
# default measure is the first one
self
.
selected_measures
=
[
self
.
measures
[
0
]]
@
classmethod
@
classmethod
def
get_cubes_names
(
self
):
def
get_cubes_names
(
self
):
...
@@ -51,8 +54,9 @@ class MdxEngine:
...
@@ -51,8 +54,9 @@ class MdxEngine:
location
=
os
.
path
.
join
(
location
=
os
.
path
.
join
(
os
.
path
.
abspath
(
os
.
path
.
abspath
(
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
".."
,
".."
,
".."
,
os
.
path
.
join
(
".."
)),
MdxEngine
.
CUBE_FOLDER
)
os
.
path
.
dirname
(
__file__
),
".."
,
".."
,
".."
,
".."
)),
MdxEngine
.
CUBE_FOLDER
)
return
[
return
[
file
for
file
in
os
.
listdir
(
location
)
file
for
file
in
os
.
listdir
(
location
)
if
os
.
path
.
isdir
(
os
.
path
.
join
(
location
,
file
))
if
os
.
path
.
isdir
(
os
.
path
.
join
(
location
,
file
))
...
@@ -67,8 +71,9 @@ class MdxEngine:
...
@@ -67,8 +71,9 @@ class MdxEngine:
'''
'''
return
os
.
path
.
join
(
return
os
.
path
.
join
(
os
.
path
.
abspath
(
os
.
path
.
abspath
(
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
'..'
,
".."
,
'..'
,
os
.
path
.
join
(
'..'
)),
self
.
cube_folder
)
os
.
path
.
dirname
(
__file__
),
'..'
,
".."
,
'..'
,
'..'
)),
self
.
cube_folder
)
def
_load_tables
(
self
):
def
_load_tables
(
self
):
"""
"""
...
@@ -297,7 +302,7 @@ class MdxEngine:
...
@@ -297,7 +302,7 @@ class MdxEngine:
== tup_att)]
== tup_att)]
cols = list(itertools.chain.from_iterable(columns_to_keep))
cols = list(itertools.chain.from_iterable(columns_to_keep))
return df[cols + self.measures]
return df[cols + self.
selected_
measures]
def add_missed_column(self, dataframe1, dataframe2):
def add_missed_column(self, dataframe1, dataframe2):
"""
"""
...
@@ -446,7 +451,7 @@ class MdxEngine:
...
@@ -446,7 +451,7 @@ class MdxEngine:
query_axes = self.decorticate_query(self.mdx_query)
query_axes = self.decorticate_query(self.mdx_query)
if self.change_measures(query_axes['all']):
if self.change_measures(query_axes['all']):
self.measures = self.change_measures(query_axes['all'])
self.
selected_
measures = self.change_measures(query_axes['all'])
# get only used columns and dimensions for all query
# get only used columns and dimensions for all query
start_df = self.load_star_schema_dataframe
start_df = self.load_star_schema_dataframe
...
@@ -499,7 +504,8 @@ class MdxEngine:
...
@@ -499,7 +504,8 @@ class MdxEngine:
self.execute_one_tuple(tupl, start_df,
self.execute_one_tuple(tupl, start_df,
columns_to_keep.values()))
columns_to_keep.values()))
cols = list(itertools.chain.from_iterable(columns_to_keep.values()))
cols = list(
itertools.chain.from_iterable(columns_to_keep.values()))
# TODO BUG !!! https://github.com/pandas-dev/pandas/issues/15525
# TODO BUG !!! https://github.com/pandas-dev/pandas/issues/15525
# solution 1 .astype(str) ( take a lot of time from execution)
# solution 1 .astype(str) ( take a lot of time from execution)
...
@@ -522,6 +528,6 @@ class MdxEngine:
...
@@ -522,6 +528,6 @@ class MdxEngine:
else:
else:
return {
return {
'result': start_df[self.measures].sum().to_frame().T,
'result': start_df[self.
selected_
measures].sum().to_frame().T,
'columns_desc': tables_n_columns
'columns_desc': tables_n_columns
}
}
olapy/core/services/xmla_execute_tools.py
View file @
d699346b
...
@@ -102,16 +102,15 @@ class XmlaExecuteTools():
...
@@ -102,16 +102,15 @@ class XmlaExecuteTools():
else
:
else
:
# ['Facts', 'Amount', 'Amount']
# ['Facts', 'Amount', 'Amount']
tuples
=
[[[[
self
.
executer
.
facts
]
+
[
mes
]
+
[
mes
]]]
tuples
=
[[[[
self
.
executer
.
facts
]
+
[
mes
]
+
[
mes
]]]
for
mes
in
self
.
executer
.
measures
]
for
mes
in
self
.
executer
.
selected_
measures
]
first_att
=
3
first_att
=
3
# query with on columns and on rows (without measure)
# query with on columns and on rows (without measure)
elif
mdx_execution_result
[
'columns_desc'
][
elif
mdx_execution_result
[
'columns_desc'
][
'columns'
]
and
mdx_execution_result
[
'columns_desc'
][
'rows'
]:
'columns'
]
and
mdx_execution_result
[
'columns_desc'
][
'rows'
]:
# ['Geography','America']
# ['Geography','America']
tuples
=
[
tuples
=
[
zip
(
*
[[[
key
]
+
list
(
row
)
zip
(
*
[[[
key
]
+
list
(
row
)
for
row
in
splited_df
[
key
].
itertuples
(
index
=
False
)]
for
row
in
splited_df
[
key
].
itertuples
(
index
=
False
)]
for
key
in
splited_df
.
keys
()
for
key
in
splited_df
.
keys
()
if
key
is
not
self
.
executer
.
facts
])
if
key
is
not
self
.
executer
.
facts
])
...
@@ -121,23 +120,20 @@ class XmlaExecuteTools():
...
@@ -121,23 +120,20 @@ class XmlaExecuteTools():
# query with on columns and on rows (many measures selected)
# query with on columns and on rows (many measures selected)
else
:
else
:
# ['Geography','Amount','America']
# ['Geography','Amount','America']
tuples
=
[
tuples
=
[
zip
(
*
[[[
key
]
+
[
mes
]
+
list
(
row
)
zip
(
*
[[[
key
]
+
[
mes
]
+
list
(
row
)
for
row
in
splited_df
[
key
].
itertuples
(
index
=
False
)]
for
row
in
splited_df
[
key
].
itertuples
(
index
=
False
)]
for
key
in
splited_df
.
keys
()
for
key
in
splited_df
.
keys
()
if
key
is
not
self
.
executer
.
facts
])
if
key
is
not
self
.
executer
.
facts
])
for
mes
in
self
.
executer
.
measures
for
mes
in
self
.
executer
.
selected_
measures
]
]
first_att
=
3
first_att
=
3
for
tupls
in
itertools
.
chain
(
*
tuples
):
for
tupls
in
itertools
.
chain
(
*
tuples
):
axis0
+=
"<Tuple>
\
n
"
axis0
+=
"<Tuple>
\
n
"
# [u'Geography', u'Amount', 'America']
# tupls[0][1] --> Measure
if
tupls
[
0
][
1
]
in
self
.
executer
.
measures
and
len
(
if
tupls
[
0
][
1
]
in
self
.
executer
.
measures
and
len
(
self
.
executer
.
measures
)
>
1
:
self
.
executer
.
selected_
measures
)
>
1
:
axis0
+=
"""
axis0
+=
"""
<Member Hierarchy="[Measures]">
<Member Hierarchy="[Measures]">
...
@@ -150,7 +146,7 @@ class XmlaExecuteTools():
...
@@ -150,7 +146,7 @@ class XmlaExecuteTools():
</Member>
</Member>
"""
.
format
(
tupls
[
0
][
1
])
"""
.
format
(
tupls
[
0
][
1
])
if
len
(
tupls
)
==
1
:
if
tupls
[
0
][
-
1
]
in
self
.
executer
.
measures
:
axis0
+=
"</Tuple>
\
n
"
axis0
+=
"</Tuple>
\
n
"
continue
continue
...
@@ -368,7 +364,9 @@ class XmlaExecuteTools():
...
@@ -368,7 +364,9 @@ class XmlaExecuteTools():
to_write
=
"[{0}].[{0}]"
.
format
(
dim_diff
)
to_write
=
"[{0}].[{0}]"
.
format
(
dim_diff
)
if
dim_diff
==
'Measures'
:
if
dim_diff
==
'Measures'
:
# if measures > 1 we don't have to write measure
# if measures > 1 we don't have to write measure
if
len
(
self
.
executer
.
measures
)
>
1
:
if
self
.
executer
.
facts
in
mdx_execution_result
[
'columns_desc'
][
'all'
]
and
len
(
mdx_execution_result
[
'columns_desc'
][
'all'
][
self
.
executer
.
facts
])
>
1
:
continue
continue
else
:
else
:
to_write
=
"[Measures]"
to_write
=
"[Measures]"
...
@@ -425,20 +423,11 @@ class XmlaExecuteTools():
...
@@ -425,20 +423,11 @@ class XmlaExecuteTools():
:return:
:return:
"""
"""
all_dimensions_names
=
self
.
executer
.
get_all_tables_names
(
ignore_fact
=
True
)
hierarchy_info
=
""
hierarchy_info
=
""
all_dimensions_names
.
append
(
'Measures'
)
# measure must be written at the top
for
table_name
in
mdx_execution_result
[
'columns_desc'
][
mdx_query_axis
]:
if
self
.
executer
.
facts
in
mdx_execution_result
[
'columns_desc'
][
to_write
=
"[{0}].[{0}]"
.
format
(
table_name
)
mdx_query_axis
].
keys
()
and
len
(
mdx_execution_result
[
# measures must be added to axis0 if measures selected > 1
'columns_desc'
][
mdx_query_axis
][
self
.
executer
.
facts
])
>
1
:
if
table_name
==
self
.
executer
.
facts
and
len
(
mdx_execution_result
[
'columns_desc'
][
mdx_query_axis
][
table_name
])
>
1
:
to_write
=
"[Measures]"
all_dimensions_names
.
remove
(
'Measures'
)
elif
table_name
==
self
.
executer
.
facts
:
continue
hierarchy_info
+=
"""
hierarchy_info
+=
"""
<HierarchyInfo name="{0}">
<HierarchyInfo name="{0}">
<UName name="{0}.[MEMBER_UNIQUE_NAME]" type="xs:string"/>
<UName name="{0}.[MEMBER_UNIQUE_NAME]" type="xs:string"/>
...
@@ -449,7 +438,22 @@ class XmlaExecuteTools():
...
@@ -449,7 +438,22 @@ class XmlaExecuteTools():
<PARENT_UNIQUE_NAME name="{0}.[PARENT_UNIQUE_NAME]" type="xs:string"/>
<PARENT_UNIQUE_NAME name="{0}.[PARENT_UNIQUE_NAME]" type="xs:string"/>
<HIERARCHY_UNIQUE_NAME name="{0}.[HIERARCHY_UNIQUE_NAME]" type="xs:string"/>
<HIERARCHY_UNIQUE_NAME name="{0}.[HIERARCHY_UNIQUE_NAME]" type="xs:string"/>
</HierarchyInfo>
</HierarchyInfo>
"""
.
format
(
to_write
)
"""
.
format
(
'[Measures]'
)
for
table_name
in
mdx_execution_result
[
'columns_desc'
][
mdx_query_axis
]:
if
table_name
!=
self
.
executer
.
facts
:
hierarchy_info
+=
"""
<HierarchyInfo name="[{0}].[{0}]">
<UName name="[{0}].[{0}].[MEMBER_UNIQUE_NAME]" type="xs:string"/>
<Caption name="[{0}].[{0}].[MEMBER_CAPTION]" type="xs:string"/>
<LName name="[{0}].[{0}].[LEVEL_UNIQUE_NAME]" type="xs:string"/>
<LNum name="[{0}].[{0}].[LEVEL_NUMBER]" type="xs:int"/>
<DisplayInfo name="[{0}].[{0}].[DISPLAY_INFO]" type="xs:unsignedInt"/>
<PARENT_UNIQUE_NAME name="[{0}].[{0}].[PARENT_UNIQUE_NAME]" type="xs:string"/>
<HIERARCHY_UNIQUE_NAME name="[{0}].[{0}].[HIERARCHY_UNIQUE_NAME]" type="xs:string"/>
</HierarchyInfo>
"""
.
format
(
table_name
)
if
hierarchy_info
:
if
hierarchy_info
:
hierarchy_info
=
"""
hierarchy_info
=
"""
<AxisInfo name='{0}'>
<AxisInfo name='{0}'>
...
@@ -522,8 +526,8 @@ class XmlaExecuteTools():
...
@@ -522,8 +526,8 @@ class XmlaExecuteTools():
tuple
=
""
tuple
=
""
# not used dimensions
# not used dimensions
for
dim_diff
in
list
(
for
dim_diff
in
list
(
set
(
self
.
executer
.
get_all_tables_names
(
ignore_fact
=
True
))
-
set
(
set
(
self
.
executer
.
get_all_tables_names
(
ignore_fact
=
True
))
-
[
set
(
[
table_name
table_name
for
table_name
in
mdx_execution_result
[
'columns_desc'
][
for
table_name
in
mdx_execution_result
[
'columns_desc'
][
'all'
]
'all'
]
...
@@ -541,7 +545,7 @@ class XmlaExecuteTools():
...
@@ -541,7 +545,7 @@ class XmlaExecuteTools():
self
.
executer
.
tables_loaded
[
dim_diff
].
iloc
[
0
][
0
])
self
.
executer
.
tables_loaded
[
dim_diff
].
iloc
[
0
][
0
])
# if we have zero on one only measures used
# if we have zero on one only measures used
if
len
(
self
.
executer
.
measures
)
<=
1
:
if
len
(
self
.
executer
.
selected_
measures
)
<=
1
:
tuple
+=
"""
tuple
+=
"""
<Member Hierarchy="[Measures]">
<Member Hierarchy="[Measures]">
<UName>[Measures].[{0}]</UName>
<UName>[Measures].[{0}]</UName>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment