Search in sources :

Example 1 with Value

use of com.aerospike.client.Value in project aerospike-client-java by aerospike.

the class TestLargeList method runWithSerializedBin.

@Test
@SuppressWarnings("unchecked")
public void runWithSerializedBin() throws IOException {
    if (!args.validateLDT()) {
        return;
    }
    Key key = new Key(args.namespace, args.set, "accountId");
    // Delete record if it already exists.
    client.delete(null, key);
    // Initialize large list operator.
    LargeList list = client.getLargeList(null, key, "trades");
    // Write trades
    Map<String, Value> map = new HashMap<String, Value>();
    ByteArrayOutputStream byteStream = new ByteArrayOutputStream(500);
    DataOutputStream writer = new DataOutputStream(byteStream);
    Calendar timestamp1 = new GregorianCalendar(2014, 6, 25, 12, 18, 43);
    map.put("key", Value.get(timestamp1.getTimeInMillis()));
    // ticker
    writer.writeUTF("IBM");
    // qty
    writer.writeInt(100);
    // price
    writer.writeDouble(181.82);
    map.put("value", Value.get(byteStream.toByteArray()));
    list.add(Value.get(map));
    Calendar timestamp2 = new GregorianCalendar(2014, 6, 26, 9, 33, 17);
    map.put("key", Value.get(timestamp2.getTimeInMillis()));
    byteStream.reset();
    // ticker
    writer.writeUTF("GE");
    // qty
    writer.writeInt(500);
    // price
    writer.writeDouble(26.36);
    map.put("value", Value.get(byteStream.toByteArray()));
    list.add(Value.get(map));
    Calendar timestamp3 = new GregorianCalendar(2014, 6, 27, 14, 40, 19);
    map.put("key", Value.get(timestamp3.getTimeInMillis()));
    byteStream.reset();
    // ticker
    writer.writeUTF("AAPL");
    // qty
    writer.writeInt(75);
    // price
    writer.writeDouble(91.85);
    map.put("value", Value.get(byteStream.toByteArray()));
    list.add(Value.get(map));
    // Verify list size
    int size = list.size();
    assertEquals(3, size);
    // Filter on range of timestamps
    Calendar begin = new GregorianCalendar(2014, 6, 26);
    Calendar end = new GregorianCalendar(2014, 6, 28);
    List<Map<String, Object>> results = (List<Map<String, Object>>) list.range(Value.get(begin.getTimeInMillis()), Value.get(end.getTimeInMillis()));
    assertNotNull(results);
    assertEquals(2, results.size());
    // Verify data.
    validateWithSerializedBin(results, 0, timestamp2, "GE", 500, 26.36);
    validateWithSerializedBin(results, 1, timestamp3, "AAPL", 75, 91.85);
}
Also used : HashMap(java.util.HashMap) LargeList(com.aerospike.client.large.LargeList) DataOutputStream(java.io.DataOutputStream) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) GregorianCalendar(java.util.GregorianCalendar) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Value(com.aerospike.client.Value) ArrayList(java.util.ArrayList) LargeList(com.aerospike.client.large.LargeList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) Key(com.aerospike.client.Key) Test(org.junit.Test)

Example 2 with Value

use of com.aerospike.client.Value in project aerospike-client-java by aerospike.

the class InsertTaskSync method largeListAdd.

private void largeListAdd(Key key, Value value, long timestamp) {
    // Create entry
    Map<String, Value> entry = new HashMap<String, Value>();
    entry.put("key", Value.get(timestamp));
    entry.put("log", value);
    // Add entry
    LargeList list = client.getLargeList(args.writePolicy, key, "listltracker");
    list.add(Value.get(entry));
}
Also used : HashMap(java.util.HashMap) LargeList(com.aerospike.client.large.LargeList) Value(com.aerospike.client.Value)

Example 3 with Value

use of com.aerospike.client.Value in project aerospike-client-java by aerospike.

the class InsertTaskSync method largeStackPush.

private void largeStackPush(Key key, Value value, long timestamp) {
    // Create entry
    Map<String, Value> entry = new HashMap<String, Value>();
    entry.put("key", Value.get(timestamp));
    entry.put("log", value);
    // Push entry
    LargeStack lstack = client.getLargeStack(args.writePolicy, key, "stackltracker", null);
    lstack.push(Value.get(entry));
}
Also used : HashMap(java.util.HashMap) Value(com.aerospike.client.Value) LargeStack(com.aerospike.client.large.LargeStack)

Example 4 with Value

use of com.aerospike.client.Value in project aerospike-client-java by aerospike.

the class RWTaskSync method largeListAdd.

private void largeListAdd(Key key, Value value, long timestamp) {
    // Create entry
    Map<String, Value> entry = new HashMap<String, Value>();
    entry.put("key", Value.get(timestamp));
    entry.put("log", value);
    // Add entry
    LargeList list = client.getLargeList(args.writePolicy, key, "listltracker");
    list.add(Value.get(entry));
}
Also used : HashMap(java.util.HashMap) LargeList(com.aerospike.client.large.LargeList) Value(com.aerospike.client.Value)

Example 5 with Value

use of com.aerospike.client.Value in project aerospike-client-java by aerospike.

the class Command method parseKey.

protected final Key parseKey(int fieldCount) {
    byte[] digest = null;
    String namespace = null;
    String setName = null;
    Value userKey = null;
    for (int i = 0; i < fieldCount; i++) {
        int fieldlen = Buffer.bytesToInt(dataBuffer, dataOffset);
        dataOffset += 4;
        int fieldtype = dataBuffer[dataOffset++];
        int size = fieldlen - 1;
        switch(fieldtype) {
            case FieldType.DIGEST_RIPE:
                digest = new byte[size];
                System.arraycopy(dataBuffer, dataOffset, digest, 0, size);
                break;
            case FieldType.NAMESPACE:
                namespace = Buffer.utf8ToString(dataBuffer, dataOffset, size);
                break;
            case FieldType.TABLE:
                setName = Buffer.utf8ToString(dataBuffer, dataOffset, size);
                break;
            case FieldType.KEY:
                int type = dataBuffer[dataOffset++];
                size--;
                userKey = Buffer.bytesToKeyValue(type, dataBuffer, dataOffset, size);
                break;
        }
        dataOffset += size;
    }
    return new Key(namespace, digest, setName, userKey);
}
Also used : Value(com.aerospike.client.Value) Key(com.aerospike.client.Key)

Aggregations

Value (com.aerospike.client.Value)79 Key (com.aerospike.client.Key)61 Record (com.aerospike.client.Record)54 ArrayList (java.util.ArrayList)52 Test (org.junit.Test)50 HashMap (java.util.HashMap)40 List (java.util.List)32 Bin (com.aerospike.client.Bin)20 Map (java.util.Map)12 Collections.singletonList (java.util.Collections.singletonList)9 HLLValue (com.aerospike.client.Value.HLLValue)8 AerospikeException (com.aerospike.client.AerospikeException)5 StringValue (com.aerospike.client.Value.StringValue)5 ListPolicy (com.aerospike.client.cdt.ListPolicy)5 MapPolicy (com.aerospike.client.cdt.MapPolicy)5 LargeList (com.aerospike.client.large.LargeList)5 GregorianCalendar (java.util.GregorianCalendar)5 Calendar (java.util.Calendar)4 Entry (java.util.Map.Entry)4 CTX (com.aerospike.client.cdt.CTX)3