Operating system requirements: iOS 5.0 or later.
Mobile device: iPad.
This example describes some methods of working with time series database data source. After starting the example the following operations are executed:
The number of pairs "key-value" in data matrix is displayed in the development environment console.
A data source is created based on description of the repository object obtained from selected dimension.
A data source dimension array is obtained.
A time series database data source is created based on description of the repository object obtained from selected dimension, and array of dimensions.
Text description of time series database data source and information about the object, based on which time series database data source is created, is retrieved.
Description of data table for time series database is obtained, and also information about name, primary key, fact key, and data table value key for time series database are retrieved.
Description of timer series database fact table is obtained, and also information about name, primary key, data level key, factor key, and fact table mnemonic key for time series database is retrieved.
Information about name, type, identifier of linked dimension is retrieved for one of data table fields, and time series database fact table.
A new time series database table field is created.
Executing the example requires that mobile application opens the express report using time series database. Then place the following code in the body of the executeExample method of the ViewController class (see the Displaying of Express Report section):
-(void)executeExample { // Get array of time series database dimensions located in left header SNArray leftDimensions = m_olapReport->leftDimensions(); // Get first dimension of time series database in array SPPLDimension dimension = leftDimensions->objectAtIndex<PPLDimension>(0); // Get description of object, based on which the current dimension is created SPPLMetabaseRepositoryObjectDescriptor dimensionObjectDescriptor = dimension->relatedObjectDescriptor(); // Create a data source based on repository object description SPPLDataSource createdDataSource = PPLDataSource::dataSource(dimensionObjectDescriptor); // Get array of data source dimensions SNArray baseDimensions = createdDataSource->dimensions(); // Create a time series database data source based on obtained repository object description SPPLRubricatorDataSource rubricatorDataSourse = PPLRubricatorDataSource::rubricatorDataSource(dimensionObjectDescriptor); // Display number of pairs "key-value" in data matrix in the development environment console [self getMatrixInfoForRubricatorDataSource: rubricatorDataSourse]; // Get text description of time series database object SNString rubricatorDescription = rubricatorDataSourse->description(); // Display text description of time series database object in the development environment console printf("Description of time series database:\n\n%s", rubricatorDescription->UTF8String()); // Get description of repository object, based on which data source is created SPPLMetabaseRepositoryObjectDescriptor rubricatorDescriptor = rubricatorDataSourse->descriptor(); // Get name of time series database object SNString rubricatorDescriptorName = rubricatorDescriptor->name(); /* Display repository object name in the development environment console, based on which data source is created for time series database */ printf("Name of repository object, based on which data source is created for time series database: %s\n", rubricatorDescriptorName->UTF8String()); // Get data table description for time series database SPPLRubricatorDataTableInfo rubricatorDataTableInfo = PPLRubricatorDataTableInfo::dataTableInfo([self getDescriptionForRubricatorDataTableInfo: (rubricatorDataSourse->dataTableInfo())]); // Get data table name for time series database SNString rubricatorDataTableName = rubricatorDataTableInfo->name(); // Display data table name for time series database in the development environment console printf("Data table name for time series database: %s\n", rubricatorDataTableName->UTF8String()); // Get data table primary key for time series database SNString rubricatorDataTablePrimaryKey = rubricatorDataTableInfo->primaryKey(); // Display data table primary key for time series database in the development environment console printf("Data table primary key for time series database: %s\n", rubricatorDataTablePrimaryKey->UTF8String()); // Get data table factor key for time series database SNString rubricatorDataTableFactsKey = rubricatorDataTableInfo->factsKey(); // Display data table factor key for time series database in the development environment console printf("Data table factor key for time series database: %s\n", rubricatorDataTableFactsKey->UTF8String()); // Get data table date key for time series database SNString rubricatorDataTableDateKey = rubricatorDataTableInfo->dateKey(); if (rubricatorDataTableDateKey != NULL) { // Display data table date key for time series database in the development environment console printf("Data table date key for time series database: %s\n", rubricatorDataTableDateKey->UTF8String()); } else { printf("Data table date key for time series database is not available"); } // Get data table value key for time series database SNString rubricatorDataTableValueKey = rubricatorDataTableInfo->valueKey(); // Display data table value key for time series database in the development environment console printf("Data table value key for time series database: %s\n", rubricatorDataTableValueKey->UTF8String()); // Get array of all data table fields for time series database SNArray rubricatorDataTableFields = rubricatorDataTableInfo->fields(); // Get object of data table last field SPPLRubricatorTableField rubricatorDataTableField = rubricatorDataTableFields->objectAtIndex<PPLRubricatorTableField>(rubricatorDataTableFields->count() - 1); // Get field name SNString rubricatorDataTableFieldName = rubricatorDataTableField->name(); // Get field type SNString rubricatorDataTableFieldType = rubricatorDataTableField->type(); // Display field name and type in the development environment console printf("Data table field:\"%s\", type %s\n", rubricatorDataTableFieldName->UTF8String(), rubricatorDataTableFieldType->UTF8String()); // Get identifier of field0linked dimension SNString rubricatorDataTableFieldRelatedDimensionsID = rubricatorDataTableField->relatedDimensionsId(); // Display information about identifier of field-linked dimension in the development environment console if(rubricatorDataTableFieldRelatedDimensionsID != NULL) { printf("Identifier of field-linked dimension \"%s\": %s\n", rubricatorDataTableFieldName->UTF8String(), rubricatorDataTableFieldRelatedDimensionsID->UTF8String()); } else { printf("Identifier of field-linked dimension \"%s\", missing\n", rubricatorDataTableFieldName->UTF8String()); } // Get description of time series database fact table SPPLRubricatorFactsTableInfo rubricatorFactsTableInfo = PPLRubricatorFactsTableInfo::factsTableInfo([self getDescriptionForRubricatorFactsTableInfo:(rubricatorDataSourse->factsTableInfo())]); // Get name of time series database fact table SNString rubricatorFactsTableName = rubricatorFactsTableInfo->name(); // Display name of time series database fact table in the development environment console printf("Name of time series database fact table: %s\n", rubricatorFactsTableName->UTF8String()); // Get primary key name of time series database fact table SNString rubricatorFactsTablePrimaryKey = rubricatorFactsTableInfo->primaryKey(); // Display primary key of time series database fact table in the development environment console printf("Primary key of time series database fact table: %s\n", rubricatorFactsTablePrimaryKey->UTF8String()); // Get data level key of time series database fact table SNString rubricatorFactsTableDataLevelKey = rubricatorFactsTableInfo->dataLevelKey(); // Display data level key of time series database fact table in the development environment console printf("Data level key of time series database fact table: %s\n", rubricatorFactsTableDataLevelKey->UTF8String()); // Get factor key of time series database fact table SNString rubricatorFactsTableFactorKey = rubricatorFactsTableInfo->factorKey(); // Display factor key of time series database fact table in the development environment console printf("Factor key of time series database fact table: %s\n", rubricatorFactsTableFactorKey->UTF8String()); // Get mnemonic key of time series database fact table SNString rubricatorFactsTableMnemoKey = rubricatorFactsTableInfo->mnemo(); // Display mnemonic key of time series database fact table in the development environment console printf("Mnemonic key of time series database fact table: %s\n", rubricatorFactsTableMnemoKey->UTF8String()); // Get array of all fact table fields of time series database SNArray rubricatorFactsTableFields = rubricatorFactsTableInfo->fields(); // Get object of fact table last field SPPLRubricatorTableField rubricatorFactsTableField = rubricatorFactsTableFields->objectAtIndex<PPLRubricatorTableField>(rubricatorFactsTableFields->count() - 1); // Get field name SNString rubricatorFactsTableFieldName = rubricatorFactsTableField->name(); // Get field type SNString rubricatorFactsTableFieldType = rubricatorFactsTableField->type(); // Display field name and type in the development environment console printf("Fact table field:\"%s\", type %s\n", rubricatorFactsTableFieldName->UTF8String(), rubricatorFactsTableFieldType->UTF8String()); // Get identifier of field-linked dimension SNString rubricatorFactsTableFieldRelatedDimensionsID = rubricatorFactsTableField->relatedDimensionsId(); // Display information about identifier of field-linked dimension in the development environment console if(rubricatorFactsTableFieldRelatedDimensionsID != NULL) { printf("Identifier of field-linked dimension \"%s\": %s\n", rubricatorFactsTableFieldName->UTF8String(), rubricatorFactsTableFieldRelatedDimensionsID->UTF8String()); } else { printf("Identifier of field-linked dimension\"%s\", missing\n", rubricatorFactsTableFieldName->UTF8String()); } // Create a dictionary containing description of new field of time series database table SNMutableDictionary fieldDescription = NMutableDictionary::mutableDictionary(); // Add field name to dictionary fieldDescription->setObjectForKey(NStr("Comments"), NStr("name")); // Add field type to dictionary fieldDescription->setObjectForKey(NStr("INTEGER"), NStr("type")); // Create a new fieldo f time series database table SPPLRubricatorTableField field = PPLRubricatorTableField::tableField(fieldDescription); // Get new field name SNString tableName = field->name(); // Display new field name in the development environment console printf("New field name of time series database table: %s\n", tableName->UTF8String()); } // Returns dictionary with settings of time series database table -(SNDictionary)getDescriptionForRubricatorDataTableInfo: (SPPLRubricatorDataTableInfo) rubricatorInfo { SNMutableDictionary description = NMutableDictionary::mutableDictionary(); description->setObjectForKey(rubricatorInfo->name(), NStr("name")); description->setObjectForKey(rubricatorInfo->primaryKey(), NStr("primarykey")); description->setObjectForKey(rubricatorInfo->factsKey(), NStr("facts")); description->setObjectForKey(rubricatorInfo->dateKey(), NStr("data")); description->setObjectForKey(rubricatorInfo->valueKey(), NStr("value")); SNMutableArray fieldDescriptions = NMutableArray::mutableArray(); for (int i = 0; i < rubricatorInfo->fields()->count(); i++) { SPPLRubricatorTableField field = rubricatorInfo->fields()->objectAtIndex<PPLRubricatorTableField>(i); fieldDescriptions->addObject([self getDescriptionForRubricatorTableField: field]); } description->setObjectForKey(fieldDescriptions, NStr("Fields")); return description; } // Returns dictionary with settings of time series database table -(SNDictionary)getDescriptionForRubricatorFactsTableInfo: (SPPLRubricatorFactsTableInfo) rubricatorInfo { SNMutableDictionary description = NMutableDictionary::mutableDictionary(); description->setObjectForKey(rubricatorInfo->name(), NStr("name")); description->setObjectForKey(rubricatorInfo->primaryKey(), NStr("primarykey")); description->setObjectForKey(rubricatorInfo->dataLevelKey(), NStr("datalevel")); description->setObjectForKey(rubricatorInfo->factorKey(), NStr("factor")); description->setObjectForKey(rubricatorInfo->mnemo(), NStr("mnemo")); SNMutableArray fieldDescriptions = NMutableArray::mutableArray(); for (int i = 0; i < rubricatorInfo->fields()->count(); i++) { SPPLRubricatorTableField field = rubricatorInfo->fields()->objectAtIndex<PPLRubricatorTableField>(i); fieldDescriptions->addObject([self getDescriptionForRubricatorTableField: field]); } description->setObjectForKey(fieldDescriptions, NStr("Fields")); return description; } // Returns dictionary with table field settings -(SNDictionary)getDescriptionForRubricatorTableField: (SPPLRubricatorTableField) rubricatorField { SNMutableDictionary description = NMutableDictionary::mutableDictionary(); description->setObjectForKey(rubricatorField->name(), NStr("name")); description->setObjectForKey(rubricatorField->type(), NStr("type")); description->setObjectForKey(rubricatorField->relatedDimensionsId(), NStr("dim")); return description; } -(void)getMatrixInfoForRubricatorDataSource: (SPPLRubricatorDataSource) rubricatorDataSource { // Get data matrix by selection and dimensions SPPLDataSourceMatrix matrix = rubricatorDataSource->obtainMatrix(m_olapReport->selectionSet(), [self allDimensions]); printf("Number of pairs "key-value" in data matrix: %d\n", matrix->dataCount()); }
After executing the example the development environment console displays the number of pairs "key-value" in data matrix, information about data source for time series database, and also name of the created field of time series database table:
Number of pairs "key-value" in data matrix: 545
Description of time series database:
descriptor: Object:
Key: 112
Object Id: TSDB_WORLD
Name: World Development Indicators
Type: 4
Modified date: NDate: Wed 28 Dec 2011 18:11:09
Data source ref id: NULL
Hidden NO
Size: 427962
Version: 1688197
Dependencies: e9b5a4b9818bd9f9a4ebf63bb27405c3
dimensions: <NMutableArray:
id: CALENDAR_119
name: Calendar
Elements tree:
Elements count: 30
id: FACTS_WDI_COPY_1557
name: Indicators
Elements tree:
Elements count: 3
id: CUT_REGIONS_68045
name: Regions
Elements tree:
Elements count: 4
id: CDW_MEASURES_COPY_1559
name: Measures
Elements tree:
Elements count: 208
id: UNITS_123
name: Units
Elements tree:
Elements count: 478
>
Name of repository object, based on which time series database data source is created: World Development Indicators
Name of time series database data table: RUB_DATA
Primary key of time series database data table: D_KEY
Fact key of time series database data table: F_KEY
Date key of time series database data table: DT
Value key of time series database data table: VALUE
Data table field:"VALUE", type REAL
Identifier of dimension linked to the "VALUE" field is missing
Name of time series database fact table: RUB_FACTS
Primary key of time series database fact table: F_KEY
Data level key of time series database fact table: DL
Factor key of time series database fact table: FACTOR
Mnemonic key of time series database fact table: MNEMO
Fact table field:"DL", type INTEGER
Identifier of dimension linked to the "DL" field is missing
New field name of time series database table: Comments
See also: