This is an automated email from the ASF dual-hosted git repository. acosentino pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel.git
commit d9594601010c2fb7a8e1f2fadf463624001c84f5 Author: Fabrizio Spataro <fabrizio.spat...@bizmate.it> AuthorDate: Wed Jan 3 15:18:27 2018 +0100 CAMEL-12118: DynamoDB: Execute query using secondary indexes --- components/camel-aws/src/main/docs/aws-ddb-component.adoc | 2 ++ .../java/org/apache/camel/component/aws/ddb/DdbConstants.java | 2 ++ .../java/org/apache/camel/component/aws/ddb/QueryCommand.java | 11 +++++++++-- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/components/camel-aws/src/main/docs/aws-ddb-component.adoc b/components/camel-aws/src/main/docs/aws-ddb-component.adoc index 19544e9..cc3145b 100644 --- a/components/camel-aws/src/main/docs/aws-ddb-component.adoc +++ b/components/camel-aws/src/main/docs/aws-ddb-component.adoc @@ -105,6 +105,8 @@ returned. |`CamelAwsDdbConsistentRead` |`Boolean` |If set to true, then a consistent read is issued, otherwise eventually consistent is used. +|`CamelAwsDdbIndexName` |`String` |If set will be used as Secondary Index for Query operation. + |`CamelAwsDdbItem` |`Map<String, AttributeValue>` |A map of the attributes for the item, and must include the primary key values that define the item. diff --git a/components/camel-aws/src/main/java/org/apache/camel/component/aws/ddb/DdbConstants.java b/components/camel-aws/src/main/java/org/apache/camel/component/aws/ddb/DdbConstants.java index 6c2dbae..6ababab 100644 --- a/components/camel-aws/src/main/java/org/apache/camel/component/aws/ddb/DdbConstants.java +++ b/components/camel-aws/src/main/java/org/apache/camel/component/aws/ddb/DdbConstants.java @@ -32,6 +32,8 @@ public interface DdbConstants { // String EXACT_COUNT = "CamelAwsDdbExactCount"; // Removed from DynamoDB v1 to v2 // String HASH_KEY_VALUE = "CamelAwsDdbHashKeyValue"; + // Added INDEX_NAME for querying secondary indexes + String INDEX_NAME = "CamelAwsDdbIndexName"; String ITEM = "CamelAwsDdbItem"; String ITEMS = "CamelAwsDdbItems"; String ITEM_COUNT = "CamelAwsDdbTableItemCount"; diff --git a/components/camel-aws/src/main/java/org/apache/camel/component/aws/ddb/QueryCommand.java b/components/camel-aws/src/main/java/org/apache/camel/component/aws/ddb/QueryCommand.java index 8719bfe..d64e9ee 100644 --- a/components/camel-aws/src/main/java/org/apache/camel/component/aws/ddb/QueryCommand.java +++ b/components/camel-aws/src/main/java/org/apache/camel/component/aws/ddb/QueryCommand.java @@ -34,7 +34,7 @@ public class QueryCommand extends AbstractDdbCommand { @Override public void execute() { - QueryResult result = ddbClient.query(new QueryRequest() + QueryRequest query = new QueryRequest() .withTableName(determineTableName()) .withAttributesToGet(determineAttributeNames()) .withConsistentRead(determineConsistentRead()) @@ -42,7 +42,14 @@ public class QueryCommand extends AbstractDdbCommand { .withKeyConditions(determineKeyConditions()) .withExclusiveStartKey(determineStartKey()) .withLimit(determineLimit()) - .withScanIndexForward(determineScanIndexForward())); + .withScanIndexForward(determineScanIndexForward()); + + // Check if we have set an Index Name + if(exchange.getIn().getHeader(DdbConstants.INDEX_NAME, String.class) != null) { + query.withIndexName(exchange.getIn().getHeader(DdbConstants.INDEX_NAME, String.class)); + } + + QueryResult result = ddbClient.query(query); Map tmp = new HashMap<>(); tmp.put(DdbConstants.ITEMS, result.getItems()); -- To stop receiving notification emails like this one, please contact "commits@camel.apache.org" <commits@camel.apache.org>.