Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

N for range search #6

Open
fayland opened this issue Oct 15, 2012 · 2 comments
Open

N for range search #6

fayland opened this issue Oct 15, 2012 · 2 comments

Comments

@fayland
Copy link
Contributor

fayland commented Oct 15, 2012

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
Copy link
Owner

ukautz commented Oct 15, 2012

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
Copy link
Contributor Author

fayland commented Oct 16, 2012

OK. thanks for the fast response. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants