Build SQL for materialized cubes#608
Merged
shangyian merged 4 commits intoDataJunction:mainfrom Jul 6, 2023
Merged
Conversation
✅ Deploy Preview for thriving-cassata-78ae72 canceled.
|
agorajek
approved these changes
Jul 6, 2023
Member
agorajek
left a comment
There was a problem hiding this comment.
This is good. Two small comments in line.
| existing_cubes = session.exec(statement).unique().all() | ||
| for cube in existing_cubes: | ||
| return cube | ||
| return None |
Member
There was a problem hiding this comment.
Not necessary, None is the default return value.
| # The cube needs to have a materialization configured and an availability state | ||
| # posted in order for us to use the materialized datasource directly | ||
| cube = find_existing_cube(session, metric_columns, dimension_columns) | ||
| if cube and cube.materializations and cube.availability: |
Member
There was a problem hiding this comment.
nit: I wonder if it makes sense to add this condition to the find_existing_cube() method itself... perhaps not, but then I feel like we could add a wrapper on that one called find_materialized_cube() and have this condition in there for reuse.
Collaborator
Author
There was a problem hiding this comment.
Agreed, I think it would be a good idea to add an option to look for materialized cubes. I added a parameter to find_existing_cube called materialized so that we can filter for materialized cubes if desired.
youngman-droid
pushed a commit
to youngman-droid/dj
that referenced
this pull request
Aug 26, 2023
Build SQL for materialized cubes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds functionality to build queries for materialized cube nodes. This was also in the presentation, but I've gone through this a second time to handle various edge cases.
The main changes include:
combinerexpression that combines the measures back into the metric.build_sql_for_multiple_metricsthat generates SQL for both the/sqland/dataendpointsExample
Let's say we have a cube named
default.repairs_cubethat contains the following metrics and dimensions:default.discounted_orders_rate(metric)default.num_repair_orders(metric)default.avg_repair_price(metric)default.hard_hat.country(dim)default.hard_hat.city(dim)After we post an availability state for this cube, whenever we query metrics or dimensions that are in the cube, we'll generate SQL that queries the materialized cube directly. For example, if we ask for
default.discounted_orders_rate,default.num_repair_ordersanddefault.avg_repair_pricegrouped bydefault.hard_hat.country, we'll get the following query:Test Plan
make checkpassesmake testshows 100% unit test coverageDeployment Plan