Class FilterExpression
- Direct Known Subclasses:
ConditionExpression, ConditionExpression.Builder
Used as a filter expression (post-read filtering) in Scan and
Query operations, and as a condition expression (pre-write
gating) in PutItem, UpdateItem, and DeleteItem
operations. DynamoDB distinguishes these two semantics, see the DynamoDB
Developer Guide for details on the difference.
Provides a chainable API for building complex filter conditions including
comparisons (=, <>, <, <=, >, >=),
string functions (begins_with, contains), server-side
size() comparisons, attribute existence checks, attribute type checks,
BETWEEN, IN, and logical combinators (AND, OR,
NOT). All attribute names and values are automatically mapped to
expression attribute names (#n0, #n1, ...) and expression
attribute values (:v0, :v1, ...) to avoid reserved word
conflicts and simplify value handling.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumRepresents a DynamoDB attribute type for use withattributeType(String, AttributeType). -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedCreates an empty filter expression.protectedFilterExpression(FilterExpression other) Creates a copy of the given filter expression. -
Method Summary
Modifier and TypeMethodDescription@NonNull FilterExpressionand()Appends anANDlogical operator to combine two filter conditions.@NonNull FilterExpressionattributeType(@NonNull String attribute, @NonNull FilterExpression.AttributeType type) Adds anattribute_typecondition that checks whether the specified attribute is of the given DynamoDB type.@NonNull FilterExpressionbeginsWith(@NonNull String attribute, @NonNull String prefix) Adds abegins_withfunction condition checking whether the attribute value starts with the given prefix.@NonNull FilterExpressionAdds aBETWEENcondition:attribute BETWEEN low AND high(inclusive).static @NonNull FilterExpressionbuilder()Creates a newFilterExpressionbuilder.@NonNull FilterExpressionAdds acontainsfunction condition checking whether the attribute value contains the given substring (for strings) or element (for sets).@NonNull FilterExpressionAdds an equality condition:attribute = value.@NonNull FilterExpressionAdds anattribute_existscondition that checks whether the specified attribute is present on the item.@NonNull FilterExpressionAdds a greater-than-or-equal condition:attribute >= value.@NonNull StringReturns the built filter expression string (e.g.,"#n0 = :v0 AND begins_with(#n1, :v1)").Returns the map of expression attribute names used in this expression.Returns the map of expression attribute values used in this expression.@NonNull FilterExpressiongroup(@NonNull FilterExpression nested) Wraps the given nestedFilterExpressionin parentheses and merges its expression attribute names and values into this builder.@NonNull FilterExpressionAdds a greater-than condition:attribute > value.@NonNull FilterExpressionAdds anINcondition:attribute IN (val1, val2, ...).booleanisEmpty()Returns whether no conditions have been added to this expression yet.@NonNull FilterExpressionAdds a less-than-or-equal condition:attribute <= value.@NonNull FilterExpressionAdds a less-than condition:attribute < value.@NonNull FilterExpressionAdds a not-equal condition:attribute <> value.@NonNull FilterExpressionAdds an equality condition on a nested attribute path (e.g.,address.city).@NonNull FilterExpressionnot()Appends aNOTlogical operator to negate the following condition.@NonNull FilterExpressionAdds anattribute_not_existscondition that checks whether the specified attribute is not present on the item.@NonNull FilterExpressionor()Appends anORlogical operator to combine two filter conditions.@NonNull FilterExpressionsizeBetween(String attribute, int minSize, int maxSize) Adds a condition that the server-sidesize()of the attribute is between the given minimum and maximum values (inclusive).@NonNull FilterExpressionAdds a condition that the server-sidesize()of the attribute equals the given value.@NonNull FilterExpressionAdds a condition that the server-sidesize()of the attribute is greater than or equal to the given value.@NonNull FilterExpressionAdds a condition that the server-sidesize()of the attribute is greater than the given value.@NonNull FilterExpressionAdds a condition that the server-sidesize()of the attribute is less than or equal to the given value.@NonNull FilterExpressionAdds a condition that the server-sidesize()of the attribute is less than the given value.@NonNull software.amazon.awssdk.enhanced.dynamodb.ExpressionConverts this filter expression into an AWS SDKExpressionfor use with enhanced client request builders.
-
Constructor Details
-
FilterExpression
protected FilterExpression()Creates an empty filter expression. -
FilterExpression
Creates a copy of the given filter expression. Subclasses can use this to create instances backed by an existingFilterExpression.- Parameters:
other- the filter expression to copy
-
-
Method Details
-
builder
Creates a newFilterExpressionbuilder.- Returns:
- a new empty
FilterExpression
-
toSdkExpression
public @NonNull software.amazon.awssdk.enhanced.dynamodb.Expression toSdkExpression()Converts this filter expression into an AWS SDKExpressionfor use with enhanced client request builders.- Returns:
- the SDK expression
-
eq
Adds an equality condition:attribute = value.- Parameters:
attribute- the attribute namevalue- the value to compare against- Returns:
- this builder for chaining
-
ne
Adds a not-equal condition:attribute <> value.- Parameters:
attribute- the attribute namevalue- the value to compare against- Returns:
- this builder for chaining
-
lt
Adds a less-than condition:attribute < value.- Parameters:
attribute- the attribute namevalue- the value to compare against- Returns:
- this builder for chaining
-
le
Adds a less-than-or-equal condition:attribute <= value.- Parameters:
attribute- the attribute namevalue- the value to compare against- Returns:
- this builder for chaining
-
gt
Adds a greater-than condition:attribute > value.- Parameters:
attribute- the attribute namevalue- the value to compare against- Returns:
- this builder for chaining
-
ge
Adds a greater-than-or-equal condition:attribute >= value.- Parameters:
attribute- the attribute namevalue- the value to compare against- Returns:
- this builder for chaining
-
beginsWith
Adds abegins_withfunction condition checking whether the attribute value starts with the given prefix.- Parameters:
attribute- the attribute nameprefix- the string prefix to test- Returns:
- this builder for chaining
-
contains
Adds acontainsfunction condition checking whether the attribute value contains the given substring (for strings) or element (for sets).- Parameters:
attribute- the attribute namevalue- the value to search for within the attribute- Returns:
- this builder for chaining
-
sizeEq
Adds a condition that the server-sidesize()of the attribute equals the given value.- Parameters:
attribute- the attribute namesize- the expected size- Returns:
- this builder for chaining
-
sizeLt
Adds a condition that the server-sidesize()of the attribute is less than the given value.- Parameters:
attribute- the attribute namesize- the size to compare against- Returns:
- this builder for chaining
-
sizeLe
Adds a condition that the server-sidesize()of the attribute is less than or equal to the given value.- Parameters:
attribute- the attribute namesize- the size to compare against- Returns:
- this builder for chaining
-
sizeGt
Adds a condition that the server-sidesize()of the attribute is greater than the given value.- Parameters:
attribute- the attribute namesize- the size to compare against- Returns:
- this builder for chaining
-
sizeGe
Adds a condition that the server-sidesize()of the attribute is greater than or equal to the given value.- Parameters:
attribute- the attribute namesize- the size to compare against- Returns:
- this builder for chaining
-
sizeBetween
Adds a condition that the server-sidesize()of the attribute is between the given minimum and maximum values (inclusive).- Parameters:
attribute- the attribute nameminSize- the minimum sizemaxSize- the maximum size- Returns:
- this builder for chaining
-
exists
Adds anattribute_existscondition that checks whether the specified attribute is present on the item.- Parameters:
attribute- the attribute name- Returns:
- this builder for chaining
-
notExists
Adds anattribute_not_existscondition that checks whether the specified attribute is not present on the item.- Parameters:
attribute- the attribute name- Returns:
- this builder for chaining
-
attributeType
public @NonNull FilterExpression attributeType(@NonNull String attribute, @NonNull FilterExpression.AttributeType type) Adds anattribute_typecondition that checks whether the specified attribute is of the given DynamoDB type.- Parameters:
attribute- the attribute nametype- the expectedFilterExpression.AttributeType- Returns:
- this builder for chaining
-
between
public @NonNull FilterExpression between(@NonNull String attribute, @NonNull Object low, @NonNull Object high) Adds aBETWEENcondition:attribute BETWEEN low AND high(inclusive). Supports strings, numbers, and binaries.- Parameters:
attribute- the attribute namelow- the lower boundhigh- the upper bound- Returns:
- this builder for chaining
-
in
Adds anINcondition:attribute IN (val1, val2, ...). The attribute must match at least one of the provided values.- Parameters:
attribute- the attribute namevalues- one or more values to test against- Returns:
- this builder for chaining
-
and
Appends anANDlogical operator to combine two filter conditions.- Returns:
- this builder for chaining
-
or
Appends anORlogical operator to combine two filter conditions.- Returns:
- this builder for chaining
-
not
Appends aNOTlogical operator to negate the following condition.- Returns:
- this builder for chaining
-
group
Wraps the given nestedFilterExpressionin parentheses and merges its expression attribute names and values into this builder. Useful for creating grouped or nested conditions with proper precedence.- Parameters:
nested- the filter expression to wrap in parentheses- Returns:
- this builder for chaining
-
nestedEq
Adds an equality condition on a nested attribute path (e.g.,address.city). Dot-separated path segments are resolved to individual expression attribute names, and list indices (e.g.,items[0]) are supported.- Parameters:
path- the nested attribute path (e.g.,"address.city")value- the value to compare against- Returns:
- this builder for chaining
-
getExpression
Returns the built filter expression string (e.g.,"#n0 = :v0 AND begins_with(#n1, :v1)").- Returns:
- the filter expression string
-
getExpressionNames
-
getExpressionValues
public @NonNull Map<String, software.amazon.awssdk.services.dynamodb.model.AttributeValue> getExpressionValues()Returns the map of expression attribute values used in this expression. Keys are the generated placeholders (e.g.,:v0) and values are the correspondingAttributeValueinstances.- Returns:
- the expression attribute values map
-
isEmpty
public boolean isEmpty()Returns whether no conditions have been added to this expression yet.- Returns:
trueif the expression is empty,falseotherwise
-