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
1fc8aba4
Commit
1fc8aba4
authored
Jul 17, 2017
by
mouadh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix query parsing
parent
6f9df817
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
85 additions
and
43 deletions
+85
-43
tests/queries.py
tests/queries.py
+43
-0
tests/test_execute_mdx.py
tests/test_execute_mdx.py
+40
-0
tests/test_parsing_queries.py
tests/test_parsing_queries.py
+2
-43
No files found.
tests/queries.py
0 → 100644
View file @
1fc8aba4
CUBE
=
'sales'
query1
=
"""SELECT
{[Measures].[Amount]} ON COLUMNS
FROM [sales]"""
query2
=
"""SELECT
{[Geography].[Economy].[Partnership]} ON COLUMNS
FROM [sales]"""
query3
=
"""SELECT
non empty {[Geography].[Geo].[Country].members} ON COLUMNS,
{[Measures].[Amount]} ON ROWS
FROM [sales]"""
query4
=
"""SELECT
{[Geography].[Economy].[Partnership]} ON COLUMNS,
non empty {[Geography].[Geo].[Country].members} ON ROWS
FROM [sales]"""
query5
=
"""SELECT
{[Geography].[Economy].[Partnership].[EU],
[Geography].[Economy].[Partnership].[None],
[Geography].[Economy].[Partnership].[NAFTA]} ON COLUMNS,
{[Product].[Prod].[Company].[Crazy Development],
[Product].[Prod].[Company].[Company_test],
[Product].[Prod].[Company].[test_Development]} ON ROWS
FROM [sales]"""
# GENERATED BY EXCEL
query6
=
"""
SELECT NON EMPTY Hierarchize(AddCalculatedMembers(DrilldownMember({{DrilldownMember({{DrilldownMember({{
[Time].[Time].[Year].Members}}, {
[Time].[Time].[Year].[2010]})}}, {
[Time].[Time].[Quarter].[2010].[Q2 2010]})}}, {
[Time].[Time].[Month].[2010].[Q2 2010].[May 2010]}))) DIMENSION PROPERTIES PARENT_UNIQUE_NAME,HIERARCHY_UNIQUE_NAME
ON COLUMNS
FROM [sales] WHERE ([Measures].[Amount])
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
tests/test_execute_mdx.py
0 → 100644
View file @
1fc8aba4
import
pandas
as
pd
from
olapy.core.mdx.executor.execute
import
MdxEngine
from
pandas.util.testing
import
assert_frame_equal
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
()
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
()
assert
assert_frame_equal
(
df
,
test_df
)
is
None
tests/test_parsing_queries.py
View file @
1fc8aba4
from
__future__
import
absolute_import
,
division
,
print_function
from
olapy.core.mdx.executor.execute
import
MdxEngine
CUBE
=
'sales'
query1
=
"""SELECT
{[Measures].[Amount]} ON COLUMNS
FROM [sales]"""
query2
=
"""SELECT
{[Geography].[Economy].[Partnership]} ON COLUMNS
FROM [sales]"""
query3
=
"""SELECT
non empty {[Geography].[Geo].[Country].members} ON COLUMNS,
{[Measures].[Amount]} ON ROWS
FROM [sales]"""
query4
=
"""SELECT
{[Geography].[Economy].[Partnership]} ON COLUMNS,
non empty {[Geography].[Geo].[Country].members} ON ROWS
FROM [sales]"""
query5
=
"""SELECT
{[Geography].[Economy].[Partnership].[EU],
[Geography].[Economy].[Partnership].[None],
[Geography].[Economy].[Partnership].[NAFTA]} ON COLUMNS,
{[Product].[Prod].[Company].[Crazy Development],
[Product].[Prod].[Company].[Company_test],
[Product].[Prod].[Company].[test_Development]} ON ROWS
FROM [sales]"""
# GENERATED BY EXCEL
query6
=
"""
SELECT NON EMPTY Hierarchize(AddCalculatedMembers(DrilldownMember({{DrilldownMember({{DrilldownMember({{
[Time].[Time].[Year].Members}}, {
[Time].[Time].[Year].[2010]})}}, {
[Time].[Time].[Quarter].[2010].[Q2 2010]})}}, {
[Time].[Time].[Month].[2010].[Q2 2010].[May 2010]}))) DIMENSION PROPERTIES PARENT_UNIQUE_NAME,HIERARCHY_UNIQUE_NAME
ON COLUMNS
FROM [sales] WHERE ([Measures].[Amount])
CELL PROPERTIES VALUE, FORMAT_STRING, LANGUAGE, BACK_COLOR, FORE_COLOR, FONT_FLAGS
"""
where
=
"WHERE [Time].[Calendar].[Day].[May 12,2010]"
from
tests.queries
import
CUBE
,
query1
,
where
,
query2
,
query3
,
query4
,
query5
,
query6
executer
=
MdxEngine
(
CUBE
)
...
...
@@ -189,3 +147,4 @@ def test_parsing_query6():
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'
]]
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