Logo Search packages:      
Sourcecode: relational version File versions  Download package

def relational::relation::relation::join (   self,
  other 
)
Natural join, joins on shared attributes (one or more). If there are no
shared attributes, it will behave as cartesian product.

Definition at line 331 of file relation.py.

                        :
        '''Natural join, joins on shared attributes (one or more). If there are no
        shared attributes, it will behave as cartesian product.'''
        shared=[]
        for i in self.header.attributes:
            if i in other.header.attributes:
                shared.append(i)
        
        newt=relation() #Creates the new relation
        
        #Adds all the attributes of the 1st relation
        newt.header=header(list(self.header.attributes))
        
        #Adds all the attributes of the 2nd, when non shared
        for i in other.header.attributes:
            if i not in shared:
                newt.header.attributes.append(i)
        #Shared ids of self
        sid=self.header.getAttributesId(shared)
        #Shared ids of the other relation
        oid=other.header.getAttributesId(shared)
        
        #Non shared ids of the other relation
        noid=[]
        for i in range(len(other.header.attributes)):
            if i not in oid:
                noid.append(i)
        
        for i in self.content:
            for j in other.content:
                match=True
                for k in range(len(sid)):
                    match=match and ( i[sid[k]]== j[oid[k]])
                        
                if match:
                    item=list(i)
                    for l in noid:
                        item.append(j[l])
                    
                    newt.content.append(item)
        
        return newt

Generated by  Doxygen 1.6.0   Back to index