Search in sources :

Example 51 with RecordSet

use of com.aerospike.client.query.RecordSet in project aerospike-client-java by aerospike.

the class TestQueryKey method queryKey.

@Test
public void queryKey() {
    int begin = 2;
    int end = 5;
    Statement stmt = new Statement();
    stmt.setNamespace(args.namespace);
    stmt.setSetName(args.set);
    stmt.setBinNames(binName);
    stmt.setFilter(Filter.range(binName, begin, end));
    RecordSet rs = client.query(null, stmt);
    try {
        int count = 0;
        while (rs.next()) {
            Key key = rs.getKey();
            assertNotNull(key.userKey);
            Object userkey = key.userKey.getObject();
            assertNotNull(userkey);
            count++;
        }
        assertEquals(4, count);
    } finally {
        rs.close();
    }
}
Also used : Statement(com.aerospike.client.query.Statement) RecordSet(com.aerospike.client.query.RecordSet) Key(com.aerospike.client.Key) Test(org.junit.Test)

Example 52 with RecordSet

use of com.aerospike.client.query.RecordSet in project aerospike-client-java by aerospike.

the class TestQueryString method queryString.

@Test
public void queryString() {
    String filter = valuePrefix + 3;
    Statement stmt = new Statement();
    stmt.setNamespace(args.namespace);
    stmt.setSetName(args.set);
    stmt.setBinNames(binName);
    stmt.setFilter(Filter.equal(binName, filter));
    RecordSet rs = client.query(null, stmt);
    try {
        int count = 0;
        while (rs.next()) {
            Record record = rs.getRecord();
            String result = record.getString(binName);
            assertEquals(filter, result);
            count++;
        }
        assertNotEquals(0, count);
    } finally {
        rs.close();
    }
}
Also used : Statement(com.aerospike.client.query.Statement) Record(com.aerospike.client.Record) RecordSet(com.aerospike.client.query.RecordSet) Test(org.junit.Test)

Example 53 with RecordSet

use of com.aerospike.client.query.RecordSet in project aerospike-client-java by aerospike.

the class TestQueryExecute method validateRecords.

private void validateRecords() {
    int begin = 1;
    int end = size + 100;
    Statement stmt = new Statement();
    stmt.setNamespace(args.namespace);
    stmt.setSetName(args.set);
    stmt.setFilter(Filter.range(binName1, begin, end));
    RecordSet rs = client.query(null, stmt);
    try {
        int[] expectedList = new int[] { 1, 2, 3, 104, 5, 106, 7, 108, -1, 10 };
        int expectedSize = size - 1;
        int count = 0;
        while (rs.next()) {
            Record record = rs.getRecord();
            int value1 = record.getInt(binName1);
            int value2 = record.getInt(binName2);
            int val1 = value1;
            if (val1 == 9) {
                fail("Data mismatch. value1 " + val1 + " should not exist");
            }
            if (val1 == 5) {
                if (value2 != 0) {
                    fail("Data mismatch. value2 " + value2 + " should be null");
                }
            } else if (value1 != expectedList[value2 - 1]) {
                fail("Data mismatch. Expected " + expectedList[value2 - 1] + ". Received " + value1);
            }
            count++;
        }
        assertEquals(expectedSize, count);
    } finally {
        rs.close();
    }
}
Also used : Statement(com.aerospike.client.query.Statement) Record(com.aerospike.client.Record) RecordSet(com.aerospike.client.query.RecordSet)

Example 54 with RecordSet

use of com.aerospike.client.query.RecordSet in project aerospike-client-java by aerospike.

the class TestQueryFilterExp method queryLastUpdate.

@Test
public void queryLastUpdate() {
    int begin = 10;
    int end = 45;
    Statement stmt = new Statement();
    stmt.setNamespace(args.namespace);
    stmt.setSetName(setName);
    stmt.setFilter(Filter.range(binName, begin, end));
    // record last update time > (currentTimeMillis() * 1000000L + 100)
    QueryPolicy policy = new QueryPolicy();
    policy.filterExp = Exp.build(Exp.gt(Exp.lastUpdate(), Exp.val(System.currentTimeMillis() * 1000000L + 100)));
    RecordSet rs = client.query(policy, stmt);
    try {
        while (rs.next()) {
        // Record record = rs.getRecord();
        // System.out.println(record.getValue(binName).toString() + ' ' + record.expiration);
        // count++;
        }
    // Do not asset count since some tests can run after this one.
    // assertEquals(0, count);
    } finally {
        rs.close();
    }
}
Also used : Statement(com.aerospike.client.query.Statement) RecordSet(com.aerospike.client.query.RecordSet) QueryPolicy(com.aerospike.client.policy.QueryPolicy) Test(org.junit.Test)

Example 55 with RecordSet

use of com.aerospike.client.query.RecordSet in project aerospike-client-java by aerospike.

the class TestQueryFilterExp method queryBinType.

@Test
public void queryBinType() {
    int begin = 1;
    int end = 10;
    Statement stmt = new Statement();
    stmt.setNamespace(args.namespace);
    stmt.setSetName(setName);
    stmt.setFilter(Filter.range(binName, begin, end));
    QueryPolicy policy = new QueryPolicy();
    policy.filterExp = Exp.build(Exp.eq(Exp.binType("listbin"), Exp.val(ParticleType.LIST)));
    RecordSet rs = client.query(policy, stmt);
    try {
        int count = 0;
        while (rs.next()) {
            count++;
        }
        assertEquals(9, count);
    } finally {
        rs.close();
    }
}
Also used : Statement(com.aerospike.client.query.Statement) RecordSet(com.aerospike.client.query.RecordSet) QueryPolicy(com.aerospike.client.policy.QueryPolicy) Test(org.junit.Test)

Aggregations

RecordSet (com.aerospike.client.query.RecordSet)65 Statement (com.aerospike.client.query.Statement)63 Test (org.junit.Test)43 QueryPolicy (com.aerospike.client.policy.QueryPolicy)28 Record (com.aerospike.client.Record)22 Key (com.aerospike.client.Key)9 AerospikeException (com.aerospike.client.AerospikeException)6 AerospikeClient (com.aerospike.client.AerospikeClient)4 ArrayList (java.util.ArrayList)3 GregorianCalendar (java.util.GregorianCalendar)3 Node (com.aerospike.client.cluster.Node)2 ExecuteTask (com.aerospike.client.task.ExecuteTask)2 Calendar (java.util.Calendar)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Bin (com.aerospike.client.Bin)1 Expression (com.aerospike.client.exp.Expression)1 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 AerospikeQueryResult (org.apache.gora.aerospike.query.AerospikeQueryResult)1