@@ -40,6 +40,7 @@ module DynamoDBFilterExpr {
40
40
import StandardLibrary. String
41
41
import CompoundBeacon
42
42
import SE = AwsCryptographyDbEncryptionSdkStructuredEncryptionTypes
43
+ import Norm = DynamoDbNormalizeNumber
43
44
44
45
// extract all the attributes from a filter expression
45
46
// except for those which do not need the attribute's value
@@ -1125,9 +1126,11 @@ module DynamoDBFilterExpr {
1125
1126
}
1126
1127
1127
1128
// true if middle between left and right
1128
- predicate method is_between (middle : DDB .AttributeValue, left : DDB .AttributeValue, right : DDB .AttributeValue)
1129
+ function method is_between (middle : DDB .AttributeValue, left : DDB .AttributeValue, right : DDB .AttributeValue) : Result < bool , Error >
1129
1130
{
1130
- AttributeLE (left, middle) && AttributeLE (middle, right)
1131
+ var leftRet :- AttributeLE (left, middle);
1132
+ var rightRet :- AttributeLE (middle, right);
1133
+ Success (leftRet && rightRet)
1131
1134
}
1132
1135
1133
1136
// true if target in list
@@ -1166,7 +1169,8 @@ module DynamoDBFilterExpr {
1166
1169
Failure (E("No Stack for Between"))
1167
1170
else
1168
1171
if stack[|stack|- 1]. Str? && stack[|stack|- 2]. Str? && stack[|stack|- 3]. Str? then
1169
- Success (Bool(is_between(stack[|stack|-3].s, stack[|stack|-2].s, stack[|stack|-1].s)))
1172
+ var ret :- is_between (stack[|stack|-3].s, stack[|stack|-2].s, stack[|stack|-1].s);
1173
+ Success (Bool(ret))
1170
1174
else
1171
1175
Failure (E("Wrong Types for contains"))
1172
1176
@@ -1257,43 +1261,66 @@ module DynamoDBFilterExpr {
1257
1261
LexicographicLessOrEqual (b, a, less)
1258
1262
}
1259
1263
1260
- predicate method CharLess (a: char , b: char ) { a < b }
1261
- predicate method ByteLess (a: uint8 , b: uint8 ) { a < b }
1264
+ function method CompareFloat (x : string , y : string ) : Result< FloatCompare. CompareType, Error>
1265
+ {
1266
+ var newX :- Norm. NormalizeNumber (x). MapFailure (e => E(e));
1267
+ var newY :- Norm. NormalizeNumber (y). MapFailure (e => E(e));
1268
+ Success (FloatCompare.CompareFloat(newX, newY))
1269
+ }
1262
1270
1263
- predicate method AttributeLE (a : DDB .AttributeValue, b : DDB .AttributeValue)
1271
+ function method AttributeEQ (a : DDB .AttributeValue, b : DDB .AttributeValue) : Result < bool , Error >
1264
1272
{
1265
1273
if a. N? && b. N? then
1266
- FloatCompare. CompareFloat (a.N, b.N) <= 0
1274
+ var ret :- CompareFloat (a.N, b.N);
1275
+ Success (ret == 0)
1276
+ else
1277
+ Success (a == b)
1278
+ }
1279
+
1280
+ function method AttributeNE (a : DDB .AttributeValue, b : DDB .AttributeValue) : Result< bool , Error>
1281
+ {
1282
+ var ret :- AttributeEQ (a, b);
1283
+ Success (!ret)
1284
+ }
1285
+
1286
+ function method AttributeLE (a : DDB .AttributeValue, b : DDB .AttributeValue) : Result< bool , Error>
1287
+ {
1288
+ if a. N? && b. N? then
1289
+ var ret :- CompareFloat (a.N, b.N);
1290
+ Success (ret <= 0)
1267
1291
else if a. S? && b. S? then
1268
- LexicographicLessOrEqual (a.S, b.S, CharLess)
1292
+ Success ( LexicographicLessOrEqual(a.S, b.S, CharLess) )
1269
1293
else if a. B? && b. B? then
1270
- LexicographicLessOrEqual (a.B, b.B, ByteLess)
1294
+ Success ( LexicographicLessOrEqual(a.B, b.B, ByteLess) )
1271
1295
else
1272
- false
1296
+ Success ( false)
1273
1297
}
1274
- predicate method AttributeLT (a : DDB .AttributeValue, b : DDB .AttributeValue)
1298
+ function method AttributeLT (a : DDB .AttributeValue, b : DDB .AttributeValue) : Result < bool , Error >
1275
1299
{
1276
- ! AttributeLE (b,a)
1300
+ var ret :- AttributeLE (b,a);
1301
+ Success (!ret)
1277
1302
}
1278
- predicate method AttributeGT (a : DDB .AttributeValue, b : DDB .AttributeValue)
1303
+ function method AttributeGT (a : DDB .AttributeValue, b : DDB .AttributeValue) : Result < bool , Error >
1279
1304
{
1280
- ! AttributeLE (a,b)
1305
+ var ret :- AttributeLE (a,b);
1306
+ Success (!ret)
1281
1307
}
1282
- predicate method AttributeGE (a : DDB .AttributeValue, b : DDB .AttributeValue)
1308
+ function method AttributeGE (a : DDB .AttributeValue, b : DDB .AttributeValue) : Result < bool , Error >
1283
1309
{
1284
- AttributeLE (b,a)
1310
+ var ret :- AttributeLE (b,a);
1311
+ Success (ret)
1285
1312
}
1286
1313
1287
1314
// apply the comparison function
1288
1315
function method apply_binary_comp (input : Token , x : DDB .AttributeValue, y : DDB .AttributeValue) : Result< bool , Error>
1289
1316
{
1290
1317
match input
1291
- case Eq => Success (x == y)
1292
- case Ne => Success (x != y)
1293
- case Le => Success ( AttributeLE(x, y) )
1294
- case Lt => Success ( AttributeLT(x, y) )
1295
- case Ge => Success ( AttributeGE(x, y) )
1296
- case Gt => Success ( AttributeGT(x, y) )
1318
+ case Eq => AttributeEQ (x, y)
1319
+ case Ne => AttributeNE (x, y)
1320
+ case Le => AttributeLE (x, y)
1321
+ case Lt => AttributeLT (x, y)
1322
+ case Ge => AttributeGE (x, y)
1323
+ case Gt => AttributeGT (x, y)
1297
1324
case _ => Failure (E("invalid op in apply_binary_bool"))
1298
1325
}
1299
1326
0 commit comments