Natural ordering isn't working
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:
-
natural_ordercomes toorder_queryfromDrilldown.natural_order; -
order_queryexpectsnatural_orderto be the dictionary of names->directions; -
Drilldown.natural_orderreturns a list of tuples instead; - this causes
if name in natural_orderto be syntactically correct but always return false, soORDER BYclause is not generated.
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"}
}
}
]
}
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.