예제 #1
0
    def selectListFilter(self, select_list, node, new_dic, new_list):
	print node.table_list, node.table_alias_dic
	for table in node.table_list:
	    if table == self.table_name:
		if util.isColumnInTable(self.column_name, table):
		    flag = False
		    for exp in new_list:
			if exp.compare(self):
			    flag = True
			    break
		    if flag is False:
			new_exp = copy.deepcopy(self)
			new_list.append(new_exp)
			new_dic[new_exp] = select_list.exp_alias_dic[self]
		    break

	for table in node.table_alias_dic.keys():
	    if table == self.table_name:
		if util.isColumnInTable(self.column_name, node.table_alias_dic[table]):
		    flag = False
		    for exp in new_list:
			if exp.compare(self):
			    flag = True
			    break
		    if flag is False:
			new_exp = copy.deepcopy(self)
			new_list.append(new_exp)
			new_dic[new_exp] = select_list.exp_alias_dic[self]
예제 #2
0
    def booleanFilter(self, node, rm_flag):
	ret_exp = None
	func_list = ["AND", "OR"]
	if not isinstance(self, Function):
	    # TODO error
	    return
	# debug
	print "self", self.func_name
	if self.func_name == "IS":
	    return None
	if self.func_name in func_list:
	    exp_list = []
	    tmp_flag = True
	    for exp in self.para_list:
		if isinstance(exp, Function):
		    # debug
		    print "para_list", exp.func_name
		    if self.func_name == "OR":
		        tmp_exp = exp.booleanFilter(node, False)
		    else:
		        tmp_exp = exp.booleanFilter(node, rm_flag)
		    print "tmp_exp", tmp_exp
		    if self.func_name == "OR" and tmp_exp is None:
		        tmp_flag = False
		    if tmp_exp is not None:
		        exp_list.append(tmp_exp)

	    if tmp_flag is False or len(exp_list) == 0:
		return None
	    elif len(exp_list) == 1:
		ret_exp = copy.deepcopy(exp_list[0])
		if rm_flag is True:
		    exp_list[0].removePara()
		return ret_exp
	    else:
		if rm_flag is True:
		    for exp in exp_list:
			exp.removePara()
		ret_exp = Function(self.func_name, exp_list)
		return ret_exp
	else:
	    exp_flag = True
	    for exp in self.para_list:
		print exp.evaluate()
		tmp_flag = False
		if isinstance(exp, Column):
		    print node.table_list
		    for table in node.table_list:
			if table == exp.table_name and util.isColumnInTable(exp.column_name, table):
			    tmp_flag = True
			    print "tmp_flag is true"
			    break
		    for key in node.table_alias_dic.keys():
			if key == exp.table_name and isColumnInTable(exp.column_name, node.table_alias_dic[key]):
			    tmp_flag = True
			    break
		elif isinstance(exp, Constant):
		    tmp_flag = True
		else:
		    if exp.booleanFilter(node, False) is not None:
			tmp_flag = True
		exp_flag = tmp_flag and exp_flag
	    print "exp_flag is ", exp_flag, "remove_flag is ", rm_flag
	    if exp_flag is True:
		ret_exp = copy.deepcopy(self)
		if rm_flag is True:
		    self.removePara()
		return ret_exp
	    else:
		return None