Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Natural ordering isn't working #468

Open
anton-kaidalov opened this issue Mar 10, 2019 · 1 comment
Open

Natural ordering isn't working #468

anton-kaidalov opened this issue Mar 10, 2019 · 1 comment

Comments

@anton-kaidalov
Copy link

anton-kaidalov commented Mar 10, 2019

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_order comes to order_query from Drilldown.natural_order;
  • order_query expects natural_order to be the dictionary of names->directions;
  • Drilldown.natural_order returns a list of tuples instead;
  • this causes if name in natural_order to be syntactically correct but always return false, so ORDER BY clause 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"}
            }
        }
    ]
}
@KhaledTo
Copy link
Contributor

KhaledTo commented May 11, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants