php - dyanmodb batchGetItem and Partition Key and Sort Key -


i tried use batchgetitem return attributes of more 1 item table seems works combination of partition key , range key, if want identify requested items primary key ? way create table without range key ?

    // adding items     $client->putitem(array(         'tablename' => $table,         'item' => array(             'id'     => array('s' => '2a49ab04b1534574e578a08b8f9d7441'),             'name'   => array('s' => 'test1'),             'user_name'   => array('s' => 'aaa.bbb')         )     ));      // adding items     $client->putitem(array(         'tablename' => $table,         'item' => array(             'id'     => array('s' => '4fd70b72cc21fab4f745a6073326234d'),             'name'   => array('s' => 'test2'),             'user_name'   => array('s' => 'aaaa.bbbb'),             'user_name1'   => array('s' => 'aaaaa.bbbbb')         )     ));  $client->batchgetitem(array(     "requestitems" => array(         $table => array(             "keys" => array(                 // hash key                 array(                     "id"  => array( 's' => "2a49ab04b1534574e578a08b8f9d7441"),                 // range key                     "name" => array( 's' => "test1"),                 ),                 array(                 // hash key                     "id"  => array( 's' => "4fd70b72cc21fab4f745a6073326234d"),                 // range key                     "name" => array( 's' => "test2"),                 ),             )         )     ) )); 

as per official documentation:

http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/howitworks.partitions.html

if table has composite primary key (partition key , sort key), dynamodb calculates hash value of partition key in same way described in data distribution: partition key—but stores of items same partition key value physically close together, ordered sort key value.

what advantages using partition key , sort key beside stores of items same partition key value physically close ?

as per official documentation:

a single operation can retrieve 16 mb of data, can contain many 100 items. batchgetitem return partial result if response size limit exceeded, table's provisioned throughput exceeded, or internal processing failure occurs.

how handle request if need more 100 items ? loop through items code , request each time 100 times or there way achieve via aws sdk dynamodb?

example of table creation:

$client->createtable(array(         'tablename' => $table,         'attributedefinitions' => array(             array(                 'attributename' => 'id',                 'attributetype' => 'n'                   ),             array(                 'attributename' => 'name',                 'attributetype' => 's'             )         ),         'keyschema' => array(             array(                 'attributename' => 'id',                 'keytype'       => 'hash'             ),             array(                 'attributename' => 'name',                 'keytype'       => 'range'             )         ),         'provisionedthroughput' => array(             'readcapacityunits'  => 5,             'writecapacityunits' => 5         )     )); 

thanks

update - question mark b answer:

yes can create index without range key. range key entirely optional. however, if have range key defined optional include in query. can specify hash key in query items hash key, returned in order based on range key.

if specify hash key in query on table hash key , range key, getting below error, if specify hash key in query on table without range key works. please note table without index.

an uncaught exception encountered  type:        aws\dynamodb\exception\dynamodbexception message:     error executing "batchgetitem" on "https://dynamodb.eu-central-1.amazonaws.com"; aws http error: client error: `post https://dynamodb.eu-central-1.amazonaws.com` resulted in `400 bad request` response: {"__type":"com.amazon.coral.validate#validationexception","message":"the provided key element not match schema" (truncated...)  validationexception (client): provided key element not match schema - {"__type":"com.amazon.coral.validate#validationexception","message":"the provided key element not match schema"} filename:    /var/app/vendor/aws/aws-sdk-php/src/wrappedhttphandler.php 

but if want identify requested items primary key ? way create table without range key ?

yes can create index without range key. range key entirely optional. however, if have range key defined optional include in query. can specify hash key in query items hash key, returned in order based on range key.

what advantages using partition key , sort key beside stores of items same partition key value physically close ?

the 2 fields combined primary key, guarantees uniqueness. range/sort key determines order results returned in.

how handle request if need more 100 items ?

from documentation (emphasis mine):

the maximum number of item attributes can retrieved single operation 100. also, number of items retrieved constrained 1 mb size limit. if response size limit exceeded or partial result returned due internal processing failure, amazon dynamodb returns unprocessedkeys value can retry operation starting next item get.

for example, if ask retrieve 100 items, each individual item 50k in size, system returns 20 items , appropriate unprocessedkeys value can next page of results. if necessary, application needs own logic assemble pages of results 1 set.

so need check unprocessedkeys value of result , continue making requests in application until there no more unprocessedkeys.


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -