Performing aggregation on cube throws unexpected error

57 views Asked by At

I want to create a cube from csv data file and to perform and aggregation on it, the code is below:

from sqlalchemy import create_engine
from cubes.tutorial.sql import create_table_from_csv
from cubes import Workspace, Cell, browser

import data
if __name__ == '__main__':
    engine = create_engine('sqlite:///data.sqlite')
    create_table_from_csv(engine,
                             "../data/data.csv",
                             table_name="irbd_balance",
                             fields=[
                                ("category", "string"),
                                ("category_label", "string"),
                                 ("subcategory", "string"),
                                  ("subcategory_label", "string"),
                                  ("line_item", "string"),
                                 ("year", "integer"),
                                 ("amount", "integer")],
                            create_id=True
                      )
    print("done. file data.sqlite created")
    workspace = Workspace()
    workspace.register_default_store("sql", url="sqlite:///data.sqlite")
    workspace.import_model("../model.json")


    cube = workspace.cube("irbd_balance")

    browser = workspace.browser("irbd_balance")

    cell = Cell(cube)
    result = browser.aggregate(cell, drilldown=["year"])
    for record in result.drilldown:
        print(record)

The tutorial and the library are available here:

https://pythonhosted.org/cubes/tutorial.html

The error stack is :

result = browser.aggregate(cell, drilldown=["year"])
  File "C:\Users\path\venv\lib\site-packages\cubes\browser.py", line 145, in aggregate
    result = self.provide_aggregate(cell,
  File "C:\path\venv\lib\site-packages\cubes\sql\browser.py", line 400, in provide_aggregate
    (statement, labels) = self.aggregation_statement(cell,
  File "C:\path\venv\lib\site-packages\cubes\sql\browser.py", line 532, in aggregation_statement
    raise ArgumentError("List of aggregates should not be empty")
cubes.errors.ArgumentError: List of aggregates should not be empty

It seems the tutorial is containing some typos. Any idea how to fix this? Else is there any other better olap cubes library for Python that has great docs?

0

There are 0 answers