module ProjectM36.FunctionalDependency where
import ProjectM36.Base
import qualified Data.Set as S
data FunctionalDependency = FunctionalDependency AttributeNames AttributeNames RelationalExpr
inclusionDependenciesForFunctionalDependency :: FunctionalDependency -> (InclusionDependency, InclusionDependency)
inclusionDependenciesForFunctionalDependency (FunctionalDependency attrNamesSource attrNamesDependent relExpr) = (
InclusionDependency countSource countDep,
InclusionDependency countDep countSource)
where
countDep = relExprCount relExpr (UnionAttributeNames attrNamesSource attrNamesDependent)
countSource = relExprCount relExpr attrNamesSource
projectZName = Project (AttributeNames (S.singleton "z"))
zCount = FunctionAtomExpr "count" [AttributeAtomExpr "x"] ()
extendZName = Extend (AttributeExtendTupleExpr "z" zCount)
relExprCount expr projectionAttrNames = projectZName (extendZName
(Group projectionAttrNames "x" (Project projectionAttrNames expr)))