使用NameMap搜索JSON属性的DynamoDb扫描过滤器表达式失败(Java)

时间:2019-03-23 14:03:17

标签: amazon-dynamodb

为什么nameMap替换对排序键(skey)可以正常工作,但对JSON属性子值(jsonvalue.adminLevel)不起作用?

我的表包含此项目,其中“ jsonvalue”存储为JSON:

{ Item: {pkey=_ROOT_ADMIN, skey=admin, jsonvalue={name=adminName, userId=adminUid, hashedPass=adminHashedPass, adminLevel=0}} }

此扫描/过滤器成功检索到该项目(table.scan()函数很重要,它使用属性和子值的直接名称,其中nameMap值之一被注释掉了):

public List<Admin> getAdminsByLevel(AdminLevel level) {
        NameMap nameMap = new NameMap()
            .with("#skey", "skey");
            // .with("#jsonvalue_adminLevel","jsonvalue.adminLevel");
        ValueMap valueMap = new ValueMap()
            .withString(":skey", Admins.ADMIN_SKEY)
            .withInt(":jsonvalue_adminLevel", level.getValue());
        ItemCollection<ScanOutcome> items = 
            this.ddb.table.scan("#skey = :skey AND jsonvalue.adminLevel = :jsonvalue_adminLevel", nameMap, valueMap);
        Iterator<Item> iter = items.iterator();
        List<Admin> list = new ArrayList<Admin>();
        while (iter.hasNext()) {
            Item item = iter.next();
            Admin admin = DtoUtils.toAdmin(item);
            list.add(admin);
        }
        return list;
    }

但是此扫描/过滤器(将jsonvalue.adminLevel替换为映射名称#jsonvalue_adminLevel)不会出错,但也不会返回该项目:

public List<Admin> getAdminsByLevel(AdminLevel level) {
        NameMap nameMap = new NameMap()
            .with("#skey", "skey")
            .with("#jsonvalue_adminLevel","jsonvalue.adminLevel");
        ValueMap valueMap = new ValueMap()
            .withString(":skey", Admins.ADMIN_SKEY)
            .withInt(":jsonvalue_adminLevel", level.getValue());
        ItemCollection<ScanOutcome> items = 
            this.ddb.table.scan("#skey = :skey AND #jsonvalue_adminLevel = :jsonvalue_adminLevel", nameMap, valueMap);
        Iterator<Item> iter = items.iterator();
        List<Admin> list = new ArrayList<Admin>();
        while (iter.hasNext()) {
            Item item = iter.next();
            Admin admin = DtoUtils.toAdmin(item);
            list.add(admin);
        }
        return list;
    }

为什么nameMap替换对排序键(skey)可以正常工作,但对JSON属性子值(jsonvalue.adminLevel)不起作用?

0 个答案:

没有答案