-
Notifications
You must be signed in to change notification settings - Fork 3
Defining Analyzer
An Analyzer object is practically any instance of a class that inherits from AnalyticalObject<T>
In actuality, in the constructor of the class doing the inheritance is where the actual definition happens.
class AnotherClass {
public string Id {get; set;}
}
class SomeClass {
public int Number {get; set;}
public string Id {get; set;}
public AnotherClass NestedClass {get; set;}
}
To de-normalize this, we define an Analyzer as follows:
// This gives a denormalized TypeMap with defaults for each property.
class SomeClassAnalyzer : AnalyticalObject<SomeClass> {}
To add type casting and the like, we need to use the Fluent Syntax
class SomeClassAnalyzer : AnalyticalObject<SomeClass> {
public SomeClassAnalyzer(){
//This will cast Number correlate the number
//to type string for use in other modules, like loading into a database
Property(s => s.Number).HasInternalType(InternalType.STRING)
}
}
It is possible in this constructor, to bring reference to classes that are not within the scope of the current model. For example:
class OutsideClass {
public string Name {get; set;}
public int Number {get; set;}
}
class SomeClass {
public int Number {get; set;}
public string Id {get; set;}
public AnotherClass NestedClass {get; set;}
//We have the id for a class that will need to be retrieved.
public int OutsideClassId {get; set;}
}
To solve this problem, we can define that this need will be used to retrieve further data like so:
class SomeClassAnalyzer : AnalyticalObject<SomeClass> {
public SomeClassAnalyzer(){
//This will cast Number correlate the number
//to type string for use in other modules, like loading into a database
Property(s => s.Number).HasInternalType(InternalType.STRING)
// We define the name of the service, and pass an analyzer.
// Note, this creates a default analyzer and a custom analyzer may be passed.
Property(s => s.OutsideClassId)
.GetFromService("OutsideClassService", AnalyticalObject<OutsidClass>())
}
}
For handling of pre-initialization business of the definition, a builder object can be passed to the base constructor.
class SomeClassAnalyzer : AnalyticalObject<SomeClass> {
public SomeClassAnalyzer() : base(a => {
// To handle reference loops (self-referencing classes)
a.ReferenceLoopDepthLimit = 2;
// To ignore.
a.Ignore(s => s.Number);
})
{
Property(s => s.OutsideClassId)
.GetFromService("OutsideClassService", AnalyticalObject<OutsidClass>())
}
}
Although less efficient, it is possible to remove properties after they have already been initialized.
class SomeClassAnalyzer : AnalyticalObject<SomeClass> {
public SomeClassAnalyzer(){
//This will cast Number correlate the number
//to type string for use in other modules, like loading into a database
Property(s => s.Number).HasInternalType(InternalType.STRING)
Remove(s => s.Number);
}
}
This could be used if you need to alter the schema at runtime.
SomeClassAnalyzer analyzer = new SomeClassAnalyzer();
analyzer.Remove(s => s.Number);
FluentOlap is still growing and will continue to become more stable over time.