Skip to content

Commit 4d71a04

Browse files
authored
DDB Mapper filter expressions (runtime components) (#1401)
1 parent b08e24d commit 4d71a04

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+4000
-119
lines changed

gradle/libs.versions.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[versions]
22
kotlin-version = "2.0.10"
3-
ksp-version = "2.0.0-1.0.24" # Keep in sync with kotlin-version
3+
ksp-version = "2.0.10-1.0.24" # Keep in sync with kotlin-version
44

55
dokka-version = "1.9.10"
66

@@ -29,7 +29,6 @@ slf4j-version = "2.0.9"
2929
[libraries]
3030
aws-kotlin-repo-tools-build-support = { module="aws.sdk.kotlin.gradle:build-support", version.ref = "aws-kotlin-repo-tools-version" }
3131

32-
kotlin-reflect = { module = "org.jetbrains.kotlin:kotlin-reflect", version.ref = "kotlin-version" }
3332
kotlin-stdlib = { module = "org.jetbrains.kotlin:kotlin-stdlib", version.ref = "kotlin-version" }
3433
kotlin-stdlib-jdk8 = { module = "org.jetbrains.kotlin:kotlin-stdlib-jdk8", version.ref = "kotlin-version" }
3534
kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin-version" }

hll/dynamodb-mapper/dynamodb-mapper/api/dynamodb-mapper.api

Lines changed: 451 additions & 0 deletions
Large diffs are not rendered by default.

hll/dynamodb-mapper/dynamodb-mapper/build.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ kotlin {
3434

3535
commonTest {
3636
dependencies {
37-
implementation(libs.kotlin.reflect)
3837
implementation(libs.kotlinx.coroutines.test)
3938
implementation(libs.kotest.assertions.core)
4039
implementation(libs.kotest.runner.junit5)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
package aws.sdk.kotlin.hll.dynamodbmapper.expressions
6+
7+
import aws.sdk.kotlin.hll.dynamodbmapper.expressions.internal.AndExprImpl
8+
9+
/**
10+
* Represents an `AND` expression as described in
11+
* [DynamoDB's **logical evaluations** documentation](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.LogicalEvaluations).
12+
* This expression will be true if `(operand[0] && operand[1] && ... && operand[n - 1])`.
13+
*/
14+
public interface AndExpr : BooleanExpr {
15+
/**
16+
* A list of 2 or more [BooleanExpr] conditions which are ANDed together
17+
*/
18+
public val operands: List<BooleanExpr>
19+
20+
override fun <T> accept(visitor: ExpressionVisitor<T>): T = visitor.visit(this)
21+
}
22+
23+
/**
24+
* Creates a new [AndExpr] with the given [operands]
25+
* @param operands A list of 2 or more [BooleanExpr] conditions which are ANDed together
26+
*/
27+
public fun AndExpr(operands: List<BooleanExpr>): AndExpr = AndExprImpl(operands)
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
package aws.sdk.kotlin.hll.dynamodbmapper.expressions
6+
7+
import aws.sdk.kotlin.hll.dynamodbmapper.expressions.internal.AttrPathIndexImpl
8+
import aws.sdk.kotlin.hll.dynamodbmapper.expressions.internal.AttrPathNameImpl
9+
import aws.sdk.kotlin.hll.dynamodbmapper.expressions.internal.AttributePathImpl
10+
11+
/**
12+
* Represents an element in an [AttributePath]
13+
*/
14+
public sealed interface AttrPathElement {
15+
/**
16+
* Represents the name of a top-level attribute or a key in a map
17+
*/
18+
public interface Name : AttrPathElement {
19+
/**
20+
* The name or key of this element
21+
*/
22+
public val name: String
23+
}
24+
25+
/**
26+
* Represents an index into a list/set
27+
*/
28+
public interface Index : AttrPathElement {
29+
/**
30+
* The index (starting at `0`)
31+
*/
32+
public val index: Int
33+
}
34+
}
35+
36+
/**
37+
* Represents an expression that consists of an attribute. Attributes are referenced by attribute paths, analogous to
38+
* [document paths in DynamoDB](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.Attributes.html#Expressions.Attributes.NestedElements.DocumentPathExamples).
39+
* Attribute paths consist of one or more elements, which are either names (e.g., of a top-level attribute or a nested
40+
* key in a map attribute) or indices (i.e., into a list). The first (and often only) element of an attribute path is a
41+
* name.
42+
*
43+
* See [Filter] for more information about creating references to attributes.
44+
*/
45+
public interface AttributePath : Expression {
46+
/**
47+
* The [AttrPathElement] for this path
48+
*/
49+
public val element: AttrPathElement
50+
51+
/**
52+
* The parent [AttributePath] (if any). If [parent] is `null` then this instance represents a top-level attribute
53+
* and [element] must be a name (not an index).
54+
*/
55+
public val parent: AttributePath?
56+
57+
override fun <T> accept(visitor: ExpressionVisitor<T>): T = visitor.visit(this)
58+
}
59+
60+
/**
61+
* Creates a new [AttributePath] reference with the given name and optional parent path
62+
* @param name The name or key of this element
63+
* @param parent The parent [AttributePath] (if any) of this element. If [parent] is `null` then this instance
64+
* represents a top-level attribute.
65+
*/
66+
public fun AttributePath(name: String, parent: AttributePath? = null): AttributePath =
67+
AttributePathImpl(AttrPathNameImpl(name), parent)
68+
69+
/**
70+
* Creates a new [AttributePath] reference with the given index and parent path
71+
* @param index The index (starting at `0`) of this element
72+
* @param parent The parent [AttributePath] of this element
73+
*/
74+
public fun AttributePath(index: Int, parent: AttributePath): AttributePath =
75+
AttributePathImpl(AttrPathIndexImpl(index), parent)
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
package aws.sdk.kotlin.hll.dynamodbmapper.expressions
6+
7+
/**
8+
* Represents a
9+
* [DynamoDB attribute data type](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/HowItWorks.NamingRulesDataTypes.html#HowItWorks.DataTypes)
10+
* @param abbreviation The DynamoDB type name
11+
*/
12+
public enum class AttributeType(public val abbreviation: kotlin.String) {
13+
/**
14+
* Binary data type, denoted in DynamoDB as `B`
15+
*/
16+
Binary("B"),
17+
18+
/**
19+
* Binary set data type, denoted in DynamoDB as `BS`
20+
*/
21+
BinarySet("BS"),
22+
23+
/**
24+
* Boolean data type, denoted in DynamoDB as `BOOL`
25+
*/
26+
Boolean("BOOL"),
27+
28+
/**
29+
* List data type, denoted in DynamoDB as `L`
30+
*/
31+
List("L"),
32+
33+
/**
34+
* Map data type, denoted in DynamoDB as `M`
35+
*/
36+
Map("M"),
37+
38+
/**
39+
* Null data type, denoted in DynamoDB as `NULL`
40+
*/
41+
Null("NULL"),
42+
43+
/**
44+
* Number data type, denoted in DynamoDB as `N`
45+
*/
46+
Number("N"),
47+
48+
/**
49+
* Number set data type, denoted in DynamoDB as `NS`
50+
*/
51+
NumberSet("NS"),
52+
53+
/**
54+
* String data type, denoted in DynamoDB as `S`
55+
*/
56+
String("S"),
57+
58+
/**
59+
* String set data type, denoted in DynamoDB as `SS`
60+
*/
61+
StringSet("SS"),
62+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
package aws.sdk.kotlin.hll.dynamodbmapper.expressions
6+
7+
import aws.sdk.kotlin.hll.dynamodbmapper.expressions.internal.BetweenExprImpl
8+
9+
/**
10+
* Represents a `BETWEEN` expression as described in
11+
* [DynamoDB's **making comparisons** documentation](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Comparators).
12+
* This expression will be true if `value >= min && value <= max`.
13+
*/
14+
public interface BetweenExpr : BooleanExpr {
15+
/**
16+
* The value being compared to the [min] and [max]
17+
*/
18+
public val value: Expression
19+
20+
/**
21+
* The minimum bound for the comparison
22+
*/
23+
public val min: Expression
24+
25+
/**
26+
* The maximum bound for the comparison
27+
*/
28+
public val max: Expression
29+
30+
override fun <T> accept(visitor: ExpressionVisitor<T>): T = visitor.visit(this)
31+
}
32+
33+
/**
34+
* Creates a new [BetweenExpr] for the given [value] and range bounded by [min] and [max]
35+
* @param value The value being compared to the [min] and [max]
36+
* @param min The minimum bound for the comparison
37+
* @param max The maximum bound for the comparison
38+
*/
39+
public fun BetweenExpr(value: Expression, min: Expression, max: Expression): BetweenExpr =
40+
BetweenExprImpl(value, min, max)
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
package aws.sdk.kotlin.hll.dynamodbmapper.expressions
6+
7+
/**
8+
* Identifies a
9+
* [DynamoDB expression function](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Functions)
10+
* which returns a boolean value
11+
* @param exprString The literal name of the function to use in expression strings
12+
*/
13+
public enum class BooleanFunc(public val exprString: String) {
14+
/**
15+
* The `attribute_exist` function
16+
*/
17+
ATTRIBUTE_EXISTS("attribute_exists"),
18+
19+
/**
20+
* The `attribute_not_exists` function
21+
*/
22+
ATTRIBUTE_NOT_EXISTS("attribute_not_exists"),
23+
24+
/**
25+
* The `attribute_type` function
26+
*/
27+
ATTRIBUTE_TYPE("attribute_type"),
28+
29+
/**
30+
* The `begins_with` function
31+
*/
32+
BEGINS_WITH("begins_with"),
33+
34+
/**
35+
* The `contains` function
36+
*/
37+
CONTAINS("contains"),
38+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
package aws.sdk.kotlin.hll.dynamodbmapper.expressions
6+
7+
import aws.sdk.kotlin.hll.dynamodbmapper.expressions.internal.BooleanFuncExprImpl
8+
9+
/**
10+
* Represents a function expression that yields a boolean result as described in
11+
* [DynamoDB's **function** documentation](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Functions)
12+
*/
13+
public interface BooleanFuncExpr : BooleanExpr {
14+
/**
15+
* The specific boolean function to use
16+
*/
17+
public val func: BooleanFunc
18+
19+
/**
20+
* The attribute path to pass as the function's first argument
21+
*/
22+
public val path: AttributePath
23+
24+
/**
25+
* Any additional arguments used by the function
26+
*/
27+
public val additionalOperands: List<Expression>
28+
29+
override fun <T> accept(visitor: ExpressionVisitor<T>): T = visitor.visit(this)
30+
}
31+
32+
/**
33+
* Creates a new boolean function expression
34+
* @param func The specific boolean function to use
35+
* @param path The attribute path to pass as the function's first argument
36+
* @param additionalOperands Any additional arguments used by the function
37+
*/
38+
public fun BooleanFuncExpr(
39+
func: BooleanFunc,
40+
path: AttributePath,
41+
additionalOperands: List<Expression> = listOf(),
42+
): BooleanFuncExpr = BooleanFuncExprImpl(func, path, additionalOperands)
43+
44+
/**
45+
* Creates a new boolean function expression
46+
* @param func The specific boolean function to use
47+
* @param path The attribute path to pass as the function's first argument
48+
* @param additionalOperands Any additional arguments used by the function
49+
*/
50+
public fun BooleanFuncExpr(
51+
func: BooleanFunc,
52+
path: AttributePath,
53+
vararg additionalOperands: Expression,
54+
): BooleanFuncExpr = BooleanFuncExprImpl(func, path, additionalOperands.toList())
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
package aws.sdk.kotlin.hll.dynamodbmapper.expressions
6+
7+
/**
8+
* Identifies a comparison operator to use in an expression
9+
* @param exprString The literal value of the operator to use in an expression string
10+
*/
11+
public enum class Comparator(public val exprString: String) {
12+
/**
13+
* An equality comparison, equivalent to `==` in Kotlin and to `=` in DynamoDB
14+
*/
15+
EQUALS("="),
16+
17+
/**
18+
* An inequality comparison, equivalent to `!=` in Kotlin and to `<>` in DynamoDB
19+
*/
20+
NOT_EQUALS("<>"),
21+
22+
/**
23+
* A less-than comparison, equivalent to `<` in Kotlin and DynamoDB
24+
*/
25+
LESS_THAN("<"),
26+
27+
/**
28+
* A less-than-or-equal-to comparison, equivalent to `<=` in Kotlin and DynamoDB
29+
*/
30+
LESS_THAN_OR_EQUAL("<="),
31+
32+
/**
33+
* A greater-than comparison, equivalent to `>` in Kotlin and DynamoDB
34+
*/
35+
GREATER_THAN(">"),
36+
37+
/**
38+
* A greater-than-or-equal-to comparison, equivalent to `>=` in Kotlin and DynamoDB
39+
*/
40+
GREATER_THAN_OR_EQUAL(">="),
41+
}

0 commit comments

Comments
 (0)