Commit 1fc8aba4 authored by mouadh's avatar mouadh

fix query parsing

parent 6f9df817
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
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
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']]
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