当前位置: 首页>>代码示例>>Python>>正文


Python DynamoDBConnection.scan方法代码示例

本文整理汇总了Python中boto.dynamodb2.layer1.DynamoDBConnection.scan方法的典型用法代码示例。如果您正苦于以下问题:Python DynamoDBConnection.scan方法的具体用法?Python DynamoDBConnection.scan怎么用?Python DynamoDBConnection.scan使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在boto.dynamodb2.layer1.DynamoDBConnection的用法示例。


在下文中一共展示了DynamoDBConnection.scan方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: DynamoDBv2Layer1Test

# 需要导入模块: from boto.dynamodb2.layer1 import DynamoDBConnection [as 别名]
# 或者: from boto.dynamodb2.layer1.DynamoDBConnection import scan [as 别名]

#.........这里部分代码省略.........
        # Now a query.
        lsi_results = self.dynamodb.query(
            self.table_name,
            index_name='MostRecentIndex',
            key_conditions={
                'username': {
                    'AttributeValueList': [
                        {'S': 'johndoe'},
                    ],
                    'ComparisonOperator': 'EQ',
                },
            },
            consistent_read=True
        )
        self.assertEqual(lsi_results['Count'], 1)

        results = self.dynamodb.query(self.table_name, key_conditions={
            'username': {
                'AttributeValueList': [
                    {'S': 'jane'},
                ],
                'ComparisonOperator': 'EQ',
            },
            'date_joined': {
                'AttributeValueList': [
                    {'N': '1366050000'}
                ],
                'ComparisonOperator': 'GT',
            }
        }, consistent_read=True)
        self.assertEqual(results['Count'], 1)

        # Now a scan.
        results = self.dynamodb.scan(self.table_name)
        self.assertEqual(results['Count'], 2)
        s_items = sorted([res['username']['S'] for res in results['Items']])
        self.assertEqual(s_items, ['jane', 'johndoe'])

        self.dynamodb.delete_item(self.table_name, key={
            'username': {'S': 'johndoe'},
            'date_joined': {'N': '1366056668'},
        })

        results = self.dynamodb.scan(self.table_name)
        self.assertEqual(results['Count'], 1)

        # Parallel scan (minus client-side threading).
        self.dynamodb.batch_write_item({
            self.table_name: [
                {
                    'PutRequest': {
                        'Item': {
                            'username': {'S': 'johndoe'},
                            'first_name': {'S': 'Johann'},
                            'last_name': {'S': 'Does'},
                            'date_joined': {'N': '1366058000'},
                            'friend_count': {'N': '1'},
                            'friends': {'SS': ['jane']},
                        },
                    },
                    'PutRequest': {
                        'Item': {
                            'username': {'S': 'alice'},
                            'first_name': {'S': 'Alice'},
                            'last_name': {'S': 'Expert'},
                            'date_joined': {'N': '1366056800'},
开发者ID:0t3dWCE,项目名称:boto,代码行数:70,代码来源:test_layer1.py

示例2: DynamoDBConnection

# 需要导入模块: from boto.dynamodb2.layer1 import DynamoDBConnection [as 别名]
# 或者: from boto.dynamodb2.layer1.DynamoDBConnection import scan [as 别名]
import simplejson as json
from boto.dynamodb2.layer1 import DynamoDBConnection

# Connect to Dynamo DB, by default it will connect us-east-1 as mentioned in .boto config
ddb2_conn = DynamoDBConnection(profile_name = "dhap-test")

# Open the log file to write the table data
filename_meta_name = 'temp.log'
filename_meta_open = open(filename_meta_name, "w")

# While loop to get the data using exclusive_start_key
ExclusiveStartKey = None

# Loop over the table scan, it provide max 1 MB of data at a given time
while True:
    individual_table = ddb2_conn.scan('DHA_AMP_ORGANIZATION', exclusive_start_key=ExclusiveStartKey)

    for each in individual_table['Items']:
        filename_meta_open.write(json.dumps(each) + "\n")

    individual_table_json_dump = json.dumps(individual_table)
    LastEvaluatedKey_flag = individual_table_json_dump.find('LastEvaluatedKey')
    print individual_table['ConsumedCapacityUnits']

    if LastEvaluatedKey_flag == -1:
        break
    else:
        ExclusiveStartKey = individual_table['LastEvaluatedKey']

# Close the file handle
filename_meta_open.close()
开发者ID:balbir97,项目名称:opsdiary,代码行数:33,代码来源:get_ddb_data.py

示例3: Table

# 需要导入模块: from boto.dynamodb2.layer1 import DynamoDBConnection [as 别名]
# 或者: from boto.dynamodb2.layer1.DynamoDBConnection import scan [as 别名]

#.........这里部分代码省略.........
        DynamoDB's maximum batch size is 25 items per request. If you attempt
        to put/delete more than that, the context manager will batch as many
        as it can up to that number, then flush them to DynamoDB & continue
        batching as more calls come in.

        Example::

            # Assuming a table with one record...
            >>> with users.batch_write() as batch:
            ...     batch.put_item(data={
            ...         'username': 'johndoe',
            ...         'first_name': 'John',
            ...         'last_name': 'Doe',
            ...         'owner': 1,
            ...     })
            ...     # Nothing across the wire yet.
            ...     batch.delete_item(username='bob')
            ...     # Still no requests sent.
            ...     batch.put_item(data={
            ...         'username': 'jane',
            ...         'first_name': 'Jane',
            ...         'last_name': 'Doe',
            ...         'date_joined': 127436192,
            ...     })
            ...     # Nothing yet, but once we leave the context, the
            ...     # put/deletes will be sent.

        """
        # PHENOMENAL COSMIC DOCS!!! itty-bitty code.
        return BatchTable(self)

    def _build_filters(self, filter_kwargs, using=QUERY_OPERATORS):
        """
        An internal method for taking query/scan-style ``**kwargs`` & turning
        them into the raw structure DynamoDB expects for filtering.
        """
        filters = {}

        for field_and_op, value in filter_kwargs.items():
            field_bits = field_and_op.split("__")
            fieldname = "__".join(field_bits[:-1])

            try:
                op = using[field_bits[-1]]
            except KeyError:
                raise exceptions.UnknownFilterTypeError(
                    "Operator '%s' from '%s' is not recognized." % (field_bits[-1], field_and_op)
                )

            lookup = {"AttributeValueList": [], "ComparisonOperator": op}

            # Special-case the ``NULL/NOT_NULL`` case.
            if field_bits[-1] == "null":
                del lookup["AttributeValueList"]

                if value is False:
                    lookup["ComparisonOperator"] = "NOT_NULL"
                else:
                    lookup["ComparisonOperator"] = "NULL"
            # Special-case the ``BETWEEN`` case.
            elif field_bits[-1] == "between":
                if len(value) == 2 and isinstance(value, (list, tuple)):
                    lookup["AttributeValueList"].append(self._dynamizer.encode(value[0]))
                    lookup["AttributeValueList"].append(self._dynamizer.encode(value[1]))
            else:
                # Fix up the value for encoding, because it was built to only work
开发者ID:kolencherry,项目名称:dd-agent,代码行数:70,代码来源:table.py

示例4: Table

# 需要导入模块: from boto.dynamodb2.layer1 import DynamoDBConnection [as 别名]
# 或者: from boto.dynamodb2.layer1.DynamoDBConnection import scan [as 别名]

#.........这里部分代码省略.........
        DynamoDB's maximum batch size is 25 items per request. If you attempt
        to put/delete more than that, the context manager will batch as many
        as it can up to that number, then flush them to DynamoDB & continue
        batching as more calls come in.

        Example::

            # Assuming a table with one record...
            >>> with users.batch_write() as batch:
            ...     batch.put_item(data={
            ...         'username': 'johndoe',
            ...         'first_name': 'John',
            ...         'last_name': 'Doe',
            ...         'owner': 1,
            ...     })
            ...     # Nothing across the wire yet.
            ...     batch.delete_item(username='bob')
            ...     # Still no requests sent.
            ...     batch.put_item(data={
            ...         'username': 'jane',
            ...         'first_name': 'Jane',
            ...         'last_name': 'Doe',
            ...         'date_joined': 127436192,
            ...     })
            ...     # Nothing yet, but once we leave the context, the
            ...     # put/deletes will be sent.

        """
        # PHENOMENAL COSMIC DOCS!!! itty-bitty code.
        return BatchTable(self)

    def _build_filters(self, filter_kwargs, using=QUERY_OPERATORS):
        """
        An internal method for taking query/scan-style ``**kwargs`` & turning
        them into the raw structure DynamoDB expects for filtering.
        """
        filters = {}

        for field_and_op, value in filter_kwargs.items():
            field_bits = field_and_op.split('__')
            fieldname = '__'.join(field_bits[:-1])

            try:
                op = using[field_bits[-1]]
            except KeyError:
                raise exceptions.UnknownFilterTypeError(
                    "Operator '%s' from '%s' is not recognized." % (
                        field_bits[-1],
                        field_and_op
                    )
                )

            lookup = {
                'AttributeValueList': [],
                'ComparisonOperator': op,
            }

            # Special-case the ``NULL/NOT_NULL`` case.
            if field_bits[-1] == 'null':
                del lookup['AttributeValueList']

                if value is False:
                    lookup['ComparisonOperator'] = 'NOT_NULL'
                else:
                    lookup['ComparisonOperator'] = 'NULL'
            # Special-case the ``BETWEEN`` case.
开发者ID:Revmetrix,项目名称:boto,代码行数:70,代码来源:table.py


注:本文中的boto.dynamodb2.layer1.DynamoDBConnection.scan方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。