Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

N for range search #6

Open
fayland opened this Issue · 2 comments

2 participants

@fayland

Hello.

is there any reason that you have

$value = $item_ref->{ $key } .'';

in line 720. the . '' seems quite weird for me when the key is N.

for example, I set table as

{"Table":{"CreationDateTime":1.350285647082E9,"ItemCount":0,"KeySchema":{"HashKeyElement":{"AttributeName":"id","AttributeType":"S"},"RangeKeyElement":{"AttributeName":"version","AttributeType":"N"}},"ProvisionedThroughput":{"ReadCapacityUnits":10,"WriteCapacityUnits":5},"TableName":"test_picture","TableSizeBytes":0,"TableStatus":"ACTIVE"}}

then put_item I set

{"Item":{"keywords":{"S":"Perl\nDynamoDB"},"filename":{"S":"1.jpg"},"date":{"N":"1350287320"},"version":{"N":"1"},"id":{"S":"MPCBvJwW4hGSd_kERh+kNg"},"tbuser":{"N":"999"}},"TableName":"test_picture"}

see, you have version converted into "1" here. actually I set version=1 in Perl.

and it will be broken for

get_item('test_picture', { id => $id, version => 1})

{"TableName":"test_picture","ConsistentRead":false,"Key":{"RangeKeyElement":{"N":1},"HashKeyElement":{"S":"MPCBvJwW4hGSd_kERh+kNg"}}}

it returns error
'_content' => '{"__type":"com.amazon.coral.service#SerializationException","Message":"class java.lang.Short can not be converted to an String"}',

but if I query with

get_item('test_picture', { id => $id, version => "1"})

it works:

{"TableName":"test_picture","ConsistentRead":false,"Key":{"RangeKeyElement":{"N":"1"},"HashKeyElement":{"S":"BO+oGaAW4hGmv4ycE82ppw"}}}

I just do not understand why we have . ''; when put_item?

any idea?

Thanks

@ukautz
Owner

Hey Fayland

Just to be clear:
Are you asking why I am "casting" every value in put_item() to string? Or why I don't do it in get_item()?

For the former: Amazon seems not to accept non-quoted numeric values, even if the type is "N" (and even though RFC 4627 does allow non-quoted numeric values). They throw the SerializationException, you've seen.
So: putting {"id": "1"} works, putting {"id": 1} fails (with the execption).

For the latter: This would be a bug, i will fix it - thanks for finding :)
For now, you can "stringify" your values beforehand yourself eg:

$pk_ref = { map { ( $_ => $pk_ref->{$_}. '' ) } keys %$pk_ref };
$ddb->get_item( $table => $pk_ref );

Greets
Ulrich

@fayland

OK. thanks for the fast response. :+1:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.