Search in sources :

Example 1 with MapRecord

use of org.nustaq.reallive.records.MapRecord in project kontraktor by RuedigerMoeller.

the class Basic method testTableSpace.

@Test
public void testTableSpace() {
    TableSpaceActor ts = Actors.AsActor(TableSpaceActor.class);
    ts.init();
    ts.createOrLoadTable(new TableDescription("blogs").numEntries(500_000).storageType(TableDescription.StorageType.TEMP).sizeMB(500)).await();
    ts.createOrLoadTable(new TableDescription("articles").numEntries(500_000 * 10).storageType(TableDescription.StorageType.TEMP).sizeMB(500 * 10)).await();
    RealLiveTable blogs = ts.getTableAsync("blogs").await();
    RealLiveTable articles = ts.getTableAsync("articles").await();
    int numBP = 30_000;
    for (int i = 0; i < numBP; i++) {
        MapRecord blogEntry = MapRecord.New("blog" + i);
        blogEntry.put("title", "Java is beautiful").put("description", "High performance Java, realtime distributed computing, other stuff").put("tags", "#tech #java #distributed #actors #concurrency #webcomponents #realtime").put("author", "R.Moeller").put("likes", 199).put("reads", 3485).put("sequence", i);
        blogs.addRecord(blogEntry);
    }
    System.out.println("finished blogs");
    for (int i = 0; i < numBP * 10; i++) {
        MapRecord article = MapRecord.New("art" + i);
        // article
        // .putRecord("title", "WebComponents BLabla")
        // .putRecord("description", "High performance Java, realtime distributed computing, other stuff")
        // .putRecord("tags", "#tech #java #distributed #actors #concurrency #webcomponents #realtime")
        // .putRecord("author", "R.Moeller")
        // .putRecord("likes", 199)
        // .putRecord("reads", 3485)
        // .putRecord("blog", "blog"+i)
        // .putRecord("date", new Date() );
        article.put("tags", new String[] { "#tech", "#java2", "#distributed", "#actors", "#concurrency", "#webcomponents", "#realtime" }).put("likes", 199).put("reads", 3485).put("blog", "blog" + i).put("date", System.currentTimeMillis());
        articles.addRecord(article);
    }
    System.out.println("finished articles");
    // while( true )
    {
        long tim = System.currentTimeMillis();
        AtomicInteger counter = new AtomicInteger(0);
        blogs.forEachWithSpore(new FilterSpore(record -> record.getKey().indexOf("99") >= 0).setForEach((r, e) -> {
        }));
        blogs.ping().await();
        System.out.println("time blo " + (System.currentTimeMillis() - tim));
        System.out.println("hits:" + counter.get());
        counter.set(0);
        tim = System.currentTimeMillis();
        articles.forEachWithSpore(new FilterSpore(record -> record.getKey().indexOf("999") >= 0).setForEach((r, e) -> {
        }));
        articles.ping().await();
        System.out.println("time art " + (System.currentTimeMillis() - tim));
        System.out.println("hits:" + counter.get());
    }
// ts.shutDown();
}
Also used : IntStream(java.util.stream.IntStream) org.nustaq.reallive.api(org.nustaq.reallive.api) TableSpaceActor(org.nustaq.reallive.impl.tablespace.TableSpaceActor) Iterator(java.util.Iterator) Test(org.junit.Test) Promise(org.nustaq.kontraktor.Promise) PromiseLatch(org.nustaq.kontraktor.util.PromiseLatch) TableSharding(org.nustaq.reallive.impl.actors.TableSharding) org.nustaq.reallive.impl.storage(org.nustaq.reallive.impl.storage) MapRecord(org.nustaq.reallive.records.MapRecord) IPromise(org.nustaq.kontraktor.IPromise) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) org.nustaq.reallive.impl(org.nustaq.reallive.impl) Map(java.util.Map) Actor(org.nustaq.kontraktor.Actor) Actors(org.nustaq.kontraktor.Actors) ShardFunc(org.nustaq.reallive.impl.actors.ShardFunc) RealLiveTableActor(org.nustaq.reallive.impl.actors.RealLiveTableActor) MapRecord(org.nustaq.reallive.records.MapRecord) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TableSpaceActor(org.nustaq.reallive.impl.tablespace.TableSpaceActor) Test(org.junit.Test)

Example 2 with MapRecord

use of org.nustaq.reallive.records.MapRecord in project kontraktor by RuedigerMoeller.

the class Parser method main.

public static void main(String[] args) throws Throwable {
    // Parser p = Query.newParser();
    // CompiledQuery compile = p.compile("test == 'hallo' && a < 101 && a <= 100 && b > 199 && b >= 200 && a+b == 300 && !0");
    // 
    MapRecord hm = MapRecord.New("key").put("test", "hallo").put("a", 100).put("c", -1).put("time", System.currentTimeMillis()).put("b", 200);
    Thread.sleep(2000);
    CompiledQuery nums = Query.compile("c!= -1");
    System.out.println(nums.evaluate(hm));
    if (1 != 0)
        return;
    CompiledQuery ctrue = Query.compile("time < age(1,\"sec\")");
    CompiledQuery cfalse = Query.compile("time < age(5,'sec')");
    CompiledQuery tim = Query.compile("a<1000000000");
    System.out.println(ctrue.evaluate(hm));
    System.out.println(cfalse.evaluate(hm));
    System.out.println(tim.evaluate(hm));
// 
// System.out.println(
// compile.evaluate(hm)
// );
// System.out.println(Query.eval(" lower('HELLO'+'O')+'O' ",null));
// System.out.println(Query.eval("lower('HELLO'+'O')", null));
// System.out.println(Query.compile("3 * -3").evaluate(null));
// System.out.println(Query.compile("3555 ** 55").evaluate(null));
// System.out.println(Query.compile("'RuedI' ** 'dii'").evaluate(null));
// while( true ) {
// long now = System.currentTimeMillis();
// int cnt = 0;
// while( System.currentTimeMillis() - now < 1000 ) {
// compile.evaluate(hm);
// cnt++;
// }
// System.out.println("COUNT: "+cnt);
// }
}
Also used : MapRecord(org.nustaq.reallive.records.MapRecord)

Example 3 with MapRecord

use of org.nustaq.reallive.records.MapRecord in project kontraktor by RuedigerMoeller.

the class Record method rec.

/**
 * creates and sets an empty record in case
 * @param field
 * @return
 */
default Record rec(String field) {
    Object val = get(field);
    if (val == null) {
        MapRecord aNew = MapRecord.New(null);
        put(field, aNew);
        return aNew;
    }
    return (Record) val;
}
Also used : MapRecord(org.nustaq.reallive.records.MapRecord) MapRecord(org.nustaq.reallive.records.MapRecord)

Example 4 with MapRecord

use of org.nustaq.reallive.records.MapRecord in project kontraktor by RuedigerMoeller.

the class Record method reduced.

default Record reduced(String[] reducedFields) {
    MapRecord rec = MapRecord.New(getKey());
    for (int i = 0; i < reducedFields.length; i++) {
        String reducedField = reducedFields[i];
        Object val = get(reducedField);
        if (val != null) {
            rec.put(reducedField, val);
        }
    }
    return rec;
}
Also used : MapRecord(org.nustaq.reallive.records.MapRecord)

Aggregations

MapRecord (org.nustaq.reallive.records.MapRecord)4 Iterator (java.util.Iterator)1 Map (java.util.Map)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 IntStream (java.util.stream.IntStream)1 Test (org.junit.Test)1 Actor (org.nustaq.kontraktor.Actor)1 Actors (org.nustaq.kontraktor.Actors)1 IPromise (org.nustaq.kontraktor.IPromise)1 Promise (org.nustaq.kontraktor.Promise)1 PromiseLatch (org.nustaq.kontraktor.util.PromiseLatch)1 org.nustaq.reallive.api (org.nustaq.reallive.api)1 org.nustaq.reallive.impl (org.nustaq.reallive.impl)1 RealLiveTableActor (org.nustaq.reallive.impl.actors.RealLiveTableActor)1 ShardFunc (org.nustaq.reallive.impl.actors.ShardFunc)1 TableSharding (org.nustaq.reallive.impl.actors.TableSharding)1 org.nustaq.reallive.impl.storage (org.nustaq.reallive.impl.storage)1 TableSpaceActor (org.nustaq.reallive.impl.tablespace.TableSpaceActor)1