Skip to content

Conversation

bdunleavy22
Copy link
Contributor

Add parameter to get elements dynamically from subset object

Add parameter to get elements dynamically from subset object
@MariusWirtz
Copy link
Collaborator

What do you think about merging the subset and subset_name arguments into 1 argument like this?

def get_element_names(
    self,
    dimension_name: str,
    hierarchy_name: str,
    subset: Union[str, "Subset"],
    private: bool = False,
    **kwargs
) -> List[str]:
    """
    Retrieve element names from a static or dynamic subset.

    :param dimension_name: Name of the dimension.
    :param hierarchy_name: Name of the hierarchy.
    :param subset: Subset name (str) or Subset object.
    :param private: Whether the subset is private.
    :param kwargs: Additional arguments.
    :return: List of element names.
    """
    if isinstance(subset, str):
        subset = self.get(subset, dimension_name, hierarchy_name, private=private, **kwargs)
    elif not isinstance(subset, Subet):
        raise ValueError(...)

    if subset.is_static:
        return list(subset_obj.elements)

    element_service = ElementService(self._rest)
    tuples = element_service.execute_set_mdx(
        mdx=subset_obj.expression,
        member_properties=["Name"],
        element_properties=None,
        parent_properties=None,
        **kwargs
    )
    return [entry[0].get("Name", "") for entry in tuples if entry and "Name" in entry[0]]

@bdunleavy22
Copy link
Contributor Author

I think that's a great idea!

Modified argument options for get_element_names
Added `update_static_elements()`
Modified `update()` to use `update_static_elements()` to reduce number of requests from 2 to 1 for static subset updates
@bdunleavy22
Copy link
Contributor Author

Modified argument options for get_element_names
Added update_static_elements()
Modified update() to use update_static_elements() to reduce number of requests from 2 to 1 for static subset updates

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.

2 participants