Aws-sdk-net: DynamoDb with a bool filter getting no result

Created on 17 Dec 2018  路  6Comments  路  Source: aws/aws-sdk-net

Hi guys,

I am trying to do a QueryAsync in DynamoDb with a bool filter. I am getting no result back from dynamoDb. Are there some known problem with filters on bool values?

I am using the object persistence model. It works fine with the low level "raw stringy concat" model.

/Johan

bug closing-soon documentation guidance

Most helpful comment

@incolor2 , @chernihiv, @isolatedThinker, this could be better, but there is a workaround that you can use.

I think we could provide a better developer experience by not initializing the Conversion property if it has not been set. Due to the confusing nature of the current experience, I'm labeling this as a bug. However, it is unlikely that we will change the current behavior in the current major version because it could be a breaking change in behavior for customers depending on the current implementation.

The workaround is to do one of the following (I recommend 1):

  1. Set the DynamoDBOperationConfig's Conversion property to DynamoDBEntryConversion.V2
  2. Set the DynamoDBOperationConfig's Conversion property to null and set the DynamoDBContextConfig's Conversion property to DynamoDBEntryConversion.V2

All 6 comments

Could you provide a code snippet of how you are using the object persistence model to do the the QueryAsync?

One thing I would look into is what is on the DynamoDBContextConfig object you pass in to your context object is the Conversion property set to. The default is DynamoDBEntryConversion.V1 which is the original conversion and stores bools as numbers (0 or 1). The DynamoDBEntryConversion.V2 uses the newer BOOL type. So make sure the conversion setting is set to how the bools are stored stored in your table?

Hi Norm,

I have used the .V2 version. Are there some dynamoDb bool datatype i need to use?
See code sample below

Item in Db

{ "Created": { "S": "2010-03-01T06:57:11.683Z" }, "Id": { "S": "e5fb0d0f-7af1-49cb-99cb-d99ce917a4d3" }, "NormalRoadConditions": { "BOOL": true }, "OrganizationId": { "S": "52049e96-14fa-4960-b3ce-f7400c4ac6cd" }, "Status": { "N": "7" } }

The code
` private static void BoolFilterTest()
{
string TableName = "SomeTable";
List partionKeys = new List() { "52049E96-14FA-4960-B3CE-F7400C4AC6CD", "01F3DF08-4D0F-4E92-BBE3-8E46BA77E73B", "52117BC1-7256-4C36-868E-465DB2178286" };

        if (!string.IsNullOrEmpty(TableName))
        {
            AWSConfigsDynamoDB.Context.TypeMappings[typeof(Plan)] = new Amazon.Util.TypeMapping(typeof(Plan), TableName);
        }

        int totalCount = 0;

        var config = new DynamoDBContextConfig { Conversion = DynamoDBEntryConversion.V2 };
        var client = new AmazonDynamoDBClient(new StoredProfileAWSCredentials("SomeProfile"), RegionEndpoint.EUWest1);
        DbContext = new DynamoDBContext(client, config);
        var opConfig = new DynamoDBOperationConfig { IndexName = "OrganizationId-Created-index" };

        opConfig.QueryFilter =
            new List<ScanCondition>
            {
                new ScanCondition("Status", ScanOperator.Equal, 10),
                new ScanCondition("NormalRoadConditions", ScanOperator.Equal, true)

            };

        foreach (var partionKey in partionKeys)
        {
            var result = Program.DbContext.QueryAsync<Plan>(partionKey.ToLower(), opConfig);

            while (!result.IsDone)
            {
                var plans = result.GetNextSetAsync().Result;

                totalCount += plans.Count;
            }

        }

        System.Console.WriteLine($"ItemCount: {totalCount}");
    }`

@normj

I also have similar problem.
There are public and private entities in table, but condition filter by boolean props returns empty collection.

        public async Task<List<Test>> GetPublicTestsAsync()
        {
            var operationConfig = new DynamoDBOperationConfig
            {
                OverrideTableName = TableName
            };

            var conditions = new List<ScanCondition>
            {
                new ScanCondition(nameof(Test.IsPublic), ScanOperator.Equal, true)
            };

            return await _dbContext
                .ScanAsync<Test>(conditions, operationConfig)
                .GetRemainingAsync();
        }

IsPublic is non nullable property.

Same issue here with this example code. Is this still being looked at? I have checked that my value is stored as the BOOL type and that my context is configured to use the V2 conversion.

            var result = await dynamoDBContext.QueryAsync<ClassificationConfiguration>(oemName, new DynamoDBOperationConfig
            {
                IndexName = applicationOptions.ClassificationConfigurationOemIndexName,
                QueryFilter = new List<ScanCondition>
                {
                    new ScanCondition(nameof(ClassificationConfiguration.IsCurrent), ScanOperator.Equal, true)
                }
            }).GetRemainingAsync();

@incolor2 , @chernihiv, @isolatedThinker, this could be better, but there is a workaround that you can use.

I think we could provide a better developer experience by not initializing the Conversion property if it has not been set. Due to the confusing nature of the current experience, I'm labeling this as a bug. However, it is unlikely that we will change the current behavior in the current major version because it could be a breaking change in behavior for customers depending on the current implementation.

The workaround is to do one of the following (I recommend 1):

  1. Set the DynamoDBOperationConfig's Conversion property to DynamoDBEntryConversion.V2
  2. Set the DynamoDBOperationConfig's Conversion property to null and set the DynamoDBContextConfig's Conversion property to DynamoDBEntryConversion.V2

Instead of giving the scan filter value as bool give it as DynamoDBBool();
eg : scanFilter.AddCondition("BoolColumn", ScanOperator.Equal, new DynamoDBBool(true));

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jefhai picture jefhai  路  5Comments

Lapeno94 picture Lapeno94  路  4Comments

McDoit picture McDoit  路  4Comments

genifycom picture genifycom  路  4Comments

ShahriatHossain picture ShahriatHossain  路  4Comments