-
Notifications
You must be signed in to change notification settings - Fork 37
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
query() function from dynamodb() #402
Comments
Sorry about that. Unfortunately there isn't anything built in -- Paws doesn't do anything extra with what DynamoDB returns, at least at the moment. However, I put together the # Example DynamoDB result data.
a <- list(
Foo = list(
S = character(0),
N = list(),
B = list(),
L = list(),
M = list(
Bar = list(
S = "1",
N = list(),
B = list(),
L = list(),
M = list()
)
)
)
)
# Flatten a DynamoDB query response, into an object that has only attribute names and values.
flatten <- function(x) {
result <- list()
for (name in names(x)) {
result[[name]] <- get_value(x[[name]])
}
return(result)
}
# Get the value from a single attribute.
get_value <- function(x) {
element <- names(x)[sapply(x, function(el) length(el) > 0)]
if (element == "M") return(flatten(x[[element]]))
return(x[[element]])
}
# Test the flatten function on the example data.
b <- flatten(a)
# > str(b)
# List of 1
# $ Foo:List of 1
# ..$ Bar: chr "1" |
Hi David, Don't know why dynamo returns the full list of data types like this. You can close the issue. |
Awesome! Glad to hear it. My guess about that response shape is I think it's designed for languages that have fixed data types, so they have a slot for strings, for integers, etc. Thanks for bringing it up. This is a good example and if I get some time, I'll put it in the examples folder too. Have a good one! |
Hi,
query() returns me a nested list.
in the Items sections, every attribute of a record is itself a list.
Is there any way of telling query() to return just the attribute with its corresponding value?
I couln't find it in the doc.
thanks,
The text was updated successfully, but these errors were encountered: