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

Fixes incorrect handling of table alias in flat dimensions. #441

Closed jjmontesl closed 7 years ago

jjmontesl commented 7 years ago

Fixes the issue causing the SQL browser to access an attribute using table name instead of the alias defined in the joins section.

jjmontesl commented 7 years ago

Sorry for the mistake. I have updated the PR.

christian-proust commented 6 years ago

Hi,

I do not know exactly what purpose were in mind, but I think the new implementation disallow the ability to have a flat dimension. Have you test parameters that gave you a wrong result?

The tests shows clearly the example of the regression with the examples tests.sql.test_mapper.MapperTestCase.test_physical_refs_dimensions. For this tests, the cube sales have a dimension flag, that is normally a flat dimension (embedded in fact table sales, see test/models/mapper_test.json). But now the value of flag is assumed to be in a table also called flag.

Have you a workaround to fit the flat dimension issue with the new version?

jjmontesl commented 5 years ago

Hello @christian-proust . Thank you very much for your insight.

Indeed tests were failing. This fix was done very quick and indeed we should have realized this had a larger impact.

After reviewing this I have decided to keep the change and update the tests. The reason being that I find no other suitable way of handling aliased dimensions.

With this change, flat dimensions require the mapping to explicitly state the name of the dimension and the level. For example:

        "details": [
            "FirstName",
            "LastName",
            "Address",
            "CustomerId"
        ],
        "dimensions": [
            "Company",
            "City",
            "State",
            "Country",
            "SupportRepId",
            "SupportRepId_Title",
            "SupportRepId_BirthDate",
        ],
        "joins": [
            {
                "alias": "SupportRepId",
                "detail": "Employee.EmployeeId",
                "master": "Customer.SupportRepId"
            }
        ],
        "key": "CustomerId",
        "label": "Customer",
        "mappings": {
            "Address": "Customer.Address",
            "City.City": "Customer.City",
            "Company.Company": "Customer.Company",
            "Country.Country": "Customer.Country",
            "CustomerId": "Customer.CustomerId",
            "FirstName": "Customer.FirstName",
            "LastName": "Customer.LastName",
            "State.State": "Customer.State",
            "SupportRepId": "Customer.SupportRepId",
            "SupportRepId.EmployeeId": "SupportRepId.EmployeeId",
            "SupportRepId.FirstName": "SupportRepId.FirstName",
            "SupportRepId_BirthDate.day": {
                "column": "BirthDate",
                "extract": "day",
                "table": "SupportRepId"
            },
            "SupportRepId_BirthDate.month": { ...

I admit this may not be the best solution but I was having a hard time trying to fix the table alias problem and this was the method I found. Please feel free to comment if you find any related issue.