<Database>

[ Shared data | Schema Declarations | tuple | relation | vector | lock | sql ]


Shared data

All variables declarations preceeded by the modifier shared will be persistent and shared among all session threads and will be managed by <bigwig>'s internal database. Fine grained concurrency control is not provided by the compiler and must be programmed explicitly by the service programmer.

The macro package "sql.wigmac" provides an SQL like interface to the database.


Schema Declarations

All tuples, relations, and vector variables need to be declared according to some schema. The schemas themselves are declared explicitly as follows:

schema ::= schema id { field_list }
field_list ::= field*
field ::= type id_list ;

It is also possible to extend already declared schemas. This has the following syntax:

schema ::= schema id extends id { field_list }

Note that schemas are only allowed to contain basic types.


Tuples

The tuple type is defined relative to a schema which is essentially a mapping of identifiers to basic types. A tuple value is thus a mapping from identifiers to basic types corresponding to the names and types of the associated schema. The tuple identifiers are commonly referred to as attributes. The following constructor is available for creating tuples:

exp ::= tuple { exp_list }

The expression list must be assignments to identifiers that are the attribute names. Below is a list of the operators for manipulating tuples.

Operator Description
__==__ equal. The conjunction of the equality of the tuple's constituents.
__!=__ not equal. The negation of the conjunction of the equality of the tuple's constituents.
__=__ assignment. Conceptually assign-by-value, but implemented as copy-on-write.
__<<__ left tuple overwrite. Creates a tuple with the union of all the attributes of the two tuples. Whenever both tuples have a given attribute, the value of the rightmost argument tuple is taken.
__>>__ right tuple overwrite. Creates a tuple with the union of all the attributes of the two tuples. Whenever both tuples have a given attribute, the value of the leftmost argument tuple is taken.
__.__ tuple member reference. Accesses a member field in a tuple.
__\+__ tuple project. Creates a copy of the left argument tuple, keepin only the attributes mentioned in the right argument (a comma separated list of identifiers in parentheses).
__\-__ tuple project complement. Creates a copy of the left argument tuple, projecting away all attributes mentioned in the right argument (a comma separated list of identifiers in parentheses).


Relations

A relation is a set of tuples with no notion of order and where no value is present twice (any redundant values are implicitly removed). The following two operators operate on relations:

Operator Description
__=__ assignment. Conceptually assign-by-value, but implemented as copy-on-write.
|__| size. Returns the number of tuples in the relation.

The following built-in functions operate on relations:

exp ::= relation { exp_list }
Takes a comma separated list of tuple expressions in curly brackets and turns them into a relation.

exp ::= cart ( exp , exp )
Takes two relation arguments in parentheses and produces the cartesian product.

exp ::= factor ( exp_list ) stm
exp ::= factor ( exp_list ; id_list ) stm
First we explain the semantics of the simplest possible factor expression, namely when there is only one expression and no identifiers. The expression is evaluated to a relation on which the factor expression will operate. The statement is executed once for each tuple in this relation where "#" will hold the current tuple. The statement may return tuples or relations (all required to have the same schema) which are union'ed together to form the ultimate result of the factor operation.

The next case is when a comma separated list of identifiers is supplied after the semi-colon. The relation resulting from the evaluation of the expression argument is projected onto these attributes forming a new relation for which any duplicates are removed. The statement will then be executed once per tuple in this relation, setting "#" to the value of the current tuple. The remaining attributes will be available in the variable "@" (or "@1") that will be a relation containing all tuples that contributed to the current "#" tuple.

Finally, multiple expressions may be given as arguments. In this case, all expressions are evaluated to relations from left to right. If no identifiers are specified, the type of "#" will be a tuple with the intersection of the attributes from all the expressions. As usual, the statement will be executed on the relation with all such tuples, setting "#" to the current. The individual contributions from the expressions will be available in the variables "@1" to "@n", where "n" is the number of identifiers specified ("@" is a shortcut for "@1").


Vectors

There are two kinds of Vectors (a.k.a. lists or arrays) in <bigwig>; basic vectors and tuple vectors. Basic vectors are capable of storing lists of basic values, while tuple vectors contain lists of tuples. Both kinds can be multi-dimensional. The following operators operate on vectors:

Operator Description
__=__ assignment. Conceptually assign-by-value, but implemented as copy-on-write.
__+__ concatenation. Returns the concatenation of two vectors.
__+=__ concatenation, then assignment. Concatenates the left and right hand side expressions and assigns the result to the leftmost.
__[__] index. Takes a vector and an integer (n) in square parentheses and extracts the nth element from the vector.
__[__..__] range. Takes a vector and two integers (low and high) separated by two dots and extracts the subvector beginning with low and ending in high-1.
|__| length. Returns the number of elements in the vector.

The following built-in functions operate on vectors:

exp ::= vector { exp_list }
Takes a comma separated list of expressions (of the same type) in curly brackets and constructs a vector from them.

exp ::= sort ( exp )
exp ::= sort ( exp ; id_list )
There are two variants of the sort function; one for sorting basic vectors and one for sorting tuple vectors. The basic vector variant takes a basic vector and sorts it. The tuple vector variant takes a tuple vector, a semi-colon token, and a list of identifiers and sorts the tuple vector according to the attributes specified in the identifier list.


Locking

decl ::= lock id_list ;
Declares a (Unix FCNTL) lock that can be used in read and write statements.

stm ::= read ( id ) stm
stm ::= read ( id ) stm timeout exp : stm
Acquires a read lock on the lock denoted by the identifier, executes the statement, and releases the lock. Multiple read locks can be held at the same time. If the read lock cannot be acquired (because someone holds a write lock on it), this read statement will block until the lock can be acquired. The read statement may also have a timeout part where the expression denotes the number of seconds the statement will block before giving up the lock acquisition and executing the timeout statement.

stm ::= write ( id ) stm
stm ::= write ( id ) stm timeout exp : stm
Acquires a write lock on the lock denoted by the identifier, executes the statement, and releases the lock. Only one write lock can be held at a time. If the write lock cannot be acquired (because someone else holds a write lock on it or a read lock is held on it), this write statement will block until the lock can be acquired. The write statement may also have a timeout part where the expression denotes the number of seconds the statement will block before giving up the lock acquisition and executing the timeout statement.


SQL subset

stm ::= update id set tupleexp_list ;
stm ::= update id set tupleexp_list where id ;
...

stm ::= insert into id values exp_list ;
...

stm ::= delete from id where exp ;
...

stm ::= delete from id where exp ;
...

exp ::= select selectclause_list from id_list
...


bigwig@brics.dk
Last updated: November 2, 2001
Valid HTML 4.01!