Search in sources :

Example 1 with BytecodeAssembler

use of com.questdb.std.BytecodeAssembler in project questdb by bluestreak01.

the class HashJoinRecordSourceTest method testHashJoinRecordSource.

@Test
public void testHashJoinRecordSource() throws Exception {
    bw.append(new Band().setName("band1").setType("rock").setUrl("http://band1.com"));
    bw.append(new Band().setName("band2").setType("blues").setUrl("http://band2.com"));
    bw.append(new Band().setName("band3").setType("jazz").setUrl("http://band3.com"));
    bw.append(new Band().setName("band1").setType("jazz").setUrl("http://new.band1.com"));
    bw.commit();
    aw.append(new Album().setName("album X").setBand("band1").setGenre("pop"));
    aw.append(new Album().setName("album Y").setBand("band3").setGenre("metal"));
    aw.append(new Album().setName("album BZ").setBand("band1").setGenre("rock"));
    aw.commit();
    StringSink sink = new StringSink();
    RecordSourcePrinter p = new RecordSourcePrinter(sink);
    RecordSource joinResult = new SelectedColumnsRecordSource(new HashJoinRecordSource(new JournalRecordSource(new JournalPartitionSource(bw.getMetadata(), false), new AllRowSource()), new IntList() {

        {
            add(bw.getMetadata().getColumnIndex("name"));
        }
    }, new JournalRecordSource(new JournalPartitionSource(aw.getMetadata(), false), new AllRowSource()), new IntList() {

        {
            add(aw.getMetadata().getColumnIndex("band"));
        }
    }, false, 4 * 1024 * 1024, 4 * 1024 * 1024, 1024 * 1024, new RecordKeyCopierCompiler(new BytecodeAssembler())), new ObjList<CharSequence>() {

        {
            add("genre");
        }
    });
    p.print(joinResult, getFactory());
    Assert.assertEquals("pop\n" + "rock\n" + "metal\n" + "pop\n" + "rock\n", sink.toString());
}
Also used : Album(com.questdb.model.Album) Band(com.questdb.model.Band) StringSink(com.questdb.std.str.StringSink) HashJoinRecordSource(com.questdb.ql.join.HashJoinRecordSource) BytecodeAssembler(com.questdb.std.BytecodeAssembler) IntList(com.questdb.std.IntList) SelectedColumnsRecordSource(com.questdb.ql.select.SelectedColumnsRecordSource) HashJoinRecordSource(com.questdb.ql.join.HashJoinRecordSource) RecordKeyCopierCompiler(com.questdb.ql.map.RecordKeyCopierCompiler) SelectedColumnsRecordSource(com.questdb.ql.select.SelectedColumnsRecordSource)

Example 2 with BytecodeAssembler

use of com.questdb.std.BytecodeAssembler in project questdb by bluestreak01.

the class HashJoinRecordSourceTest method testHashJoinJournalRecordSource.

@Test
public void testHashJoinJournalRecordSource() throws Exception {
    bw.append(new Band().setName("band1").setType("rock").setUrl("http://band1.com"));
    bw.append(new Band().setName("band2").setType("blues").setUrl("http://band2.com"));
    bw.append(new Band().setName("band3").setType("jazz").setUrl("http://band3.com"));
    bw.append(new Band().setName("band1").setType("jazz").setUrl("http://new.band1.com"));
    bw.commit();
    aw.append(new Album().setName("album X").setBand("band1").setGenre("pop"));
    aw.append(new Album().setName("album Y").setBand("band3").setGenre("metal"));
    aw.append(new Album().setName("album BZ").setBand("band1").setGenre("rock"));
    aw.commit();
    StringSink sink = new StringSink();
    RecordSourcePrinter p = new RecordSourcePrinter(sink);
    RecordSource joinResult = new SelectedColumnsRecordSource(new HashJoinRecordSource(new JournalRecordSource(new JournalPartitionSource(bw.getMetadata(), false), new AllRowSource()), new IntList() {

        {
            add(bw.getMetadata().getColumnIndex("name"));
        }
    }, new JournalRecordSource(new JournalPartitionSource(aw.getMetadata(), false), new AllRowSource()), new IntList() {

        {
            add(aw.getMetadata().getColumnIndex("band"));
        }
    }, false, 4 * 1024 * 1024, 4 * 1024 * 1024, 1024 * 1024, new RecordKeyCopierCompiler(new BytecodeAssembler())), new ObjList<CharSequence>() {

        {
            add("genre");
        }
    });
    p.print(joinResult, getFactory());
    Assert.assertEquals("pop\n" + "rock\n" + "metal\n" + "pop\n" + "rock\n", sink.toString());
}
Also used : Album(com.questdb.model.Album) Band(com.questdb.model.Band) StringSink(com.questdb.std.str.StringSink) HashJoinRecordSource(com.questdb.ql.join.HashJoinRecordSource) BytecodeAssembler(com.questdb.std.BytecodeAssembler) IntList(com.questdb.std.IntList) SelectedColumnsRecordSource(com.questdb.ql.select.SelectedColumnsRecordSource) HashJoinRecordSource(com.questdb.ql.join.HashJoinRecordSource) RecordKeyCopierCompiler(com.questdb.ql.map.RecordKeyCopierCompiler) SelectedColumnsRecordSource(com.questdb.ql.select.SelectedColumnsRecordSource)

Example 3 with BytecodeAssembler

use of com.questdb.std.BytecodeAssembler in project questdb by bluestreak01.

the class RecordKeyCopierCompilerTest method testCompiler.

@Test
public void testCompiler() throws Exception {
    try (JournalWriter w = compiler.createWriter(FACTORY_CONTAINER.getFactory(), "create table x (a INT, b BYTE, c SHORT, d LONG, e FLOAT, f DOUBLE, g DATE, h BINARY, t DATE, x SYMBOL, z STRING, y BOOLEAN) timestamp(t) partition by MONTH record hint 100")) {
        JournalEntryWriter ew = w.entryWriter();
        IntList keyColumns = new IntList();
        ew.putInt(0, 12345);
        keyColumns.add(0);
        ew.put(1, (byte) 128);
        keyColumns.add(1);
        ew.putShort(2, (short) 6500);
        keyColumns.add(2);
        ew.putLong(3, 123456789);
        keyColumns.add(3);
        ew.putFloat(4, 0.345f);
        keyColumns.add(4);
        ew.putDouble(5, 0.123456789);
        keyColumns.add(5);
        ew.putDate(6, 10000000000L);
        keyColumns.add(6);
        ew.putSym(9, "xyz");
        keyColumns.add(9);
        ew.putStr(10, "abc");
        keyColumns.add(10);
        ew.putBool(11, true);
        keyColumns.add(11);
        ew.append();
        w.commit();
        try (RecordSource src = compileSource("x")) {
            RecordKeyCopierCompiler cc = new RecordKeyCopierCompiler(new BytecodeAssembler());
            RecordKeyCopier copier = cc.compile(src.getMetadata(), keyColumns);
            IntList valueTypes = new IntList();
            valueTypes.add(ColumnType.DOUBLE);
            MetadataTypeResolver metadataTypeResolver = new MetadataTypeResolver();
            TypeListResolver typeListResolver = new TypeListResolver();
            try (DirectMap map = new DirectMap(1024, metadataTypeResolver.of(src.getMetadata(), keyColumns), typeListResolver.of(valueTypes))) {
                RecordCursor cursor = src.prepareCursor(FACTORY_CONTAINER.getFactory());
                try {
                    while (cursor.hasNext()) {
                        Record r = cursor.next();
                        DirectMap.KeyWriter kw = map.keyWriter();
                        copier.copy(r, kw);
                        DirectMapValues val = map.getOrCreateValues();
                        val.putDouble(0, 5000.01);
                    }
                    cursor.toTop();
                    while (cursor.hasNext()) {
                        Record r = cursor.next();
                        DirectMap.KeyWriter kw = map.keyWriter();
                        copier.copy(r, kw);
                        Assert.assertEquals(map.getValues().getDouble(0), 5000.01, 0.00000001);
                    }
                } finally {
                    cursor.releaseCursor();
                }
            }
        }
    }
}
Also used : JournalWriter(com.questdb.store.JournalWriter) RecordCursor(com.questdb.common.RecordCursor) BytecodeAssembler(com.questdb.std.BytecodeAssembler) IntList(com.questdb.std.IntList) RecordSource(com.questdb.ql.RecordSource) Record(com.questdb.common.Record) JournalEntryWriter(com.questdb.store.JournalEntryWriter) Test(org.junit.Test) AbstractOptimiserTest(com.questdb.parser.sql.AbstractOptimiserTest)

Example 4 with BytecodeAssembler

use of com.questdb.std.BytecodeAssembler in project questdb by bluestreak01.

the class HashJoinRecordSourceTest method testOuterHashJoin.

@Test
public void testOuterHashJoin() throws Exception {
    bw.append(new Band().setName("band1").setType("rock").setUrl("http://band1.com"));
    bw.append(new Band().setName("band2").setType("blues").setUrl("http://band2.com"));
    bw.append(new Band().setName("band3").setType("jazz").setUrl("http://band3.com"));
    bw.append(new Band().setName("band1").setType("jazz").setUrl("http://new.band1.com"));
    bw.append(new Band().setName("band5").setType("jazz").setUrl("http://new.band5.com"));
    bw.commit();
    aw.append(new Album().setName("album X").setBand("band1").setGenre("pop"));
    aw.append(new Album().setName("album Y").setBand("band3").setGenre("metal"));
    aw.append(new Album().setName("album BZ").setBand("band1").setGenre("rock"));
    aw.commit();
    StringSink sink = new StringSink();
    RecordSourcePrinter p = new RecordSourcePrinter(sink);
    RecordSource joinResult = new SelectedColumnsRecordSource(new HashJoinRecordSource(new JournalRecordSource(new JournalPartitionSource(bw.getMetadata(), false), new AllRowSource()), new IntList() {

        {
            add(bw.getMetadata().getColumnIndex("name"));
        }
    }, new JournalRecordSource(new JournalPartitionSource(aw.getMetadata(), false), new AllRowSource()), new IntList() {

        {
            add(aw.getMetadata().getColumnIndex("band"));
        }
    }, true, 4 * 1024 * 1024, 4 * 1024 * 1024, 1024 * 1024, new RecordKeyCopierCompiler(new BytecodeAssembler())), new ObjList<CharSequence>() {

        {
            add("genre");
            add("url");
        }
    });
    p.print(joinResult, getFactory());
    Assert.assertEquals("pop\thttp://band1.com\n" + "rock\thttp://band1.com\n" + "\thttp://band2.com\n" + "metal\thttp://band3.com\n" + "pop\thttp://new.band1.com\n" + "rock\thttp://new.band1.com\n" + "\thttp://new.band5.com\n", sink.toString());
}
Also used : Album(com.questdb.model.Album) Band(com.questdb.model.Band) StringSink(com.questdb.std.str.StringSink) HashJoinRecordSource(com.questdb.ql.join.HashJoinRecordSource) BytecodeAssembler(com.questdb.std.BytecodeAssembler) IntList(com.questdb.std.IntList) SelectedColumnsRecordSource(com.questdb.ql.select.SelectedColumnsRecordSource) HashJoinRecordSource(com.questdb.ql.join.HashJoinRecordSource) RecordKeyCopierCompiler(com.questdb.ql.map.RecordKeyCopierCompiler) SelectedColumnsRecordSource(com.questdb.ql.select.SelectedColumnsRecordSource)

Aggregations

BytecodeAssembler (com.questdb.std.BytecodeAssembler)4 IntList (com.questdb.std.IntList)4 Album (com.questdb.model.Album)3 Band (com.questdb.model.Band)3 HashJoinRecordSource (com.questdb.ql.join.HashJoinRecordSource)3 RecordKeyCopierCompiler (com.questdb.ql.map.RecordKeyCopierCompiler)3 SelectedColumnsRecordSource (com.questdb.ql.select.SelectedColumnsRecordSource)3 StringSink (com.questdb.std.str.StringSink)3 Record (com.questdb.common.Record)1 RecordCursor (com.questdb.common.RecordCursor)1 AbstractOptimiserTest (com.questdb.parser.sql.AbstractOptimiserTest)1 RecordSource (com.questdb.ql.RecordSource)1 JournalEntryWriter (com.questdb.store.JournalEntryWriter)1 JournalWriter (com.questdb.store.JournalWriter)1 Test (org.junit.Test)1