Hilang Definition Statement


| Statement | Property | Name | Inheritance | View | Key | Value | Extent | Hash |

Definitions describe the elements of a HiLang model, with different keyworks used to describe the way that each element is stored in Hiperspace. The definition must include the storage class of the element and name, but all other parts are optional.

type

The element is externally defined, and only the reference is included in the HiLang file. “type” does not normally have keys, values, or extensions.

QLNet integration is an example of externally to find types that are referenced from Hilang model.

In this example BusinessDayConvention is defined in QLNet but declared in a HiLang model for reference by makeBusinessDayConvention function and used in the calculation model.

/*
    Functions to create QLNet objects
*/
%function(unary, makeBusinessDayConvention, QL.Helper.BusinessDayConvention, QLNet.BusinessDayConvention);
%function(unary, makeCalendar, QL.Helper.Calendar, QLNet.Calendar);
%function(unary, makeCurve, QL.Helper.FlatForward, QLNet.Handle<QLNet.YieldTermStructure>);

/*    
    Reference to QLNet types 
*/
type QLNet.BusinessDayConvention;
type QLNet.Calendar;
type QLNet.CashFlow;
type QLNet.Handle<QLNet.YieldTermStructure>;

value

“value” is stored in the element that references it. Values can include any number of values, or references as needed to model the domain “value Fixing(At:DateTime);” can be included as “Fixings:Set<Fixing>” within another element.

Plan.Duration is an example of value definition that has start end times, validation criteria that Start must become before end and an extension property that returns the number of hours between date.

values can have a arbitrarily complex structure ( up to total 2Gb limit of values ). When compression is enabled (For Hiperspace.Rocks ) huge values are compressed to eliminate repeating values. Plan.Duration is an example of a value

value Plan.Duration
{
    Start    : DateTime,
    End      : DateTime,
    Valid    = Start <= End ? true : false
}
[
    Time     = hours (End , Start)
];

entity

The element will be stored in Hiperspace using its key with a SetSpace<entity> included in the domain space for lookup. Any references to the entity in other elements will include just the key, with lookup within Hiperspace as needed. Entities must have a key, but values are optional. Cousins.Person is a simple example of an Entity Cousins.Person that has a reference to their optional parents. FatherChild and MotherChild are extension properties to navigate to children.

entity Cousins.Person                                                       /* define Person                       */
(                                                                           /* Keys                                 */
    Name        : String                                                    /* Person has Name as key               */
)
{                                                                           /* Values                               */
    Mother      : Cousins.Person,                                           /* Person has reference to Mother       */
    Father      : Cousins.Person                                            /* Person has reference to Father       */
[
    FatherChild : Cousins.Person (Father = this),
    MotherChild : Cousins.Person (Mother = this),
];	

segment

Segments are dependent types of the entity that is extended with them, and inherit a reference to the entity that owns them, so “segment Payment … ;” for Account and Book will be generated as “AccountPayment” and “BookPayment”, each concrete definition including “owner” key to refer to the Account or Book that owns them. As with entities, segments have a “SetSpace<segment>” reference in the domain space for lookup directly (using their owner and or through the owning element. Segments can also have segments, each of which inherits the owner reference to the elements that are extended with them.

Segments can be added to Hiperspace either by the owner’s extension property or directly through the Domain's SetSpace.

entity Person : Versioned 
	= Node (SKey = SKey, Name = Name, TypeName = "Person"), 
	  Edge (From = this, To = City, Name = "", TypeName = "Lives In") 
	( Id : Int32) { Name : String, City : City } [ Friends : Friend, Likes : Likes, Ownes : Option<Restaurant> ]; 
entity Restaurant 
	= Node (SKey = SKey, Name = Name, TypeName = "Restaurant"),
	  Edge (From = this, To = City, Name = "", TypeName = "Located In") 
	  ( Id : Int32) {Name : String, City : City };
segment Friend 
	= Edge (From = owner, To = Of, Name = "", TypeName = "Friend")
	(Of : Person) {When : DateTime};	

aspect

Aspects are like segments but must not have keys since they are fully identified by the element that owns them. In the generated code, they are referenced like an attribute since we know there will only be one of them. Aspects are especially useful for information that is not known when an entity is created, or that can change later. Examples include closing price, or business-status. As with entities and segments, aspects can be referenced directly in Hiperspace.

Plan.Tasks.Actual is an example of an aspect for aggregated booked time that is subject to approval. In this case Approval has Horizon Filter to guard update permissions and inclusion in reporting

@Versioned
aspect Plan.Tasks.Actual
{
    Duration    : Plan.Duration,
    Close       : DateTime,
    "set of the controllers that have approved this update"
    Approval    : Set<String>,
    Cost        : Decimal
};	

view

Views are not stored directly within HiperSpace but do have a SetSpace<view> for direct lookup. Lookup of a view in a domain space will enumerate every element that includes the view in its definition. The prime example of view is Node and Edge that provide the Graph view of data within a Hiperspace.

Unlike relational views, HiLang views do not include condition

"node in a graph view of data"
view Node #2
(
    SKey        : String    #1
)
{
    TypeName    : String    #2,
    Name        : String    #3
}
[
    From        : Edge (From = this),
    To          : Edge (To = this)
];

"edge between nodes"
view Edge #3
(
    From        : Node      #2,
    To          : Node      #3,
    TypeName    : String    #4
)
{
    Name        : String    #5,
};
Copyright © Cepheis 2024