【问题标题】:Aerospike aql: How to fetch records from aerospike using predicate based on the Map fieldAerospike aql:如何使用基于 Map 字段的谓词从 Aerospike 中获取记录
【发布时间】:2021-04-27 03:17:00
【问题描述】:

下面是数据传输对象的类定义。我使用 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?


【问题讨论】:

    标签: aerospike aerospike-ce


    【解决方案1】:

    尝试执行:

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

    基于以下结构:

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

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

    如果您使用 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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-29
      • 2021-04-16
      相关资源
      最近更新 更多