Operating system requirements: iOS 5.0 or later.
Mobile device: iPad.
This example describes some methods of working with data source dimension. After starting the example the following operations are executed:
Name, type, key, identifier, and attributes of selected dimension are retrieved.
Text description of selected dimension attributes is retrieved.
A new array of attributes based on existing array is created.
Attributes is searched in the array by specified identifier.
Text description, identifier, name, type and visibility of one of the attributes in the created array are retrieved.
A table that stores selected dimension data is retrieved.
Name, text description, primary key, parent key and array of table fields are retrieved.
A new data table is created.
Array of selected dimension elements is retrieved.
Selected dimension object is deleted.
Executing the example requires to place the following code instead of the executeExample method of the ViewController class (see the Data Analysis section):
-(void)executeExample {
// Get array of cube dimensions
SNArray allDimensions = [self allDimensions];
if (allDimensions->count() > 0) {
// Get first cube dimension in array
SNMutableDictionary description = dimensionDescription(allDimensions->objectAtIndex<PPLDimension>(0));
SPPLDimension dimension = PPLDimension::dimension(description, m_olapReport->descriptor());
// Get current dimension name
SNString dimensionName = dimension->name();
// Determine type of obtained dimension
SNString dimensionType = NStr("unknown");
switch (dimension->type()) {
case PPLDimension::kCalendarDimension: dimensionType = NStr("calendar");break;
case PPLDimension::kCalendarPeriodDimension: dimensionType = NStr("calendar periodic");break;
case PPLDimension::kStandardDimension: dimensionType = NStr("standard");break;
default:break;
}
// Display name and type of current dimension in the development environment console
printf("Dimension \"%s\" is %s dimension\n", dimensionName->UTF8String(), dimensionType->UTF8String());
// Get current dimension key
int dimensionKey = dimension->key();
printf("Dimension key \"%s\": %d\n", dimensionName->UTF8String(), dimensionKey);
// Get current dimension identifier
SNString dimensionId = dimension->id();
// Display dimension identifier in the development environment console
printf("Dimension identifier \"%s\": %s\n", dimensionName->UTF8String(), dimensionId->UTF8String());
// Get current dimension attributes
SPPLDimensionAttributes dimensionAttributes = dimension->attributes();
// Get text description of current dimension attributes
SNString attributesDescription = dimensionAttributes->description();
// Display description of current dimension attributes in the development environment console
printf("Dimension attribute description:\n%s\n", attributesDescription->UTF8String());
// Get array of attributes
SNArray attributesArray = dimensionAttributes->items();
// Create new attributes based on obtained array of attributes
SPPLDimensionAttributes createdDimensionAttributes = new PPLDimensionAttributes(attributesArray);
// Get dictionary of settings of last dimension attribute array
SNDictionary attributeDescriptor = dimensionAttributeDescription(attributesArray->objectAtIndex<PPLDimensionAttribute>(attributesArray->count() - 1));
// Create a dimension attribute based on dictionary with settings
SPPLDimensionAttribute attribute = PPLDimensionAttribute::attribute(attributeDescriptor);
// Get attribute identifier
SNString attributeID = attribute->id();
// Find attribute by specified identifier in created array
SPPLDimensionAttribute attributeToFind = createdDimensionAttributes->getAttributeById(attributeID);
// Get attribute name
SNString attributeName = attributeToFind->name();
// Get attribute type
SNString attributeType = attributeToFind->type();
// Get whether attribute is visible
bool attributeIsVisible = attributeToFind->isVisible();
// Create a string for storing attribute visibility description
SNString attributeVisibility = NStr("no");
// Change description if attribute is visible
if(attributeIsVisible)attributeVisibility = NStr("yes");
// Display name, type and description of obtained attribute visibility in the development environment console
printf("Attribute \"%s\", type: %s, visible: %s\n", attributeName->UTF8String(), attributeType->UTF8String(), attributeVisibility->UTF8String());
// Get text description of obtained attribute
SNString attributeDescription = attribute->description();
// Display description of obtained attribute in the development environment attribute
printf("Attribute description:\n%s\n", attributeDescription->UTF8String());
// Get information about table that stores current dimension data
SPPLDimensionTableInfo dataSourceDimensionTableInfo = dimension->tableInfo();
// Get table name
printf("Name of the table that stores dimension data: %s\n", dataSourceDimensionTableInfo->name()->UTF8String());
// Get text description of dimension table
SNString dataSourceDimensionTableDescription = dataSourceDimensionTableInfo->description();
// Display dimension table description in the development environment console
printf("Dimension table description:\n%s\n", dataSourceDimensionTableDescription->UTF8String());
// Get primary table key
SNString dataSourceDimensionTablePrimaryKey = dataSourceDimensionTableInfo->primaryKey();
printf("Table primary key: %s\n", dataSourceDimensionTablePrimaryKey->UTF8String());
// Get table parent key
SNString dataSourceDimensionTableParentKey = dataSourceDimensionTableInfo->parentKey();
printf("Table parent key: %s\n", dataSourceDimensionTableParentKey->UTF8String());
// Create a dictionary that contains new dimension data table description
SNMutableDictionary tableDescription = NMutableDictionary::mutableDictionary();
// Add table name to dictionary
tableDescription->setObjectForKey(NStr("Data Table"), NStr("name"));
// Create a new data table
SPPLDimensionTableInfo createdTable = PPLDimensionTableInfo::tableInfo(tableDescription);
// Get new table name
printf("New data table name: %s\n", createdTable->name()->UTF8String());
// Get information about table fields in use
SPPLDimensionFields dataSourceDimensionFields = dimension->fields();
// Get array of table fields
SNArray dataSourceDimensionFieldsItems = dataSourceDimensionFields->items();
// Retrieve first table field from array of fields
SPPLDimensionField dataSourceDimensionField= dataSourceDimensionFieldsItems->objectAtIndex<PPLDimensionField>(0);
// Get first table field name
printf("Table field: %s\n", dataSourceDimensionField->name()->UTF8String());
if (dimension->elements() != NULL) {
printf("Number of dimension elements: %d\n", dimension->elements()->itemsCount());
} else {
printf("Dimension does not contain elements");
}
}
}
// Returns dictionary with description of specified dimension
SNMutableDictionary dimensionDescription (SPPLDimension dimension) {
SNMutableDictionary dimensionDictionary = NMutableDictionary::mutableDictionary();
// Set array of dictionaries with dimension attribute settings
SNMutableArray attributeDescriptions = NMutableArray::mutableArray();
N_FOREACH(SPPLDimensionAttribute, attribute, dimension->attributes()->items()) {
attributeDescriptions->addObject(dimensionAttributeDescription(attribute));
}
dimensionDictionary->setObjectForKey(attributeDescriptions, NStr("Attributes"));
// Set dictionary with dimension table settings
dimensionDictionary->setObjectForKey(dimensionTableInfoDescription(dimension->tableInfo()), NStr("TableInfo"));
// Set array of dictionaries with dimension field settings
SNMutableArray fieldDescriptions = NMutableArray::mutableArray();
N_FOREACH(SPPLDimensionField, field, dimension->fields()->items()) {
fieldDescriptions->addObject(dimensionFieldDescription(field));
}
dimensionDictionary->setObjectForKey(fieldDescriptions, NStr("Fields"));
// Set dictionary with dimension settings
dimensionDictionary->setObjectForKey(dimensionInfoDescription(dimension), NStr("DimInfo"));
return dimensionDictionary;
}
// Returns dictionary with dimension settings
SNMutableDictionary dimensionInfoDescription(SPPLDimension dimension) {
SNMutableDictionary dimensionInfoDescription = NMutableDictionary::mutableDictionary();
dimensionInfoDescription->setObjectForKey(dimension->id(), NStr("id"));
dimensionInfoDescription->setObjectForKey(dimension->name(), NStr("name"));
SNString key = NString::stringWithFormat(NStr("%lld"), dimension->key());
dimensionInfoDescription->setObjectForKey(key, NStr("key"));
SNString type;
switch (dimension->type()) {
case PPLDimension::kCalendarDimension:
type = NStr("calendar");
break;
case PPLDimension::kStandardDimension:
type = NStr("std");
break;
default:break;
}
dimensionInfoDescription->setObjectForKey(type, NStr("type"));
return dimensionInfoDescription;
}
// Returns dictionary with specified dimension table settings
SNMutableDictionary dimensionTableInfoDescription(SPPLDimensionTableInfo tableInfo) {
SNMutableDictionary tableInfoDescription = NMutableDictionary::mutableDictionary();
tableInfoDescription->setObjectForKey(tableInfo->name(), NStr("name"));
tableInfoDescription->setObjectForKey(tableInfo->primaryKey(), NStr("primarykey"));
tableInfoDescription->setObjectForKey(tableInfo->parentKey(), NStr("parentkey"));
return tableInfoDescription;
}
// Returns dictionary with specified dimension attribute settings
SNMutableDictionary dimensionAttributeDescription(SPPLDimensionAttribute attribute) {
SNMutableDictionary attributeDescription = NMutableDictionary::mutableDictionary();
attributeDescription->setObjectForKey(attribute->id(), NStr("id"));
attributeDescription->setObjectForKey(attribute->name(), NStr("name"));
attributeDescription->setObjectForKey(attribute->type(), NStr("type"));
attributeDescription->setObjectForKey(NString::stringWithFormat(NStr("%d"),
attribute->isVisible()), NStr("visible"));
return attributeDescription;
}
// Returns dictionary with specified dimension field settings
SNMutableDictionary dimensionFieldDescription(SPPLDimensionField field) {
SNMutableDictionary fieldDescription = NMutableDictionary::mutableDictionary();
fieldDescription->setObjectForKey(field->name(), NStr("name"));
fieldDescription->setObjectForKey(field->type(), NStr("type"));
fieldDescription->setObjectForKey(field->attribute(), NStr("attr"));
return fieldDescription;
}
After executing the example the development environment console displays information about selected dimension, and also information about dimension attributes, elements and data table:
The "Calendar" dimension is a calendar dimension
Key of the "Calendar" dimension: 533
Identifier of the "Calendar" dimension: CALENDAR_Y_ENG_533
Dimension attribute description:
<NMutableArray:
id: BLOCK_TYPE
name: Calendar block type
type: INTEGER
is visible: NO
id: START_DATE
name: Period start date
type: DATETIME
is visible: NO
id: NAME
name: Calendar element name
type: TEXT
is visible: YES
id: ID
name: Identifier
type: TEXT
is visible: NO
id: ORDER
name: Order
type: INTEGER
is visible: NO
>
The "Order" attribute, type: INTEGER, visible: no
Attribute description:
id: ORDER
name: Order
type: INTEGER
is visible: NO
Name of the table that stores dimension data: CALENDAR_Y_ENG_533
Dimension table description:
name: CALENDAR_Y_ENG_533
primary key: KEY
parent key: PARENT_KEY
Table primary key: KEY
Table parent key: PARENT_KEY
New data table name: Data Table
Table field: KEY
Number of dimension elements: 11
See also: