use of com.questdb.std.str.StringSink 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);
}
use of com.questdb.std.str.StringSink in project questdb by bluestreak01.
the class MultiIntervalPartitionSourceTest method testIntervalMerge.
@Test
public void testIntervalMerge() throws Exception {
StringSink sink = new StringSink();
try (JournalWriter<Quote> w = getFactory().writer(Quote.class)) {
TestUtils.generateQuoteData(w, 600, DateFormatUtils.parseDateTime("2014-03-10T02:00:00.000Z"), Dates.MINUTE_MILLIS);
w.commit();
RecordSourcePrinter p = new RecordSourcePrinter(sink);
LongList intervals = new LongList();
intervals.add(DateFormatUtils.parseDateTime("2014-03-10T07:00:00.000Z"));
intervals.add(DateFormatUtils.parseDateTime("2014-03-10T07:15:00.000Z"));
p.print(new JournalRecordSource(new MultiIntervalPartitionSource(new JournalPartitionSource(w.getMetadata(), true), intervals), new AllRowSource()), getFactory());
}
final String expected = "2014-03-10T07:00:00.000Z\tGKN.L\t290.000000000000\t320.000000000000\t1070060020\t627764827\tFast trading\tLXE\n" + "2014-03-10T07:01:00.000Z\tLLOY.L\t0.001271238521\t0.000000010817\t855783502\t444545168\tFast trading\tLXE\n" + "2014-03-10T07:02:00.000Z\tRRS.L\t0.000010917804\t272.000000000000\t1212565949\t1829154977\tFast trading\tLXE\n" + "2014-03-10T07:03:00.000Z\tTLW.L\t245.300086975098\t363.160156250000\t1722093204\t448833342\tFast trading\tLXE\n" + "2014-03-10T07:04:00.000Z\tTLW.L\t0.025095539168\t0.000000122058\t1703832336\t180642477\tFast trading\tLXE\n" + "2014-03-10T07:05:00.000Z\tADM.L\t902.500000000000\t24.333267211914\t781438951\t502201118\tFast trading\tLXE\n" + "2014-03-10T07:06:00.000Z\tAGK.L\t144.695419311523\t0.000039814179\t639071723\t1848238665\tFast trading\tLXE\n" + "2014-03-10T07:07:00.000Z\tLLOY.L\t0.000035416079\t15.248794555664\t1987214795\t856360285\tFast trading\tLXE\n" + "2014-03-10T07:08:00.000Z\tAGK.L\t0.207015849650\t0.199165701866\t1090730005\t1076974002\tFast trading\tLXE\n" + "2014-03-10T07:09:00.000Z\tLLOY.L\t447.510742187500\t209.001678466797\t136979290\t653726755\tFast trading\tLXE\n" + "2014-03-10T07:10:00.000Z\tBT-A.L\t662.032958984375\t0.000000007138\t1140333902\t1156896957\tFast trading\tLXE\n" + "2014-03-10T07:11:00.000Z\tAGK.L\t512.000000000000\t33.973937988281\t1723438228\t349327821\tFast trading\tLXE\n" + "2014-03-10T07:12:00.000Z\tWTB.L\t384.000000000000\t0.000000832384\t2145991300\t1388483923\tFast trading\tLXE\n" + "2014-03-10T07:13:00.000Z\tTLW.L\t0.000000093063\t0.000071085584\t1186156647\t1143726003\tFast trading\tLXE\n" + "2014-03-10T07:14:00.000Z\tAGK.L\t0.006215140224\t0.000000004051\t2086874501\t1272052914\tFast trading\tLXE\n" + "2014-03-10T07:15:00.000Z\tBP.L\t642.189208984375\t148.932441711426\t1552494421\t348870719\tFast trading\tLXE\n";
Assert.assertEquals(expected, sink.toString());
}
use of com.questdb.std.str.StringSink in project questdb by bluestreak01.
the class TableReaderMetadataTest method assertThat.
private void assertThat(String expected, ColumnManipulator manipulator, int columnCount) throws Exception {
TestUtils.assertMemoryLeak(() -> {
try (Path path = new Path().of(root).concat("all")) {
try (TableReaderMetadata metadata = new TableReaderMetadata(FilesFacadeImpl.INSTANCE, "all", path.concat(TableUtils.META_FILE_NAME).$())) {
try (TableWriter writer = new TableWriter(configuration, "all")) {
manipulator.restructure(writer);
}
long pTranstionIndex = metadata.createTransitionIndex();
StringSink sink = new StringSink();
try {
metadata.applyTransitionIndex(pTranstionIndex);
Assert.assertEquals(columnCount, metadata.getColumnCount());
for (int i = 0; i < columnCount; i++) {
RecordColumnMetadata m = metadata.getColumnQuick(i);
sink.put(m.getName()).put(':').put(ColumnType.nameOf(m.getType())).put('\n');
}
TestUtils.assertEquals(expected, sink);
if (expected.length() > 0) {
String[] lines = expected.split("\n");
Assert.assertEquals(columnCount, lines.length);
for (int i = 0; i < columnCount; i++) {
int p = lines[i].indexOf(':');
Assert.assertEquals(i, metadata.getColumnIndexQuiet(lines[i].substring(0, p)));
}
}
} finally {
TableReaderMetadata.freeTransitionIndex(pTranstionIndex);
}
}
}
});
}
use of com.questdb.std.str.StringSink in project questdb by bluestreak01.
the class TableReaderMetadataTimestampTest method assertThat.
private void assertThat(String expected, int expectedInitialTimestampIndex) throws Exception {
int columnCount = 11;
TestUtils.assertMemoryLeak(() -> {
try (Path path = new Path().of(root).concat("all")) {
try (TableReaderMetadata metadata = new TableReaderMetadata(FilesFacadeImpl.INSTANCE, "all", path.concat(TableUtils.META_FILE_NAME).$())) {
Assert.assertEquals(12, metadata.getColumnCount());
Assert.assertEquals(expectedInitialTimestampIndex, metadata.getTimestampIndex());
try (TableWriter writer = new TableWriter(configuration, "all")) {
writer.removeColumn("timestamp");
}
long pTransitionIndex = metadata.createTransitionIndex();
StringSink sink = new StringSink();
try {
metadata.applyTransitionIndex(pTransitionIndex);
Assert.assertEquals(columnCount, metadata.getColumnCount());
for (int i = 0; i < columnCount; i++) {
RecordColumnMetadata m = metadata.getColumnQuick(i);
sink.put(m.getName()).put(':').put(ColumnType.nameOf(m.getType())).put('\n');
}
TestUtils.assertEquals(expected, sink);
Assert.assertEquals(-1, metadata.getTimestampIndex());
} finally {
TableReaderMetadata.freeTransitionIndex(pTransitionIndex);
}
}
}
});
}
use of com.questdb.std.str.StringSink in project questdb by bluestreak01.
the class TableReaderMetadataTimestampTest method assertThatTimestampRemains.
private void assertThatTimestampRemains(TableReaderMetadataTest.ColumnManipulator manipulator, String expected, int expectedInitialTimestampIndex, int expectedFinalTimestampIndex, int expectedColumnCount) throws Exception {
TestUtils.assertMemoryLeak(() -> {
try (Path path = new Path().of(root).concat("all")) {
try (TableReaderMetadata metadata = new TableReaderMetadata(FilesFacadeImpl.INSTANCE, "all", path.concat(TableUtils.META_FILE_NAME).$())) {
Assert.assertEquals(12, metadata.getColumnCount());
Assert.assertEquals(expectedInitialTimestampIndex, metadata.getTimestampIndex());
try (TableWriter writer = new TableWriter(configuration, "all")) {
manipulator.restructure(writer);
}
long address = metadata.createTransitionIndex();
StringSink sink = new StringSink();
try {
metadata.applyTransitionIndex(address);
Assert.assertEquals(expectedColumnCount, metadata.getColumnCount());
for (int i = 0; i < expectedColumnCount; i++) {
RecordColumnMetadata m = metadata.getColumnQuick(i);
sink.put(m.getName()).put(':').put(ColumnType.nameOf(m.getType())).put('\n');
}
TestUtils.assertEquals(expected, sink);
Assert.assertEquals(expectedFinalTimestampIndex, metadata.getTimestampIndex());
} finally {
TableReaderMetadata.freeTransitionIndex(address);
}
}
}
});
}
Aggregations