Instructions

A relation program is a sequence of instructions. Normally, each instruction is executed one after the other. Some instructions are global, others work on a stack of relations. In the latter case they are executed for each row in a relation.

Each instruction is on one line. It starts with a keyword and then may have options.

Global instructions

name options example
set field = expression set currentyear = 2020

Create relations

name options example
relation columnlist relation film, director, year
insert expressionlist insert "Home", "Ursula Meier", 2007
data expressionlist data
Home, Ursula Meier, 2007
Beresina,Daniel Schmid,1998
end data
read (encoding) filename read "films.csv"
import filename import "rawtext.txt"

Output relations

name options example
echo expression echo "5 * 4 "
format field format format year "0"
label label for header label electeurs "électeurs"
print (lines) print
write filename write "films.csv"

Unary relational algebra

name options example
select expression select year > 2005
project fieldlist project title, year
rename field newfield rename title original_title
extend field = expression extend title2 = upper(title)

Binary relational algebra

name options example
join expression join natural
union - union
difference - difference
intersection - intersection

Not really relational algebra

name options example
order field mode order year 9
limit start length limit 125 25

Stack operators

name options example
dup - dup
pop - pop
swap - swap

Flow control

name options example
if expression if currentyear > 2005
beep
end if
while expression set currentyear 2000
while currentyear < 2005
beep
set currentyear currentyear + 1
end while

Substructures

name options example
function paramerterlist function double n

set result 2 * n
end function
program paramerterlist program prg n
read "file".n."csv"
end program
run programname parameterlist run prg 2020
transaction - transaction
write "data.csv"
assert unique id
end transaction

Advanced functions

name options example
beep (tones) beep
assert option expression assert all year > 2005
compile expression compile 5+4
deserialize deserialize
include filename include "header.rel"
parse field regex fieldlist parse line "(dd)s(dd)" year, month
serialize serialize
template filename template "tmp.txt"
stack - stack