Example #1
0
    async def scan(self,
                   table_name,
                   filter_condition=None,
                   attributes_to_get=None,
                   limit=None,
                   return_consumed_capacity=None,
                   exclusive_start_key=None,
                   segment=None,
                   total_segments=None,
                   consistent_read=None,
                   index_name=None):
        """
        Performs the scan operation
        """
        self._check_condition('filter_condition', filter_condition)

        operation_kwargs = {TABLE_NAME: table_name}
        name_placeholders = {}
        expression_attribute_values = {}

        if filter_condition is not None:
            filter_expression = filter_condition.serialize(
                name_placeholders, expression_attribute_values)
            operation_kwargs[FILTER_EXPRESSION] = filter_expression
        if attributes_to_get is not None:
            projection_expression = create_projection_expression(
                attributes_to_get, name_placeholders)
            operation_kwargs[PROJECTION_EXPRESSION] = projection_expression
        if index_name:
            operation_kwargs[INDEX_NAME] = index_name
        if limit is not None:
            operation_kwargs[LIMIT] = limit
        if return_consumed_capacity:
            operation_kwargs.update(
                self.get_consumed_capacity_map(return_consumed_capacity))
        if exclusive_start_key:
            operation_kwargs.update(await self.get_exclusive_start_key_map(
                table_name, exclusive_start_key))
        if segment is not None:
            operation_kwargs[SEGMENT] = segment
        if total_segments:
            operation_kwargs[TOTAL_SEGMENTS] = total_segments
        if consistent_read:
            operation_kwargs[CONSISTENT_READ] = consistent_read
        if name_placeholders:
            operation_kwargs[EXPRESSION_ATTRIBUTE_NAMES] = self._reverse_dict(
                name_placeholders)
        if expression_attribute_values:
            operation_kwargs[
                EXPRESSION_ATTRIBUTE_VALUES] = expression_attribute_values

        try:
            return await self.dispatch(SCAN, operation_kwargs)
        except BOTOCORE_EXCEPTIONS as e:
            raise ScanError("Failed to scan table: {}".format(e)) from e
Example #2
0
 def scan(self,
          table_name,
          attributes_to_get=None,
          limit=None,
          conditional_operator=None,
          scan_filter=None,
          return_consumed_capacity=None,
          exclusive_start_key=None,
          segment=None,
          total_segments=None):
     """
     Performs the scan operation
     """
     operation_kwargs = {TABLE_NAME: table_name}
     if attributes_to_get is not None:
         operation_kwargs[ATTRS_TO_GET] = attributes_to_get
     if limit is not None:
         operation_kwargs[LIMIT] = limit
     if return_consumed_capacity:
         operation_kwargs.update(
             self.get_consumed_capacity_map(return_consumed_capacity))
     if exclusive_start_key:
         operation_kwargs.update(
             self.get_exclusive_start_key_map(table_name,
                                              exclusive_start_key))
     if segment is not None:
         operation_kwargs[SEGMENT] = segment
     if total_segments:
         operation_kwargs[TOTAL_SEGMENTS] = total_segments
     if scan_filter:
         operation_kwargs[SCAN_FILTER] = {}
         for key, condition in scan_filter.items():
             operator = condition.get(COMPARISON_OPERATOR)
             if operator not in SCAN_FILTER_VALUES:
                 raise ValueError("{0} must be one of {1}".format(
                     COMPARISON_OPERATOR, SCAN_FILTER_VALUES))
             values = []
             for value in condition.get(ATTR_VALUE_LIST, []):
                 attr_type = self.get_attribute_type(table_name, key, value)
                 values.append({attr_type: self.parse_attribute(value)})
             operation_kwargs[SCAN_FILTER][key] = {
                 COMPARISON_OPERATOR: operator
             }
             if len(values):
                 operation_kwargs[SCAN_FILTER][key][
                     ATTR_VALUE_LIST] = values
         if conditional_operator:
             operation_kwargs.update(
                 self.get_conditional_operator(conditional_operator))
     try:
         return self.dispatch(SCAN, operation_kwargs)
     except BOTOCORE_EXCEPTIONS as e:
         raise ScanError("Failed to scan table: {0}".format(e))
Example #3
0
 def scan(self,
          table_name,
          attributes_to_get=None,
          limit=None,
          scan_filter=None,
          return_consumed_capacity=None,
          exclusive_start_key=None,
          segment=None,
          total_segments=None):
     """
     Performs the scan operation
     """
     operation_kwargs = {pythonic(TABLE_NAME): table_name}
     if attributes_to_get is not None:
         operation_kwargs[pythonic(ATTRS_TO_GET)] = attributes_to_get
     if limit is not None:
         operation_kwargs[pythonic(LIMIT)] = limit
     if return_consumed_capacity:
         operation_kwargs.update(self.get_consumed_capacity_map(return_consumed_capacity))
     if exclusive_start_key:
         operation_kwargs.update(self.get_exclusive_start_key_map(table_name, exclusive_start_key))
     if segment is not None:
         operation_kwargs[pythonic(SEGMENT)] = segment
     if total_segments:
         operation_kwargs[pythonic(TOTAL_SEGMENTS)] = total_segments
     if scan_filter:
         operation_kwargs[pythonic(SCAN_FILTER)] = {}
         for key, condition in scan_filter.items():
             operator = condition.get(COMPARISON_OPERATOR)
             if operator not in SCAN_FILTER_VALUES:
                 raise ValueError("{0} must be one of {1}".format(COMPARISON_OPERATOR, SCAN_FILTER_VALUES))
             values = []
             for value in condition.get(ATTR_VALUE_LIST, []):
                 attr_type = self.get_attribute_type(table_name, key, value)
                 values.append({attr_type: self.parse_attribute(value)})
             operation_kwargs[pythonic(SCAN_FILTER)][key] = {
                 COMPARISON_OPERATOR: operator
             }
             if len(values):
                 operation_kwargs[pythonic(SCAN_FILTER)][key][ATTR_VALUE_LIST] = values
     response, data = self.dispatch(SCAN, operation_kwargs)
     if not response.ok:
         raise ScanError("Failed to scan table: {0}".format(response.content))
     return data