Search in sources :

Example 1 with HashJoinRecordSource

use of com.questdb.ql.join.HashJoinRecordSource in project questdb by bluestreak01.

the class JoinQueryTest method testJoinNoRowid.

@Test
public void testJoinNoRowid() throws Exception {
    final String expected = "100\tPJFSREKEUNMKWOF\tUVKWCCVTJSKMXVEGPIG\t\tVMY\tRT\tEYYPDVRGRQG\t2015-07-10T00:00:00.100Z\t104281903\t100\t1138\tKWK\t2015-07-10T00:00:14.518Z\tFBLGGTZEN\n" + "100\tPJFSREKEUNMKWOF\tUVKWCCVTJSKMXVEGPIG\t\tVMY\tRT\tEYYPDVRGRQG\t2015-07-10T00:00:00.100Z\t1191623531\t100\t1210\tSR\t2015-07-10T00:00:18.175Z\tYM\n" + "100\tPJFSREKEUNMKWOF\tUVKWCCVTJSKMXVEGPIG\t\tVMY\tRT\tEYYPDVRGRQG\t2015-07-10T00:00:00.100Z\t1662742408\t100\t1828\tQH\t2015-07-10T00:00:19.509Z\tEYBI\n" + "100\tPJFSREKEUNMKWOF\tUVKWCCVTJSKMXVEGPIG\t\tVMY\tRT\tEYYPDVRGRQG\t2015-07-10T00:00:00.100Z\t220389\t100\t1293\tDGEEWB\t2015-07-10T00:00:56.196Z\tEYBI\n" + "100\tPJFSREKEUNMKWOF\tUVKWCCVTJSKMXVEGPIG\t\tVMY\tRT\tEYYPDVRGRQG\t2015-07-10T00:00:00.100Z\t798408721\t100\t803\tZIHLGS\t2015-07-10T00:00:56.977Z\tVTNNKVOLHLLNN\n" + "100\tPJFSREKEUNMKWOF\tUVKWCCVTJSKMXVEGPIG\t\tVMY\tRT\tEYYPDVRGRQG\t2015-07-10T00:00:00.100Z\t966974434\t100\t870\tJEOBQ\t2015-07-10T00:00:57.981Z\tW\n" + "100\tPJFSREKEUNMKWOF\tUVKWCCVTJSKMXVEGPIG\t\tVMY\tRT\tEYYPDVRGRQG\t2015-07-10T00:00:00.100Z\t258318715\t100\t1036\tOPWOGS\t2015-07-10T00:01:00.608Z\tEYBI\n" + "100\tPJFSREKEUNMKWOF\tUVKWCCVTJSKMXVEGPIG\t\tVMY\tRT\tEYYPDVRGRQG\t2015-07-10T00:00:00.100Z\t1528068156\t100\t400\tYBQE\t2015-07-10T00:01:20.643Z\tQXOLEEXZ\n" + "100\tPJFSREKEUNMKWOF\tUVKWCCVTJSKMXVEGPIG\t\tVMY\tRT\tEYYPDVRGRQG\t2015-07-10T00:00:00.100Z\t1935884354\t100\t1503\tD\t2015-07-10T00:01:43.507Z\tRZVZJQRNYSRKZSJ\n";
    final RecordSource m = compileSource("customers where customerName ~ 'PJFSREKEUNMKWOF'");
    final RecordSource s = new NoRowIdRecordSource().of(compileSource("orders"));
    RecordSource r = new HashJoinRecordSource(m, new IntList() {

        {
            add(m.getMetadata().getColumnIndex("customerId"));
        }
    }, s, new IntList() {

        {
            add(s.getMetadata().getColumnIndex("customerId"));
        }
    }, false, 4 * 1024 * 1024, 4 * 1024 * 1024, 1024 * 1024, new RecordKeyCopierCompiler(new BytecodeAssembler()));
    sink.clear();
    printer.print(r, FACTORY_CONTAINER.getFactory());
    TestUtils.assertEquals(expected, sink);
    assertThat(expected, "customers c join orders o on c.customerId = o.customerId where customerName ~ 'PJFSREKEUNMKWOF'");
}
Also used : NoRowIdRecordSource(com.questdb.ql.NoRowIdRecordSource) HashJoinRecordSource(com.questdb.ql.join.HashJoinRecordSource) RecordSource(com.questdb.ql.RecordSource) RecordKeyCopierCompiler(com.questdb.ql.map.RecordKeyCopierCompiler) HashJoinRecordSource(com.questdb.ql.join.HashJoinRecordSource) NoRowIdRecordSource(com.questdb.ql.NoRowIdRecordSource) Test(org.junit.Test)

Example 2 with HashJoinRecordSource

use of com.questdb.ql.join.HashJoinRecordSource 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 3 with HashJoinRecordSource

use of com.questdb.ql.join.HashJoinRecordSource 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 4 with HashJoinRecordSource

use of com.questdb.ql.join.HashJoinRecordSource 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)

Example 5 with HashJoinRecordSource

use of com.questdb.ql.join.HashJoinRecordSource in project questdb by bluestreak01.

the class QueryCompiler method createHashJoin.

private RecordSource createHashJoin(QueryModel model, RecordSource master, RecordSource slave) throws ParserException {
    JoinContext jc = model.getContext();
    RecordMetadata bm = master.getMetadata();
    RecordMetadata am = slave.getMetadata();
    IntList masterColIndices = null;
    IntList slaveColIndices = null;
    for (int k = 0, kn = jc.aIndexes.size(); k < kn; k++) {
        CharSequence ca = jc.aNames.getQuick(k);
        CharSequence cb = jc.bNames.getQuick(k);
        int ia = am.getColumnIndex(ca);
        int ib = bm.getColumnIndex(cb);
        if (am.getColumnQuick(ia).getType() != bm.getColumnQuick(ib).getType()) {
            Misc.free(master);
            Misc.free(slave);
            throw QueryError.$(jc.aNodes.getQuick(k).position, "Column type mismatch");
        }
        if (masterColIndices == null) {
            // these go together, so checking one for null is enough
            masterColIndices = new IntList();
            slaveColIndices = new IntList();
        }
        masterColIndices.add(ib);
        slaveColIndices.add(ia);
    }
    return new HashJoinRecordSource(master, masterColIndices, slave, slaveColIndices, model.getJoinType() == QueryModel.JOIN_OUTER, configuration.getDbHashKeyPage(), configuration.getDbHashDataPage(), configuration.getDbHashRowPage(), new RecordKeyCopierCompiler(new BytecodeAssembler()));
}
Also used : RecordKeyCopierCompiler(com.questdb.ql.map.RecordKeyCopierCompiler) FlyweightCharSequence(com.questdb.std.str.FlyweightCharSequence) HashJoinRecordSource(com.questdb.ql.join.HashJoinRecordSource)

Aggregations

HashJoinRecordSource (com.questdb.ql.join.HashJoinRecordSource)5 RecordKeyCopierCompiler (com.questdb.ql.map.RecordKeyCopierCompiler)5 Album (com.questdb.model.Album)3 Band (com.questdb.model.Band)3 SelectedColumnsRecordSource (com.questdb.ql.select.SelectedColumnsRecordSource)3 BytecodeAssembler (com.questdb.std.BytecodeAssembler)3 IntList (com.questdb.std.IntList)3 StringSink (com.questdb.std.str.StringSink)3 NoRowIdRecordSource (com.questdb.ql.NoRowIdRecordSource)1 RecordSource (com.questdb.ql.RecordSource)1 FlyweightCharSequence (com.questdb.std.str.FlyweightCharSequence)1 Test (org.junit.Test)1