The Monoid Algebra


The following are the algebraic operators used by lambda-DB:

For example, the OQL query

select distinct struct( E: e.name,
			M: ( select c.name
			     from c in e.children
			    where c.age > 18 ) )
from e in Employees
where e.name = "Smith";
has the following algebraic form:
reduce(set,
       nest(bag,
            unnest(bag,
                   get(set,
                       Employees,
                       e,
                       and(eq(project(e,name),"Smith"))),
                   c,
                   project(e,children),
                   and(gt(project(c,age),18)),
                   e),
            x,
            project(c,name),
            e,
            and()),
       y,
       struct(bind(E,project(e,name)),bind(M,x)),
       and())
and each of the above operations yields values of the following types:
get     -> bag(< e: Employee >)
unnest  -> bag(< e: Employee, c: Person >)
nest    -> bag(< e: Employee, x: bag(string) >)
reduce  -> set(< E: string, M: bag(string) >)
Notice that the unnest operation has keep=e, i.e., it keeps every employee even if this employee has no children older than 18. In that case, c is bound to null. This null value is converted to the empty bag (the zero of the bag monoid) during the nest operation.


Last modified: 1/20/99 by Leonidas Fegaras