Search in sources :

Example 11 with RecordCursor

use of com.questdb.common.RecordCursor in project questdb by bluestreak01.

the class AbstractOptimiserTest method assertString.

protected void assertString(String query, int columnIndex) throws ParserException {
    try (RecordSource rs = compiler.compile(FACTORY_CONTAINER.getFactory(), query)) {
        RecordCursor cursor = rs.prepareCursor(FACTORY_CONTAINER.getFactory());
        try {
            while (cursor.hasNext()) {
                Record r = cursor.next();
                int len = r.getStrLen(columnIndex);
                CharSequence s = r.getFlyweightStr(columnIndex);
                if (s != null) {
                    CharSequence csB = r.getFlyweightStrB(columnIndex);
                    TestUtils.assertEquals(s, csB);
                    Assert.assertEquals(len, s.length());
                    Assert.assertFalse(s == csB);
                } else {
                    Assert.assertEquals(-1, len);
                    Assert.assertNull(r.getFlyweightStr(columnIndex));
                    Assert.assertNull(r.getFlyweightStrB(columnIndex));
                }
            }
        } finally {
            cursor.releaseCursor();
        }
    }
}
Also used : RecordSource(com.questdb.ql.RecordSource) RecordCursor(com.questdb.common.RecordCursor) Record(com.questdb.common.Record)

Example 12 with RecordCursor

use of com.questdb.common.RecordCursor in project questdb by bluestreak01.

the class AbstractOptimiserTest method assertSymbol.

public static void assertSymbol(String query, int columnIndex) throws ParserException {
    try (RecordSource src = compiler.compile(FACTORY_CONTAINER.getFactory(), query)) {
        RecordCursor cursor = src.prepareCursor(FACTORY_CONTAINER.getFactory());
        try {
            SymbolTable tab = cursor.getStorageFacade().getSymbolTable(columnIndex);
            while (cursor.hasNext()) {
                Record r = cursor.next();
                TestUtils.assertEquals(r.getSym(columnIndex), tab.value(r.getInt(columnIndex)));
            }
        } finally {
            cursor.releaseCursor();
        }
    }
}
Also used : RecordSource(com.questdb.ql.RecordSource) RecordCursor(com.questdb.common.RecordCursor) SymbolTable(com.questdb.common.SymbolTable) Record(com.questdb.common.Record)

Example 13 with RecordCursor

use of com.questdb.common.RecordCursor in project questdb by bluestreak01.

the class AsOfPartitionedJoinRecordSourceTest method testStrings.

@Test
public void testStrings() throws Exception {
    try (AsOfPartitionedJoinRecordSource source = new AsOfPartitionedJoinRecordSource(compileSource("y"), 0, new NoRowIdRecordSource().of(compileSource("x")), 0, keys, keys, 512, 512, 512, cc)) {
        StringSink testSink = new StringSink();
        int idx = source.getMetadata().getColumnIndex("trader");
        RecordCursor cursor = source.prepareCursor(FACTORY_CONTAINER.getFactory());
        try {
            for (Record r : cursor) {
                testSink.clear();
                r.getStr(idx, testSink);
                if (r.getFlyweightStr(idx) == null) {
                    Assert.assertTrue(testSink.length() == 0);
                } else {
                    TestUtils.assertEquals(r.getFlyweightStr(idx), testSink);
                }
                TestUtils.assertEquals(r.getFlyweightStr(idx), r.getFlyweightStr(idx));
            }
        } finally {
            cursor.releaseCursor();
        }
    }
}
Also used : RecordCursor(com.questdb.common.RecordCursor) StringSink(com.questdb.std.str.StringSink) Record(com.questdb.common.Record) AsOfPartitionedJoinRecordSource(com.questdb.ql.join.AsOfPartitionedJoinRecordSource) Test(org.junit.Test) AbstractOptimiserTest(com.questdb.parser.sql.AbstractOptimiserTest)

Example 14 with RecordCursor

use of com.questdb.common.RecordCursor in project questdb by bluestreak01.

the class DDLTests method testCast.

public void testCast(int from, int to) throws Exception {
    int n = 100;
    try (JournalWriter w1 = compiler.createWriter(getFactory(), "create table y (a " + ColumnType.nameOf(from) + ") record hint 100")) {
        Rnd rnd = new Rnd();
        for (int i = 0; i < n; i++) {
            JournalEntryWriter ew = w1.entryWriter();
            switch(from) {
                case ColumnType.INT:
                    ew.putInt(0, rnd.nextInt());
                    break;
                case ColumnType.LONG:
                    ew.putLong(0, rnd.nextLong());
                    break;
                case ColumnType.DATE:
                    ew.putDate(0, rnd.nextLong());
                    break;
                case ColumnType.BYTE:
                    ew.put(0, rnd.nextByte());
                    break;
                case ColumnType.SHORT:
                    ew.putShort(0, rnd.nextShort());
                    break;
                case ColumnType.FLOAT:
                    ew.putFloat(0, rnd.nextFloat());
                    break;
                case ColumnType.DOUBLE:
                    ew.putDouble(0, rnd.nextDouble());
                    break;
                case ColumnType.SYMBOL:
                    ew.putSym(0, rnd.nextChars(10));
                    break;
                case ColumnType.STRING:
                    ew.putStr(0, rnd.nextChars(10));
                    break;
                default:
                    break;
            }
            ew.append();
        }
        w1.commit();
    }
    exec("create table x as (y), cast(a as " + ColumnType.nameOf(to) + ") record hint 100");
    try (RecordSource rs = compiler.compile(getFactory(), "x")) {
        Rnd rnd = new Rnd();
        Assert.assertEquals(to, rs.getMetadata().getColumnQuick(0).getType());
        RecordCursor cursor = rs.prepareCursor(getFactory());
        try {
            while (cursor.hasNext()) {
                switch(from) {
                    case ColumnType.INT:
                        switch(to) {
                            case ColumnType.SHORT:
                                Assert.assertEquals((short) rnd.nextInt(), cursor.next().getShort(0));
                                break;
                            case ColumnType.LONG:
                                Assert.assertEquals((long) rnd.nextInt(), cursor.next().getLong(0));
                                break;
                            case ColumnType.BYTE:
                                Assert.assertEquals((byte) rnd.nextInt(), cursor.next().getByte(0));
                                break;
                            case ColumnType.FLOAT:
                                Assert.assertEquals((float) rnd.nextInt(), cursor.next().getFloat(0), 0.000000001f);
                                break;
                            case ColumnType.DOUBLE:
                                Assert.assertEquals((double) rnd.nextInt(), cursor.next().getDouble(0), 0.000000001);
                                break;
                            case ColumnType.DATE:
                                Assert.assertEquals((long) rnd.nextInt(), cursor.next().getDate(0));
                                break;
                            case ColumnType.INT:
                                Assert.assertEquals(rnd.nextInt(), cursor.next().getInt(0));
                                break;
                            default:
                                break;
                        }
                        break;
                    case ColumnType.LONG:
                    case ColumnType.DATE:
                        switch(to) {
                            case ColumnType.SHORT:
                                Assert.assertEquals((short) rnd.nextLong(), cursor.next().getShort(0));
                                break;
                            case ColumnType.LONG:
                                Assert.assertEquals(rnd.nextLong(), cursor.next().getLong(0));
                                break;
                            case ColumnType.BYTE:
                                Assert.assertEquals((byte) rnd.nextLong(), cursor.next().getByte(0));
                                break;
                            case ColumnType.FLOAT:
                                Assert.assertEquals((float) rnd.nextLong(), cursor.next().getFloat(0), 0.000000001f);
                                break;
                            case ColumnType.DOUBLE:
                                Assert.assertEquals((double) rnd.nextLong(), cursor.next().getDouble(0), 0.000000001);
                                break;
                            case ColumnType.DATE:
                                Assert.assertEquals(rnd.nextLong(), cursor.next().getDate(0));
                                break;
                            case ColumnType.INT:
                                Assert.assertEquals((int) rnd.nextLong(), cursor.next().getInt(0));
                                break;
                            default:
                                break;
                        }
                        break;
                    case ColumnType.BYTE:
                        switch(to) {
                            case ColumnType.SHORT:
                                Assert.assertEquals((short) rnd.nextByte(), cursor.next().getShort(0));
                                break;
                            case ColumnType.LONG:
                                Assert.assertEquals((long) rnd.nextByte(), cursor.next().getLong(0));
                                break;
                            case ColumnType.BYTE:
                                Assert.assertEquals(rnd.nextByte(), cursor.next().getByte(0));
                                break;
                            case ColumnType.FLOAT:
                                Assert.assertEquals((float) rnd.nextByte(), cursor.next().getFloat(0), 0.000000001f);
                                break;
                            case ColumnType.DOUBLE:
                                Assert.assertEquals((double) rnd.nextByte(), cursor.next().getDouble(0), 0.000000001);
                                break;
                            case ColumnType.DATE:
                                Assert.assertEquals((long) rnd.nextByte(), cursor.next().getDate(0));
                                break;
                            case ColumnType.INT:
                                Assert.assertEquals((int) rnd.nextByte(), cursor.next().getInt(0));
                                break;
                            default:
                                break;
                        }
                        break;
                    case ColumnType.SHORT:
                        switch(to) {
                            case ColumnType.SHORT:
                                Assert.assertEquals(rnd.nextShort(), cursor.next().getShort(0));
                                break;
                            case ColumnType.LONG:
                                Assert.assertEquals((long) rnd.nextShort(), cursor.next().getLong(0));
                                break;
                            case ColumnType.BYTE:
                                Assert.assertEquals((byte) rnd.nextShort(), cursor.next().getByte(0));
                                break;
                            case ColumnType.FLOAT:
                                Assert.assertEquals((float) rnd.nextShort(), cursor.next().getFloat(0), 0.000000001f);
                                break;
                            case ColumnType.DOUBLE:
                                Assert.assertEquals((double) rnd.nextShort(), cursor.next().getDouble(0), 0.000000001);
                                break;
                            case ColumnType.DATE:
                                Assert.assertEquals((long) rnd.nextShort(), cursor.next().getDate(0));
                                break;
                            case ColumnType.INT:
                                Assert.assertEquals((int) rnd.nextShort(), cursor.next().getInt(0));
                                break;
                            default:
                                break;
                        }
                        break;
                    case ColumnType.FLOAT:
                        switch(to) {
                            case ColumnType.SHORT:
                                Assert.assertEquals((short) rnd.nextFloat(), cursor.next().getShort(0));
                                break;
                            case ColumnType.LONG:
                                Assert.assertEquals((long) rnd.nextFloat(), cursor.next().getLong(0));
                                break;
                            case ColumnType.BYTE:
                                Assert.assertEquals((byte) rnd.nextFloat(), cursor.next().getByte(0));
                                break;
                            case ColumnType.FLOAT:
                                Assert.assertEquals(rnd.nextFloat(), cursor.next().getFloat(0), 0.000000001f);
                                break;
                            case ColumnType.DOUBLE:
                                Assert.assertEquals((double) rnd.nextFloat(), cursor.next().getDouble(0), 0.000000001);
                                break;
                            case ColumnType.DATE:
                                Assert.assertEquals((long) rnd.nextFloat(), cursor.next().getDate(0));
                                break;
                            case ColumnType.INT:
                                Assert.assertEquals((int) rnd.nextFloat(), cursor.next().getInt(0));
                                break;
                            default:
                                break;
                        }
                        break;
                    case ColumnType.DOUBLE:
                        switch(to) {
                            case ColumnType.SHORT:
                                Assert.assertEquals((short) rnd.nextDouble(), cursor.next().getShort(0));
                                break;
                            case ColumnType.LONG:
                                Assert.assertEquals((long) rnd.nextDouble(), cursor.next().getLong(0));
                                break;
                            case ColumnType.BYTE:
                                Assert.assertEquals((byte) rnd.nextDouble(), cursor.next().getByte(0));
                                break;
                            case ColumnType.FLOAT:
                                Assert.assertEquals((float) rnd.nextDouble(), cursor.next().getFloat(0), 0.000000001f);
                                break;
                            case ColumnType.DOUBLE:
                                Assert.assertEquals(rnd.nextDouble(), cursor.next().getDouble(0), 0.000000001);
                                break;
                            case ColumnType.DATE:
                                Assert.assertEquals((long) rnd.nextDouble(), cursor.next().getDate(0));
                                break;
                            case ColumnType.INT:
                                Assert.assertEquals((int) rnd.nextDouble(), cursor.next().getInt(0));
                                break;
                            default:
                                break;
                        }
                        break;
                    case ColumnType.STRING:
                        switch(to) {
                            case ColumnType.SYMBOL:
                                TestUtils.assertEquals(rnd.nextChars(10), cursor.next().getSym(0));
                                break;
                            default:
                                TestUtils.assertEquals(rnd.nextChars(10), cursor.next().getFlyweightStr(0));
                                break;
                        }
                        break;
                    case ColumnType.SYMBOL:
                        switch(to) {
                            case ColumnType.STRING:
                                TestUtils.assertEquals(rnd.nextChars(10), cursor.next().getFlyweightStr(0));
                                break;
                            default:
                                TestUtils.assertEquals(rnd.nextChars(10), cursor.next().getSym(0));
                                break;
                        }
                        break;
                    default:
                        break;
                }
            }
        } finally {
            cursor.releaseCursor();
        }
    }
}
Also used : JournalWriter(com.questdb.store.JournalWriter) RecordCursor(com.questdb.common.RecordCursor) JournalEntryWriter(com.questdb.store.JournalEntryWriter)

Example 15 with RecordCursor

use of com.questdb.common.RecordCursor in project questdb by bluestreak01.

the class MergingRowSourceTest method testHeapMerge.

@Test
public void testHeapMerge() throws JournalException, NumericException {
    try (JournalWriter<Quote> w = getFactory().writer(Quote.class)) {
        TestUtils.generateQuoteData(w, 100000, DateFormatUtils.parseDateTime("2014-02-11T00:00:00.000Z"), 10);
        RowSource srcA = new KvIndexSymLookupRowSource("sym", "BP.L", true);
        RowSource srcB = new KvIndexSymLookupRowSource("sym", "WTB.L", true);
        RecordSource rs = new JournalRecordSource(new JournalPartitionSource(w.getMetadata(), true), new HeapMergingRowSource(srcA, srcB));
        long last = 0;
        RecordCursor c = rs.prepareCursor(getFactory());
        try {
            int ts = rs.getMetadata().getColumnIndex("timestamp");
            while (c.hasNext()) {
                long r = c.next().getDate(ts);
                Assert.assertTrue(r > last);
                last = r;
            }
        } finally {
            c.releaseCursor();
        }
    }
}
Also used : Quote(com.questdb.model.Quote) RecordCursor(com.questdb.common.RecordCursor) KvIndexSymLookupRowSource(com.questdb.ql.latest.KvIndexSymLookupRowSource) HeapMergingRowSource(com.questdb.ql.latest.HeapMergingRowSource) KvIndexSymLookupRowSource(com.questdb.ql.latest.KvIndexSymLookupRowSource) MergingRowSource(com.questdb.ql.latest.MergingRowSource) HeapMergingRowSource(com.questdb.ql.latest.HeapMergingRowSource) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Aggregations

RecordCursor (com.questdb.common.RecordCursor)26 Record (com.questdb.common.Record)19 Test (org.junit.Test)14 RecordSource (com.questdb.ql.RecordSource)11 AbstractTest (com.questdb.test.tools.AbstractTest)7 JournalWriter (com.questdb.store.JournalWriter)6 JournalEntryWriter (com.questdb.store.JournalEntryWriter)5 RecordSourcePrinter (com.questdb.ql.RecordSourcePrinter)3 Rnd (com.questdb.std.Rnd)3 StringSink (com.questdb.std.str.StringSink)3 EntryLockedException (com.questdb.cairo.pool.ex.EntryLockedException)2 EntryUnavailableException (com.questdb.cairo.pool.ex.EntryUnavailableException)2 PoolClosedException (com.questdb.cairo.pool.ex.PoolClosedException)2 SymbolTable (com.questdb.common.SymbolTable)2 Quote (com.questdb.model.Quote)2 AbstractOptimiserTest (com.questdb.parser.sql.AbstractOptimiserTest)2 HeapMergingRowSource (com.questdb.ql.latest.HeapMergingRowSource)2 KvIndexSymLookupRowSource (com.questdb.ql.latest.KvIndexSymLookupRowSource)2 MergingRowSource (com.questdb.ql.latest.MergingRowSource)2 RedBlackTree (com.questdb.std.RedBlackTree)2