Skip to content

Commit

Permalink
refactor: add some typing info.
Browse files Browse the repository at this point in the history
  • Loading branch information
sfermigier committed Jul 31, 2019
1 parent f855e0d commit 004dc3b
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 22 deletions.
12 changes: 7 additions & 5 deletions olapy/core/mdx/executor/execute.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- encoding: utf8 -*-
"""Olapy main's module, this module manipulate Mdx Queries and execute them.
Execution need two main objects:
"""Olapy's main module, this module manipulate MDX Queries and executes them.
Execution needs two main objects:
- table_loaded: which contains all tables needed to construct a cube
- star_schema: which is the cube
Expand All @@ -20,7 +21,8 @@
import os
from collections import OrderedDict
from os.path import expanduser
from typing import Any, Dict, List

from typing import Dict, List, Text, Optional, Any

import attr
import numpy as np
Expand Down Expand Up @@ -59,7 +61,7 @@ class MdxEngine(object):
cube = attr.ib(default=None)
facts = attr.ib(default="Facts")
source_type = attr.ib(default="csv")
parser = attr.ib(default=Parser())
parser = attr.ib(default=attr.Factory(Parser))
csv_files_cubes = attr.ib(default=attr.Factory(list))
db_cubes = attr.ib(default=attr.Factory(list))
sqla_engine = attr.ib(default=None)
Expand Down Expand Up @@ -157,7 +159,7 @@ def load_cube(
self.star_schema_dataframe = self.get_star_schema_dataframe(sep=sep)

def load_tables(self, sep):
# type: (str) -> Dict[str, pd.DataFrame]
# type: (Text) -> Dict[Text, pd.DataFrame]
"""
Load all tables as dict of { Table_name : DataFrame } for the current
cube instance.
Expand Down
12 changes: 7 additions & 5 deletions olapy/core/services/dict_discover_request_handler.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
"""Managing all `DISCOVER <https://technet.microsoft.com/fr-
fr/library/ms186653(v=sql.110).aspx>`_ requests and responses."""
# -*- encoding: utf8 -*-
"""Managing all
`DISCOVER <https://technet.microsoft.com/fr-fr/library/ms186653(v=sql.110).aspx>`_
requests and responses."""

from __future__ import absolute_import, division, print_function, \
unicode_literals

import os
import uuid

from olapy.core.mdx.executor import MdxEngine
from ..services.xmla_discover_request_utils import discover_literals_response_rows, \
discover_schema_rowsets_response_rows
from ..services.xmla_discover_xsds import discover_preperties_xsd
Expand All @@ -25,6 +27,7 @@ class DictDiscoverReqHandler:
"""

def __init__(self, mdx_engine):
# type: (MdxEngine) -> None
"""
:param mdx_engine: mdx_engine engine instance
Expand Down Expand Up @@ -168,9 +171,9 @@ def _get_properties_by_restrictions(self, request):
)

elif request.Restrictions.RestrictionList.PropertyName == "MdpropMdxSubqueries":

if request.Properties.PropertyList.Catalog is not None:
self.change_cube(request.Properties.PropertyList.Catalog)

return self._get_properties(
discover_preperties_xsd,
"MdpropMdxSubqueries",
Expand All @@ -185,9 +188,9 @@ def _get_properties_by_restrictions(self, request):
request.Restrictions.RestrictionList.PropertyName
== "MdpropMdxDrillFunctions"
):

if request.Properties.PropertyList.Catalog is not None:
self.change_cube(request.Properties.PropertyList.Catalog)

return self._get_properties(
discover_preperties_xsd,
"MdpropMdxDrillFunctions",
Expand Down Expand Up @@ -217,7 +220,6 @@ def discover_properties_response(self, request):
return self._get_properties(discover_preperties_xsd, "", "", "", "", "", "")

def discover_schema_rowsets_response(self, request):

rows = discover_schema_rowsets_response_rows

def generate_resp(rows):
Expand Down
8 changes: 5 additions & 3 deletions olapy/core/services/dict_execute_request_handler.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- encoding: utf8 -*-
"""Managing all `EXECUTE <https://technet.microsoft.com/fr-
fr/library/ms186691(v=sql.110).aspx>`_ requests and responses."""
"""Managing all
`EXECUTE <https://technet.microsoft.com/fr-fr/library/ms186691(v=sql.110).aspx>`_
requests and responses."""
from __future__ import absolute_import, division, print_function, \
unicode_literals

Expand All @@ -12,7 +13,8 @@


class DictExecuteReqHandler:
"""DictExecuteReqHandler handles xmla commands to an instance of MdxEngine. \
"""DictExecuteReqHandler handles xmla commands to an instance of MdxEngine.
This includes requests involving data transfer, such as retrieving data on the server."""

def __init__(self, executor, mdx_query=None, convert2formulas=False):
Expand Down
2 changes: 1 addition & 1 deletion olapy/core/services/xmla_discover_request_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def change_cube(self, new_cube):

@staticmethod
def discover_datasources_response():
"""list of data sources that are available on the server.
"""List the data sources available on the server.
:return:
"""
Expand Down
18 changes: 10 additions & 8 deletions olapy/core/services/xmla_execute_request_handler.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- encoding: utf8 -*-
"""Managing all `EXECUTE <https://technet.microsoft.com/fr-
fr/library/ms186691(v=sql.110).aspx>`_ requests and responses."""
"""Managing all
`EXECUTE <https://technet.microsoft.com/fr-fr/library/ms186691(v=sql.110).aspx>`_
requests and responses."""
from __future__ import absolute_import, division, print_function, \
unicode_literals

Expand All @@ -9,7 +10,7 @@

import numpy as np
import xmlwitch
from six import text_type
from typing import Text, List

from .dict_execute_request_handler import DictExecuteReqHandler
from .xmla_execute_xsds import execute_xsd
Expand All @@ -18,7 +19,7 @@
class XmlaExecuteReqHandler(DictExecuteReqHandler):
"""The Execute method executes XMLA commands provided in the Command
element and returns any resulting data using the XMLA MDDataSet data type
(for multidimensional result sets.)
(for multidimensional result sets).
Example::
Expand Down Expand Up @@ -213,7 +214,7 @@ def _gen_xs0_grouped_tuples(self, axis, tuples_groups):
def generate_xs0_one_axis(self, splitted_df, mdx_query_axis="all", axis="Axis0"):
"""
:param splitted_df: spllited dataframes (with split_dataframe() function)
:param splitted_df: splitted dataframes (with split_dataframe() function)
:param mdx_query_axis: axis to which you want generate xs0 xml, (rows, columns or all)
:param axis: axis0 or axis1
:return:
Expand Down Expand Up @@ -380,7 +381,7 @@ def _generate_cells_data_convert2formulas(self):
return str(xml)

def generate_cell_data(self):
# type: () -> text_type
# type: () -> Text
"""Returns Cell elements representing the cell data contained by a root
element that uses the MDDataSet data type.
Expand Down Expand Up @@ -567,10 +568,11 @@ def _gen_measures_one_axis_info(self, xml):
return xml

def _generate_table_axis_info(self, xml, dimensions_names):
# type: (xmlwitch.Builder, List[Text]) -> None
"""Add AxisInfo elements, representing the axis metadata contained by
the parent OlapInfo element for Dimension to the passed xml structure.
:param xml: xml structure to update
:param xml: xml structure to update (mutable)
:param dimensions_names: dimension names (without facts table)
"""
for dimension_name in dimensions_names:
Expand Down Expand Up @@ -609,7 +611,7 @@ def _generate_table_axis_info(self, xml, dimensions_names):
)

def generate_one_axis_info(self, mdx_query_axis="columns", Axis="Axis0"):
"""AxisInfo elements for one axis (axis0 or axis1)
"""AxisInfo elements for one axis (axis0 or axis1).
Example AxisInfo::
Expand Down

0 comments on commit 004dc3b

Please sign in to comment.