Skip to content

Conversation

@adscheevel
Copy link
Collaborator

Method for finding views that contain specified dim/subset as requested in this issue: #738 (comment)

I included an enhancement to the get_all function in View Service to specify whether or not the returned list of views should include elements. By excluding the element list, the get_all function leveraged by this new search method runs 10x faster.

I put the subset search function in the cube service as I needed to leverage the get_names_with_dimension function and didn't want to mess with the dependencies.

Ideally, there would be a good odata query to do all of this right in the URL, but that's proving somewhat complex.

added include_elements filter to get_all function. Setting to false will return view object without element details, a potentially much faster query.
search across cubes for any views with specified dim subset. returned object is list of view objects
@gbryant-dev
Copy link
Contributor

gbryant-dev commented Jun 18, 2022

Something like this seems to work for a OData query to find any views that contains a given dim and subset. Note the type filter using isof to restrict to native views before attempting to filter on nested properties. Probably needs more testing but appears to do the trick.

Cubes?$select=Name&$expand=Views($select=Name;
  $filter=isof(tm1.NativeView) and 
    (
        (tm1.NativeView/Rows/any (r: r/Subset/Name eq 'Default' and r/Subset/Hierarchy/Dimension/Name eq 'Version'))
        or 
       (tm1.NativeView/Columns/any (c: c/Subset/Name eq 'Default' and c/Subset/Hierarchy/Dimension/Name eq 'Version')) 
        or 
       (tm1.NativeView/Titles/any (t: t/Subset/Name eq 'Default' and t/Subset/Hierarchy/Dimension/Name eq 'Version'))
     )
)

Note sure i'd necessarily pick it over the approach you've taken but it's good to know it's possible through OData.

@MariusWirtz
Copy link
Collaborator

Hi,

nice work @adscheevel and @gbryant-dev. Thanks!

I assume the odata query does the filtering more efficiently. I think we should implement the search function based on the query.

In any case, I think we should merge the change that the view skips the element names. That's a useful feature.

@adscheevel
Copy link
Collaborator Author

Thanks @gbryant-dev! I agree an odata query would be preferred and almost surely more efficient. The only issue I have with this query is that it will return a list of all cubes and the matching views for each cube. The result will be a bunch of cubes with null results. This can easily be cleaned up on the python side but it would be nice to have the cube list filtered too, that is a filter both inside and outside of the $expand statement.

@gbryant-dev
Copy link
Contributor

It's possible but I can't find a better way of doing it without duplicating the filter like this:

Cubes?$select=Name&$filter=Views/any (v:v/isof(tm1.NativeView) and ((tm1.NativeView/Rows/any (r: r/Subset/Name eq 'Default' and r/Subset/Hierarchy/Name eq 'Version')) or (tm1.NativeView/Columns/any (r: r/Subset/Name eq 'Default' and r/Subset/Hierarchy/Name eq 'Version')) or (tm1.NativeView/Titles/any (r: r/Subset/Name eq 'Default' and r/Subset/Hierarchy/Name eq 'Version'))))&$expand=Views($select=Name;$filter=isof(tm1.NativeView) and ((tm1.NativeView/Rows/any (r: r/Subset/Name eq 'Default' and r/Subset/Hierarchy/Name eq 'Version')) or (tm1.NativeView/Columns/any (r: r/Subset/Name eq 'Default' and r/Subset/Hierarchy/Name eq 'Version')) or (tm1.NativeView/Titles/any (r: r/Subset/Name eq 'Default' and r/Subset/Hierarchy/Name eq 'Version'))))

removed search_subset function, will add odata query to  view service
find all views with subset. similar to prior work in cube service that is now superseded by this
@adscheevel
Copy link
Collaborator Author

I was afraid of that, knew the filter would need to be present in both places but wasn't sure how messy it'd be. My latest commit 4da336c splits the difference and uses @gbryant-dev's filter in the expand statement and then filters out the null view collections via python. I removed my original function in cube service via this commit 4591636.

fixed errors that i should have picked up in testing
@MariusWirtz
Copy link
Collaborator

Nice work! I will review and add tests

Copy link
Contributor

@gbryant-dev gbryant-dev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've left some comments 🙂

updated name on subset search so clear it's for native views
added select statement to cube on subset search function
changed to f string for proper single quote handling when cube_name specified
added better view list generation when cube_name specified, other minor refactoring
updated url for subset and dim to be case and space insensitive
@adscheevel
Copy link
Collaborator Author

Thank you @gbryant-dev for the suggestions and review of my poorly tested code!

@MariusWirtz
Copy link
Collaborator

Closed in favor of #752

Hi @adscheevel, @gbryant-dev,

I add some tests to the code. Please approve #752 and I will merge the changes.

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

Successfully merging this pull request may close these issues.

3 participants