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.
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.
[ [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.
[ 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:
Type: The value returned has the type of the field.
Example: rec.data1
Syntax: record.field := value
Type: The value must be a value matching the type of the field of the record. The expression returns a record.
Example: rec.data1 := 10
Syntax: record := recordObject or record := recordVariable.
Examples:
Record object assignment outTrades := [ TradeId = 1; Symbol = 'SAP'; | Volume = 100; TradePrice = 150.0; undate('2012-03-01 10:30:35'); ];
Assigning one record variable to another: outTrades := inTrades;
See the section on record casting rules for information on how the compiler deals with scenarios where the source record type does not exactly match the target record type.
1 means "insert"
3 means "update"
5 means "delete"
7 means "upsert"(insert if not present, update otherwise)
13 means "safe delete"(delete if present, ignore otherwise)
Syntax: getOpcode(record)
Type: The argument must be an event. The function returns an integer.
Example: getOpcode(input)
Syntax: setOpcode(record,opCodenumber)
Type: The first argument must be a record, and the second an integer. The function returns the modified record.
Example: setOpcode(input,insert)
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.