def execute(self, environment): newEnv = Environment(environment, dbtemp) global envVariables envVariables.append(newEnv) s1 = self.s1.execute(newEnv) s2 = self.s2.execute(newEnv) df1 = s1[0] df2 = s2[0] types1 = list(s1[1].values()) types2 = list(s2[1].values()) if len(df1.columns) != len(df2.columns): syntaxPostgreSQL.append( "Error: 42611: INTERSEC definicion en numero de columnas invalida " ) return "Error: El numero de columnas no coinciden" for i in range(len(types1)): if types1[i] != types2[i]: semanticErrors.append( ["Error discrepancia de tipo de datos entre columnas", self.row] ) syntaxPostgreSQL.append( "Error: 42804: discrepancia de tipo de datos entre columnas " ) return "Error: Los tipos de columnas no coinciden" df = df1.merge(df2).drop_duplicates(ignore_index=True) return df
def execute(self, environment): newEnv = Environment(environment, dbtemp) global envVariables envVariables.append(newEnv) s1 = self.s1.execute(newEnv) s2 = self.s2.execute(newEnv) df1 = s1[0] df2 = s2[0] types1 = list(s1[1].values()) types2 = list(s2[1].values()) if len(df1.columns) != len(df2.columns): syntaxPostgreSQL.append( "Error: 42611: EXCEPT definicion en numero de columnas invalida " ) return "Error: El numero de columnas no coinciden" for i in range(len(types1)): if types1[i] != types2[i]: semanticErrors.append( ["Error discrepancia de tipo de datos entre columnas", self.row] ) syntaxPostgreSQL.append( "Error: 42804: discrepancia de tipo de datos entre columnas" ) return "Error: Los tipos de columnas no coinciden" df = df1.merge(df2, how="outer", indicator=True).loc[ lambda x: x["_merge"] == "left_only" ] del df["_merge"] return df
def execute(self, environment): try: newEnv = Environment(environment, dbtemp) global envVariables envVariables.append(newEnv) labels = [] values = {} for i in range(len(self.params)): v = self.params[i].execute(newEnv) values[self.params[i].temp] = [v.value] labels.append(self.params[i].temp) newEnv.types[labels[i]] = v.type newEnv.dataFrame = pd.DataFrame(values) return [newEnv.dataFrame, newEnv.types] except: syntaxPostgreSQL.append( "Error: P0001: Error en la instruccion SELECT")
def execute(self, environment): try: newEnv = Environment(environment, dbtemp) global envVariables envVariables.append(newEnv) self.fromcl.execute(newEnv) if self.wherecl != None: self.wherecl.execute(newEnv) if self.groupbyCl != None: newEnv.groupCols = len(self.groupbyCl) groupDf = None groupEmpty = True if self.params: params = [] for p in self.params: if isinstance(p, TableAll): result = p.execute(newEnv) for r in result: params.append(r) else: params.append(p) labels = [p.temp for p in params] if self.groupbyCl != None: value = [] for i in range(len(params)): ex = params[i].execute(newEnv) val = ex.value newEnv.types[labels[i]] = ex.type # Si no es columna de agrupacion if i < len(self.groupbyCl): if not (isinstance(val, pd.core.series.Series) or isinstance(val, pd.DataFrame)): nval = { val: [ val for i in range( len(newEnv.dataFrame.index)) ] } nval = pd.DataFrame(nval) val = nval newEnv.dataFrame = pd.concat( [newEnv.dataFrame, val], axis=1) else: if groupEmpty: countGr = newEnv.groupCols # Obtiene las ultimas columnas metidas (Las del group by) df = newEnv.dataFrame.iloc[:, -countGr:] cols = list(df.columns) groupDf = df.groupby(cols).sum().reset_index() groupDf = pd.concat([groupDf, val], axis=1) groupEmpty = False else: groupDf = pd.concat([groupDf, val], axis=1) if groupEmpty: countGr = newEnv.groupCols # Obtiene las ultimas columnas metidas (Las del group by) df = newEnv.dataFrame.iloc[:, -countGr:] cols = list(df.columns) groupDf = df.groupby(cols).sum().reset_index() groupEmpty = False else: value = [p.execute(newEnv) for p in params] for j in range(len(labels)): newEnv.types[labels[j]] = value[j].type newEnv.dataFrame[labels[j]] = value[j].value else: value = [newEnv.dataFrame[p] for p in newEnv.dataFrame] labels = [p for p in newEnv.dataFrame] if value != []: if self.wherecl == None: df_ = newEnv.dataFrame.filter(labels) if self.limitCl: df_ = self.limitCl.execute(df_, newEnv) if self.distinct: return [df_.drop_duplicates(), newEnv.types] return [df_, newEnv.types] w2 = newEnv.dataFrame.filter(labels) # Si la clausula WHERE devuelve un dataframe vacio if w2.empty: return None df_ = w2 if self.limitCl: df_ = self.limitCl.execute(df_, newEnv) if self.distinct: return [df_.drop_duplicates(), newEnv.types] return [df_, newEnv.types] else: newNames = {} i = 0 for (columnName, columnData) in groupDf.iteritems(): newNames[columnName] = labels[i] i += 1 groupDf.rename(columns=newNames, inplace=True) df_ = groupDf if self.limitCl: df_ = self.limitCl.execute(df_, newEnv) if self.distinct: return [df_.drop_duplicates(), newEnv.types] return [df_, newEnv.types] except: syntaxPostgreSQL.append( "Error: P0001: Error en la instruccion SELECT")