Tokens and Types : Record Token Types : Defining Record Types
 
Share this page                  
Defining Record Types
Since record token types are composed of combinations of scalar token types, it is impossible to statically enumerate all of them, unlike the scalar token types. Thus, each RecordTokenType object must contain the schema describing its record structure. A consequence of this is that record types cannot be statically checked; type checking of records is always done at run time.
There are two ways of defining a record schema, depending on whether the schema is statically known or discovered at run time. If the schema is known at compile time, the static convenience methods of TokenTypeConstant can be used to describe the type, as illustrated below.
Statically declaring a record type
import static com.pervasive.datarush.types.TokenTypeConstant.record;
import static com.pervasive.datarush.types.TokenTypeConstant.INT;
import static com.pervasive.datarush.types.TokenTypeConstant.STRING;

// Create an employee record type with fields id, firstName, lastName
RecordTokenType employee =
    record(INT("id"), STRING("firstName"), STRING("lastName"));
If the schema is derived from information not known until run time, a RecordTokenTypeBuilder must be used to construct the token type instead.
Dynamically building a RecordTokenType
// Create an employee record type with fields from input attributes
RecordTokenTypeBuilder typeBuilder = new RecordTokenTypeBuilder();
typeBuilder.addField("id", TokenTypeConstant.INT);
for (int i = 0; i < 50; i++ ) {
   typeBuilder.addField("attr" + i, TokenTypeConstant.DOUBLE);
}
RecordTokenType type = typeBuilder.toType();