Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions client/src/com/aerospike/client/query/IndexType.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*/
public enum IndexType {
/**
* Number index.
* Number index. Use {@link #INTEGER} for server versions 8.1.3+.
*/
NUMERIC,

Expand All @@ -38,5 +38,11 @@ public enum IndexType {
/**
* 2-dimensional spherical geospatial index.
*/
GEO2DSPHERE;
GEO2DSPHERE,

/**
* Integer index. Requires server version 8.1.3+. Use {@link #NUMERIC} for
* server versions prior to 8.1.3.
*/
INTEGER;
}
72 changes: 72 additions & 0 deletions test/src/com/aerospike/test/sync/query/TestIndex.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,20 @@
import org.junit.Test;

import com.aerospike.client.AerospikeException;
import com.aerospike.client.Bin;
import com.aerospike.client.Info;
import com.aerospike.client.Key;
import com.aerospike.client.ResultCode;
import com.aerospike.client.Value;
import com.aerospike.client.cdt.CTX;
import com.aerospike.client.cluster.Node;
import com.aerospike.client.exp.Exp;
import com.aerospike.client.exp.Expression;
import com.aerospike.client.exp.LoopVarPart;
import com.aerospike.client.query.Filter;
import com.aerospike.client.query.IndexType;
import com.aerospike.client.query.RecordSet;
import com.aerospike.client.query.Statement;
import com.aerospike.client.task.IndexTask;
import com.aerospike.client.util.Version;
import com.aerospike.test.sync.TestSync;
Expand All @@ -39,6 +44,9 @@ public class TestIndex extends TestSync {
private static final String indexName = "testindex";
private static final String binName = "testbin";
private static final String setIndexName = "testsetindex";
private static final String integerIndexName = "testintegerindex";
private static final String integerBinName = "testintegerbin";
private static final String integerKeyPrefix = "testintegerkey";

@Test
public void createDrop() {
Expand Down Expand Up @@ -116,6 +124,70 @@ public void setIndexCreateDrop() {
}
}

@Test
public void integerIndexCreateQueryDrop() {
Assume.assumeTrue("INTEGER index type requires server version 8.1.3 or later",
args.serverVersion.isGreaterOrEqual(8, 1, 3, 0));

IndexTask task;

// Drop index if it already exists.
try {
task = client.dropIndex(args.indexPolicy, args.namespace, args.set, integerIndexName);
task.waitTillComplete();
}
catch (AerospikeException ae) {
if (ae.getResultCode() != ResultCode.INDEX_NOTFOUND) {
throw ae;
}
}

task = client.createIndex(args.indexPolicy, args.namespace, args.set, integerIndexName, integerBinName, IndexType.INTEGER);
task.waitTillComplete();

int size = 20;

for (int i = 1; i <= size; i++) {
Key key = new Key(args.namespace, args.set, integerKeyPrefix + i);
Bin bin = new Bin(integerBinName, i);
client.put(null, key, bin);
}

Statement stmt = new Statement();
stmt.setNamespace(args.namespace);
stmt.setSetName(args.set);
stmt.setBinNames(integerBinName);
stmt.setFilter(Filter.range(integerBinName, 4, 8));

RecordSet rs = client.query(null, stmt);

try {
int count = 0;

while (rs.next()) {
count++;
}
assertEquals(5, count);
}
finally {
rs.close();
}

task = client.dropIndex(args.indexPolicy, args.namespace, args.set, integerIndexName);
task.waitTillComplete();

// Ensure all nodes have dropped the index.
Node[] nodes = client.getNodes();

for (Node node : nodes) {
String cmd = IndexTask.buildStatusCommand(args.namespace, integerIndexName, node.getServerVersion());
String response = Info.request(node, cmd);
int code = Info.parseResultCode(response);

assertEquals(201, code);
}
}

@Test
public void ctxRestore() {
CTX[] ctx1 = new CTX[] {
Expand Down
Loading