def selection(collumn, field, mustEqual, data): newRelation = toyRelation.Relation() for item in data.getRows(): if (field in item[collumn].dic): if (item[collumn].dic[field] == mustEqual): newRelation.addRow(item) return newRelation
def projection(attribute, data): #attribute retains a trailing whitespace, gotta fix newRelation = toyRelation.Relation() attribute = attribute[:-1] #[:-1] for trailing whitespace if attribute != "*": for row in data.getRows(): #print(row[attribute]) newRelation.addRow({attribute: row[attribute]}) else: newRelation = data return newRelation
def expandIn(target,source,relation,graph): newRelation = toyRelation.Relation() for row in relation.getRows(): if target in row: for edge in toyGraph.findInGoingEdges(row[target],graph[1]): newRow = copy.deepcopy(row) yxCollumn = source + target #the middle collumn in : X| YX | Y newRow[yxCollumn] = edge newRow[source] = edge.source newRelation.addRow(newRow) return newRelation
def expandOut(source,target,relation,graph): newRelation = toyRelation.Relation() for row in relation.getRows(): if source in row: for edge in toyGraph.findOutGoingEdges(row[source],graph[1]): newRow = copy.deepcopy(row) xyCollumn = source + target #the middle collumn in : X| XY | Y newRow[xyCollumn] = edge newRow[target] = edge.target newRelation.addRow(newRow) return newRelation
def hashJoin(table1, table2, index1, index2): h = defaultdict(list) # hash phase for s in table1.getRows(): h[s[index1].iden].append(s) newRelation = toyRelation.Relation() for r in table2.getRows(): for s in (h[r[index2].iden]): r.update(s) newRelation.addRow(r) return newRelation
def getNodes(argument,graph): newRelation = toyRelation.Relation() for node in graph[0]: newRelation.addRow({argument : node}) return newRelation