java - Spring-data-aerospike 与 aql 创建的索引不兼容

标签 java spring-data aerospike

我的计算机上安装了 aerospike 服务器 v 3.8.3,并尝试在 aql 中使用以下命令创建索引:

aql> CREATE INDEX indexA ON namespace.setA(binA) STRING 

这是aql> showindexes命令的结果

+----------------+--------+------------+---------+-------+------------+-------+------------+------------+
| ns             | bin    | indextype  | set     | state | indexname  | path  | sync_state | type       |
+----------------+--------+------------+---------+-------+------------+-------+------------+------------+
| "namespace"    | "binA" | "NONE"     | "setA"  | "RW"  | "indexA"   | "BinB | "synced"   | "STRING"   |
+----------------+--------+------------+---------+-------+------------+-------+------------+------------+

spring-data-aerospike 期望使用以下 bin 构建索引

+----------------+-----------------+--------+----------+-------+-----------+------------+--------------+
| ns             | bins            | set    | num_bins | state | indexname | sync_state | type         |
+----------------+-----------------+--------+----------+-------+-----------+------------+--------------+
| "user_profile" | "last_activity" | "west" | 1        | "WO"  | "ix1"     | "synced"   | "INT SIGNED" |
+----------------+-----------------+--------+----------+-------+-----------+------------+--------------

文档 here 中提到了这两种格式和 here

索引创建中存在不兼容性,我应该修复 spring-data-aerospike 还是修复索引以匹配 spring-data-aerospike 中的预期输出

com/aerospike/helper/model/Index.java第79行

/* 
 * Copyright 2012-2015 Aerospike, Inc.
 *
 * Portions may be licensed to Aerospike, Inc. under one or more contributor
 * license agreements.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package com.aerospike.helper.model;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import com.aerospike.client.query.IndexType;
/**
 * This class represents a Secondary Index
 * created in the cluster.
 * 
 * @author peter
 *
 */
public class Index {

    protected Map<String, String> values;
    public Index(String info) {
        setIndexInfo(info);

    }
    public String getName() {
        return  values.get("indexname");

    }



    public List<NameValuePair> getValues(){
        List<NameValuePair> result = new ArrayList<NameValuePair>();
        Set<String> keys = this.values.keySet();
        for (String key : keys){
            NameValuePair nvp = new NameValuePair(this, key, this.values.get(key));
            result.add(nvp);
        }
        return result;
    }

    public void setIndexInfo(String info){
        //ns=phobos_sindex:set=longevity:indexname=str_100_idx:num_bins=1:bins=str_100_bin:type=TEXT:sync_state=synced:state=RW;
        if (!info.isEmpty()){
            String[] parts = info.split(":");
            if (values == null){
                values = new HashMap<String, String>();
            }
            for (String part : parts){
                kvPut(part, this.values);
            }
        }
    }
    private void kvPut(String kv, Map<String, String> map){
        String[] kvParts = kv.split("=");
        map.put(kvParts[0], kvParts[1]);
    };

    @Override
    public String toString() {
        return this.getName();
    }
    public String getBin() {
        return  values.get("bins");
    }
    public IndexType getType(){
        String indexTypeString = values.get("type");
        if (indexTypeString.equalsIgnoreCase("TEXT"))
            return IndexType.STRING;
        else
            return IndexType.NUMERIC;
    }
}

最佳答案

修复 spring-data-aerospike,因为 aerospike-server 自 48f1ae5 以来改变了其行为.

响应服务器上“显示索引”的代码(在 as/src/base/secondary_index.c 中)是:

/*
 * Client API to list all the indexes in a namespace, returns list of imd with
 * index information, Caller should free it up
 */
int
as_sindex_list_str(as_namespace *ns, cf_dyn_buf *db)
{
......

您可以在 link 中查看更改。 .

关于java - Spring-data-aerospike 与 aql 创建的索引不兼容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37754308/

相关文章:

java - 用Java编写的开源规则引擎

spring-data - 使用 Spring Boot + Spring Data 时 @EnableAutoConfiguration 和 @@ComponentScan 出错

Aerospike 的 Redis 桌面管理器?

go - 如何执行纯 aql 查询?

java - Spring Security 应用程序的用户类

java - 如何测试在 JUnit 中的测试方法下创建的线程的完成情况

Java:JDOQL以查询开始,区分大小写

java - 使用 Spring Data 4 JPA 自定义保存方法

spring - 如何将spring资源注入(inject)Apache Ignite类?

nosql - 在 NoSQL(Aerospike) 中更新冗余数据/非规范化数据