FactsOnQuery: Boolean;
The FactsOnQuery property determines whether the facts dictionary is based on a query.
Available values:
True. Facts dictionary is based on a query. The query text is determined by the IMetaAttributes.SelectQueryText property returned by the IRubricator.Facts.Attributes property.
False. Facts dictionary is not based on a query.
Executing the example requires that the repository contains the following:
Data table with the T_TSDB identifier that contains the following fields:
Identifier | Field type | Comment |
COUNTRY | Integer | Mandatory and included into the primary index. |
INDICATOR | Integer | Mandatory and included into the primary index. |
DL | Integer | Mandatory and included into the primary index. |
VALUE | Real | Optional. |
DT | Date | Optional. |
MDM repository with MDM_REPO identifier that contains the following:
The countries dictionary with the DICT_CTR identifier.
Factors dictionary with the DICT_IND identifier.
Add links to the Mb, Cubes, Rds, Dal, Dimensions system assemblies.
Sub UserProc;
Var
mb: IMetabase;
ci: IMetabaseObjectCreateInfo;
o: IMetabaseObject;
r: IRubricator;
rds: IMetabaseObjectDescriptor;
CountryFactAttr, IndicatorFactAttr: IMetaAttribute;
FactIndex: IMetaIndex;
fDict, rDict, vDict: IMetaDictionary;
s: String;
Atts: IMetaAttributes;
Begin
mb := MetabaseClass.Active;
// Create time series database
ci := mb.CreateCreateInfo;
ci.ClassId := MetabaseObjectClass.KE_CLASS_RUBRICATOR;
ci.Parent := mb.Root;
ci.Name := "Time series database on query";
ci.Id := Mb.GenerateId("RUB_QUERY");
o := mb.CreateObject(ci).Edit As IMetabaseObject;
r := o As IRubricator;
// Set MDM repository
rds := mb.ItemById("RDS_REPO");
r.Database := rds.Bind As IRdsDatabase;
// Determine that dictionaries of facts,
// values and revisions are built on query
r.FactsOnQuery := True;
r.RevisionsOnQuery := True;
r.ValuesOnQuery := True;
// Time series have composite key
r.CompoundFactorKey := True;
// Create other parameters of time series database
r.KeepHistory := False;
r.HasEmptyAttribute := False;
r.HasMnemonics := False;
// Create dictionaries of facts, revisions, values
r.CreateRevisions;
r.CreateFacts;
r.CreateValues;
// Create the Country factor attribute
CountryFactAttr := r.Facts.Attributes.Add(False);
CountryFactAttr.Id := "COUNTRY";
CountryFactAttr.Name := "Country";
CountryFactAttr.DataType := DbDataType.Integer;
CountryFactAttr.Kind := (MetaAttributeKind.Dimension);
CountryFactAttr.ValuesObject := mb.ItemByIdNamespace("DICT_CTR", rds.Key);
CountryFactAttr.Nullable := False;
If r.Dimensions.FindByKey(CountryFactAttr.ValuesObject.Key) = Null Then
r.Dimensions.AddDimensionEx(CountryFactAttr.ValuesObject.Bind As IDimensionModel);
End If;
// Create the Factor factor attribute
IndicatorFactAttr := r.Facts.Attributes.Add(False);
IndicatorFactAttr.Id := "INDICATOR";
IndicatorFactAttr.Name := "Factor";
IndicatorFactAttr.DataType := DbDataType.Integer;
IndicatorFactAttr.Kind := (MetaAttributeKind.Dimension);
IndicatorFactAttr.ValuesObject := mb.ItemByIdNamespace("DICT_IND", rds.Key);
IndicatorFactAttr.Nullable := False;
If r.Dimensions.FindByKey(IndicatorFactAttr.ValuesObject.Key) = Null Then
r.Dimensions.AddDimensionEx(IndicatorFactAttr.ValuesObject.Bind As IDimensionModel);
End If;
r.CreateFacts;
// Create a primary index of time series database
FactIndex := r.Facts.Indexes.Add;
FactIndex.Primary := True;
FactIndex.Unique := True;
If CountryFactAttr <> Null Then
FactIndex.Attributes.Add(CountryFactAttr);
End If;
If IndicatorFactAttr <> Null Then
FactIndex.Attributes.Add(IndicatorFactAttr);
End If;
FactIndex.Attributes.Add(r.Facts.Attributes.FindById("DL"));
// Determine query for facts dictionary
fDict := r.Facts;
fDict.UseQuery := True;
fDict.CompoundFactorKey := True;
s := "Select distinct country, indicator, dl, " +
"country *1000 + indicator as 'KEY', " +
"country *1000 + indicator as factor, " +
"1 as REV, 0 as DLT, cast(NULL as int) as OBT, " +
"cast(NULL as int) as UNIT from T_TSDB" ;
Atts := fDict.Attributes;
Atts.UseQuery := True;
Atts.SelectQueryText := s;
// Determine query for dictionary of revisions
rDict := r.Revisions;
rDict.UseQuery := True;
s := "select 1 'KEY', 'SOURCE' NAM, current_timestamp DT, 0 KIN, " +
"'' USR, cast(NULL as int) CMT , 0 OBT" ;
Atts := rDict.Attributes;
Atts.UseQuery := True;
Atts.SelectQueryText := s;
// Determine query for dictionary of values
vDict := r.Values;
vDict.UseQuery := True;
s := "Select country *100000 + indicator * 100 + " +
"datediff(dd,DT,{d'1980-01-01'}) 'KEY', " +
"country *1000 + indicator FACTOR, 1 REV, " +
"DL, value VL ,indicator, country, DT, -1 SC, " +
"CAST(NULL as NVarchar(255)) CMT, " +
"CAST(null as int) UNIT from T_TSDB" ;
Atts := vDict.Attributes;
Atts.UseQuery := True;
Atts.SelectQueryText := s;
// Save time series database
o.Save;
End Sub UserProc;
On executing the example, time series database based on queries to the T_TSDB data table will be created. The database contains custom attributes of the COUNTRY and INDICATOR factors that refer to the DICT_CTR and DICT_IND MDM dictionaries.
See also: