def execute(self, environment): exp1 = self.exp1.execute(environment) exp2 = self.exp2.execute(environment) operator = self.operator try: if exp1.type != TYPE.BOOLEAN or exp2.type != TYPE.BOOLEAN: raise Exception if isinstance(exp1.value, pd.core.series.Series) or isinstance( exp2.value, pd.core.series.Series): if operator == "AND": value = exp1.value & exp2.value elif operator == "OR": value = exp1.value | exp2.value else: raise Exception else: if operator == "AND": value = exp1.value and exp2.value elif operator == "OR": value = exp1.value or exp2.value else: raise Exception return primitive.Primitive(TYPE.BOOLEAN, value, self.temp, self.row, self.column) except: expression.list_errors.append( "Error: 42883: la operacion no existe entre: " + str(exp1.type) + " " + str(operator) + " " + str(exp2.type) + "\n En la linea: " + str(self.row))
def execute(self, environment): exp = self.exp.execute(environment) operator = self.operator try: if operator == "ISNULL": value = exp.value == None elif operator == "NOTNULL": value = exp.value != None elif operator == "ISTRUE": value = exp.value == True elif operator == "ISFALSE": value = exp.value == False elif operator == "ISUNKNOWN": value = exp.value == None elif operator == "ISNOTNULL": value = exp.value != None elif operator == "ISNOTTRUE": value = exp.value != True elif operator == "ISNOTFALSE": value = exp.value != False elif operator == "ISNOTUNKNOWN": value = exp.value != None else: raise TypeError return primitive.Primitive(TYPE.BOOLEAN, value, self.temp, self.row, self.column) except TypeError: expression.list_errors.append( "Error: 42883: la operacion no existe entre: " + str(exp.type) + " " + str(operator) + " " + "\n En la linea: " + str(self.row)) except: expression.list_errors.append( "Error: XX000: Error interno (Unary Relational Operation)" + "\n En la linea: " + str(self.row))
def execute(self, environment): exp1 = self.exp1.execute(environment) exp2 = self.exp2.execute(environment) operator = self.operator try: if operator == "<": value = exp1.value < exp2.value elif operator == ">": value = exp1.value > exp2.value elif operator == ">=": value = exp1.value >= exp2.value elif operator == "<=": value = exp1.value <= exp2.value elif operator == "=": value = exp1.value == exp2.value elif operator == "!=": value = exp1.value != exp2.value elif operator == "<>": value = exp1.value != exp2.value elif operator == "ISDISTINCTFROM": value = exp1.value != exp2.value elif operator == "ISNOTDISTINCTFROM": value = exp1.value == exp2.value else: expression.list_errors.append( "Error: 22P02: entrada invalida: " + str(exp1.type) + " " + str(operator) + " " + str(exp2.type) + "\n En la linea: " + str(self.row) ) raise Exception return primitive.Primitive( TYPE.BOOLEAN, value, self.temp, self.row, self.column ) except TypeError: expression.list_errors.append( "Error: 42883: la operacion no existe entre: " + str(exp1.type) + " " + str(operator) + " " + str(exp2.type) + "\n En la linea: " + str(self.row) ) raise Exception except: expression.list_errors.append( "Error: XX000: Error interno (Binary Relational Operation)" + "\n En la linea: " + str(self.row) )
def execute(self, environment): exp1 = self.exp1.execute(environment) exp2 = self.exp2.execute(environment) exp3 = self.exp3.execute(environment) operator = self.operator try: if (isinstance(exp1.value, pd.core.series.Series) or isinstance(exp2.value, pd.core.series.Series) or isinstance(exp3.value, pd.core.series.Series)): if operator == "BETWEEN": value = (exp1.value > exp2.value) & (exp1.value < exp3.value) elif operator == "NOTBETWEEN": value = not ((exp1.value > exp2.value) & (exp1.value < exp3.value)) elif operator == "BETWEENSYMMETRIC": t1 = (exp1.value > exp2.value) & (exp1.value < exp3.value) t2 = (exp1.value < exp2.value) & (exp1.value > exp3.value) value = t1 | t2 else: expression.list_errors.append( "Error: 42601: Error sintactico: " + "\n En la linea: " + str(self.row)) return AssertionError else: if operator == "BETWEEN": value = exp1.value > exp2.value and exp1.value < exp3.value elif operator == "NOTBETWEEN": value = not (exp1.value > exp2.value and exp1.value < exp3.value) elif operator == "BETWEENSYMMETRIC": t1 = exp1.value > exp2.value and exp1.value < exp3.value t2 = exp1.value < exp2.value and exp1.value > exp3.value value = t1 or t2 else: expression.list_errors.append( "Error: 42601: Error sintactico: " + "\n En la linea: " + str(self.row)) return AssertionError return primitive.Primitive(TYPE.BOOLEAN, value, self.temp, self.row, self.column) except TypeError: expression.list_errors.append( "Error: 42883: la operacion no existe entre: " + str(exp1.type) + " " + str(operator) + " " + str(exp2.type) + " y " + str(exp3.type) + "\n En la linea: " + str(self.row)) return AssertionError except: expression.list_errors.append( "Error: XX000: Error interno (Ternary Relational Operation)" + "\n En la linea: " + str(self.row)) pass
def execute(self, environment): exp = self.exp.execute(environment) operator = self.operator try: if exp.type != TYPE.BOOLEAN: raise TypeError if isinstance(exp.value, pd.core.series.Series): if operator == "NOT": value = ~exp.value elif operator == "ISTRUE": value = exp.value == True elif operator == "ISFALSE": value = exp.value == False elif operator == "ISUNKNOWN": value = exp.value == None elif operator == "ISNOTTRUE": value = exp.value != True elif operator == "ISNOTFALSE": value = exp.value != False elif operator == "ISNOTUNKNOWN": value = exp.value != None else: raise TypeError else: if operator == "NOT": value = not exp.value elif operator == "ISTRUE": value = exp.value == True elif operator == "ISFALSE": value = exp.value == False elif operator == "ISUNKNOWN": value = exp.value == None elif operator == "ISNOTTRUE": value = exp.value != True elif operator == "ISNOTFALSE": value = exp.value != False elif operator == "ISNOTUNKNOWN": value = exp.value != None else: raise TypeError return primitive.Primitive(TYPE.BOOLEAN, value, self.temp, self.row, self.column) except TypeError: expression.list_errors.append( "Error: 42883: la operacion no existe entre: " + str(exp.type) + " y el operador " + str(operator) + "\n En la linea: " + str(self.row)) except: expression.list_errors.append( "Error: XX000: Error interno (Binary Aritmethic Operation)" + "\n En la linea: " + str(self.row))
def execute(self, environment): try: exp1 = self.exp1.execute(environment) exp2 = self.exp2.execute(environment) operator = self.operator if exp1.type != TYPE.STRING and exp2.type != TYPE.STRING: expression.list_errors.append( "Error: 42883: la operacion no existe entre: " + str(exp1.type) + " " + str(operator) + " " + str(exp2.type) + "\n En la linea: " + str(self.row) ) raise Exception if isinstance(exp1.value, pd.core.series.Series): exp1.value = exp1.value.apply(str) else: exp1.value = str(exp1.value) if isinstance(exp2.value, pd.core.series.Series): exp2.value = exp2.value.apply(str) else: exp2.value = str(exp2.value) if operator == "||": value = exp1.value + exp2.value else: expression.list_errors.append( "Error: 42725: el operador no es unico: " + str(exp1.type) + " " + str(operator) + " " + str(exp2.type) + "\n En la linea: " + str(self.row) ) raise Exception return primitive.Primitive( TYPE.STRING, value, self.temp, self.row, self.column ) except: expression.list_errors.append( "Error: XX000: Error interno (Binary String Operation)" + "\n En la linea: " + str(self.row) )
def execute(self, environment): exp1 = self.exp1.execute(environment) exp2 = self.exp2.execute(environment) operator = self.operator try: if exp1.type != TYPE.NUMBER or exp2.type != TYPE.NUMBER: raise TypeError if operator == "+": value = exp1.value + exp2.value elif operator == "-": value = exp1.value - exp2.value elif operator == "*": value = exp1.value * exp2.value elif operator == "/": if exp2.value == 0: expression.list_errors.append( "Error: 22012: No se puede dividir por cero") value = 0 else: value = exp1.value / exp2.value elif operator == "^": value = exp1.value**exp2.value elif operator == "%": if exp2.value == 0: expression.list_errors.append( "Error: 22012: No se puede modular por cero") value = 0 else: value = exp1.value % exp2.value else: raise TypeError return primitive.Primitive(TYPE.NUMBER, value, self.temp, self.row, self.column) except TypeError: expression.list_errors.append( "Error: 42883: la operacion no existe entre: " + str(exp1.type) + " " + str(operator) + " " + str(exp2.type) + "\n En la linea: " + str(self.row)) except: expression.list_errors.append( "Error: XX000: Error interno (Binary Aritmethic Operation)" + "\n En la linea: " + str(self.row))
def execute(self, environment): exp = self.exp.execute(environment) operator = self.operator if exp.type != TYPE.NUMBER: expression.list_errors.append( "Error: 42883: la operacion no existe entre: " + str(operator) + " " + str(exp.type) + "\n En la linea: " + str(self.row)) return ArithmeticError if operator == "+": value = exp.value elif operator == "-": value = exp.value * -1 else: expression.list_errors.append( "Error: 42883: la operacion no existe entre: " + str(operator) + " " + str(exp.type) + "\n En la linea: " + str(self.row)) raise Exception return primitive.Primitive(TYPE.NUMBER, value, self.temp, self.row, self.column)
def Primitive(type_, value, temp, row, column): return primitive.Primitive(type_, value, temp, row, column)