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

def relational::relation::relation::outer_left (   self,
  other,
  swap = False 
)

Outer left join. Considers self as left and param as right. If the 
tuple has no corrispondence, empty attributes are filled with a "---" 
string. This is due to the fact that empty string or a space would cause
problems when saving the relation.
Just like natural join, it works considering shared attributes.

Definition at line 275 of file relation.py.

00275                                          :
        '''Outer left join. Considers self as left and param as right. If the 
        tuple has no corrispondence, empty attributes are filled with a "---" 
        string. This is due to the fact that empty string or a space would cause
        problems when saving the relation.
        Just like natural join, it works considering shared attributes.'''
        
        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:
            #Tuple partecipated to the join?
            added=False
            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)
                    added=True
            #If it didn't partecipate, adds it
            if not added:
                item=list(i)
                for l in range(len(noid)):
                    item.append("---")
                newt.content.append(item)
        
        return newt
    
    def join(self,other):


Generated by  Doxygen 1.6.0   Back to index