diff --git a/CHANGELOG b/CHANGELOG
index 8f01182..db0fad0 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -82,3 +82,5 @@
- Implemented subsequent_renames general optimization
- Implemented swap_rename_select general optimization
- Implemented selection_and_product specific optimization
+- Added stub for converting SQL to relational algebra
+- Implemented futile_union_intersection_subtraction general optimization
\ No newline at end of file
diff --git a/relational/optimizations.py b/relational/optimizations.py
index cc95378..e667d42 100644
--- a/relational/optimizations.py
+++ b/relational/optimizations.py
@@ -52,6 +52,39 @@ def duplicated_select(n):
changes+=duplicated_select(n.left)
return changes
+def futile_union_intersection_subtraction(n):
+ '''This function locates things like r ᑌ r, and replaces them with r'''
+ #TODO document into the wiki
+ changes=0
+
+ if n.name in ('ᑌ','ᑎ') and n.left==n.right:
+ changes=1
+ n.name=n.left.name
+ n.kind=n.left.kind
+ if n.kind==optimizer.UNARY:
+ n.child=n.left.child
+ n.prop=n.left.prop
+ elif n.kind==optimizer.BINARY:
+ n.right=n.left.right
+ n.left=n.left.left
+ pass
+ elif n.name=='-' and n.left==n.right:#Empty relation
+ changes=1
+ n.kind=optimizer.UNARY
+ n.name='σ'
+ n.prop='False'
+ n.child=n.left
+ #n.left=n.right=None
+
+ #recoursive scan
+ if n.kind==optimizer.UNARY:
+ changes+=futile_union_intersection_subtraction(n.child)
+ elif n.kind==optimizer.BINARY:
+ changes+=futile_union_intersection_subtraction(n.right)
+ changes+=futile_union_intersection_subtraction(n.left)
+ return changes
+
+
def down_to_unions_subtractions_intersections(n):
'''This funcion locates things like σ i==2 (c ᑌ d), where the union
can be a subtraction and an intersection and replaces them with
@@ -355,5 +388,5 @@ def selection_and_product(n,rels):
changes+=selection_and_product(n.left,rels)
return changes
-general_optimizations=[duplicated_select,down_to_unions_subtractions_intersections,duplicated_projection,selection_inside_projection,subsequent_renames,swap_rename_select]
+general_optimizations=[duplicated_select,down_to_unions_subtractions_intersections,duplicated_projection,selection_inside_projection,subsequent_renames,swap_rename_select,futile_union_intersection_subtraction]
specific_optimizations=[selection_and_product]
\ No newline at end of file
diff --git a/relational/optimizer.py b/relational/optimizer.py
index aa290e6..81a102e 100644
--- a/relational/optimizer.py
+++ b/relational/optimizer.py
@@ -267,24 +267,24 @@ if __name__=="__main__":
import relation,optimizations
- rels={}
+ '''rels={}
rels["P1"]= relation.relation("/home/salvo/dev/relational/trunk/samples/people.csv")
rels["P2"]= relation.relation("/home/salvo/dev/relational/trunk/samples/people.csv")
rels["R1"]= relation.relation("/home/salvo/dev/relational/trunk/samples/person_room.csv")
rels["R2"]= relation.relation("/home/salvo/dev/relational/trunk/samples/person_room.csv")
rels["D1"]= relation.relation("/home/salvo/dev/relational/trunk/samples/dates.csv")
rels["S1"]= relation.relation("/home/salvo/dev/relational/trunk/samples/skillo.csv")
- print rels
+ print rels'''
#n=tree("π indice,qq,name (ρ age➡qq,id➡indice (P1-P2))")
#n=tree("σ id==3 and indice==2 and name==5 or name<2(P1 * S1)")
#print optimizations.selection_and_product(n,rels)
- print specific_optimize("σ name==skill and age>21 and id==indice and skill=='C'(P1ᐅᐊS1)",rels)
+ #print specific_optimize("σ name==skill and age>21 and id==indice and skill=='C'(P1ᐅᐊS1)",rels)
#print n
#print n.result_format(rels)
- #a=general_optimize("σ age==3 and qq<=2 or nome!='ciccio d\\'urso'(ρ ciccio➡age,nome➡nom(R-Q))")
+ a=general_optimize("ρ i➡index(ρ id➡i (people))")
#a=general_optimize("σ i==2 (σ b>5 (d))")
#print a
#print node(a)
diff --git a/relational/parallel.py b/relational/parallel.py
index d39c573..0cf8b16 100644
--- a/relational/parallel.py
+++ b/relational/parallel.py
@@ -19,7 +19,20 @@
'''This module offers capability of executing relational queries in parallel.'''
-def weight (n):
+import optimizer
+
+def weight (n,rels):
'''This function returns a weight that tries to give an approssimation of the
time that will be required to execute the expression'''
+ if n.kind==optimizer.RELATION: #Weight of a relation is its size
+ r=rels[n.name]
+ return len(r.content) * len(r.header.attributes)
+ elif n.kind==optimizer.BINARY and n.name=='ρ':
+ pass
+ elif n.kind==optimizer.BINARY and n.name=='σ':
+ pass
+ elif n.kind==optimizer.BINARY and n.name=='π':
+ pass
+
+
pass
\ No newline at end of file
diff --git a/relational/sql.py b/relational/sql.py
new file mode 100644
index 0000000..f5fd31a
--- /dev/null
+++ b/relational/sql.py
@@ -0,0 +1,26 @@
+# -*- coding: utf-8 -*-
+# Relational
+# Copyright (C) 2009 Salvo "LtWorf" Tomaselli
+#
+# Relation is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see .
+#
+# author Salvo "LtWorf" Tomaselli
+
+'''This module converts SQL queries into relational algebra expressions'''
+
+def stub():
+ "NATURAL JOIN"
+ "CROSS JOIN" ,
+
+
\ No newline at end of file