Search in sources :

Example 11 with IndexTask

use of com.aerospike.client.task.IndexTask in project aerospike-client-java by aerospike.

the class QuerySum method createIndex.

private void createIndex(AerospikeClient client, Parameters params, String indexName, String binName) throws Exception {
    console.info("Create index: ns=%s set=%s index=%s bin=%s", params.namespace, params.set, indexName, binName);
    Policy policy = new Policy();
    // Do not timeout on index create.
    policy.socketTimeout = 0;
    try {
        IndexTask task = client.createIndex(policy, params.namespace, params.set, indexName, binName, IndexType.NUMERIC);
        task.waitTillComplete();
    } catch (AerospikeException ae) {
        if (ae.getResultCode() != ResultCode.INDEX_ALREADY_EXISTS) {
            throw ae;
        }
    }
}
Also used : Policy(com.aerospike.client.policy.Policy) AerospikeException(com.aerospike.client.AerospikeException) IndexTask(com.aerospike.client.task.IndexTask)

Example 12 with IndexTask

use of com.aerospike.client.task.IndexTask in project aerospike-client-java by aerospike.

the class TestQueryPredExp method prepare.

@BeforeClass
public static void prepare() {
    Policy policy = new Policy();
    // Do not timeout on index create.
    policy.socketTimeout = 0;
    try {
        IndexTask task = client.createIndex(policy, args.namespace, setName, indexName, binName, IndexType.NUMERIC);
        task.waitTillComplete();
    } catch (AerospikeException ae) {
        if (ae.getResultCode() != ResultCode.INDEX_ALREADY_EXISTS) {
            throw ae;
        }
    }
    for (int i = 1; i <= size; i++) {
        Key key = new Key(args.namespace, setName, keyPrefix + i);
        List<Integer> list = null;
        Map<String, String> map = null;
        if (i == 1) {
            list = new ArrayList<Integer>(5);
            list.add(1);
            list.add(2);
            list.add(4);
            list.add(9);
            list.add(20);
        // map will be null, which means mapbin will not exist in this record.
        } else if (i == 2) {
            list = new ArrayList<Integer>(3);
            list.add(5);
            list.add(9);
            list.add(100);
        // map will be null, which means mapbin will not exist in this record.
        } else if (i == 3) {
            map = new HashMap<String, String>();
            map.put("A", "AAA");
            map.put("B", "BBB");
            map.put("C", "BBB");
        // list will be null, which means listbin will not exist in this record.
        } else {
            list = new ArrayList<Integer>(0);
            map = new HashMap<String, String>(0);
        }
        client.put(null, key, new Bin(binName, i), new Bin("bin2", i), new Bin("listbin", list), new Bin("mapbin", map));
    }
}
Also used : Policy(com.aerospike.client.policy.Policy) AerospikeException(com.aerospike.client.AerospikeException) Bin(com.aerospike.client.Bin) IndexTask(com.aerospike.client.task.IndexTask) ArrayList(java.util.ArrayList) Key(com.aerospike.client.Key) BeforeClass(org.junit.BeforeClass)

Example 13 with IndexTask

use of com.aerospike.client.task.IndexTask in project apex-malhar by apache.

the class AerospikeTransactionalStore method createIndexes.

private void createIndexes() {
    IndexTask task;
    try {
        task = client.createIndex(null, namespace, metaSet, "operatorIdIndex", metaTableOperatorIdColumn, IndexType.NUMERIC);
        task.waitTillComplete();
        task = client.createIndex(null, namespace, metaSet, "appIdIndex", metaTableAppIdColumn, IndexType.STRING);
        task.waitTillComplete();
    } catch (AerospikeException ex) {
        throw new RuntimeException(ex);
    }
}
Also used : AerospikeException(com.aerospike.client.AerospikeException) IndexTask(com.aerospike.client.task.IndexTask)

Example 14 with IndexTask

use of com.aerospike.client.task.IndexTask in project aerospike-client-java by aerospike.

the class TestQueryExecute method prepare.

@BeforeClass
public static void prepare() {
    RegisterTask rtask = client.register(null, TestQueryExecute.class.getClassLoader(), "udf/record_example.lua", "record_example.lua", Language.LUA);
    rtask.waitTillComplete();
    Policy policy = new Policy();
    // Do not timeout on index create.
    policy.socketTimeout = 0;
    try {
        IndexTask itask = client.createIndex(policy, args.namespace, args.set, indexName, binName1, IndexType.NUMERIC);
        itask.waitTillComplete();
    } catch (AerospikeException ae) {
        if (ae.getResultCode() != ResultCode.INDEX_ALREADY_EXISTS) {
            throw ae;
        }
    }
    for (int i = 1; i <= size; i++) {
        Key key = new Key(args.namespace, args.set, keyPrefix + i);
        client.put(null, key, new Bin(binName1, i), new Bin(binName2, i));
    }
}
Also used : Policy(com.aerospike.client.policy.Policy) AerospikeException(com.aerospike.client.AerospikeException) Bin(com.aerospike.client.Bin) IndexTask(com.aerospike.client.task.IndexTask) RegisterTask(com.aerospike.client.task.RegisterTask) Key(com.aerospike.client.Key) BeforeClass(org.junit.BeforeClass)

Example 15 with IndexTask

use of com.aerospike.client.task.IndexTask in project aerospike-client-java by aerospike.

the class TestQueryGeo method prepare.

@BeforeClass
public static void prepare() {
    Policy policy = new Policy();
    // Do not timeout on index create.
    policy.socketTimeout = 0;
    try {
        IndexTask task = client.createIndex(policy, args.namespace, setName, indexName, binName, IndexType.GEO2DSPHERE);
        task.waitTillComplete();
    } catch (AerospikeException ae) {
        if (ae.getResultCode() != ResultCode.INDEX_ALREADY_EXISTS) {
            throw ae;
        }
    }
    // Insert points
    for (int i = 1; i <= size; i++) {
        Key key = new Key(args.namespace, setNamePoints, i);
        double lng = -122 + (0.1 * i);
        double lat = 37.5 + (0.1 * i);
        String loc = "{ \"type\": \"Point\", \"coordinates\": [" + lng + ", " + lat + "] }";
        Bin bin = Bin.asGeoJSON("loc", loc);
        client.put(null, key, bin);
    }
    // Insert regions
    double[][] starbucks = { { -122.1708441, 37.4241193 }, { -122.1492040, 37.4273569 }, { -122.1441078, 37.4268202 }, { -122.1251714, 37.4130590 }, { -122.0964289, 37.4218102 }, { -122.0776641, 37.4158199 }, { -122.0943475, 37.4114654 }, { -122.1122861, 37.4028493 }, { -122.0947230, 37.3909250 }, { -122.0831037, 37.3876090 }, { -122.0707119, 37.3787855 }, { -122.0303178, 37.3882739 }, { -122.0464861, 37.3786236 }, { -122.0582128, 37.3726980 }, { -122.0365083, 37.3676930 } };
    for (int i = 0; i < starbucks.length; i++) {
        Key key = new Key(args.namespace, setNameRegions, i);
        String loc = "{ \"type\": \"AeroCircle\", \"coordinates\": [[" + starbucks[i][0] + ", " + starbucks[i][1] + "], 3000.0 ] }";
        Bin bin = Bin.asGeoJSON("loc", loc);
        client.put(null, key, bin);
    }
}
Also used : QueryPolicy(com.aerospike.client.policy.QueryPolicy) Policy(com.aerospike.client.policy.Policy) AerospikeException(com.aerospike.client.AerospikeException) Bin(com.aerospike.client.Bin) IndexTask(com.aerospike.client.task.IndexTask) Key(com.aerospike.client.Key) BeforeClass(org.junit.BeforeClass)

Aggregations

AerospikeException (com.aerospike.client.AerospikeException)29 IndexTask (com.aerospike.client.task.IndexTask)29 Policy (com.aerospike.client.policy.Policy)28 BeforeClass (org.junit.BeforeClass)13 Bin (com.aerospike.client.Bin)11 Key (com.aerospike.client.Key)11 RegisterTask (com.aerospike.client.task.RegisterTask)6 QueryPolicy (com.aerospike.client.policy.QueryPolicy)3 WritePolicy (com.aerospike.client.policy.WritePolicy)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)1 Test (org.junit.Test)1