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
b582ad40
Commit
b582ad40
authored
May 03, 2017
by
mouadh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
format
parent
b162e5c9
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
75 additions
and
64 deletions
+75
-64
olapy/core/mdx/executor/execute.py
olapy/core/mdx/executor/execute.py
+7
-5
olapy/core/services/xmla.py
olapy/core/services/xmla.py
+24
-17
olapy/core/services/xmla_execute_tools.py
olapy/core/services/xmla_execute_tools.py
+44
-42
No files found.
olapy/core/mdx/executor/execute.py
View file @
b582ad40
...
...
@@ -331,8 +331,8 @@ class MdxEngine:
for
cubes
in
config_file_parser
.
construct_cubes
():
# TODO cubes.source == 'csv'
if
cubes
.
source
==
'postgres'
:
fusion
=
self
.
_construct_star_schema_config_file
(
cube_name
,
cubes
)
fusion
=
self
.
_construct_star_schema_config_file
(
cube_name
,
cubes
)
elif
cube_name
in
self
.
csv_files_cubes
:
fusion
=
self
.
_construct_star_schema_csv_files
(
cube_name
)
...
...
@@ -690,8 +690,9 @@ class MdxEngine:
:return: updated columns_to_keep
"""
if len(tuple_as_list) == 3 and tuple_as_list[-1] in self.tables_loaded[
tuple_as_list[0]].columns:
if len(
tuple_as_list
) == 3 and tuple_as_list[-1] in self.tables_loaded[tuple_as_list[0]].columns:
# in case of [Geography].[Geography].[Country]
cols = [tuple_as_list[-1]]
else:
...
...
@@ -774,7 +775,8 @@ class MdxEngine:
self.execute_one_tuple(tupl, start_df,
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
# solution 1 .astype(str) ( take a lot of time from execution)
...
...
olapy/core/services/xmla.py
View file @
b582ad40
...
...
@@ -38,12 +38,12 @@ class XmlaProviderService(ServiceBase):
discover_tools
=
XmlaDiscoverTools
()
sessio_id
=
discover_tools
.
session_id
@
rpc
(
DiscoverRequest
,
_returns
=
AnyXml
,
_body_style
=
"bare"
,
_out_header
=
Session
,
_throws
=
InvalidCredentialsError
)
@
rpc
(
DiscoverRequest
,
_returns
=
AnyXml
,
_body_style
=
"bare"
,
_out_header
=
Session
,
_throws
=
InvalidCredentialsError
)
def
Discover
(
ctx
,
request
):
"""
the first principle function of xmla protocol
...
...
@@ -61,10 +61,12 @@ class XmlaProviderService(ServiceBase):
ctx
.
out_header
=
Session
(
SessionId
=
str
(
XmlaProviderService
.
sessio_id
))
config_parser
=
ConfigParser
(
discover_tools
.
executer
.
cube_path
)
if
config_parser
.
xmla_authentication
()
and
ctx
.
transport
.
req_env
[
'QUERY_STRING'
]
!=
'admin'
:
if
config_parser
.
xmla_authentication
(
)
and
ctx
.
transport
.
req_env
[
'QUERY_STRING'
]
!=
'admin'
:
raise
InvalidCredentialsError
(
fault_string
=
'You do not have permission to access this resource'
,
fault_string
=
'You do not have permission to access this resource'
,
fault_object
=
None
)
# TODO call (labster) login function or create login with token (according to labster db)
...
...
@@ -99,7 +101,8 @@ class XmlaProviderService(ServiceBase):
return
discover_tools
.
discover_mdschema_measures__response
(
request
)
elif
request
.
RequestType
==
"MDSCHEMA_DIMENSIONS"
:
return
discover_tools
.
discover_mdschema_dimensions_response
(
request
)
return
discover_tools
.
discover_mdschema_dimensions_response
(
request
)
elif
request
.
RequestType
==
"MDSCHEMA_HIERARCHIES"
:
return
discover_tools
.
discover_mdschema_hierarchies_response
(
...
...
@@ -117,17 +120,19 @@ class XmlaProviderService(ServiceBase):
request
)
elif
request
.
RequestType
==
"MDSCHEMA_PROPERTIES"
:
return
discover_tools
.
discover_mdschema_properties_response
(
request
)
return
discover_tools
.
discover_mdschema_properties_response
(
request
)
elif
request
.
RequestType
==
"MDSCHEMA_MEMBERS"
:
return
discover_tools
.
discover_mdschema_members_response
(
request
)
# Execute function must take 2 argument ( JUST 2 ! ) Command and Properties
# we encapsulate them in ExecuteRequest object
@
rpc
(
ExecuteRequest
,
_returns
=
AnyXml
,
_body_style
=
"bare"
,
_out_header
=
Session
)
@
rpc
(
ExecuteRequest
,
_returns
=
AnyXml
,
_body_style
=
"bare"
,
_out_header
=
Session
)
def
Execute
(
ctx
,
request
):
"""
the second principle function of xmla protocol
...
...
@@ -236,11 +241,13 @@ def start_server(write_on_file=False):
# TODO FIX it with os
if
write_on_file
:
home_directory
=
expanduser
(
"~"
)
if
not
os
.
path
.
isdir
(
os
.
path
.
join
(
home_directory
,
'olapy-data'
,
'logs'
)):
os
.
makedirs
(
os
.
path
.
join
(
home_directory
,
'olapy-data'
,
'logs'
))
if
not
os
.
path
.
isdir
(
os
.
path
.
join
(
home_directory
,
'olapy-data'
,
'logs'
)):
os
.
makedirs
(
os
.
path
.
join
(
home_directory
,
'olapy-data'
,
'logs'
))
logging
.
basicConfig
(
level
=
logging
.
DEBUG
,
filename
=
os
.
path
.
join
(
home_directory
,
'olapy-data'
,
'logs'
,
'xmla.log'
))
filename
=
os
.
path
.
join
(
home_directory
,
'olapy-data'
,
'logs'
,
'xmla.log'
))
else
:
logging
.
basicConfig
(
level
=
logging
.
DEBUG
)
logging
.
getLogger
(
'spyne.protocol.xml'
).
setLevel
(
logging
.
DEBUG
)
...
...
olapy/core/services/xmla_execute_tools.py
View file @
b582ad40
...
...
@@ -78,7 +78,7 @@ class XmlaExecuteTools():
"""
for
att
in
tuple
[::
-
1
]:
if
att
!=
-
1
:
return
tuple
[:
tuple
.
index
(
att
)
+
1
]
return
tuple
[:
tuple
.
index
(
att
)
+
1
]
return
tuple
...
...
@@ -94,8 +94,9 @@ class XmlaExecuteTools():
"""
axis0
=
""
# only measure selected
if
mdx_execution_result
[
'columns_desc'
][
mdx_query_axis
].
keys
()
==
[
self
.
executer
.
facts
]:
if
mdx_execution_result
[
'columns_desc'
][
mdx_query_axis
].
keys
()
==
[
self
.
executer
.
facts
]:
if
len
(
mdx_execution_result
[
'columns_desc'
][
mdx_query_axis
][
self
.
executer
.
facts
])
==
1
:
# to ignore for tupls in itertools.chain(*tuples)
...
...
@@ -107,14 +108,14 @@ class XmlaExecuteTools():
first_att
=
3
# query with on columns and on rows (without measure)
elif
mdx_execution_result
[
'columns_desc'
][
'columns'
]
and
mdx_execution_result
[
'columns_desc'
][
'rows'
]:
elif
mdx_execution_result
[
'columns_desc'
][
'columns'
]
and
mdx_execution_result
[
'columns_desc'
][
'rows'
]:
# ['Geography','America']
tuples
=
[
zip
(
*
[[[
key
]
+
list
(
row
)
for
row
in
splited_df
[
key
].
itertuples
(
index
=
False
)]
for
key
in
splited_df
.
keys
()
if
key
is
not
self
.
executer
.
facts
])
zip
(
*
[[[
key
]
+
list
(
row
)
for
row
in
splited_df
[
key
].
itertuples
(
index
=
False
)]
for
key
in
splited_df
.
keys
()
if
key
is
not
self
.
executer
.
facts
])
]
first_att
=
2
...
...
@@ -123,10 +124,11 @@ class XmlaExecuteTools():
else
:
# ['Geography','Amount','America']
tuples
=
[
zip
(
*
[[[
key
]
+
[
mes
]
+
list
(
row
)
for
row
in
splited_df
[
key
].
itertuples
(
index
=
False
)]
for
key
in
splited_df
.
keys
()
if
key
is
not
self
.
executer
.
facts
])
zip
(
*
[[[
key
]
+
[
mes
]
+
list
(
row
)
for
row
in
splited_df
[
key
].
itertuples
(
index
=
False
)]
for
key
in
splited_df
.
keys
()
if
key
is
not
self
.
executer
.
facts
])
for
mes
in
self
.
executer
.
selected_measures
]
first_att
=
3
...
...
@@ -250,8 +252,7 @@ class XmlaExecuteTools():
# TODO must be OPTIMIZED every time!!!!!
dfs
=
self
.
split_dataframe
(
mdx_execution_result
)
if
mdx_execution_result
[
'columns_desc'
][
'rows'
]
and
mdx_execution_result
[
'columns_desc'
][
'columns'
]:
if
mdx_execution_result
[
'columns_desc'
][
'rows'
]
and
mdx_execution_result
[
'columns_desc'
][
'columns'
]:
return
"""
{0}
...
...
@@ -304,24 +305,27 @@ class XmlaExecuteTools():
columns_loop
=
[]
if
(
(
len
(
mdx_execution_result
[
'columns_desc'
][
'columns'
].
keys
())
==
0
)
^
(
len
(
mdx_execution_result
[
'columns_desc'
][
'rows'
].
keys
())
==
0
)
)
and
self
.
executer
.
facts
in
mdx_execution_result
[
'columns_desc'
][
'all'
].
keys
():
# iterate DataFrame horizontally
columns_loop
=
itertools
.
chain
(
*
[
mdx_execution_result
[
'result'
][
measure
]
for
measure
in
mdx_execution_result
[
'result'
].
columns
])
(
len
(
mdx_execution_result
[
'columns_desc'
][
'columns'
].
keys
())
==
0
)
^
(
len
(
mdx_execution_result
[
'columns_desc'
][
'rows'
].
keys
())
==
0
)
)
and
self
.
executer
.
facts
in
mdx_execution_result
[
'columns_desc'
][
'all'
].
keys
(
):
# iterate DataFrame horizontally
columns_loop
=
itertools
.
chain
(
*
[
mdx_execution_result
[
'result'
][
measure
]
for
measure
in
mdx_execution_result
[
'result'
].
columns
])
else
:
# iterate DataFrame vertically
columns_loop
=
itertools
.
chain
(
*
[
tuple
for
tuple
in
mdx_execution_result
[
'result'
].
itertuples
(
index
=
False
)
])
columns_loop
=
itertools
.
chain
(
*
[
tuple
for
tuple
in
mdx_execution_result
[
'result'
].
itertuples
(
index
=
False
)
])
cell_data
=
""
index
=
0
...
...
@@ -375,8 +379,7 @@ class XmlaExecuteTools():
slicer_list
=
list
(
set
(
all_dimensions_names
)
-
set
(
table_name
for
table_name
in
mdx_execution_result
[
'columns_desc'
][
'all'
]
))
for
table_name
in
mdx_execution_result
[
'columns_desc'
][
'all'
]))
# we have to write measures after dimensions !
if
'Measures'
in
slicer_list
:
...
...
@@ -388,9 +391,9 @@ class XmlaExecuteTools():
to_write
=
"[{0}].[{0}]"
.
format
(
dim_diff
)
if
dim_diff
==
'Measures'
:
# if measures > 1 we don't have to write measure
if
self
.
executer
.
facts
in
mdx_execution_result
[
'columns_desc'
][
'all'
]
and
len
(
mdx_execution_result
[
'columns_desc'
][
'all'
]
[
self
.
executer
.
facts
])
>
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
else
:
to_write
=
"[Measures]"
...
...
@@ -449,9 +452,9 @@ class XmlaExecuteTools():
hierarchy_info
=
""
# measure must be written at the top
if
self
.
executer
.
facts
in
mdx_execution_result
[
'columns_desc'
][
mdx_query_axis
].
keys
()
and
len
(
mdx_execution_result
[
'columns_desc'
][
mdx_query_axis
]
[
self
.
executer
.
facts
])
>
1
:
if
self
.
executer
.
facts
in
mdx_execution_result
[
'columns_desc'
][
mdx_query_axis
].
keys
(
)
and
len
(
mdx_execution_result
[
'columns_desc'
][
mdx_query_axis
]
[
self
.
executer
.
facts
])
>
1
:
hierarchy_info
+=
"""
<HierarchyInfo name="{0}">
<UName name="{0}.[MEMBER_UNIQUE_NAME]" type="xs:string"/>
...
...
@@ -551,11 +554,10 @@ class XmlaExecuteTools():
tuple
=
""
# not used dimensions
for
dim_diff
in
list
(
set
(
self
.
executer
.
get_all_tables_names
(
ignore_fact
=
True
))
-
set
(
table_name
for
table_name
in
mdx_execution_result
[
'columns_desc'
][
'all'
]
)):
set
(
self
.
executer
.
get_all_tables_names
(
ignore_fact
=
True
))
-
set
(
table_name
for
table_name
in
mdx_execution_result
[
'columns_desc'
]
[
'all'
])):
tuple
+=
"""
<Member Hierarchy="[{0}].[{0}]">
<UName>[{0}].[{0}].[{1}].[{2}]</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