Menu

Using uniqueName to find the Member instance

2012-03-20
2012-10-08
  • Charlie Hubbard

    Charlie Hubbard - 2012-03-20

    I have a uniqueName of a member that I got from getUniqueName(), but I can't
    seem to figure out to find that member instance using the API. If I pass
    uniqueName directly to IdentifierNode.ofNames() it throws an exception saying
    it can't find it. Is there a way to find the member given the uniqueName? I'm
    using the following code:

    IdentifierNode.ofNames( uniqueName ).getSegmentList()

    I don't really understand the syntax Identifier.ofNames() after reading the
    javadoc and spec.

     
  • pstoellberger

    pstoellberger - 2012-03-20

    You can use it like that:

    List<IdentifierSegment> segments =
    IdentifierParser.parseIdentifier(member.getUniqueName());

     
  • Julian Hyde

    Julian Hyde - 2012-03-20

    Parsing the unique name will give you a list of name segments (a form of parse
    tree node), but it doesn't give you the actual member. Remember that unique
    names are officially "black boxes" -- you can't reliably interpret them, only
    the engine can.

    To ask the engine for a member given its unique name, the simplest thing is to
    execute a query:

    Member getMember(OlapConnection connection, String memberUniqueName) {
        // FIXME close connection, stmt, cellset, and handle errors
        CellSet cset = connection.createStatement().executeOlapQuery("select " + uniqueName + " on 0 from [" + cubeName + "]");
        return cset.getAxes().get(0).getPositions().get(0).getMembers().get(0);
    }
    

    The method Cube.lookupMember(List<NameSegment>) should also
    work. The documentation says it will work for a fully-qualified member name
    but it should also work for a member's unique name.

     

Log in to post a comment.