Records

A Record is a data structure that contains one or more columns along with a expression that determines the data type and value for the column. One or more columns in the record can be defined to be a key column. Each record also has a operation code with the default operation code being an "insert". The compiler implicitly determines the type for each of the columns based upon the type of the column expression. A record that is created can be stored in a Stream or it can be stored in a record variable with a compatible record type.

Record Event Details

A record type contains one or more column names with a basic type such string, long, date etc associated with it. One or more the columns can be identified as a key columns.

You can declare a record type inside any block of SPLASH code including Global/Local declare blocks, functions and the ON method of a Flex operator using one of the following syntax:
[ [columnType column; [...] [|] ]

or

[ [ columnType column; [...] | ] columnType column; [...] ]
          
Where:

columnType - is one of the basic types such as integer, long, float etc. column - the name of a column in the record. A column name must be unique within a record and is case sensitive i.e. 'symbol' is not the same as 'Symbol'.

In the previous syntax the outer square brackets is part of the syntax and does not represent an optional element. Also any columns appearing before the | character represents the key columns in the record type. Note that the semicolon following the last column before the key separator | and/or the trailing ] is optional.

The following is an example:

[ integer TradeId; string Symbol; | integer Volume; float Price; date TradeTime; ] traderec;

The previous example declares a record variable called traderec with the specified record definition that has two columns namely TradeId and Symbol and three attribute columns namely Volume, Price and TradeTime.

Record Details

You can define a record in SPLASH inside any Global/Local function and inside the ON Method of a Flex Operator. To define a record use one of the following syntax:
[  column = value;  [...] [|] ]
or
[  [ column = value; [...]  |  ]   column = value; [...]   ] 
          
Where:

column - is the name of a column in the record. A column name must be unique within a record and is case sensitive i.e. symbol is not the same as Symbol.

value - is any expression including constant expressions. The column type is determined by the compiler based upon the type of this expression.

In the previous syntax the outer square brackets is part of the syntax and does not represent an optional element. Also any columns appearing before the | character represents the key columns in the record type. Note that the semicolon following the last column before the key separator | and/or the trailing ] is optional.

When a record is created its opcode is set to 'insert' by default. You can change the operation code using the setOpcode function as described in the following example:

[ integer TradeId; string Symbol; | integer Volume; float TradePrice; date TradeTime; ] traderec;
traderec := [ TradeId = 1; Symbol = 'SAP'; | Volume = 100; TradePrice = 150.0; undate('2012-03-01 10:30:35'); ];

In the above example the record variable traderec is assigned a record object with particular values.

Operations on Records

Operations on records:

Record Casting Rules

The ESP compiler does the necessary implicit casting when assigning a source record to a target record variable where the types and column names do not match exactly. This allows you to assign either a source record to a target that does not have all the columns in the target, or a source that has more columns than the target record variable type. The following casting rules are used by the compiler.

* Columns are only copied over when the source and target column names match exactly (including case).

* If the column name matches, but the column type does not, the compiler throws an error saying that you are trying to assign an expression of a wrong type.

* Columns in the source record that do not exactly match the column names and types in the target are ignored.

* The columns in the source with no matching column in the target are automatically filled in with nulls.

The following are casting examples:

[ integer TradeId; string Symbol; | integer Volume; float TradePrice; date TradeTime; ] srcTrade;
[ integer TradeId; | string Symbol; integer volume; float TradeCost; date TradeTime; ] outTrade;

outTrade := srcTrade

In the previous example, Volume and TradeCost are set to null because there is no corresponding target column in the source record variable srcTrade. Note that 'volume' is ignored because the case does not match.

The compiler produces a warning and ignores the source column 'Volume' and 'TradePrice' because they do not exist in the target record type.

Symbol is automatically cast as an attribute column in the target, even though it is a key column in the source.

Note: Casting is an expensive operation. So, where possible, explicitly create a source record with exactly the same type (for example, the same number of columns with the same column names and data types) as the target record variable type.