Every
application involves some kind of metadata build. Quite often we build
the dimension structures and then assign attributes to the elements of
dimension. When we add an attribute to a dimension, TM1 server creates a
control cube for it – }ElementAttributes_YOUR_DIMNAME. It is a 2-dimension cube, one with the dimension in question and another control dimension }ElementAttributes_YOUR_DIMNAME.
Let us build a very large dimension and populate attributes for it. You can refer to my erstwhile post on building a large dimension. The entire code of the process was in Prolog.
Option 1: Use AttrPutS / AttrPutN
Let’s tweak the process and add below code to Epilog
vs_AttrName1 = ‘Description’;
vs_AttrName2 = ‘Caption’;
vs_AttrName3 = ‘Index’;AttrDelete (vs_DimName, vs_AttrName1);
AttrInsert (vs_Dimname, ”, vs_AttrName1, ‘S’);
AttrDelete (vs_DimName, vs_AttrName2);
AttrInsert (vs_Dimname, ”, vs_AttrName2, ‘S’);
AttrDelete (vs_DimName, vs_AttrName3);
AttrInsert (vs_Dimname, ”, vs_AttrName3, ‘N’);vi_DimSiz = DimSiz (vs_DimName);
WHILE (vi_DimSiz > 0);
vs_Elem = DimNm (vs_DimName, vi_DimSiz);
AttrPutS (‘Desc_’ | vs_Elem, vs_DimName, vs_Elem, vs_AttrName1);
AttrPutS (‘Capt_’ | vs_Elem, vs_DimName, vs_Elem, vs_AttrName2);
AttrPutN (vi_DimSiz, vs_DimName, vs_Elem, vs_AttrName3);
vi_DimSiz = vi_DimSiz – 1;
END;
I am adding 3 attributes (2 of string type and 1 numeric) for testing. Let’s run the code with following values in parameter:
It took 40.16 seconds (as mentioned in the log file) to complete the process. However tm1s.log size is now increased
Let’s
delete the dimension and run SaveDataAll before we begin the next
step. Open the tm1s_TIMESTAMP_.log file. You will see tons of entries
where in the system is recording the old attribute value for the 3
attributes we created.
Option 2: Use AttrPutS / AttrPutN and disable cube logging
We
will now modify the above code, and disable logging on the attribute
cube. Therefore when an AttrPut call is made, the entry is not logged
into the tm1s.log file
vs_AttrName1 = ‘Description’;
vs_AttrName2 = ‘Caption’;
vs_AttrName3 = ‘Index’;AttrDelete (vs_DimName, vs_AttrName1);
AttrInsert (vs_Dimname, ”, vs_AttrName1, ‘S’);
AttrDelete (vs_DimName, vs_AttrName2);
AttrInsert (vs_Dimname, ”, vs_AttrName2, ‘S’);
AttrDelete (vs_DimName, vs_AttrName3);
AttrInsert (vs_Dimname, ”, vs_AttrName3, ‘N’);# Disable Cube logging on the attr cube
vs_AttrCubeName = ‘}ElementAttributes_’ | vs_DimName;
vi_OldValue = CubeGetLogChanges (vs_AttrCubeName);
CubeSetLogChanges (vs_AttrCubeName, 0);vi_DimSiz = DimSiz (vs_DimName);
WHILE (vi_DimSiz > 0);
vs_Elem = DimNm (vs_DimName, vi_DimSiz);
AttrPutS (‘Desc_’ | vs_Elem, vs_DimName, vs_Elem, vs_AttrName1);
AttrPutS (‘Capt_’ | vs_Elem, vs_DimName, vs_Elem, vs_AttrName2);
AttrPutN (vi_DimSiz, vs_DimName, vs_Elem, vs_AttrName3);
vi_DimSiz = vi_DimSiz – 1;
END;# Revert the logging value on attr cube
CubeSetLogChanges (vs_AttrCubeName , vi_OldValue);
The process took 34.78 seconds to finish (saving about 5 seconds) and the tm1s.log file is no longer bloated.
Summary:
- AttrPutS / AttrPutN are used to populate the attribute value(s) of elements in dimension. Each call of the AttrPutN / AttrPutS will create an entry in the tm1s.log file. Therefore a very large dimension with lot of attribute updates, you will likely end up executing for a longer time
- In addition, the tm1s.log file will be bloated up to almost 1 GB depending the volume of change
- It is therefore advisable to disable the attribute cube, before performing attribute updates on a dimension
- The time differences and tm1s.log bloating may not be of an issue, if you are working with dimensions that are small
AttrPutS (‘Happy Smart Attribute updating to you!’, ‘Blog’, ‘Readers’, ‘Message’)
No comments:
Post a Comment