DataBrewery / cubes

[NOT MAINTAINED] Light-weight Python OLAP framework for multi-dimensional data analysis
http://cubes.databrewery.org
Other
1.49k stars 314 forks source link

Natural ordering isn't working #468

Open anton-kaidalov opened 5 years ago

anton-kaidalov commented 5 years ago

Hi guys,

I'm only starting digging into Cubes, so please pardon if I misunderstand something. I really couldn't find any existing explanation to what I'm experiencing, and the code really seems to be somewhat wrong, so I've decided to create this issue.

In my experience, when I'm querying aggregates without explicit ordering, the order_query method in utils.py never applies the natural order, although it has it.

I performed some debugging and found out that:

Another surprising thing is the next condition in the same if: name not in order_by. What is order_by? I don't even see it declared anywhere. Looks like without those types problems with natural_order it would actually get to the second condition and crash completely.

Sorry again if I'm misunderstanding some logic and/or design intentions. I'm really looking forward to your comments.

And some details about my environment, although I don't really think they matter.

My database is PostgreSQL.

I use Cubes version 1.1, installed with pipenv.

My model:

{
    "dimensions": [
        {
            "name": "ts",
            "role": "time",
            "levels": [
                {
                    "name": "year",
                    "label": "Y"
                },
                {
                    "name": "month",
                    "label": "M"
                },
                {
                    "name": "day",
                    "label": "D"
                }
            ]
        },
        {"name": "cat1"},
        {"name": "currency"}
    ],
    "cubes": [
        {
            "name": "transactions",
            "dimensions": ["ts", "cat1", "currency"],
            "measures": [
                {"name": "amount"}
            ],
            "aggregates": [
                {
                    "name": "amount_sum",
                    "measure": "amount",
                    "function": "sum"
                }
            ],
            "mappings": {
              "ts.year": {"column":"ts", "extract":"year"},
              "ts.month": {"column":"ts", "extract":"month"},
              "ts.day": {"column":"ts", "extract":"day"}
            }
        }
    ]
}
KhaledTo commented 5 years ago

Hi @anton-kaidalov, yeah there was already an issue on natural ordering. That's some great debugging info, thank you very much. Will have a look at this.