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
7b510d7b
Commit
7b510d7b
authored
Jul 17, 2017
by
mouadh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
format
parent
1fc8aba4
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
105 additions
and
68 deletions
+105
-68
tests/queries.py
tests/queries.py
+1
-2
tests/test_execute_mdx.py
tests/test_execute_mdx.py
+31
-16
tests/test_parsing_queries.py
tests/test_parsing_queries.py
+59
-43
tests/test_xmla_notox.py
tests/test_xmla_notox.py
+14
-7
No files found.
tests/queries.py
View file @
7b510d7b
CUBE
=
'sales'
query1
=
"""SELECT
...
...
@@ -40,4 +39,4 @@ query6 = """
CELL PROPERTIES VALUE, FORMAT_STRING, LANGUAGE, BACK_COLOR, FORE_COLOR, FONT_FLAGS
"""
where
=
"WHERE [Time].[Calendar].[Day].[May 12,2010]"
\ No newline at end of file
where
=
"WHERE [Time].[Calendar].[Day].[May 12,2010]"
tests/test_execute_mdx.py
View file @
7b510d7b
import
pandas
as
pd
from
olapy.core.mdx.executor.execute
import
MdxEngine
...
...
@@ -8,33 +7,49 @@ from tests.queries import query1, CUBE, query3, query6
executer
=
MdxEngine
(
CUBE
)
def
test_execution_query1
():
executer
.
mdx_query
=
query1
assert
executer
.
execute_mdx
()[
'result'
][
'Amount'
][
0
]
==
1023
def
test_execution_query2
():
executer
.
mdx_query
=
query3
df
=
executer
.
execute_mdx
()[
'result'
]
test_df
=
pd
.
DataFrame
(
{
'Country'
:
[
'France'
,
'Spain'
,
'Switzerland'
,
'United States'
],
'Amount'
:
[
4
,
3
,
248
,
768
]}).
groupby
(
[
'Country'
]).
sum
()
df
=
executer
.
execute_mdx
()[
'result'
]
test_df
=
pd
.
DataFrame
({
'Country'
:
[
'France'
,
'Spain'
,
'Switzerland'
,
'United States'
],
'Amount'
:
[
4
,
3
,
248
,
768
]
}).
groupby
([
'Country'
]).
sum
()
assert
assert_frame_equal
(
df
,
test_df
)
is
None
assert
assert_frame_equal
(
df
,
test_df
)
is
None
def
test_execution_query6
():
executer
.
mdx_query
=
query6
df
=
executer
.
execute_mdx
()[
'result'
]
test_df
=
pd
.
DataFrame
(
{
'Year'
:
[
2010
,
2010
,
2010
,
2010
,
2010
,
2010
,
2010
,
2010
,
2010
,
2010
,
2010
,
2010
,
2010
],
'Quarter'
:
[
-
1
,
'Q2 2010'
,
'Q2 2010'
,
'Q2 2010'
,
'Q2 2010'
,
'Q2 2010'
,
'Q2 2010'
,
'Q2 2010'
,
'Q2 2010'
,
'Q2 2010'
,
'Q2 2010'
,
'Q2 2010'
,
'Q2 2010'
],
'Month'
:
[
-
1
,
-
1
,
'May 2010'
,
'May 2010'
,
'May 2010'
,
'May 2010'
,
'May 2010'
,
'May 2010'
,
'May 2010'
,
'May 2010'
,
'May 2010'
,
'May 2010'
,
'May 2010'
],
'Day'
:
[
-
1
,
-
1
,
-
1
,
'May 12,2010'
,
'May 13,2010'
,
'May 14,2010'
,
'May 15,2010'
,
'May 16,2010'
,
'May 17,2010'
,
'May 18,2010'
,
'May 19,2010'
,
'May 20,2010'
,
'May 21,2010'
],
'Amount'
:
[
1023
,
1023
,
1023
,
1
,
2
,
4
,
8
,
16
,
32
,
64
,
128
,
256
,
512
]}).
groupby
(
[
'Year'
,
'Quarter'
,
'Month'
,
'Day'
]).
sum
()
test_df
=
pd
.
DataFrame
({
'Year'
:
[
2010
,
2010
,
2010
,
2010
,
2010
,
2010
,
2010
,
2010
,
2010
,
2010
,
2010
,
2010
,
2010
],
'Quarter'
:
[
-
1
,
'Q2 2010'
,
'Q2 2010'
,
'Q2 2010'
,
'Q2 2010'
,
'Q2 2010'
,
'Q2 2010'
,
'Q2 2010'
,
'Q2 2010'
,
'Q2 2010'
,
'Q2 2010'
,
'Q2 2010'
,
'Q2 2010'
],
'Month'
:
[
-
1
,
-
1
,
'May 2010'
,
'May 2010'
,
'May 2010'
,
'May 2010'
,
'May 2010'
,
'May 2010'
,
'May 2010'
,
'May 2010'
,
'May 2010'
,
'May 2010'
,
'May 2010'
],
'Day'
:
[
-
1
,
-
1
,
-
1
,
'May 12,2010'
,
'May 13,2010'
,
'May 14,2010'
,
'May 15,2010'
,
'May 16,2010'
,
'May 17,2010'
,
'May 18,2010'
,
'May 19,2010'
,
'May 20,2010'
,
'May 21,2010'
],
'Amount'
:
[
1023
,
1023
,
1023
,
1
,
2
,
4
,
8
,
16
,
32
,
64
,
128
,
256
,
512
]
}).
groupby
([
'Year'
,
'Quarter'
,
'Month'
,
'Day'
]).
sum
()
assert
assert_frame_equal
(
df
,
test_df
)
is
None
tests/test_parsing_queries.py
View file @
7b510d7b
...
...
@@ -16,7 +16,8 @@ def test_parsing_query1():
query_parts
=
executer
.
decorticate_query
(
query1
+
'
\
n
'
+
where
)
assert
query_parts
[
'all'
]
==
[[
'Measures'
,
'Amount'
],
[
'Time'
,
'Calendar'
,
'Day'
,
'May 12,2010'
]]
assert
query_parts
[
'all'
]
==
[[
'Measures'
,
'Amount'
],
[
'Time'
,
'Calendar'
,
'Day'
,
'May 12,2010'
]]
assert
query_parts
[
'rows'
]
==
[]
assert
query_parts
[
'where'
]
==
[[
'Time'
,
'Calendar'
,
'Day'
,
'May 12,2010'
]]
assert
query_parts
[
'columns'
]
==
[[
'Measures'
,
'Amount'
]]
...
...
@@ -32,7 +33,8 @@ def test_parsing_query2():
query_parts
=
executer
.
decorticate_query
(
query2
+
'
\
n
'
+
where
)
assert
query_parts
[
'all'
]
==
[[
'Geography'
,
'Economy'
,
'Partnership'
],
[
'Time'
,
'Calendar'
,
'Day'
,
'May 12,2010'
]]
assert
query_parts
[
'all'
]
==
[[
'Geography'
,
'Economy'
,
'Partnership'
],
[
'Time'
,
'Calendar'
,
'Day'
,
'May 12,2010'
]]
assert
query_parts
[
'rows'
]
==
[]
assert
query_parts
[
'where'
]
==
[[
'Time'
,
'Calendar'
,
'Day'
,
'May 12,2010'
]]
assert
query_parts
[
'columns'
]
==
[[
'Geography'
,
'Economy'
,
'Partnership'
]]
...
...
@@ -41,14 +43,16 @@ def test_parsing_query2():
def
test_parsing_query3
():
query_parts
=
executer
.
decorticate_query
(
query3
)
assert
query_parts
[
'all'
]
==
[[
'Geography'
,
'Geo'
,
'Country'
],
[
'Measures'
,
'Amount'
]]
assert
query_parts
[
'all'
]
==
[[
'Geography'
,
'Geo'
,
'Country'
],
[
'Measures'
,
'Amount'
]]
assert
query_parts
[
'rows'
]
==
[[
'Measures'
,
'Amount'
]]
assert
query_parts
[
'where'
]
==
[]
assert
query_parts
[
'columns'
]
==
[[
'Geography'
,
'Geo'
,
'Country'
]]
query_parts
=
executer
.
decorticate_query
(
query3
+
'
\
n
'
+
where
)
assert
query_parts
[
'all'
]
==
[[
'Geography'
,
'Geo'
,
'Country'
],
[
'Measures'
,
'Amount'
],
assert
query_parts
[
'all'
]
==
[[
'Geography'
,
'Geo'
,
'Country'
],
[
'Measures'
,
'Amount'
],
[
'Time'
,
'Calendar'
,
'Day'
,
'May 12,2010'
]]
assert
query_parts
[
'rows'
]
==
[[
'Measures'
,
'Amount'
]]
assert
query_parts
[
'where'
]
==
[[
'Time'
,
'Calendar'
,
'Day'
,
'May 12,2010'
]]
...
...
@@ -58,14 +62,16 @@ def test_parsing_query3():
def
test_parsing_query4
():
query_parts
=
executer
.
decorticate_query
(
query4
)
assert
query_parts
[
'all'
]
==
[[
'Geography'
,
'Economy'
,
'Partnership'
],
[
'Geography'
,
'Geo'
,
'Country'
]]
assert
query_parts
[
'all'
]
==
[[
'Geography'
,
'Economy'
,
'Partnership'
],
[
'Geography'
,
'Geo'
,
'Country'
]]
assert
query_parts
[
'rows'
]
==
[[
'Geography'
,
'Geo'
,
'Country'
]]
assert
query_parts
[
'where'
]
==
[]
assert
query_parts
[
'columns'
]
==
[[
'Geography'
,
'Economy'
,
'Partnership'
]]
query_parts
=
executer
.
decorticate_query
(
query4
+
'
\
n
'
+
where
)
assert
query_parts
[
'all'
]
==
[[
'Geography'
,
'Economy'
,
'Partnership'
],
[
'Geography'
,
'Geo'
,
'Country'
],
assert
query_parts
[
'all'
]
==
[[
'Geography'
,
'Economy'
,
'Partnership'
],
[
'Geography'
,
'Geo'
,
'Country'
],
[
'Time'
,
'Calendar'
,
'Day'
,
'May 12,2010'
]]
assert
query_parts
[
'rows'
]
==
[[
'Geography'
,
'Geo'
,
'Country'
]]
assert
query_parts
[
'where'
]
==
[[
'Time'
,
'Calendar'
,
'Day'
,
'May 12,2010'
]]
...
...
@@ -75,42 +81,48 @@ def test_parsing_query4():
def
test_parsing_query5
():
query_parts
=
executer
.
decorticate_query
(
query5
)
assert
query_parts
[
'all'
]
==
[[
'Geography'
,
'Economy'
,
'Partnership'
,
'EU'
],
[
'Geography'
,
'Economy'
,
'Partnership'
,
'None'
],
[
'Geography'
,
'Economy'
,
'Partnership'
,
'NAFTA'
],
[
'Product'
,
'Prod'
,
'Company'
,
'Crazy Development'
],
[
'Product'
,
'Prod'
,
'Company'
,
'Company_test'
],
[
'Product'
,
'Prod'
,
'Company'
,
'test_Development'
]]
assert
query_parts
[
'all'
]
==
[[
'Geography'
,
'Economy'
,
'Partnership'
,
'EU'
],
[
'Geography'
,
'Economy'
,
'Partnership'
,
'None'
],
[
'Geography'
,
'Economy'
,
'Partnership'
,
'NAFTA'
],
[
'Product'
,
'Prod'
,
'Company'
,
'Crazy Development'
],
[
'Product'
,
'Prod'
,
'Company'
,
'Company_test'
],
[
'Product'
,
'Prod'
,
'Company'
,
'test_Development'
]]
assert
query_parts
[
'rows'
]
==
[[
'Product'
,
'Prod'
,
'Company'
,
'Crazy Development'
],
[
'Product'
,
'Prod'
,
'Company'
,
'Company_test'
],
[
'Product'
,
'Prod'
,
'Company'
,
'test_Development'
]]
assert
query_parts
[
'rows'
]
==
[[
'Product'
,
'Prod'
,
'Company'
,
'Crazy Development'
],
[
'Product'
,
'Prod'
,
'Company'
,
'Company_test'
],
[
'Product'
,
'Prod'
,
'Company'
,
'test_Development'
]]
assert
query_parts
[
'where'
]
==
[]
assert
query_parts
[
'columns'
]
==
[[
'Geography'
,
'Economy'
,
'Partnership'
,
'EU'
],
[
'Geography'
,
'Economy'
,
'Partnership'
,
'None'
],
[
'Geography'
,
'Economy'
,
'Partnership'
,
'NAFTA'
]]
assert
query_parts
[
'columns'
]
==
[[
'Geography'
,
'Economy'
,
'Partnership'
,
'EU'
],
[
'Geography'
,
'Economy'
,
'Partnership'
,
'None'
],
[
'Geography'
,
'Economy'
,
'Partnership'
,
'NAFTA'
]]
query_parts
=
executer
.
decorticate_query
(
query5
+
'
\
n
'
+
where
)
assert
query_parts
[
'all'
]
==
[[
'Geography'
,
'Economy'
,
'Partnership'
,
'EU'
],
[
'Geography'
,
'Economy'
,
'Partnership'
,
'None'
],
[
'Geography'
,
'Economy'
,
'Partnership'
,
'NAFTA'
],
[
'Product'
,
'Prod'
,
'Company'
,
'Crazy Development'
],
[
'Product'
,
'Prod'
,
'Company'
,
'Company_test'
],
[
'Product'
,
'Prod'
,
'Company'
,
'test_Development'
],
assert
query_parts
[
'all'
]
==
[[
'Geography'
,
'Economy'
,
'Partnership'
,
'EU'
],
[
'Geography'
,
'Economy'
,
'Partnership'
,
'None'
],
[
'Geography'
,
'Economy'
,
'Partnership'
,
'NAFTA'
],
[
'Product'
,
'Prod'
,
'Company'
,
'Crazy Development'
],
[
'Product'
,
'Prod'
,
'Company'
,
'Company_test'
],
[
'Product'
,
'Prod'
,
'Company'
,
'test_Development'
],
[
'Time'
,
'Calendar'
,
'Day'
,
'May 12,2010'
]]
assert
query_parts
[
'rows'
]
==
[[
'Product'
,
'Prod'
,
'Company'
,
'Crazy Development'
],
[
'Product'
,
'Prod'
,
'Company'
,
'Company_test'
],
[
'Product'
,
'Prod'
,
'Company'
,
'test_Development'
]]
assert
query_parts
[
'rows'
]
==
[[
'Product'
,
'Prod'
,
'Company'
,
'Crazy Development'
],
[
'Product'
,
'Prod'
,
'Company'
,
'Company_test'
],
[
'Product'
,
'Prod'
,
'Company'
,
'test_Development'
]]
assert
query_parts
[
'where'
]
==
[[
'Time'
,
'Calendar'
,
'Day'
,
'May 12,2010'
]]
assert
query_parts
[
'columns'
]
==
[[
'Geography'
,
'Economy'
,
'Partnership'
,
'EU'
],
[
'Geography'
,
'Economy'
,
'Partnership'
,
'None'
],
[
'Geography'
,
'Economy'
,
'Partnership'
,
'NAFTA'
]]
assert
query_parts
[
'columns'
]
==
[[
'Geography'
,
'Economy'
,
'Partnership'
,
'EU'
],
[
'Geography'
,
'Economy'
,
'Partnership'
,
'None'
],
[
'Geography'
,
'Economy'
,
'Partnership'
,
'NAFTA'
]]
def
test_parsing_query6
():
...
...
@@ -119,24 +131,28 @@ def test_parsing_query6():
query_parts
=
executer
.
decorticate_query
(
query6
)
assert
query_parts
[
'all'
]
==
[[
'Time'
,
'Time'
,
'Year'
],
[
'Time'
,
'Time'
,
'Year'
,
'2010'
],
[
'Time'
,
'Time'
,
'Quarter'
,
'2010'
,
'Q2 2010'
],
[
'Time'
,
'Time'
,
'Month'
,
'2010'
,
'Q2 2010'
,
'May 2010'
],
assert
query_parts
[
'all'
]
==
[[
'Time'
,
'Time'
,
'Year'
],
[
'Time'
,
'Time'
,
'Year'
,
'2010'
],
[
'Time'
,
'Time'
,
'Quarter'
,
'2010'
,
'Q2 2010'
],
[
'Time'
,
'Time'
,
'Month'
,
'2010'
,
'Q2 2010'
,
'May 2010'
],
[
'Measures'
,
'Amount'
]]
assert
query_parts
[
'rows'
]
==
[]
assert
query_parts
[
'where'
]
==
[[
'Measures'
,
'Amount'
]]
assert
query_parts
[
'columns'
]
==
[[
'Time'
,
'Time'
,
'Year'
],
[
'Time'
,
'Time'
,
'Year'
,
'2010'
],
[
'Time'
,
'Time'
,
'Quarter'
,
'2010'
,
'Q2 2010'
],
[
'Time'
,
'Time'
,
'Month'
,
'2010'
,
'Q2 2010'
,
'May 2010'
]]
assert
query_parts
[
'columns'
]
==
[[
'Time'
,
'Time'
,
'Year'
],
[
'Time'
,
'Time'
,
'Year'
,
'2010'
],
[
'Time'
,
'Time'
,
'Quarter'
,
'2010'
,
'Q2 2010'
],
[
'Time'
,
'Time'
,
'Month'
,
'2010'
,
'Q2 2010'
,
'May 2010'
]]
query_parts
=
executer
.
decorticate_query
(
query6
+
'
\
n
'
+
where
)
assert
query_parts
[
'all'
]
==
[[
'Time'
,
'Time'
,
'Year'
],
[
'Time'
,
'Time'
,
'Year'
,
'2010'
],
[
'Time'
,
'Time'
,
'Quarter'
,
'2010'
,
'Q2 2010'
],
[
'Time'
,
'Time'
,
'Month'
,
'2010'
,
'Q2 2010'
,
'May 2010'
],
[
'Measures'
,
'Amount'
],
assert
query_parts
[
'all'
]
==
[[
'Time'
,
'Time'
,
'Year'
],
[
'Time'
,
'Time'
,
'Year'
,
'2010'
],
[
'Time'
,
'Time'
,
'Quarter'
,
'2010'
,
'Q2 2010'
],
[
'Time'
,
'Time'
,
'Month'
,
'2010'
,
'Q2 2010'
,
'May 2010'
],
[
'Measures'
,
'Amount'
],
[
'Time'
,
'Calendar'
,
'Day'
,
'May 12,2010'
]]
assert
query_parts
[
'rows'
]
==
[]
...
...
@@ -144,7 +160,7 @@ def test_parsing_query6():
assert
query_parts
[
'where'
]
==
[[
'Measures'
,
'Amount'
],
[
'Time'
,
'Calendar'
,
'Day'
,
'May 12,2010'
]]
assert
query_parts
[
'columns'
]
==
[[
'Time'
,
'Time'
,
'Year'
],
[
'Time'
,
'Time'
,
'Year'
,
'2010'
],
[
'Time'
,
'Time'
,
'Quarter'
,
'2010'
,
'Q2 2010'
],
[
'Time'
,
'Time'
,
'Month'
,
'2010'
,
'Q2 2010'
,
'May 2010'
]]
assert
query_parts
[
'columns'
]
==
[[
'Time'
,
'Time'
,
'Year'
],
[
'Time'
,
'Time'
,
'Year'
,
'2010'
],
[
'Time'
,
'Time'
,
'Quarter'
,
'2010'
,
'Q2 2010'
],
[
'Time'
,
'Time'
,
'Month'
,
'2010'
,
'Q2 2010'
,
'May 2010'
]]
tests/test_xmla_notox.py
View file @
7b510d7b
...
...
@@ -50,7 +50,8 @@ class WSGIServer:
Copy/pasted from pytest_localserver w/ slight changes.
"""
def
__init__
(
self
,
host
=
'127.0.0.1'
,
port
=
8000
,
application
=
None
,
**
kwargs
):
def
__init__
(
self
,
host
=
'127.0.0.1'
,
port
=
8000
,
application
=
None
,
**
kwargs
):
self
.
_server
=
make_server
(
host
,
port
,
application
,
**
kwargs
)
self
.
server_address
=
self
.
_server
.
server_address
...
...
@@ -197,7 +198,8 @@ def test_query2(conn):
mems
.
append
(
Member
(
_Hierarchy
=
'[Geography].[Geography]'
,
UName
=
'[Geography].[Geography].[Country].[America].[United States]'
,
UName
=
'[Geography].[Geography].[Country].[America].[United States]'
,
Caption
=
'United States'
,
LName
=
'[Geography].[Geography].[Country]'
,
LNum
=
'1'
,
...
...
@@ -207,12 +209,14 @@ def test_query2(conn):
mems
.
append
(
Member
(
_Hierarchy
=
'[Geography].[Geography]'
,
UName
=
'[Geography].[Geography].[City].[America].[United States].[New York]'
,
UName
=
'[Geography].[Geography].[City].[America].[United States].[New York]'
,
Caption
=
'New York'
,
LName
=
'[Geography].[Geography].[City]'
,
LNum
=
'2'
,
DisplayInfo
=
'131076'
,
PARENT_UNIQUE_NAME
=
'[Geography].[Geography].[Continent].[America].[United States]'
,
PARENT_UNIQUE_NAME
=
'[Geography].[Geography].[Continent].[America].[United States]'
,
HIERARCHY_UNIQUE_NAME
=
'[Geography].[Geography]'
))
mems
.
append
(
Member
(
...
...
@@ -246,12 +250,14 @@ def test_query2(conn):
mems
.
append
(
Member
(
_Hierarchy
=
'[Geography].[Geography]'
,
UName
=
'[Geography].[Geography].[City].[Europe].[Spain].[Barcelona]'
,
UName
=
'[Geography].[Geography].[City].[Europe].[Spain].[Barcelona]'
,
Caption
=
'Barcelona'
,
LName
=
'[Geography].[Geography].[City]'
,
LNum
=
'2'
,
DisplayInfo
=
'131076'
,
PARENT_UNIQUE_NAME
=
'[Geography].[Geography].[Continent].[Europe].[Spain]'
,
PARENT_UNIQUE_NAME
=
'[Geography].[Geography].[Continent].[Europe].[Spain]'
,
HIERARCHY_UNIQUE_NAME
=
'[Geography].[Geography]'
))
mems
.
append
(
Member
(
...
...
@@ -261,7 +267,8 @@ def test_query2(conn):
LName
=
'[Geography].[Geography].[City]'
,
LNum
=
'2'
,
DisplayInfo
=
'131076'
,
PARENT_UNIQUE_NAME
=
'[Geography].[Geography].[Continent].[Europe].[Spain]'
,
PARENT_UNIQUE_NAME
=
'[Geography].[Geography].[Continent].[Europe].[Spain]'
,
HIERARCHY_UNIQUE_NAME
=
'[Geography].[Geography]'
))
mems
.
append
(
Member
(
...
...
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