From cc8b06a0f55bedc562f6af796eb133f5ab9ed0b1 Mon Sep 17 00:00:00 2001 From: Mirza Karacic Date: Tue, 7 Jul 2026 11:46:49 -0700 Subject: [PATCH] =?UTF-8?q?CLIENT-4359=20Create=20index=20to=20use=20?= =?UTF-8?q?=E2=80=9Cinteger=E2=80=9D=20instead=20of=20=E2=80=9Cnumeric?= =?UTF-8?q?=E2=80=9D=20starting=20with=20Aerospike=20server=20>=3D=208.1.3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/aerospike/client/query/IndexType.java | 10 ++- .../aerospike/test/sync/query/TestIndex.java | 72 +++++++++++++++++++ 2 files changed, 80 insertions(+), 2 deletions(-) diff --git a/client/src/com/aerospike/client/query/IndexType.java b/client/src/com/aerospike/client/query/IndexType.java index 5cfb445c4..b3d7f27d4 100644 --- a/client/src/com/aerospike/client/query/IndexType.java +++ b/client/src/com/aerospike/client/query/IndexType.java @@ -21,7 +21,7 @@ */ public enum IndexType { /** - * Number index. + * Number index. Use {@link #INTEGER} for server versions 8.1.3+. */ NUMERIC, @@ -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; } diff --git a/test/src/com/aerospike/test/sync/query/TestIndex.java b/test/src/com/aerospike/test/sync/query/TestIndex.java index 34eb78804..7b6a22346 100644 --- a/test/src/com/aerospike/test/sync/query/TestIndex.java +++ b/test/src/com/aerospike/test/sync/query/TestIndex.java @@ -22,7 +22,9 @@ 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; @@ -30,7 +32,10 @@ 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; @@ -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() { @@ -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[] {