Permalink
Browse files

(nothing interesting to see here) unfinished, just make tests pass wi…

…th new star browser
  • Loading branch information...
1 parent 03dd014 commit dee9d49b6b78e5cdca37810144bba7801668445b Stefan Urbanek committed Apr 24, 2012
Showing with 66 additions and 20 deletions.
  1. +0 −2 README.markdown
  2. +2 −2 cubes/backends/sql/common.py
  3. +64 −16 cubes/backends/sql/star_browser.py
View
@@ -58,8 +58,6 @@ Google group or write to the author.
Report bugs using github issue tracking: https://github.com/Stiivi/cubes/issues
-**Follow @DataBrewery** on Twitter for updates.
-
Development
-----------
@@ -307,7 +307,7 @@ def relevant_joins(self, attributes):
.. warning::
- Does work only for star schema, not work for snowflake yet.
+ Works only for star schema, does not work for snowflake yet.
"""
# Attribute: (schema, table, column)
@@ -323,4 +323,4 @@ def relevant_joins(self, attributes):
if table == detail:
joins.append(join)
- return joins
+ return joins
@@ -1,35 +1,37 @@
# -*- coding=utf -*-
import cubes.browser
-from cubes.backends.sql.common import AttributeMapper
+from cubes.backends.sql.common import AttributeMapper, JoinFinder
-# FIXME: required functionality
+# Required functionality checklist
#
-# * number of items in drill-down
-# * dimension values
-# * drill-down sorting
-# * drill-down pagination
-# * drill-down limits (such as top-10)
-# * facts sorting
-# * facts pagination
-# * dimension values sorting
-# * dimension values pagination
-# * remainder
-# * ratio - aggregate sum(current)/sum(total)
-# * derived measures (should be in builder)
+# * [ ] number of items in drill-down
+# * [ ] dimension values
+# * [ ] drill-down sorting
+# * [ ] drill-down pagination
+# * [ ] drill-down limits (such as top-10)
+# * [ ] facts sorting
+# * [ ] facts pagination
+# * [ ] dimension values sorting
+# * [ ] dimension values pagination
+# * [ ] remainder
+# * [ ] ratio - aggregate sum(current)/sum(total)
+# * [ ] derived measures (should be in builder)
__all__ = ["StarBrowser"]
class StarBrowser(object):
"""docstring for StarBrowser"""
- def __init__(self, cube, locale = None):
+ def __init__(self, cube, locale=None, dimension_prefix=None, schema=None):
"""StarBrowser is a SQL-based AggregationBrowser implementation that
can aggregate star and snowflake schemas without need of having
explicit view or physical denormalized table.
Attributes:
* `cube` - browsed cube
+ * `dimension_prefix` - prefix for dimension tables
+ * `schema` - default database schema name
.. warning:
@@ -47,7 +49,53 @@ def __init__(self, cube, locale = None):
raise Exception("Cube for browser should not be None.")
self.cube = cube
- self.mapper = AttributeMapper(cube, cube.mappings, locale)
+ self.dimension_prefix = dimension_prefix
+ self.schema = schema
+
+ self.mappings = cube.mappings
+ self.locale = locale
+ self.mapper = AttributeMapper(cube, self.mappings, self.locale)
+ self.mapper.dimension_table_prefix = dimension_prefix
+ self.joinfinder = JoinFinder(cube, joins=cube.joins, mapper=self.mapper)
+
+ def fact(self, key):
+ """Get the fact from cube."""
+
+ attributes = []
+
+ # 1. get all fact attributes: key, measures, details
+ attributes += self.cube.measures
+ attributes += self.cube.details
+
+ for dim in self.cube.dimensions:
+ attributes += dim.all_attributes()
+
+ # 2. Get physical references (schema, table, column)
+ physical = []
+ for attr in attributes:
+ ref = self.mapper.physical(attr.dimension, attr)
+ physical.append(ref)
+ print list(ref)
+
+ # 3. Collect tables
+ # tables = {(ref[0], ref[1]) for ref in physical}
+ # print tables
+
+ joins = self.joinfinder.relevant_joins(physical)
+ print joins
+
+ #
+ #
+ # condition = self.key_column == fact_id
+ # columns = [col.column for col in self.selection.values()]
+ #
+ # stmt = expression.select(columns,
+ # whereclause = condition,
+ # from_obj = self.view)
+ # return stmt
+
+ return {}
+
def aggregate(self, cell, measures = None, drilldown = None, details = False, **options):
pass

0 comments on commit dee9d49

Please sign in to comment.