Class DDBPredicateUtils
- java.lang.Object
-
- com.amazonaws.athena.connectors.dynamodb.util.DDBPredicateUtils
-
public class DDBPredicateUtils extends Object
Provides utility methods relating to predicate handling.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static String
aliasColumn(String columnName)
Generates a simple alias for a column to satisfy filter expressions.static String
generateFilterExpression(Set<String> columnsToIgnore, Map<String,ValueSet> predicates, List<software.amazon.awssdk.services.dynamodb.model.AttributeValue> accumulator, IncrementingValueNameProducer valueNameProducer, DDBRecordMetadata recordMetadata)
Generates a combined filter expression for the given predicates.static String
generateSingleColumnFilter(String originalColumnName, ValueSet predicate, List<software.amazon.awssdk.services.dynamodb.model.AttributeValue> accumulator, IncrementingValueNameProducer valueNameProducer, DDBRecordMetadata recordMetadata, boolean columnIsSortKey)
Generates a filter expression for a single column given aValueSet
predicate for that column.static DynamoDBIndex
getBestIndexForPredicates(DynamoDBTable table, List<String> requestedCols, Map<String,ValueSet> predicates)
Attempts to pick an optimal index (if any) from the given predicates.static List<Object>
getHashKeyAttributeValues(ValueSet valueSet)
Generates a list of distinct values from the givenValueSet
or an empty list if not possible.static boolean
indexContainsAllRequiredColumns(List<String> requestedCols, DynamoDBIndex index, DynamoDBTable table)
-
-
-
Method Detail
-
getBestIndexForPredicates
public static DynamoDBIndex getBestIndexForPredicates(DynamoDBTable table, List<String> requestedCols, Map<String,ValueSet> predicates)
Attempts to pick an optimal index (if any) from the given predicates. Returns the original table index if one was not found.- Parameters:
table
- the original tablepredicates
- the predicates- Returns:
- the optimal index if found, otherwise the original table index
-
getHashKeyAttributeValues
public static List<Object> getHashKeyAttributeValues(ValueSet valueSet)
Generates a list of distinct values from the givenValueSet
or an empty list if not possible.- Parameters:
valueSet
- the value set to generate from- Returns:
- the list of distinct values
-
aliasColumn
public static String aliasColumn(String columnName)
Generates a simple alias for a column to satisfy filter expressions. Uses a regex to convert illegal characters (any character or combination of characters that are NOT included in [a-zA-Z_0-9]) to underscore. Example: "column-$1`~!@#$%^&*()-=+[]{}\\|;:'\",.<>/?f3" -> "#column_1_f3"- Parameters:
columnName
- the input column name- Returns:
- the aliased column name
- See Also:
- https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.ExpressionAttributeNames.html
-
generateSingleColumnFilter
public static String generateSingleColumnFilter(String originalColumnName, ValueSet predicate, List<software.amazon.awssdk.services.dynamodb.model.AttributeValue> accumulator, IncrementingValueNameProducer valueNameProducer, DDBRecordMetadata recordMetadata, boolean columnIsSortKey)
Generates a filter expression for a single column given aValueSet
predicate for that column.- Parameters:
originalColumnName
- the column namepredicate
- the associated predicateaccumulator
- the value accumulator to add values tovalueNameProducer
- the value name producer to generate value aliases withrecordMetadata
- object containing any necessary metadata from the glue tablecolumnIsSortKey
- whether or not the originalColumnName column is a sort key- Returns:
- the generated filter expression
-
generateFilterExpression
public static String generateFilterExpression(Set<String> columnsToIgnore, Map<String,ValueSet> predicates, List<software.amazon.awssdk.services.dynamodb.model.AttributeValue> accumulator, IncrementingValueNameProducer valueNameProducer, DDBRecordMetadata recordMetadata)
Generates a combined filter expression for the given predicates. columnsToIgnore will contain any column that is of custom type (such as timestamp with tz) as these types are not natively supported by ddb or glue. we will need to filter them separately in the ddb query/scan result.- Parameters:
columnsToIgnore
- the columns to not generate filters forpredicates
- the map of columns to predicatesaccumulator
- the value accumulator to add values tovalueNameProducer
- the value name producer to generate value aliases withrecordMetadata
- object containing any necessary metadata from the glue table- Returns:
- the combined filter expression
-
indexContainsAllRequiredColumns
public static boolean indexContainsAllRequiredColumns(List<String> requestedCols, DynamoDBIndex index, DynamoDBTable table)
-
-