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

Allow string value for select for enhanced query request #5869

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"type": "feature",
"category": "Amazon DynamoDB Enhanced Client",
"contributor": "",
"description": "Use String instead of Select enum for ProjectionExpression to support future values"
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;
Expand All @@ -35,7 +34,6 @@
import org.junit.BeforeClass;
import org.junit.Test;
import software.amazon.awssdk.enhanced.dynamodb.model.Page;
import software.amazon.awssdk.enhanced.dynamodb.model.QueryConditional;
import software.amazon.awssdk.enhanced.dynamodb.model.QueryEnhancedRequest;
import software.amazon.awssdk.enhanced.dynamodb.model.Record;
import software.amazon.awssdk.enhanced.dynamodb.model.ScanEnhancedRequest;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public final class QueryEnhancedRequest {
private final QueryConditional queryConditional;
private final Map<String, AttributeValue> exclusiveStartKey;
private final Boolean scanIndexForward;
private final Select select;
private final String select;
private final Integer limit;
private final Boolean consistentRead;
private final Expression filterExpression;
Expand Down Expand Up @@ -119,19 +119,19 @@ public Boolean scanIndexForward() {
}

/**
* Returns the value of select, or null if it doesn't exist.
* Returns the value of select as Enum, or null if it doesn't exist.
* @return
*/
public Select select() {
return select;
return Select.fromValue(this.select);
}

/**
* Returns the value of select as a string, or null if it doesn't exist.
* @return
*/
public String selectAsString() {
return String.valueOf(select);
return select;
}

/**
Expand Down Expand Up @@ -266,7 +266,7 @@ public static final class Builder {
private QueryConditional queryConditional;
private Map<String, AttributeValue> exclusiveStartKey;
private Boolean scanIndexForward;
private Select select;
private String select;
private Integer limit;
private Boolean consistentRead;
private Expression filterExpression;
Expand Down Expand Up @@ -307,6 +307,17 @@ public Builder scanIndexForward(Boolean scanIndexForward) {
* @return a builder of this type
*/
public Builder select(Select select) {
this.select = select == null ? null : select.toString();
return this;
}

/**
* Determines the attributes to be returned in the result. See {@link Select} string values for examples and constraints.
* By default, all attributes are returned.
* @param select
* @return a builder of this type
*/
public Builder select(String select) {
this.select = select;
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ public void queryAllRecordsDefaultSettings_withSelect_specificAttributes() {
mappedTable.query(b -> b
.queryConditional(keyEqualTo(k -> k.partitionValue("id-value")))
.attributesToProject("value")
.select(Select.SPECIFIC_ATTRIBUTES)
.select("SPECIFIC_ATTRIBUTES")
).iterator();

assertThat(results.hasNext(), is(true));
Expand All @@ -606,7 +606,7 @@ public void queryAllRecordsDefaultSettings_withSelect_allAttributes() {
Iterator<Page<Record>> results =
mappedTable.query(b -> b
.queryConditional(keyEqualTo(k -> k.partitionValue("id-value")))
.select(Select.ALL_ATTRIBUTES)
.select("ALL_ATTRIBUTES")
).iterator();

assertThat(results.hasNext(), is(true));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
import software.amazon.awssdk.enhanced.dynamodb.Expression;
import software.amazon.awssdk.enhanced.dynamodb.NestedAttributeName;
import software.amazon.awssdk.enhanced.dynamodb.TableSchema;
import software.amazon.awssdk.enhanced.dynamodb.document.EnhancedDocument;
import software.amazon.awssdk.enhanced.dynamodb.functionaltests.models.InnerAttributeRecord;
import software.amazon.awssdk.enhanced.dynamodb.functionaltests.models.NestedTestRecord;
import software.amazon.awssdk.enhanced.dynamodb.mapper.StaticTableSchema;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
import software.amazon.awssdk.enhanced.dynamodb.DynamoDbTable;
import software.amazon.awssdk.enhanced.dynamodb.EnhancedType;
import software.amazon.awssdk.enhanced.dynamodb.Expression;
import software.amazon.awssdk.enhanced.dynamodb.JsonTestUtils;
import software.amazon.awssdk.enhanced.dynamodb.Key;
import software.amazon.awssdk.enhanced.dynamodb.NestedAttributeName;
import software.amazon.awssdk.enhanced.dynamodb.TableMetadata;
Expand All @@ -61,14 +60,10 @@
import software.amazon.awssdk.enhanced.dynamodb.model.Page;
import software.amazon.awssdk.enhanced.dynamodb.model.PageIterable;
import software.amazon.awssdk.enhanced.dynamodb.model.QueryEnhancedRequest;
import software.amazon.awssdk.protocols.jsoncore.JsonNode;
import software.amazon.awssdk.protocols.jsoncore.JsonNodeParser;
import software.amazon.awssdk.services.dynamodb.DynamoDbClient;
import software.amazon.awssdk.services.dynamodb.model.AttributeValue;
import software.amazon.awssdk.services.dynamodb.model.DeleteTableRequest;
import software.amazon.awssdk.services.dynamodb.model.Select;
import software.amazon.awssdk.thirdparty.jackson.core.JsonParser;
import software.amazon.awssdk.thirdparty.jackson.core.JsonToken;

public class BasicQueryTest extends LocalDynamoDbSyncTestBase {
private DynamoDbClient lowLevelClient;
Expand Down Expand Up @@ -252,7 +247,7 @@ public void queryAllRecordsDefaultSettings_withSelect_specificAttributes() {
Iterator<Page<EnhancedDocument>> results =
docMappedtable.query(b -> b
.queryConditional(keyEqualTo(k -> k.partitionValue("id-value")))
.select(Select.SPECIFIC_ATTRIBUTES)
.select("SPECIFIC_ATTRIBUTES")
.attributesToProject("value")
).iterator();

Expand Down Expand Up @@ -293,7 +288,7 @@ public void queryAllRecordsDefaultSettings_withSelect_count() {
Iterator<Page<EnhancedDocument>> results =
docMappedtable.query(b -> b
.queryConditional(keyEqualTo(k -> k.partitionValue("id-value")))
.select(Select.COUNT)
.select("COUNT")
).iterator();


Expand Down