use of com.questdb.ql.join.CrossJoinRecordSource in project questdb by bluestreak01.
the class QueryCompiler method compileJoins.
private RecordSource compileJoins(QueryModel model, Factory factory) throws ParserException {
ObjList<QueryModel> joinModels = model.getJoinModels();
IntList ordered = model.getOrderedJoinModels();
RecordSource master = null;
try {
boolean needColumnNameHistogram = model.getColumns().size() > 0;
model.getColumnNameHistogram().clear();
for (int i = 0, n = ordered.size(); i < n; i++) {
int index = ordered.getQuick(i);
QueryModel m = joinModels.getQuick(index);
// compile
RecordSource slave = m.getRecordSource();
if (slave == null) {
slave = compileJournal(m, factory);
} else {
slave = filter(m, slave);
}
if (m.getAlias() != null) {
slave.getMetadata().setAlias(m.getAlias().token);
}
if (needColumnNameHistogram) {
model.createColumnNameHistogram(slave);
}
// check if this is the root of joins
if (master == null) {
// This is an opportunistic check of order by clause
// to determine if we can get away ordering main record source only
// Ordering main record source could benefit from rowid access thus
// making it faster compared to ordering of join record source that
// doesn't allow rowid access.
master = analyseAndCompileOrderBy(model, slave);
} else {
// not the root, join to "master"
switch(m.getJoinType()) {
case QueryModel.JOIN_CROSS:
// there are fields to analyse
master = new CrossJoinRecordSource(master, slave);
break;
case QueryModel.JOIN_ASOF:
master = createAsOfJoin(model.getTimestamp(), m, master, slave);
break;
default:
master = createHashJoin(m, master, slave);
break;
}
}
// check if there are post-filters
ExprNode filter = m.getPostJoinWhereClause();
if (filter != null) {
master = new FilteredRecordSource(master, virtualColumnBuilder.createVirtualColumn(model, filter, master.getMetadata()), filter);
}
}
if (joinModelIsFalse(model)) {
return new NoOpJournalRecordSource(master);
}
return master;
} catch (ParserException e) {
Misc.free(master);
throw e;
}
}
use of com.questdb.ql.join.CrossJoinRecordSource in project questdb by bluestreak01.
the class JoinStringToSymbolTest method testCrossJoin.
@Test
public void testCrossJoin() throws Exception {
bw.append(new Band().setName("band1").setType("rock").setUrl("http://band1.com"));
bw.append(new Band().setName("band2").setType("hiphop").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 BZ").setBand("band1").setGenre("rock"));
aw.append(new Album().setName("album Y").setBand("band3").setGenre("metal"));
aw.commit();
StringSink sink = new StringSink();
RecordSourcePrinter p = new RecordSourcePrinter(sink);
try (RecordSource rs = new CrossJoinRecordSource(new JournalRecordSource(new JournalPartitionSource(aw.getMetadata(), false), new AllRowSource()), new JournalRecordSource(new JournalPartitionSource(bw.getMetadata(), false), new AllRowSource()))) {
p.print(rs, getFactory());
}
final String expected = "band1\talbum X\tpop\t1970-01-01T00:00:00.000Z\t1970-01-01T00:00:00.000Z\tband1\thttp://band1.com\trock\t\n" + "band1\talbum X\tpop\t1970-01-01T00:00:00.000Z\t1970-01-01T00:00:00.000Z\tband2\thttp://band2.com\thiphop\t\n" + "band1\talbum X\tpop\t1970-01-01T00:00:00.000Z\t1970-01-01T00:00:00.000Z\tband3\thttp://band3.com\tjazz\t\n" + "band1\talbum X\tpop\t1970-01-01T00:00:00.000Z\t1970-01-01T00:00:00.000Z\tband1\thttp://new.band1.com\tjazz\t\n" + "band1\talbum BZ\trock\t1970-01-01T00:00:00.000Z\t1970-01-01T00:00:00.000Z\tband1\thttp://band1.com\trock\t\n" + "band1\talbum BZ\trock\t1970-01-01T00:00:00.000Z\t1970-01-01T00:00:00.000Z\tband2\thttp://band2.com\thiphop\t\n" + "band1\talbum BZ\trock\t1970-01-01T00:00:00.000Z\t1970-01-01T00:00:00.000Z\tband3\thttp://band3.com\tjazz\t\n" + "band1\talbum BZ\trock\t1970-01-01T00:00:00.000Z\t1970-01-01T00:00:00.000Z\tband1\thttp://new.band1.com\tjazz\t\n" + "band3\talbum Y\tmetal\t1970-01-01T00:00:00.000Z\t1970-01-01T00:00:00.000Z\tband1\thttp://band1.com\trock\t\n" + "band3\talbum Y\tmetal\t1970-01-01T00:00:00.000Z\t1970-01-01T00:00:00.000Z\tband2\thttp://band2.com\thiphop\t\n" + "band3\talbum Y\tmetal\t1970-01-01T00:00:00.000Z\t1970-01-01T00:00:00.000Z\tband3\thttp://band3.com\tjazz\t\n" + "band3\talbum Y\tmetal\t1970-01-01T00:00:00.000Z\t1970-01-01T00:00:00.000Z\tband1\thttp://new.band1.com\tjazz\t\n";
TestUtils.assertEquals(expected, sink);
}
Aggregations