US and Worldwide: +1 (866) 660-7555
Results 1 to 3 of 3

Thread: :confused: Bug in schemaReader.getMemberByUniqueName() in Mondrian 3.2.0.13661?

  1. #1
    Join Date
    Sep 2010
    Posts
    1

    Unhappy :confused: Bug in schemaReader.getMemberByUniqueName() in Mondrian 3.2.0.13661?

    Hi all,

    I'm trying to use the Cache Control api to expire cached member values, and following posted examples I've tried to write code that looks roughly like this:

    Code:
    String schemaName = "myFactSchema";  
    String cubeName = "myCube";
    
    CacheControl cacheControl = getCacheControl(schemaName);
    SchemaReader schemaReader = getSchemaReader(schemaName);
    Cube variantFactCube = getSchemaCube(schemaName, cubeName);
    
    boolean failIfNotFound = true;
    Member memberSiteAdStructure = schemaReader.getMemberByUniqueName(Id.Segment.toList("AdStructure", "Ads", siteId.toString()),failIfNotFound);
    
    ... Go on to get the Measure members, create a crossjoin region and then flush it.
    The problem is that schemaReader.getMemberByUniqueName() always returns null! My dimension has hierarchy level names, so I've tried all kinds of variations, and still I can never get a non-null response. (As a side note, I thought setting failIfNotFound=false would throw an exception in this case - which it doesn't, but I don't really care about this at the moment). My suspicion is that I'm using dimension, hierarchy, and level names which makes the List<mondrian.olap.Id.Segment> I'm supposed to pass to getMemberByUniqueName() very non-obvious. Here is my schema definition:

    Code:
    <Dimension name="AdStructure" type="StandardDimension" highCardinality="true">
            <Hierarchy name="Ads" hasAll="true" allMemberName="All" primaryKey="ID" primaryKeyTable="PPCAD">
                <Join leftKey="GROUP_ID" leftAlias="PPCAD" rightKey="ID" rightAlias="PPCGROUP">
                    <Table name="PPCAD"/>
                    <Join leftKey="CAMPAIGN_ID" leftAlias="PPCGROUP" rightKey="ID" rightAlias="CAMPAIGN">
                        <Table name="PPCGROUP"/>
                        <Join leftKey="CUSTSITE_ID" leftAlias="CAMPAIGN" rightKey="ID" rightAlias="CUSTSITE">
                            <Table name="CAMPAIGN"/>
                            <Table name="CUSTSITE"/>
                        </Join>
                    </Join>
                </Join>
                <Level name="Site" table="CUSTSITE" column="ID" type="Integer" uniqueMembers="false" captionColumn="ORG_NAME">
                    <Property name="SiteName" column="SITE_NAME" type="String" dependsOnLevelValue="false"/>
                    <Property name="Status" column="STATUS" type="String" dependsOnLevelValue="false"/>
                </Level>
                <Level name="Campaign" table="CAMPAIGN" column="ID" type="Integer" uniqueMembers="false"
                       captionColumn="CAMP_NAME">
                    <Property name="Campaign#" column="CAMP_NUM" type="Numeric" dependsOnLevelValue="false"/>
                    <Property name="CampaignName" column="SHADOW_CAMP_NAME" type="String" dependsOnLevelValue="false"/>
                    <Property name="Status" column="STATUS" type="String" dependsOnLevelValue="false"/>
                </Level>
                <Level name="AdGroup" table="PPCGROUP" column="ID" type="Integer" uniqueMembers="false"
                       captionColumn="GROUP_NAME">
                    <Property name="AdGroup#" column="GROUP_NUM" type="Numeric" dependsOnLevelValue="false"/>
                    <Property name="AdGroupName" column="SHADOW_GROUP_NAME" type="String" dependsOnLevelValue="false"/>
                    <Property name="Status" column="STATUS" type="String" dependsOnLevelValue="false"/>
                </Level>
                <Level name="Ad" table="PPCAD" column="ID" type="Integer" uniqueMembers="false" captionColumn="HEADLINE">
                    <Property name="Ad#" column="AD_NUM" type="Numeric" dependsOnLevelValue="false"/>
                    <Property name="AdHeadline" column="SHADOW_HEADLINE" type="String" dependsOnLevelValue="false"/>
                    <Property name="Status" column="STATUS" type="String" dependsOnLevelValue="false"/>
                    <Property name="AdType" column="AD_TYPE" type="String" dependsOnLevelValue="false"/>
                    <Property name="AdDisplayURL" column="SHADOW_DISPLAY_URL" type="String" dependsOnLevelValue="false"/>
                    <Property name="AdLine1" column="SHADOW_LINE1_COPY" type="String" dependsOnLevelValue="false"/>
                    <Property name="AdLine2" column="SHADOW_LINE2_COPY" type="String" dependsOnLevelValue="false"/>
                    <Property name="AdDestinationPageId" column="DEST_PAGE_ID" type="Numeric" dependsOnLevelValue="false"/>
                </Level>
            </Hierarchy>
        </Dimension>
    
    <Cube name="VariantFact" cache="true" enabled="true">
          <Table name="VARIANTFACT" alias="VARIANTFACT">
              <AggExclude name="agg_d7ame_variantfact"/>
              <AggExclude name="agg_d7gme_variantfact"/>
              <AggExclude name="agg_d7kme_variantfact"/>
              <AggExclude name="schema_version.*"/>
              &agg_mkme;
              &agg_mame;
              &agg_mgme;
              &agg_d30kme;
              &agg_d30ame;
              &agg_d30gme;
          </Table>
        <DimensionUsage source="Date" name="Date" foreignKey="TIMEBYDAY_ID" highCardinality="false"/>
        <DimensionUsage source="Last30Days" name="Last30Days" foreignKey="TIMEBYDAY_ID" highCardinality="true"/>
        <DimensionUsage source="AdStructure" name="AdStructure" foreignKey="AD_ID" highCardinality="true"/>
     
         ... more cube stuff
    I've tried the following variations and can't get anything back:

    Code:
    schemaReader.getMemberByUniqueName(Id.Segment.toList("AdStructure", "Ads", siteId.toString()),failIfNotFound);
    
    schemaReader.getMemberByUniqueName(Id.Segment.toList("AdStructure.Ads",siteId.toString()),failIfNotFound);
    
    schemaReader.getMemberByUniqueName(Id.Segment.toList("AdStructure", "AdStructure.Ads", siteId.toString()),failIfNotFound);
    
    schemaReader.getMemberByUniqueName(Id.Segment.toList("AdStructure", "AdStructure", "Ads", siteId.toString()),failIfNotFound);
    Finally I gave up and wrote my own brute force method to look up the member. This method works and I've been able to successfully retrieve members by substituting schemaReader.getMemberByUniqueName() with a call to my brutish getMember() method. I was successfully able to crossjoin and expire these member segments from the cache.

    Code:
        private Member getMember(String[] exp, SchemaReader schemaReader, Cube variantFactCube)
        {
            if(exp.length < 3) return null;
            Dimension[] dimensions = variantFactCube.getDimensions();
            Member returnVal = null;
            for(Dimension dim : dimensions)
            {
                String dimName = dim.getName();
                if(exp[0].equals(dimName))
                {
                    for(Hierarchy hier: dim.getHierarchies())
                    {
                        String hierName = hier.getName();
                        if(exp[1].equals(hierName))
                        {
                            OlapElement oe = hier;
                            for(int i=2; i < exp.length; i++)
                            {
                               if(oe != null)
                               {
                                oe = lookupChild(schemaReader, exp[i], oe);
                               }
                            }
                            returnVal = (Member)oe;
                            return returnVal;
                        }
                    }
                }
            }
            return returnVal;
        }
    
        private OlapElement lookupChild(SchemaReader schemaReader, String segmentValue, OlapElement oe)
        {
            return oe.lookupChild(schemaReader, new Id.Segment(segmentValue, Id.Quoting.QUOTED), MatchType.EXACT);
        }
    So am I passing the wrong sequence of Id.Segments to getMemberByUniqueName()? Is there a bug, or possibly some other problem that I didn't spot?

    Thanks in advance,

    Daren

  2. #2
    Join Date
    Nov 1999
    Posts
    1,619

    Default

    I think you're getting a SchemaReader that operates at the level of a schema. If you call schemaReader.getCube() does it throw UnsupportedOperationException? Member names are unique only within a cube, so the schema's SchemaReader always returns null.

    I think that if you call cube.getSchemaReader(Role) you will get a SchemaReader that does what you want.

    However, be warned. You are using an undocumented/unsupported API and it may break in future versions. If you want future compatability, use org.olap4j.metadata.Cube.lookupMember().

    Julian

  3. #3

    Default

    I have written following code to use lookupMember -

    org.olap4j.metadata.Schema OlapSchema = olapConnection.getOlapSchema();
    NamedList<org.olap4j.metadata.Cube> cubeList = OlapSchema.getCubes();
    org.olap4j.metadata.Member m = null;
    for(org.olap4j.metadata.Cube cube: cubeList) {
    m = cube.lookupMember(IdentifierNode.parseIdentifier( "[Time].[2013].[Jul2013]").getSegmentList());
    final CacheControl cacheControl = rcon.getCacheControl(null);
    CacheControl.MemberSet regionTime = cacheControl.createMemberSet((mondrian.olap.Member)m, false);
    cacheControl.flush(regionTime);

    }

    But this throws runtime exception saying that Mondrianolap4jMember and mondrian.olap.member are incompatible.



    Quote Originally Posted by jhyde View Post
    I think you're getting a SchemaReader that operates at the level of a schema. If you call schemaReader.getCube() does it throw UnsupportedOperationException? Member names are unique only within a cube, so the schema's SchemaReader always returns null.

    I think that if you call cube.getSchemaReader(Role) you will get a SchemaReader that does what you want.

    However, be warned. You are using an undocumented/unsupported API and it may break in future versions. If you want future compatability, use org.olap4j.metadata.Cube.lookupMember().

    Julian

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •