Beispiel #1
0
 def test_aggregate_full(self):
     query = CubeQuery(self.full_cube, self.view)
     query.prepare()
     stmt = query.summary_statement
     s = str(stmt)
     self.assertNotRegexpMatches(s, 'WHERE')
     self.assertRegexpMatches(s, r'sum(.*amount.*) AS amount_sum')
     self.execute(stmt)
Beispiel #2
0
 def test_aggregate_full(self):
     query = CubeQuery(self.full_cube, self.view)
     query.prepare()
     stmt = query.summary_statement
     s = str(stmt)
     self.assertNotRegexpMatches(s, 'WHERE')
     self.assertRegexpMatches(s, r'sum(.*amount.*) AS amount_sum')
     self.execute(stmt)
Beispiel #3
0
    def test_fact_query(self):

        query = CubeQuery(self.full_cube, self.view)
        query.prepare()
        stmt = query.fact_statement(1)
        s = str(stmt)
        self.assertRegexpMatches(s, 'view\.id =')

        cell = self.full_cube.slice(cubes.PointCut(self.date_dim, [2010]))
        query = CubeQuery(cell, self.view)
        query.prepare()
        stmt = query.fact_statement(1)
        s = str(stmt)
        self.assertNotRegexpMatches(s, 'view\."date\.year" =')
Beispiel #4
0
    def test_explicit_drill_down_next_default(self):
        cell = self.full_cube

        query = CubeQuery(cell, self.view)
        query.drilldown = {"date": "year"}
        query.prepare()
        stmt = query.drilldown_statement
        s1 = str(stmt)

        query = CubeQuery(cell, self.view)
        query.drilldown = {"date": None}
        query.prepare()
        stmt = query.drilldown_statement
        s2 = str(stmt)

        self.assertEqual(s1, s2)
Beispiel #5
0
    def test_explicit_drill_down(self):
        cell = self.full_cube
        query = CubeQuery(cell, self.view)
        query.drilldown = {"date": "year"}
        query.prepare()
        stmt = query.drilldown_statement
        s = str(stmt)
        self.assertRegexpMatches(s, r'date\.year')
        self.assertNotRegexpMatches(s, r'date\.month')

        cell = cell.slice(cubes.PointCut("date", [2010]))
        query = CubeQuery(cell, self.view)
        query.drilldown = {"date": "month"}
        query.prepare()
        stmt = query.drilldown_statement
        s = str(stmt)

        self.assertRegexpMatches(s, r'date\.year')
        self.assertRegexpMatches(s, r'date\.month')
Beispiel #6
0
    def test_fact_query(self):

        query = CubeQuery(self.full_cube, self.view)
        query.prepare()
        stmt = query.fact_statement(1)
        s = str(stmt)
        self.assertRegexpMatches(s, 'view\.id =')

        cell = self.full_cube.slice(cubes.PointCut(self.date_dim, [2010]))
        query = CubeQuery(cell, self.view)
        query.prepare()
        stmt = query.fact_statement(1)
        s = str(stmt)
        self.assertNotRegexpMatches(s, 'view\."date\.year" =')
Beispiel #7
0
    def test_aggregate_point(self):
        cell = self.full_cube.slice(cubes.PointCut(self.date_dim, [2010]))

        query = CubeQuery(cell, self.view)
        query.prepare()
        stmt = query.summary_statement
        s = str(stmt)
        s = re.sub(r'\n', ' ', s)
        self.assertRegexpMatches(s, r'WHERE')
        self.assertRegexpMatches(s, r'sum(.*amount.*) AS amount_sum')
        self.assertRegexpMatches(s, r'view\."date\.year" =')
        self.assertRegexpMatches(s, r'GROUP BY .*date\.year')
        self.assertNotRegexpMatches(s, r'GROUP BY .*date\.month')
        self.assertRegexpMatches(s, r'SELECT.*date\.year.*FROM')
        self.assertNotRegexpMatches(s, r'SELECT.*date\.month.*FROM')
        self.assertNotRegexpMatches(s, r'cls')
        self.execute(stmt)
        
        cell = self.full_cube.slice(cubes.PointCut(self.date_dim, [2010, 4]))

        query = CubeQuery(cell, self.view)
        query.prepare()
        stmt = query.summary_statement
        s = str(stmt)
        self.assertRegexpMatches(s, r'GROUP BY .*date\.year')
        self.assertRegexpMatches(s, r'GROUP BY .*date\.month')
        self.assertRegexpMatches(s, r'SELECT .*date\.year')
        self.assertRegexpMatches(s, r'SELECT.*date\.month')
        self.assertRegexpMatches(s, r'SELECT.*date\.month_name')
        self.assertNotRegexpMatches(s, r'cls')
        self.execute(stmt)
        
        cell = self.full_cube.slice(cubes.PointCut(self.class_dim, [1]))

        query = CubeQuery(cell, self.view)
        query.prepare()
        stmt = query.summary_statement
        s = str(stmt)
        self.assertRegexpMatches(s, r'cls')
        self.assertRegexpMatches(s, r'group_id')
        self.assertRegexpMatches(s, r'group_desc')
        self.assertNotRegexpMatches(s, r'class')
        self.execute(stmt)
Beispiel #8
0
    def test_explicit_drill_down_next_default(self):
        cell = self.full_cube

        query = CubeQuery(cell, self.view)
        query.drilldown = {"date": "year"}
        query.prepare()
        stmt = query.drilldown_statement
        s1 = str(stmt)

        query = CubeQuery(cell, self.view)
        query.drilldown = {"date": None}
        query.prepare()
        stmt = query.drilldown_statement
        s2 = str(stmt)

        self.assertEqual(s1, s2)
Beispiel #9
0
    def test_next_drill_down(self):
        cell = self.full_cube

        query = CubeQuery(cell, self.view)
        query.drilldown = ["date"]
        query.prepare()
        stmt = query.drilldown_statement
        s = str(stmt)
        self.assertRegexpMatches(s, r'date\.year')
        self.assertNotRegexpMatches(s, r'date\.month')

        cell = self.full_cube.slice(cubes.PointCut(self.date_dim, [2010]))
        query = CubeQuery(cell, self.view)
        query.drilldown = ["date"]
        query.prepare()
        stmt = query.drilldown_statement
        s = str(stmt)
        self.assertRegexpMatches(s, r'date\.year')
        self.assertRegexpMatches(s, r'date\.month')

        cell = self.full_cube.slice(cubes.PointCut(self.date_dim, [2010, 4]))
        query = CubeQuery(cell, self.view)
        query.drilldown = ["date"]
        self.assertRaisesRegexp(ValueError, "Unable to drill-down.*last level", query.prepare)
Beispiel #10
0
    def test_explicit_drill_down(self):
        cell = self.full_cube
        query = CubeQuery(cell, self.view)
        query.drilldown = {"date": "year"}
        query.prepare()
        stmt = query.drilldown_statement
        s = str(stmt)
        self.assertRegexpMatches(s, r'date\.year')
        self.assertNotRegexpMatches(s, r'date\.month')

        cell = cell.slice(cubes.PointCut("date", [2010]))
        query = CubeQuery(cell, self.view)
        query.drilldown = {"date": "month"}
        query.prepare()
        stmt = query.drilldown_statement
        s = str(stmt)

        self.assertRegexpMatches(s, r'date\.year')
        self.assertRegexpMatches(s, r'date\.month')
Beispiel #11
0
    def test_fact_with_conditions(self):

        cell = self.full_cube.slice(cubes.PointCut(self.date_dim, [2010]))

        query = CubeQuery(cell, self.view)
        query.prepare()
        stmt = query.facts_statement
        s = str(stmt)
        self.assertRegexpMatches(s, 'WHERE')
        self.assertRegexpMatches(s, 'view\."date\.year" =')
        self.assertNotRegexpMatches(s, 'view\."date\.month" =')
        self.assertNotRegexpMatches(s, 'view\."class\.[^=]*"=')

        cell = self.full_cube.slice(cubes.PointCut(self.date_dim, [2010, 4]))
        query = CubeQuery(cell, self.view)
        query.prepare()
        stmt = query.facts_statement
        s = str(stmt)
        self.assertRegexpMatches(s, 'WHERE')
        self.assertRegexpMatches(s, r'view\."date\.year" =')
        self.assertRegexpMatches(s, r'view\."date\.month" =')
Beispiel #12
0
    def test_fact_with_conditions(self):

        cell = self.full_cube.slice(cubes.PointCut(self.date_dim, [2010]))

        query = CubeQuery(cell, self.view)
        query.prepare()
        stmt = query.facts_statement
        s = str(stmt)
        self.assertRegexpMatches(s, 'WHERE')
        self.assertRegexpMatches(s, 'view\."date\.year" =')
        self.assertNotRegexpMatches(s, 'view\."date\.month" =')
        self.assertNotRegexpMatches(s, 'view\."class\.[^=]*"=')

        cell = self.full_cube.slice(cubes.PointCut(self.date_dim, [2010, 4]))
        query = CubeQuery(cell, self.view)
        query.prepare()
        stmt = query.facts_statement
        s = str(stmt)
        self.assertRegexpMatches(s, 'WHERE')
        self.assertRegexpMatches(s, r'view\."date\.year" =')
        self.assertRegexpMatches(s, r'view\."date\.month" =')
Beispiel #13
0
 def test_natural_order(self):
     query = CubeQuery(self.full_cube, self.view)
     query.prepare()
     stmt = query.facts_statement
     s = str(stmt)
     self.assertRegexpMatches(s, 'ORDER BY')
Beispiel #14
0
    def test_next_drill_down(self):
        cell = self.full_cube

        query = CubeQuery(cell, self.view)
        query.drilldown = ["date"]
        query.prepare()
        stmt = query.drilldown_statement
        s = str(stmt)
        self.assertRegexpMatches(s, r'date\.year')
        self.assertNotRegexpMatches(s, r'date\.month')

        cell = self.full_cube.slice(cubes.PointCut(self.date_dim, [2010]))
        query = CubeQuery(cell, self.view)
        query.drilldown = ["date"]
        query.prepare()
        stmt = query.drilldown_statement
        s = str(stmt)
        self.assertRegexpMatches(s, r'date\.year')
        self.assertRegexpMatches(s, r'date\.month')

        cell = self.full_cube.slice(cubes.PointCut(self.date_dim, [2010, 4]))
        query = CubeQuery(cell, self.view)
        query.drilldown = ["date"]
        self.assertRaisesRegexp(ValueError, "Unable to drill-down.*last level",
                                query.prepare)
Beispiel #15
0
    def test_aggregate_point(self):
        cell = self.full_cube.slice(cubes.PointCut(self.date_dim, [2010]))

        query = CubeQuery(cell, self.view)
        query.prepare()
        stmt = query.summary_statement
        s = str(stmt)
        s = re.sub(r'\n', ' ', s)
        self.assertRegexpMatches(s, r'WHERE')
        self.assertRegexpMatches(s, r'sum(.*amount.*) AS amount_sum')
        self.assertRegexpMatches(s, r'view\."date\.year" =')
        self.assertRegexpMatches(s, r'GROUP BY .*date\.year')
        self.assertNotRegexpMatches(s, r'GROUP BY .*date\.month')
        self.assertRegexpMatches(s, r'SELECT.*date\.year.*FROM')
        self.assertNotRegexpMatches(s, r'SELECT.*date\.month.*FROM')
        self.assertNotRegexpMatches(s, r'cls')
        self.execute(stmt)

        cell = self.full_cube.slice(cubes.PointCut(self.date_dim, [2010, 4]))

        query = CubeQuery(cell, self.view)
        query.prepare()
        stmt = query.summary_statement
        s = str(stmt)
        self.assertRegexpMatches(s, r'GROUP BY .*date\.year')
        self.assertRegexpMatches(s, r'GROUP BY .*date\.month')
        self.assertRegexpMatches(s, r'SELECT .*date\.year')
        self.assertRegexpMatches(s, r'SELECT.*date\.month')
        self.assertRegexpMatches(s, r'SELECT.*date\.month_name')
        self.assertNotRegexpMatches(s, r'cls')
        self.execute(stmt)

        cell = self.full_cube.slice(cubes.PointCut(self.class_dim, [1]))

        query = CubeQuery(cell, self.view)
        query.prepare()
        stmt = query.summary_statement
        s = str(stmt)
        self.assertRegexpMatches(s, r'cls')
        self.assertRegexpMatches(s, r'group_id')
        self.assertRegexpMatches(s, r'group_desc')
        self.assertNotRegexpMatches(s, r'class')
        self.execute(stmt)
Beispiel #16
0
 def test_natural_order(self):
     query = CubeQuery(self.full_cube, self.view)
     query.prepare()
     stmt = query.facts_statement
     s = str(stmt)
     self.assertRegexpMatches(s, 'ORDER BY')