Database.Ferry.Algebra
Description
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 res = (Map Algebra AlgNode, res, Tags)
- union :: AlgNode -> AlgNode -> GraphM a AlgNode
- attach :: ResAttrName -> ATy -> AVal -> AlgNode -> GraphM a AlgNode
- proj :: ProjInf -> AlgNode -> GraphM a AlgNode
- getLoop :: GraphM a AlgNode
- rownum :: AttrName -> [AttrName] -> Maybe AttrName -> AlgNode -> GraphM a AlgNode
- rownum' :: AttrName -> [(AttrName, SortDir)] -> Maybe AttrName -> AlgNode -> GraphM a AlgNode
- eqJoin :: String -> String -> AlgNode -> AlgNode -> GraphM a AlgNode
- rank :: ResAttrName -> SortInf -> AlgNode -> GraphM a AlgNode
- eqTJoin :: [(String, String)] -> ProjInf -> AlgNode -> AlgNode -> GraphM a AlgNode
- distinct :: AlgNode -> GraphM a AlgNode
- rowrank :: ResAttrName -> SortInf -> AlgNode -> GraphM a AlgNode
- cast :: AttrName -> ResAttrName -> ATy -> AlgNode -> GraphM a AlgNode
- difference :: AlgNode -> AlgNode -> GraphM a AlgNode
- aggr :: [(AggrType, ResAttrName, Maybe AttrName)] -> Maybe PartAttrName -> AlgNode -> GraphM a AlgNode
- select :: SelAttrName -> AlgNode -> GraphM a AlgNode
- posSelect :: Int -> SortInf -> Maybe AttrName -> AlgNode -> GraphM a AlgNode
- dbTable :: String -> Columns -> KeyInfos -> GraphM a AlgNode
- notC :: AttrName -> AttrName -> AlgNode -> GraphM a AlgNode
- cross :: AlgNode -> AlgNode -> GraphM a AlgNode
- oper :: String -> ResAttrName -> LeftAttrName -> RightAttrName -> AlgNode -> GraphM a AlgNode
- emptyTable :: SchemaInfos -> GraphM a AlgNode
- tag :: String -> AlgNode -> GraphM a AlgNode
- litTable :: AVal -> String -> ATy -> GraphM a AlgNode
- litTable' :: [[AVal]] -> [(String, ATy)] -> GraphM a AlgNode
- withBinding :: String -> a -> GraphM a r -> GraphM a r
- withContext :: Gam a -> AlgNode -> GraphM a r -> GraphM a r
- getGamma :: GraphM a (Gam a)
- fromGam :: String -> GraphM a a
- nat :: Integer -> AVal
- int :: Integer -> AVal
- bool :: Bool -> AVal
- double :: Double -> AVal
- string :: String -> AVal
- intT, surT, natT, doubleT, boolT, stringT :: ATy
- data SortDir
- data AggrType
- data Column where
- type Columns = [Column]
- data ATy where
- data AVal
- type SchemaInfos = [(AttrName, ATy)]
- type KeyInfos = [KeyInfo]
- type AlgNode = Int
- type GraphM a = ReaderT (Gam a, AlgNode) (State (Int, Map Algebra AlgNode, Tags))
- type Gam a = [(String, a)]
- initLoop :: Algebra
- runGraph :: Algebra -> GraphM res res -> AlgPlan res
- type ProjPair = (NewAttrName, OldAttrName)
- type ProjInf = [ProjPair]
- attachM :: ResAttrName -> ATy -> AVal -> GraphM a AlgNode -> GraphM a AlgNode
- castM :: AttrName -> ResAttrName -> ATy -> GraphM a AlgNode -> GraphM a AlgNode
- eqJoinM :: String -> String -> GraphM a AlgNode -> GraphM a AlgNode -> GraphM a AlgNode
- eqTJoinM :: [(String, String)] -> ProjInf -> GraphM a AlgNode -> GraphM a AlgNode -> GraphM a AlgNode
- rankM :: ResAttrName -> SortInf -> GraphM a AlgNode -> GraphM a AlgNode
- differenceM :: GraphM a AlgNode -> GraphM a AlgNode -> GraphM a AlgNode
- rowrankM :: ResAttrName -> SortInf -> GraphM a AlgNode -> GraphM a AlgNode
- posSelectM :: Int -> SortInf -> Maybe AttrName -> GraphM a AlgNode -> GraphM a AlgNode
- selectM :: SelAttrName -> GraphM a AlgNode -> GraphM a AlgNode
- distinctM :: GraphM a AlgNode -> GraphM a AlgNode
- crossM :: GraphM a AlgNode -> GraphM a AlgNode -> GraphM a AlgNode
- notM :: AttrName -> AttrName -> GraphM a AlgNode -> GraphM a AlgNode
- unionM :: GraphM a AlgNode -> GraphM a AlgNode -> GraphM a AlgNode
- projM :: ProjInf -> GraphM a AlgNode -> GraphM a AlgNode
- aggrM :: [(AggrType, ResAttrName, Maybe AttrName)] -> Maybe PartAttrName -> GraphM a AlgNode -> GraphM a AlgNode
- rownumM :: AttrName -> [AttrName] -> Maybe AttrName -> GraphM a AlgNode -> GraphM a AlgNode
- rownum'M :: AttrName -> [(AttrName, SortDir)] -> Maybe AttrName -> GraphM a AlgNode -> GraphM a AlgNode
- operM :: String -> ResAttrName -> LeftAttrName -> RightAttrName -> GraphM a AlgNode -> GraphM a AlgNode
- tagM :: String -> GraphM a AlgNode -> GraphM a AlgNode
Documentation
type AlgPlan res = (Map Algebra AlgNode, res, Tags)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.
rownum :: AttrName -> [AttrName] -> Maybe AttrName -> AlgNode -> GraphM a 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 a AlgNodeSource
Same as rownum but columns can be assigned an ordering direction
eqJoin :: String -> String -> AlgNode -> AlgNode -> GraphM a AlgNodeSource
Join two plans where the columns n1 of table 1 and columns n2 of table 2 are equal.
rank :: ResAttrName -> SortInf -> AlgNode -> GraphM a 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 a AlgNodeSource
The same as eqJoin but with multiple columns.
rowrank :: ResAttrName -> SortInf -> AlgNode -> GraphM a AlgNodeSource
Same as rank but provides a dense numbering.
cast :: AttrName -> ResAttrName -> ATy -> AlgNode -> GraphM a AlgNodeSource
Cast column AttrName
to type ATy
and give it the name
ResAttrName
afterwards.
aggr :: [(AggrType, ResAttrName, Maybe AttrName)] -> Maybe PartAttrName -> AlgNode -> GraphM a AlgNodeSource
Apply aggregate functions to a plan
select :: SelAttrName -> AlgNode -> GraphM a AlgNodeSource
Select rows where the column SelAttrName
contains True.
posSelect :: Int -> SortInf -> Maybe AttrName -> AlgNode -> GraphM a AlgNodeSource
Get's the nth element(s) of a (partitioned) table.
dbTable :: String -> Columns -> KeyInfos -> GraphM a 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 a AlgNodeSource
Negate the boolen value in column n and store it in column r
oper :: String -> ResAttrName -> LeftAttrName -> RightAttrName -> AlgNode -> GraphM a AlgNodeSource
Apply an operator to the element in LeftAttrName
and RightAttrName
,
store the result in ResAttrName
emptyTable :: SchemaInfos -> GraphM a AlgNodeSource
Construct an empty table node with
withBinding :: String -> a -> GraphM a r -> GraphM a rSource
Evaluate the graph construction computation with the current environment extended with a binding n to v.
withContext :: Gam a -> AlgNode -> GraphM a r -> GraphM a rSource
Evaluate the graph construction computation with a differnt gamma, | and loop table. Return within he current computational context.
Sorting rows in a direction
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.
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.
Wrapper around values that can occur in an algebraic 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 GraphM a = ReaderT (Gam a, AlgNode) (State (Int, Map Algebra AlgNode, Tags))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.
runGraph :: Algebra -> GraphM res res -> AlgPlan resSource
Evaluate the monadic graph into an algebraic plan, given a loop relation.
type ProjInf = [ProjPair]Source
Projection information, a list of new attribute names, and their old names.
castM :: AttrName -> ResAttrName -> ATy -> GraphM a AlgNode -> GraphM a AlgNodeSource
Cast column AttrName
to type ATy
and give it the name
ResAttrName
afterwards.
eqJoinM :: String -> String -> GraphM a AlgNode -> GraphM a AlgNode -> GraphM a AlgNodeSource
Join two plans where the columns n1 of table 1 and columns n2 of table 2 are equal.
eqTJoinM :: [(String, String)] -> ProjInf -> GraphM a AlgNode -> GraphM a AlgNode -> GraphM a AlgNodeSource
The same as eqJoin but with multiple columns.
rankM :: ResAttrName -> SortInf -> GraphM a AlgNode -> GraphM a AlgNodeSource
Assign a number to each row in column ResAttrName
incrementing
sorted by SortInf
. The numbering is not dense!
differenceM :: GraphM a AlgNode -> GraphM a AlgNode -> GraphM a AlgNodeSource
Compute the difference between two plans.
rowrankM :: ResAttrName -> SortInf -> GraphM a AlgNode -> GraphM a AlgNodeSource
Same as rank but provides a dense numbering.
posSelectM :: Int -> SortInf -> Maybe AttrName -> GraphM a AlgNode -> GraphM a AlgNodeSource
Get's the nth element(s) of a (partitioned) table.
selectM :: SelAttrName -> GraphM a AlgNode -> GraphM a AlgNodeSource
Select rows where the column SelAttrName
contains True.
crossM :: GraphM a AlgNode -> GraphM a AlgNode -> GraphM a AlgNodeSource
Make cross product from two plans
notM :: AttrName -> AttrName -> GraphM a AlgNode -> GraphM a AlgNodeSource
Negate the boolen value in column n and store it in column r
projM :: ProjInf -> GraphM a AlgNode -> GraphM a AlgNodeSource
Project/rename certain column out of a plan
aggrM :: [(AggrType, ResAttrName, Maybe AttrName)] -> Maybe PartAttrName -> GraphM a AlgNode -> GraphM a AlgNodeSource
Apply aggregate functions to a plan
rownumM :: AttrName -> [AttrName] -> Maybe AttrName -> GraphM a AlgNode -> GraphM a AlgNodeSource
Similar to rowrank but this will assign a emph{unique} number to every row (even if two rows are equal)
rownum'M :: AttrName -> [(AttrName, SortDir)] -> Maybe AttrName -> GraphM a AlgNode -> GraphM a AlgNodeSource
Same as rownum but columns can be assigned an ordering direction