TableAlgebra-0.1.5: Ferry Table Algebra



This package provides a convenient interface to construct Table Algebra plans that can be dealt with by Pathfinder (http:www-db.informatik.uni-tuebingen.deresearchpathfinder). A describtion of the algebra can be found at: http:dbworld.informatik.uni-tuebingen.deprojectspathfinderwikiLogical_Algebra This module only provides a subset of the complete algebra.



type AlgPlan = (Map Algebra AlgNode, AlgRes)Source

An algebraic plan is the result of constructing a graph. | The pair consists of the mapping from nodes to their respective ids | and the algres from the top node.

union :: AlgNode -> AlgNode -> GraphM AlgNodeSource

Union between two plans

attach :: ResAttrName -> ATy -> AVal -> AlgNode -> GraphM AlgNodeSource

Attach a column ResAttrName of type ATy with value AVal in all rows to table AlgNode

proj :: ProjInf -> AlgNode -> GraphM AlgNodeSource

Project/rename certain column out of a plan

getLoop :: GraphM AlgNodeSource

Get the current loop table

rownum :: AttrName -> [AttrName] -> Maybe AttrName -> AlgNode -> GraphM AlgNodeSource

Similar to rowrank but this will assign a emph{unique} number to every row (even if two rows are equal)

rownum' :: AttrName -> [(AttrName, SortDir)] -> Maybe AttrName -> AlgNode -> GraphM AlgNodeSource

Same as rownum but columns can be assigned an ordering direction

eqJoin :: String -> String -> AlgNode -> AlgNode -> GraphM AlgNodeSource

Join two plans where the columns n1 of table 1 and columns n2 of table 2 are equal.

rank :: ResAttrName -> SortInf -> AlgNode -> GraphM AlgNodeSource

Assign a number to each row in column ResAttrName incrementing sorted by SortInf. The numbering is not dense!

eqTJoin :: [(String, String)] -> ProjInf -> AlgNode -> AlgNode -> GraphM AlgNodeSource

The same as eqJoin but with multiple columns.

distinct :: AlgNode -> GraphM AlgNodeSource

Remove duplicate rows

rowrank :: ResAttrName -> SortInf -> AlgNode -> GraphM AlgNodeSource

Same as rank but provides a dense numbering.

cast :: AttrName -> ResAttrName -> ATy -> AlgNode -> GraphM AlgNodeSource

Cast column AttrName to type ATy and give it the name ResAttrName afterwards.

difference :: AlgNode -> AlgNode -> GraphM AlgNodeSource

Compute the difference between two plans.

aggr :: [(AggrType, ResAttrName, Maybe AttrName)] -> Maybe PartAttrName -> AlgNode -> GraphM AlgNodeSource

Apply aggregate functions to a plan

select :: SelAttrName -> AlgNode -> GraphM AlgNodeSource

Select rows where the column SelAttrName contains True.

posSelect :: Int -> SortInf -> Maybe AttrName -> AlgNode -> GraphM AlgNodeSource

Get's the nth element(s) of a (partitioned) table.

dbTable :: String -> Columns -> KeyInfos -> GraphM AlgNodeSource

Construct a database table node The first argument is the emph{qualified} name of the database table. The second describes the columns in alphabetical order. The third argument describes the database keys (one table key can span over multiple columns).

notC :: AttrName -> AttrName -> AlgNode -> GraphM AlgNodeSource

Negate the boolen value in column n and store it in column r

cross :: AlgNode -> AlgNode -> GraphM AlgNodeSource

Make cross product from two plans

oper :: String -> ResAttrName -> LeftAttrName -> RightAttrName -> AlgNode -> GraphM AlgNodeSource

Apply an operator to the element in LeftAttrName and RightAttrName, store the result in ResAttrName

emptyTable :: SchemaInfos -> GraphM AlgNodeSource

Construct an empty table node with

withBinding :: String -> AlgRes -> GraphM a -> GraphM aSource

Evaluate the graph construction computation with the current environment extended with a binding n to v.

withContext :: Gam -> AlgNode -> GraphM a -> GraphM aSource

Evaluate the graph construction computation with a differnt gamma, | and loop table. Return within he current computational context.

getGamma :: GraphM GamSource

Get the current variable environment

fromGam :: String -> GraphM AlgResSource

Lookup a variable in the environment

nat :: Integer -> AValSource

Create an algebraic nat value

int :: Integer -> AValSource

Create an algebraic int value

bool :: Bool -> AValSource

Create an algebraic boolean value

double :: Double -> AValSource

Create an algebraic double value

string :: String -> AValSource

Create an algebraic string value

stringT :: ATySource

Types of algebraic values

data SortDir Source

Sorting rows in a direction




Eq SortDir 
Ord SortDir 
Show SortDir

The show instance results in values that are accepted in the xml plan.

data AggrType Source



newtype SubPlan Source


SubPlan (Map Int AlgRes) 


type AlgRes = (AlgNode, Columns, SubPlan)Source

An algebraic solution is a triple consisting of the node id, a description of the database columns and all subplans

data Column whereSource

The column data type is used to represent the table structure while compiling ferry core into an algebraic plan The col column contains the column number and the type of its contents The NCol column is used to group columns that together form an element of a record , its string argument is used to represent the field name.


Col :: Int -> ATy -> Column 
NCol :: String -> Columns -> Column 


type Columns = [Column]Source

One table can have multiple columns

data ATy whereSource

Algebraic types At this level we do not have any structural types anymore those are represented by columns. ASur is used for surrogate values that occur for nested lists.


AInt :: ATy 
AStr :: ATy 
ABool :: ATy 
ADec :: ATy 
ADouble :: ATy 
ANat :: ATy 
ASur :: ATy 


Eq ATy 
Ord ATy 
Show ATy

Show the algebraic types in a way that is compatible with the xml plan.

type SchemaInfos = [(AttrName, ATy)]Source

Schema information, represents a table structure, the first element of the tuple is the column name the second its type.

type KeyInfos = [KeyInfo]Source

Multiple keys

type GraphM = ReaderT (Gam, AlgNode) (State (Int, Map Algebra AlgNode))Source

Graphs are constructed in a monadic environment. | The graph constructed has to be a DAG. | The reader monad provides access to the variable environment Gamma and the loop table | The variable environment is a mapping from variable names to graphnodes that represent | their compiled form. | The state monad gives access to a supply of fresh variables, and maintains a map from | nodes to node ids. When a node is inserted and an equal node (equal means, equal node | and equal child nodes) already exists in the map the node id for that already existing | node is returned. This allows maximal sharing.

type Gam = [(String, AlgRes)]Source

Variable environemtn mapping from variables to compiled nodes.

initLoop :: AlgebraSource

Shorthand for the initial loop condition used by Ferry.

runGraph :: Algebra -> GraphM AlgRes -> AlgPlanSource

Evaluate the monadic graph into an algebraic plan, given a loop relation.