def update(self, index, column, where=None, logical_operator=None, table_name=None, condition=None, return_type=None): """ :param list or tuple index: Primary key. Eg: [('ActID', 'abc')] :param list or tuple column: Attribute column. Eg: [('PassiveParty', 'def', time.time() * 1000)] :param list or tuple where: Filter. Eg: [('StartTime', ComparatorType('>='), 0)] :param LogicalOperator logical_operator: LogicalOperator('AND') :param str table_name: Table name :param OTSRowCondition condition: Condition of existence of row :param OTSReturnType return_type: API return content :return: """ column_filter = None if table_name is None: table_name = self.table_name if logical_operator is None: logical_operator = LogicalOperator('AND') if where is not None: if not isinstance(where[0][1], ComparatorType): raise InvalidParam(doc=ComparatorType) column_filter = ts.CompositeColumnCondition(logical_operator.OTS) tuple(map(lambda c: column_filter.add_sub_condition( ts.SingleColumnCondition(c[0], c[2], c[1].OTS, *c[3:])), where)) if condition is None: condition = default.ROW_CONDITION elif not isinstance(condition, OTSRowCondition): raise InvalidParam(doc=OTSRowCondition) if return_type is not None and not isinstance(return_type, OTSReturnType): raise InvalidParam(doc=OTSReturnType) row = self.format_update_row(index, column) condition = ts.Condition(condition, column_filter) _, return_row = self.client.update_row(table_name, row, condition, return_type) return StoreData(getattr(return_row, 'primary_key', None))
def filter(where=None, logical_operator=None): """ :param list or tuple where: Filter. Eg: [('StartTime', ComparatorType('>='), 0)] :param LogicalOperator logical_operator: LogicalOperator('AND') :return: """ if where is None: return None if logical_operator is None: logical_operator = LogicalOperator('AND') if not isinstance(where[0][1], ComparatorType): raise InvalidParam(doc=ComparatorType) column_filter = ts.CompositeColumnCondition(logical_operator.OTS) tuple(map(lambda c: column_filter.add_sub_condition( ts.SingleColumnCondition(c[0], c[2], c[1].OTS, *c[3:])), where)) return column_filter
def __ne__(self, data): return myCond( tablestore.SingleColumnCondition( self.name, data, tablestore.ComparatorType.NOT_EQUAL))
def seq2filter(gene_condition): # 规范化表达式 forward_seq = standardize_seq(gene_condition) # 分词 forward_seq = np.array(re.split('(\(|\)|\&&|\|\||!)', forward_seq)) forward_seq = forward_seq[forward_seq != ''] # 中序转后序 afterward_seq = forward2afterward(forward_seq) # 后续转bool_query stack = [] for word in afterward_seq: if word not in ['||', '&&', '!']: if "==" in word: w_pair = word.split("==") stack.append( tablestore.SingleColumnCondition( w_pair[0], float(w_pair[1]), tablestore.ComparatorType.EQUAL, pass_if_missing=False)) elif "<>" in word: w_pair = word.split("<>") stack.append( tablestore.SingleColumnCondition( w_pair[0], float(w_pair[1]), tablestore.ComparatorType.NOT_EQUAL, pass_if_missing=False)) elif ">=" in word: w_pair = word.split(">=") stack.append( tablestore.SingleColumnCondition( w_pair[0], float(w_pair[1]), tablestore.ComparatorType.GREATER_EQUAL, pass_if_missing=False)) elif "<=" in word: w_pair = word.split("<=") stack.append( tablestore.SingleColumnCondition( w_pair[0], float(w_pair[1]), tablestore.ComparatorType.LESS_EQUAL, pass_if_missing=False)) elif ">" in word: w_pair = word.split(">") stack.append( tablestore.SingleColumnCondition( w_pair[0], float(w_pair[1]), tablestore.ComparatorType.GREATER_THAN, pass_if_missing=False)) elif "<" in word: w_pair = word.split("<") stack.append( tablestore.SingleColumnCondition( w_pair[0], float(w_pair[1]), tablestore.ComparatorType.LESS_THAN, pass_if_missing=False)) elif word == '!': f = tablestore.CompositeColumnCondition( tablestore.LogicalOperator.NOT) f.add_sub_condition(stack.pop()) stack.append(f) elif word == "&&": f = tablestore.CompositeColumnCondition( tablestore.LogicalOperator.AND) f.add_sub_condition(stack.pop()) f.add_sub_condition(stack.pop()) stack.append(f) else: f = tablestore.CompositeColumnCondition( tablestore.LogicalOperator.OR) f.add_sub_condition(stack.pop()) f.add_sub_condition(stack.pop()) stack.append(f) return stack.pop()
def __gt__(self, data): return myCond( tablestore.SingleColumnCondition( self.name, data, tablestore.ComparatorType.GREATER_THAN))