mirror of
https://github.com/floci-io/floci.git
synced 2026-11-24 06:20:24 -05:00
fix: support DynamoDB Query BETWEEN and ScanIndexForward=false (#160)
* docs: expand community section with GitHub Discussions * docs: simplify supported services table * fix: support DynamoDB Query BETWEEN and ScanIndexForward=false * docs: simplify supported services table
This commit is contained in:
1 parent
675d5a33d0
commit
cf2c705b7d
4 files changed
+122
-10
No files matched your search
@@ -282,12 +282,14 @@ public class DynamoDbJsonHandler {
|
||||
String filterExpr = request.has("FilterExpression")
|
||||
? request.get("FilterExpression").asText() : null;
|
||||
Integer limit = request.has("Limit") ? request.get("Limit").asInt() : null;
|
||||
Boolean scanIndexForward = request.has("ScanIndexForward")
|
||||
? request.get("ScanIndexForward").asBoolean() : null;
|
||||
String indexName = request.has("IndexName") ? request.get("IndexName").asText() : null;
|
||||
JsonNode exclusiveStartKey = request.has("ExclusiveStartKey")
|
||||
? request.get("ExclusiveStartKey") : null;
|
||||
|
||||
DynamoDbService.QueryResult result = dynamoDbService.query(tableName, keyConditions,
|
||||
exprAttrValues, keyConditionExpr, filterExpr, limit, indexName,
|
||||
exprAttrValues, keyConditionExpr, filterExpr, limit, scanIndexForward, indexName,
|
||||
exclusiveStartKey, exprAttrNames, region);
|
||||
|
||||
ObjectNode response = objectMapper.createObjectNode();
|
||||
|
||||
@@ -18,6 +18,7 @@ import org.jboss.logging.Logger;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
@@ -379,19 +380,19 @@ public class DynamoDbService {
|
||||
JsonNode expressionAttrValues, String keyConditionExpression,
|
||||
String filterExpression, Integer limit) {
|
||||
return query(tableName, keyConditions, expressionAttrValues, keyConditionExpression,
|
||||
filterExpression, limit, null, null, null, regionResolver.getDefaultRegion());
|
||||
filterExpression, limit, null, null, null, null, regionResolver.getDefaultRegion());
|
||||
}
|
||||
|
||||
public QueryResult query(String tableName, JsonNode keyConditions,
|
||||
JsonNode expressionAttrValues, String keyConditionExpression,
|
||||
String filterExpression, Integer limit, String region) {
|
||||
return query(tableName, keyConditions, expressionAttrValues, keyConditionExpression,
|
||||
filterExpression, limit, null, null, null, region);
|
||||
filterExpression, limit, null, null, null, null, region);
|
||||
}
|
||||
|
||||
public QueryResult query(String tableName, JsonNode keyConditions,
|
||||
JsonNode expressionAttrValues, String keyConditionExpression,
|
||||
String filterExpression, Integer limit, String indexName,
|
||||
String filterExpression, Integer limit, Boolean scanIndexForward, String indexName,
|
||||
JsonNode exclusiveStartKey, JsonNode exprAttrNames, String region) {
|
||||
String storageKey = regionKey(region, tableName);
|
||||
TableDefinition table = tableStore.get(storageKey)
|
||||
@@ -467,6 +468,9 @@ public class DynamoDbService {
|
||||
if (bVal == null) return 1;
|
||||
return compareValues(aVal, bVal);
|
||||
});
|
||||
if (Boolean.FALSE.equals(scanIndexForward)) {
|
||||
Collections.reverse(results);
|
||||
}
|
||||
}
|
||||
|
||||
// Apply ExclusiveStartKey offset
|
||||
@@ -1459,6 +1463,23 @@ public class DynamoDbService {
|
||||
return prefix != null && actual.startsWith(prefix);
|
||||
}
|
||||
|
||||
if (exprLower.contains(" between ")) {
|
||||
int betweenIdx = exprLower.indexOf(" between ");
|
||||
int andIdx = exprLower.indexOf(" and ", betweenIdx + " between ".length());
|
||||
if (andIdx < 0) return false;
|
||||
|
||||
String lowerExpr = expression.substring(betweenIdx + " between ".length(), andIdx).trim();
|
||||
String upperExpr = expression.substring(andIdx + " and ".length()).trim();
|
||||
String lowerPlaceholder = lowerExpr.startsWith(":") ? lowerExpr.split("\\s+")[0] : null;
|
||||
String upperPlaceholder = upperExpr.startsWith(":") ? upperExpr.split("\\s+")[0] : null;
|
||||
String lower = lowerPlaceholder != null && exprValues != null
|
||||
? extractScalarValue(exprValues.get(lowerPlaceholder)) : null;
|
||||
String upper = upperPlaceholder != null && exprValues != null
|
||||
? extractScalarValue(exprValues.get(upperPlaceholder)) : null;
|
||||
if (lower == null || upper == null) return false;
|
||||
return compareValues(actual, lower) >= 0 && compareValues(actual, upper) <= 0;
|
||||
}
|
||||
|
||||
// Detect comparison operator
|
||||
String[] operators = {"<>", "<=", ">=", "=", "<", ">"};
|
||||
for (String op : operators) {
|
||||
|
||||
Reference in new issue
Block a user