From f27342531225ce9cd3c6c1f890098b0541bd2e2c Mon Sep 17 00:00:00 2001 From: LtWorf Date: Mon, 11 May 2009 16:44:52 +0000 Subject: [PATCH] finally subsequent_renames optimization is working git-svn-id: http://galileo.dmi.unict.it/svn/relational/trunk@157 014f5005-505e-4b48-8d0a-63407b615a7c --- relational/optimizations.py | 8 +++++--- relational/optimizer.py | 6 ++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/relational/optimizations.py b/relational/optimizations.py index 1737ce1..b8a2cb1 100644 --- a/relational/optimizations.py +++ b/relational/optimizations.py @@ -100,6 +100,8 @@ def duplicated_projection(n): def selection_inside_projection(n): '''This function locates things like σ j (π k(R)) and converts them into π k(σ j (R))''' + #TODO Document this in the wiki. + changes=0 if n.name=='σ' and n.child.name=='π': @@ -132,7 +134,7 @@ def subsequent_renames(n): _vars={} for i in n.prop.split(','): q=i.split('➡') - _vars[q[0]]=q[1] + _vars[q[0].strip()]=q[1].strip() n.child=n.child.child print _vars for i in list(_vars.keys()): @@ -145,8 +147,8 @@ def subsequent_renames(n): n.prop="" print _vars for i in _vars.items(): - n.prop+="%s➡%s" % (i[0],i[1]) - + n.prop+="%s➡%s," % (i[0],i[1]) + n.prop=n.prop[:-1] #Removing ending comma #recoursive scan if n.kind==optimizer.UNARY: changes+=subsequent_renames(n.child) diff --git a/relational/optimizer.py b/relational/optimizer.py index 7d8d590..fc31c16 100644 --- a/relational/optimizer.py +++ b/relational/optimizer.py @@ -193,10 +193,8 @@ if __name__=="__main__": #a= tokenize(u"π a,b (a*b)") #a=tokenize("(a-b*c)*(b-c)") #print tree("σ i==2 (c ᑌ d - (aᑎb))") == tree("σ i==3 (c ᑌ d - (aᑎb))") - print tree("ρ age➡a,cognome➡cogn(ρ ciccio➡age,nome➡nom(R))") - - - a=general_optimize("ρ age➡a(ρ ciccio➡age(R))") + + a=general_optimize("ρ age➡a,cognome➡cogn(ρ ciccio➡age,nome➡nom(R))") #a=general_optimize("σ i==2 (σ b>5 (d))") print '=========',a #print node(a)