Esempio n. 1
0
from dep import DependencyAnalysis

from rel import Rel

r = Rel(("x", "y"))
r.add(x="A", y=1)
r.add(x="B", y=1)
r.add(x="C", y=1)
r.add(x="A", y=2)
r.add(x="C", y=2)

d = DependencyAnalysis(r)

# this will print "('B',) : (1,)" because the only dependency between the x
# and y columns is that if x = "B" then y can only be 1.

for t in d.find_dependencies(("x",), ("y",)):
    print str(t[0]), ":", ", ".join([str(v) for v in t[1]])

r.add(x="B", y=2)

d2 = DependencyAnalysis(r)

# this will print nothing because there is now no dependency between x and y
# in other words, y can take all values regardless of what x is.

for t in d2.find_dependencies(("x",), ("y",)):
    print str(t[0]), ":", ", ".join([str(v) for v in t[1]])
Esempio n. 2
0
from rel import Rel, PROJECT, RESTRICT, INTERSECT, UNION, PROJECT_VIEW, RESTRICT_VIEW

dept = Rel(("DNO", "DNAME", "BUDGET"))

dept.add(DNO="D1", DNAME="Marketing", BUDGET="10M")
dept.add(DNO="D2", DNAME="Development", BUDGET="12M")
dept.add(DNO="D3", DNAME="Research", BUDGET="5M")

emp = Rel(("ENO", "ENAME", "DNO", "SALARY"))

emp.add(ENO="E1", ENAME="Lopez", DNO="D1", SALARY="40K")
emp.add(ENO="E2", ENAME="Cheng", DNO="D1", SALARY="42K")
emp.add(ENO="E3", ENAME="Finzi", DNO="D2", SALARY="30K")

emp2 = Rel(("ENO", "ENAME", "DNO", "SALARY"))
emp2.add_multiple([
    dict(ENO="E3", ENAME="Finzi", DNO="D2", SALARY="30K"),
    dict(ENO="E4", ENAME="Saito", DNO="D2", SALARY="35K")
])

dept.display()
emp.display()
emp2.display()

print
print "PROJECT"
PROJECT(emp, ("ENO", "ENAME")).display()

print
print "RESTRICT"
RESTRICT(emp, lambda tup: tup["SALARY"] <= "40K").display()