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

dynamodb: can't run a "CountQuery" with an index #236

Open
jonathaningram opened this issue Sep 23, 2014 · 2 comments
Open

dynamodb: can't run a "CountQuery" with an index #236

jonathaningram opened this issue Sep 23, 2014 · 2 comments

Comments

@jonathaningram
Copy link

This is because there is no such method. You can't use QueryTable because it requires the JSON response to have an Items key (a dynamodb count call doesn't seem to return one) E.g. if you try some code like this:

q := dynamodb.NewQuery(table)
q.AddIndex("myIndex")
  q.AddKeyConditions([]dynamodb.AttributeComparison{
    *dynamodb.NewEqualStringAttributeComparison(AttributeStatus, status),
  })
q.AddSelect("COUNT")
res, _, err := t.QueryTable(q)
log.Println(err)

You'll get an error like this:

Unexpected response {"Count":207,"LastEvaluatedKey":{"Id":{"S":"a2f0983e-9e2a-4d67-ac88-8fde867cc250"},"Status":{"S":"Complete"}},"ScannedCount":207}

(i.e. no Items key exists)

I'd like to add a new method similar to https://github.com/crowdmob/goamz/blob/master/dynamodb/query.go#L38

func (t *Table) CountQueryOnIndex(attributeComparisons []AttributeComparison, indexName string) (int64, error) {
  // ...
}

Also, I'll move the bulk of the CountQuery method into a helper func to reduce duplication.

Would you accept a PR with that?

@alimoeeny
Copy link
Contributor

Again, we appreciate your contribution. Please send your PR. BUT, please take this into account. Unless there is no way around it, at the moment we don't want to make backward incompatible changes. We are working on a solution that let's us move forward and refactor the libraries and clean up the code in a backward incompatible way without breaking people's code. but until then, please define new functions with new signatures as needed.

@jonathaningram
Copy link
Author

@alimoeeny great thanks I'll work on a PR. Yep it's a new signature, everything else stays the same.

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