SE/relacion.py
def join(self, other):
        '''
        Natural join, joins on shared attributes (one or more). If there are no
        shared attributes, it will behave as the cartesian product.
        '''

        # List of attributes in common between the relations
        shared = self.header.intersection(other.header)

        newt = relation()  # Creates the new relation

        # Creating the header with all the fields, done like that because order is
        # needed
        h = (i for i in other.header if i not in shared)
        newt.header = Header(chain(self.header, h))

        # 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 = [i for i in range(len(other.header)) if i not in oid]

        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 = chain(i, (j[l] for l in noid))
                    newt.content.add(tuple(item))

        return newt

        Natural join, joins on shared attributes (one or more). If there are no
        shared attributes, it will behave as the cartesian product.
        
Natural join, joins on shared attributes (one or more). If there are no
shared attributes, it will behave as the cartesian product.
Natural join joins on shared attributes ( one or more ) . If there are no shared attributes it will behave as the cartesian product .
def join(self, other):
        shared = self.header.intersection(other.header)
        newt = relation()  
        h = (i for i in other.header if i not in shared)
        newt.header = Header(chain(self.header, h))
        sid = self.header.getAttributesId(shared)
        oid = other.header.getAttributesId(shared)
        noid = [i for i in range(len(other.header)) if i not in oid]
        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 = chain(i, (j[l] for l in noid))
                    newt.content.add(tuple(item))
        return newt
def join ( self , other ) : shared = self . header . intersection ( other . header ) newt = relation ( ) h = ( i for i in other . header if i not in shared ) newt . header = Header ( chain ( self . header , h ) ) sid = self . header . getAttributesId ( shared ) oid = other . header . getAttributesId ( shared ) noid = [ i for i in range ( len ( other . header ) ) if i not in oid ] 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 = chain ( i , ( j [ l ] for l in noid ) ) newt . content . add ( tuple ( item ) ) return newt
Natural join, joins on shared attributes (one or more).
Natural join joins on shared attributes ( one or more ) .
'''
        Natural join, joins on shared attributes (one or more). If there are no
        shared attributes, it will behave as the cartesian product.
        ''' # List of attributes in common between the relations # Creates the new relation # Creating the header with all the fields, done like that because order is # needed # Shared ids of self # Shared ids of the other relation # Non shared ids of the other relation
self
other