Search in sources :

Example 1 with CairoEngine

use of com.questdb.cairo.sql.CairoEngine in project questdb by bluestreak01.

the class SqlLexerOptimiserTest method testTableNameCannotOpen.

@Test
public void testTableNameCannotOpen() {
    final FilesFacade ff = new FilesFacadeImpl() {

        @Override
        public long openRO(LPSZ name) {
            if (Chars.endsWith(name, TableUtils.META_FILE_NAME)) {
                return -1;
            }
            return super.openRO(name);
        }
    };
    CairoConfiguration configuration = new DefaultCairoConfiguration(root) {

        @Override
        public FilesFacade getFilesFacade() {
            return ff;
        }
    };
    CairoEngine engine = new Engine(configuration);
    SqlLexerOptimiser lexer = new SqlLexerOptimiser(engine, configuration);
    assertSyntaxError(lexer, engine, "select * from tab", 14, "Cannot open file", modelOf("tab").col("x", ColumnType.INT));
}
Also used : FilesFacade(com.questdb.std.FilesFacade) LPSZ(com.questdb.std.str.LPSZ) FilesFacadeImpl(com.questdb.std.FilesFacadeImpl) CairoEngine(com.questdb.cairo.sql.CairoEngine) CairoEngine(com.questdb.cairo.sql.CairoEngine) Test(org.junit.Test)

Example 2 with CairoEngine

use of com.questdb.cairo.sql.CairoEngine in project questdb by bluestreak01.

the class IntervalFrameCursorTest method testReload.

public void testReload(int partitionBy, long increment, LongList intervals, int rowCount, CharSequence expected1, CharSequence expected2) throws Exception {
    TestUtils.assertMemoryLeak(() -> {
        try (TableModel model = new TableModel(configuration, "x", partitionBy).col("a", ColumnType.SYMBOL).indexed(true, 4).col("b", ColumnType.SYMBOL).indexed(true, 4).timestamp()) {
            CairoTestUtils.create(model);
        }
        final Rnd rnd = new Rnd();
        long timestamp = DateFormatUtils.parseDateTime("1980-01-01T00:00:00.000Z");
        try (CairoEngine engine = new Engine(configuration)) {
            final TableReaderRecord record = new TableReaderRecord();
            final IntervalFrameCursorFactory factory = new IntervalFrameCursorFactory(engine, "x", intervals);
            try (DataFrameCursor cursor = factory.getCursor()) {
                // assert that there is nothing to start with
                record.of(cursor.getReader());
                assertEquals("", record, cursor);
                try (TableWriter writer = new TableWriter(configuration, "x")) {
                    for (int i = 0; i < rowCount; i++) {
                        TableWriter.Row row = writer.newRow(timestamp);
                        row.putSym(0, rnd.nextChars(4));
                        row.putSym(1, rnd.nextChars(4));
                        row.append();
                        timestamp += increment;
                    }
                    writer.commit();
                    Assert.assertTrue(cursor.reload());
                    assertEquals(expected1, record, cursor);
                    timestamp = Dates.addYear(timestamp, 3);
                    for (int i = 0; i < rowCount; i++) {
                        TableWriter.Row row = writer.newRow(timestamp);
                        row.putSym(0, rnd.nextChars(4));
                        row.putSym(1, rnd.nextChars(4));
                        row.append();
                        timestamp += increment;
                    }
                    writer.commit();
                    Assert.assertTrue(cursor.reload());
                    if (expected2 != null) {
                        assertEquals(expected2, record, cursor);
                    } else {
                        assertEquals(expected1, record, cursor);
                    }
                    Assert.assertFalse(cursor.reload());
                }
            }
        }
    });
}
Also used : DataFrameCursor(com.questdb.cairo.sql.DataFrameCursor) Rnd(com.questdb.std.Rnd) CairoEngine(com.questdb.cairo.sql.CairoEngine) CairoEngine(com.questdb.cairo.sql.CairoEngine)

Aggregations

CairoEngine (com.questdb.cairo.sql.CairoEngine)2 DataFrameCursor (com.questdb.cairo.sql.DataFrameCursor)1 FilesFacade (com.questdb.std.FilesFacade)1 FilesFacadeImpl (com.questdb.std.FilesFacadeImpl)1 Rnd (com.questdb.std.Rnd)1 LPSZ (com.questdb.std.str.LPSZ)1 Test (org.junit.Test)1