Ejemplo n.º 1
0
    def encode_keys(self, prop_list, path, commit_versionstamp):
        encoded_values_by_prop = []
        for index_prop_name, direction in self.order_info:
            reverse = direction == Query_Order.DESCENDING
            encoded_values_by_prop.append(
                tuple(
                    encode_value(prop.value(), reverse) for prop in prop_list
                    if prop.name() == index_prop_name))

        encoded_value_combos = itertools.product(*encoded_values_by_prop)
        if not self.ancestor:
            return tuple(
                self.encode_key((), values, path, commit_versionstamp)
                for values in encoded_value_combos)

        keys = []
        for index in range(2, len(path), 2):
            ancestor_path = path[:index]
            remaining_path = path[index:]
            keys.extend([
                self.encode_key(ancestor_path, values, remaining_path,
                                commit_versionstamp)
                for values in encoded_value_combos
            ])

        return tuple(keys)
Ejemplo n.º 2
0
    def apply_prop_filter(self, prop_name, op, value):
        index, direction = self._prop_details(prop_name)
        prop_reverse = direction == Query_Order.DESCENDING
        encoded_value = encode_value(value, prop_reverse)
        if op == Query_Filter.EQUAL:
            self._set_start(index, encoded_value)
            self._set_stop(index, encoded_value)
            self._set_stop(index + 1, b'\xFF')
            return

        if (op == Query_Filter.GREATER_THAN_OR_EQUAL and not prop_reverse
                or op == Query_Filter.LESS_THAN_OR_EQUAL and prop_reverse):
            self._set_start(index, encoded_value)
        elif (op == Query_Filter.GREATER_THAN and not prop_reverse
              or op == Query_Filter.LESS_THAN and prop_reverse):
            self._set_start(index, encoded_value + b'\xFF')
        elif (op == Query_Filter.LESS_THAN_OR_EQUAL and not prop_reverse
              or op == Query_Filter.GREATER_THAN_OR_EQUAL and prop_reverse):
            self._set_stop(index, encoded_value)
            self._set_stop(index + 1, b'\xFF')
        elif (op == Query_Filter.LESS_THAN and not prop_reverse
              or op == Query_Filter.GREATER_THAN and prop_reverse):
            self._set_stop(index, encoded_value)
        else:
            raise BadRequest(u'Unexpected filter operation')
Ejemplo n.º 3
0
  def encode_key(self, value, path, commit_versionstamp):
    key = b''.join([self.directory.rawPrefix, encode_value(value),
                    Path.pack(path),
                    commit_versionstamp or b'\x00' * VERSIONSTAMP_SIZE])
    if not commit_versionstamp:
      key += encode_versionstamp_index(len(key) - VERSIONSTAMP_SIZE)

    return key
Ejemplo n.º 4
0
  def apply_cursor(self, op, cursor, ancestor_path):
    if op in (Query_Filter.GREATER_THAN_OR_EQUAL, Query_Filter.GREATER_THAN):
      existing_parts = self._start_parts
    else:
      existing_parts = self._stop_parts

    for prop_name, direction in self._order_info:
      cursor_prop = next((prop for prop in cursor.property_list()
                          if prop.name() == prop_name), None)
      if cursor_prop is not None:
        index = self._prop_details(prop_name)[0]
        encoded_value = encode_value(cursor_prop.value(),
                                     direction == Query_Order.DESCENDING)
        self._update_parts(existing_parts, index, encoded_value)

    self.apply_path_filter(op, cursor.key().path(), ancestor_path)