1

我在数据传输对象的类定义之下。我使用 spring-data-aerospike 来持久化。

    import org.springframework.data.annotation.Id;
    public class User implements Serializable {

        @Id
        String uid;

        Map<String, Object> ext = new HashMap<String, Object>();

        // getters & setters    
    }

数据库中的样本数据就像 -

select ext  from department.User;
+-------+-------------------------+----------------------------------+
| PK    | ext                     || @_class                         |
+-------+-------------------------+----------------------------------+
| "123" | MAP('{"idfa": "xyz"}')  | "com.tut.dto.User"               |
| "234" | MAP('{}')               | "com.tut.dto.User"               |
+-------+-------------------------+----------------------------------+

我现在需要查询数据库,因为它应该只返回在 ext 字段列中具有“idfa”键字符串的记录。

我尝试了以下。但它没有用

1.

 select * from test.UserRecord where ext.idfa is not null;
 Unsupported command format with token -  '.'
 Make sure string values are enclosed in quotes.
 Type " aql --help " from console or simply "help" from within the aql-prompt.
 ```
2. 

select * from test.UserRecord where ext contains 'idfa';
Unsupported command format with token -  ''idfa''
Make sure string values are enclosed in quotes.
Type " aql --help " from console or simply "help" from within the aql-prompt.

How can I make it work?


4

1 回答 1

2

尝试执行:

select * from department.user in mapkeys where ext = "idfa"

基于以下结构:

SELECT <bins> FROM <ns>[.<set>] IN <indextype> WHERE <bin> = <value>

假设您已经创建了一个集合类型为“MAPKEYS”的索引,您可以ext在类中的字段上使用 @Indexed 注释创建它User

如果您使用 Spring Data Aerospike 最新版本,它应该看起来像这样:

@Indexed(name = "indexName", type = IndexType.STRING, collectionType = IndexCollectionType.MAPKEYS)
Map<String, Object> ext = new HashMap<String, Object>();

如果您对通过代码(而不是 AQL)与 Aerospike 列表/地图箱进行交互感兴趣,您应该阅读有关 CDT(收集数据类型)操作的信息。

CDT 文档:

https://docs.aerospike.com/docs/guide/cdt.html

地图操作类(包括方法文档):

https://github.com/aerospike/aerospike-client-java/blob/master/client/src/com/aerospike/client/cdt/MapOperation.java

Aerospike Java 客户端中的一些示例:

https://github.com/aerospike/aerospike-client-java/blob/master/test/src/com/aerospike/test/sync/basic/TestOperateMap.java

于 2021-04-28T13:41:37.880 回答