Search in sources :

Example 96 with TableWriter

use of io.questdb.cairo.TableWriter in project questdb by bluestreak01.

the class RemovePartitionTest method testRemoveSeveralFromTop.

@Test
public void testRemoveSeveralFromTop() throws Exception {
    assertMemoryLeak(() -> {
        compiler.compile("create table tst as (select * from (select rnd_int() a, rnd_double() b, timestamp_sequence(0, 1000000000l) t from long_sequence(1000)) timestamp (t)) timestamp(t) partition by DAY", sqlExecutionContext);
        try (TableReader reader = engine.getReader(sqlExecutionContext.getCairoSecurityContext(), "tst");
            TableWriter writer = engine.getWriter(sqlExecutionContext.getCairoSecurityContext(), "tst", "testing")) {
            // utilise reader fully
            RecordCursor cursor = reader.getCursor();
            final Record record = cursor.getRecord();
            double superSum = 0;
            while (cursor.hasNext()) {
                superSum = record.getInt(0) + record.getDouble(1) + record.getTimestamp(1);
            }
            Assert.assertEquals(4.6023174787925821E18, superSum, 0.00001);
            reader.reload();
            long timestampToDelete = 0;
            for (int i = 0; i < 10; i++) {
                writer.removePartition(timestampToDelete + (i * Timestamps.DAY_MICROS));
            }
            writer.commit();
            reader.reload();
            cursor.toTop();
            String expectedAfterPartitionDelete = "a\tb\tt\n" + "1576838676\t0.08057877795249069\t1970-01-11T00:00:00.000000Z\n" + "-684086147\t0.3806487278648183\t1970-01-11T00:16:40.000000Z\n" + "-689922587\t0.2698247661309793\t1970-01-11T00:33:20.000000Z\n" + "-1918552401\t0.4531424919285716\t1970-01-11T00:50:00.000000Z\n" + "-1004453257\t0.6085797228669808\t1970-01-11T01:06:40.000000Z\n" + "-765083634\t0.4524050162454656\t1970-01-11T01:23:20.000000Z\n" + "316094146\t0.12003762630199555\t1970-01-11T01:40:00.000000Z\n" + "1068342573\t0.7082464127490494\t1970-01-11T01:56:40.000000Z\n" + "-864537248\t0.1040698566401328\t1970-01-11T02:13:20.000000Z\n" + "1543752250\t0.18600146920290805\t1970-01-11T02:30:00.000000Z\n" + "-890802851\t0.22928529042164025\t1970-01-11T02:46:40.000000Z\n" + "1672937587\t0.8520295549109822\t1970-01-11T03:03:20.000000Z\n" + "-98437117\t0.26682634958461626\t1970-01-11T03:20:00.000000Z\n" + "1278648509\t0.4121046775544003\t1970-01-11T03:36:40.000000Z\n" + "868935708\t0.05009031512448925\t1970-01-11T03:53:20.000000Z\n" + "1553180848\t0.7109170062462249\t1970-01-11T04:10:00.000000Z\n" + "1608930002\t0.9886838651440645\t1970-01-11T04:26:40.000000Z\n" + "848077524\t0.29684625166336664\t1970-01-11T04:43:20.000000Z\n" + "-872317779\t0.9455731567461921\t1970-01-11T05:00:00.000000Z\n" + "-2142917800\t0.16525810396139984\t1970-01-11T05:16:40.000000Z\n" + "1060889076\t0.5173940547749024\t1970-01-11T05:33:20.000000Z\n" + "1185624407\t0.7544676970803467\t1970-01-11T05:50:00.000000Z\n" + "-1677723040\t0.13986493405162936\t1970-01-11T06:06:40.000000Z\n" + "852766828\t0.49324528227010966\t1970-01-11T06:23:20.000000Z\n" + "841483165\t0.11070938825827936\t1970-01-11T06:40:00.000000Z\n" + "-1155434911\t0.00978072311811784\t1970-01-11T06:56:40.000000Z\n" + "1362727008\t0.44599963282948984\t1970-01-11T07:13:20.000000Z\n" + "1192991824\t0.3659276421170724\t1970-01-11T07:30:00.000000Z\n" + "1556431414\t0.026301401183052797\t1970-01-11T07:46:40.000000Z\n" + "32338029\t0.08328091072953259\t1970-01-11T08:03:20.000000Z\n" + "-1097218488\t0.06790969300705241\t1970-01-11T08:20:00.000000Z\n" + "-499968873\t0.2615339514777504\t1970-01-11T08:36:40.000000Z\n" + "-1874709376\t0.45771492702062366\t1970-01-11T08:53:20.000000Z\n" + "319944829\t0.20406886183355866\t1970-01-11T09:10:00.000000Z\n" + "772080999\t0.27575788473179963\t1970-01-11T09:26:40.000000Z\n" + "16459753\t0.6409584133875881\t1970-01-11T09:43:20.000000Z\n" + "1290921378\t0.2713721519500688\t1970-01-11T10:00:00.000000Z\n" + "375593536\t0.04336526294979903\t1970-01-11T10:16:40.000000Z\n" + "1952855598\t0.4083056333675016\t1970-01-11T10:33:20.000000Z\n" + "561962643\t0.7736395764837526\t1970-01-11T10:50:00.000000Z\n" + "-1776012188\t0.17405527561965717\t1970-01-11T11:06:40.000000Z\n" + "1399730601\t0.3854235867370095\t1970-01-11T11:23:20.000000Z\n" + "1499465486\t0.37563375709147684\t1970-01-11T11:40:00.000000Z\n" + "850982263\t0.41258159186565424\t1970-01-11T11:56:40.000000Z\n" + "-1211498921\t0.4217546132070882\t1970-01-11T12:13:20.000000Z\n" + "-518985515\t0.23889505021865998\t1970-01-11T12:30:00.000000Z\n" + "1478600023\t0.5340640161021565\t1970-01-11T12:46:40.000000Z\n" + "-757643200\t0.7700469744126617\t1970-01-11T13:03:20.000000Z\n" + "91266345\t0.6601629127014469\t1970-01-11T13:20:00.000000Z\n" + "956610416\t0.9778843606510285\t1970-01-11T13:36:40.000000Z\n" + "-1444192781\t0.06585925388777292\t1970-01-11T13:53:20.000000Z\n" + "701841024\t0.6670228450708864\t1970-01-11T14:10:00.000000Z\n" + "1863548118\t0.4653998788482615\t1970-01-11T14:26:40.000000Z\n" + "1444864868\t0.41265788151170835\t1970-01-11T14:43:20.000000Z\n" + "1797835122\t0.1914161844876806\t1970-01-11T15:00:00.000000Z\n" + "-1812360042\t0.5469257570499296\t1970-01-11T15:16:40.000000Z\n" + "-1982095870\t0.20869523440218085\t1970-01-11T15:33:20.000000Z\n" + "-1040917954\t0.47046214502342254\t1970-01-11T15:50:00.000000Z\n" + "1558850992\t0.5277233818830627\t1970-01-11T16:06:40.000000Z\n" + "-519239966\t0.2263345107996424\t1970-01-11T16:23:20.000000Z\n" + "1700554356\t0.8375723114173276\t1970-01-11T16:40:00.000000Z\n" + "-1734368808\t0.2973413048547613\t1970-01-11T16:56:40.000000Z\n" + "-251197254\t0.02206807161850266\t1970-01-11T17:13:20.000000Z\n" + "1967503676\t0.7708094983496303\t1970-01-11T17:30:00.000000Z\n" + "171793346\t0.7774992993301526\t1970-01-11T17:46:40.000000Z\n" + "1685464327\t0.8711554561766037\t1970-01-11T18:03:20.000000Z\n" + "-702939849\t0.2353405108400326\t1970-01-11T18:20:00.000000Z\n" + "118335726\t0.17485263263815565\t1970-01-11T18:36:40.000000Z\n" + "-1641406479\t0.19882280937094632\t1970-01-11T18:53:20.000000Z\n" + "1637478680\t0.8451212749109064\t1970-01-11T19:10:00.000000Z\n" + "603472290\t0.362912927226985\t1970-01-11T19:26:40.000000Z\n" + "-1987835306\t0.35083644032896444\t1970-01-11T19:43:20.000000Z\n" + "1845426751\t0.4179029808821145\t1970-01-11T20:00:00.000000Z\n" + "-983118321\t0.05905539454236053\t1970-01-11T20:16:40.000000Z\n" + "-931312258\t0.19751729781600535\t1970-01-11T20:33:20.000000Z\n" + "2096767443\t0.35820401665170765\t1970-01-11T20:50:00.000000Z\n" + "-186002027\t0.06499118875100096\t1970-01-11T21:06:40.000000Z\n" + "210529946\t0.8426876468436052\t1970-01-11T21:23:20.000000Z\n" + "316613958\t0.7947985205275171\t1970-01-11T21:40:00.000000Z\n" + "2007373598\t0.2443292452654071\t1970-01-11T21:56:40.000000Z\n" + "-1973328009\t0.09990632318082981\t1970-01-11T22:13:20.000000Z\n" + "-2050693451\t0.8935939683581362\t1970-01-11T22:30:00.000000Z\n" + "-677022047\t0.10811223855547059\t1970-01-11T22:46:40.000000Z\n" + "1194557424\t0.3236005778073523\t1970-01-11T23:03:20.000000Z\n" + "856082190\t0.09028864342090992\t1970-01-11T23:20:00.000000Z\n" + "-1037890340\t0.8731939170484669\t1970-01-11T23:36:40.000000Z\n" + "-273166864\t0.3883845787817346\t1970-01-11T23:53:20.000000Z\n" + "519573739\t0.6914252886783999\t1970-01-12T00:10:00.000000Z\n" + "-1059163764\t0.5807816609951174\t1970-01-12T00:26:40.000000Z\n" + "-1248364069\t0.47180077197626313\t1970-01-12T00:43:20.000000Z\n" + "-707410819\t0.17675145949691562\t1970-01-12T01:00:00.000000Z\n" + "694073645\t0.17231107928084932\t1970-01-12T01:16:40.000000Z\n" + "1143841840\t0.11572097670276393\t1970-01-12T01:33:20.000000Z\n" + "-1203620259\t0.10992274280613101\t1970-01-12T01:50:00.000000Z\n" + "1001513017\t0.494968979129106\t1970-01-12T02:06:40.000000Z\n" + "-1397486016\t0.13260889791591712\t1970-01-12T02:23:20.000000Z\n" + "-124098231\t0.5418085488978492\t1970-01-12T02:40:00.000000Z\n" + "1375230944\t0.36658512235236584\t1970-01-12T02:56:40.000000Z\n" + "-1602836197\t0.9557940492957487\t1970-01-12T03:13:20.000000Z\n" + "-903320803\t0.1570704400490346\t1970-01-12T03:30:00.000000Z\n" + "260033364\t0.034904847183765186\t1970-01-12T03:46:40.000000Z\n" + "-1913086326\t0.5749982450146361\t1970-01-12T04:03:20.000000Z\n" + "373991096\t0.13360028796545642\t1970-01-12T04:20:00.000000Z\n" + "2000510449\t0.5810641448245488\t1970-01-12T04:36:40.000000Z\n" + "-2081389237\t0.3443944218017603\t1970-01-12T04:53:20.000000Z\n" + "-959535924\t0.44725548780773694\t1970-01-12T05:10:00.000000Z\n" + "-1251112810\t0.6933103859471981\t1970-01-12T05:26:40.000000Z\n" + "1732259734\t0.41876634576982885\t1970-01-12T05:43:20.000000Z\n" + "-987366968\t0.7437656766929067\t1970-01-12T06:00:00.000000Z\n" + "556907040\t0.32010882429399834\t1970-01-12T06:16:40.000000Z\n" + "1569770272\t0.4288965848487438\t1970-01-12T06:33:20.000000Z\n" + "1405080657\t0.18027951967123457\t1970-01-12T06:50:00.000000Z\n" + "526853349\t0.6178183982086626\t1970-01-12T07:06:40.000000Z\n" + "-334179339\t0.8261516071359104\t1970-01-12T07:23:20.000000Z\n" + "-17513564\t0.36138284225880035\t1970-01-12T07:40:00.000000Z\n" + "354098377\t0.6953541428262865\t1970-01-12T07:56:40.000000Z\n" + "1443031361\t0.31908901955539515\t1970-01-12T08:13:20.000000Z\n" + "1175675185\t0.05899019706036246\t1970-01-12T08:30:00.000000Z\n" + "99560093\t0.16347836851309816\t1970-01-12T08:46:40.000000Z\n" + "-1674594591\t0.1407735833402206\t1970-01-12T09:03:20.000000Z\n" + "-1124656535\t0.1528299057907735\t1970-01-12T09:20:00.000000Z\n" + "-1507142148\t0.00825969166045648\t1970-01-12T09:36:40.000000Z\n" + "2049048212\t0.29309813796291284\t1970-01-12T09:53:20.000000Z\n" + "352894170\t0.5832447623746595\t1970-01-12T10:10:00.000000Z\n" + "1513826357\t0.5063850654335724\t1970-01-12T10:26:40.000000Z\n" + "1638798442\t0.28053790406505974\t1970-01-12T10:43:20.000000Z\n" + "-501102817\t0.5524335828965579\t1970-01-12T11:00:00.000000Z\n" + "-2110403420\t0.8114444771798898\t1970-01-12T11:16:40.000000Z\n" + "-1041070703\t0.6810629367436306\t1970-01-12T11:33:20.000000Z\n" + "1774933838\t0.8545511357260956\t1970-01-12T11:50:00.000000Z\n" + "-1189092035\t0.5009939966556752\t1970-01-12T12:06:40.000000Z\n" + "1108319297\t0.4007457065265131\t1970-01-12T12:23:20.000000Z\n" + "1674123731\t0.2679292897042268\t1970-01-12T12:40:00.000000Z\n" + "782820973\t0.9391935526421991\t1970-01-12T12:56:40.000000Z\n" + "413500238\t0.19676893721907063\t1970-01-12T13:13:20.000000Z\n" + "-227038447\t0.4799415921194079\t1970-01-12T13:30:00.000000Z\n";
            TestUtils.assertReader(expectedAfterPartitionDelete, reader, sink);
        }
    });
}
Also used : TableWriter(io.questdb.cairo.TableWriter) RecordCursor(io.questdb.cairo.sql.RecordCursor) Record(io.questdb.cairo.sql.Record) TableReader(io.questdb.cairo.TableReader) Test(org.junit.Test)

Example 97 with TableWriter

use of io.questdb.cairo.TableWriter in project questdb by bluestreak01.

the class JoinTest method testAsOfCorrectness.

@Test
public void testAsOfCorrectness() throws Exception {
    assertMemoryLeak(() -> {
        compiler.compile("create table orders (sym SYMBOL, amount DOUBLE, side BYTE, timestamp TIMESTAMP) timestamp(timestamp)", sqlExecutionContext);
        compiler.compile("create table quotes (sym SYMBOL, bid DOUBLE, ask DOUBLE, timestamp TIMESTAMP) timestamp(timestamp)", sqlExecutionContext);
        try (TableWriter orders = engine.getWriter(AllowAllCairoSecurityContext.INSTANCE, "orders", "testing");
            TableWriter quotes = engine.getWriter(AllowAllCairoSecurityContext.INSTANCE, "quotes", "testing")) {
            TableWriter.Row rOrders;
            TableWriter.Row rQuotes;
            // quote googl @ 10:00:02
            rQuotes = quotes.newRow(TimestampFormatUtils.parseUTCTimestamp("2018-11-02T10:00:02.000000Z"));
            rQuotes.putSym(0, "googl");
            rQuotes.putDouble(1, 100.2);
            rQuotes.putDouble(2, 100.3);
            rQuotes.append();
            // quote msft @ 10.00.02.000001
            rQuotes = quotes.newRow(TimestampFormatUtils.parseUTCTimestamp("2018-11-02T10:00:02.000001Z"));
            rQuotes.putSym(0, "msft");
            rQuotes.putDouble(1, 185.9);
            rQuotes.putDouble(2, 187.3);
            rQuotes.append();
            // quote msft @ 10.00.02.000002
            rQuotes = quotes.newRow(TimestampFormatUtils.parseUTCTimestamp("2018-11-02T10:00:02.000002Z"));
            rQuotes.putSym(0, "msft");
            rQuotes.putDouble(1, 186.1);
            rQuotes.putDouble(2, 187.8);
            rQuotes.append();
            // order googl @ 10.00.03
            rOrders = orders.newRow(TimestampFormatUtils.parseUTCTimestamp("2018-11-02T10:00:03.000000Z"));
            rOrders.putSym(0, "googl");
            rOrders.putDouble(1, 2000);
            rOrders.putByte(2, (byte) '1');
            rOrders.append();
            // quote msft @ 10.00.03.000001
            rQuotes = quotes.newRow(TimestampFormatUtils.parseUTCTimestamp("2018-11-02T10:00:02.000002Z"));
            rQuotes.putSym(0, "msft");
            rQuotes.putDouble(1, 183.4);
            rQuotes.putDouble(2, 185.9);
            rQuotes.append();
            rOrders = orders.newRow(TimestampFormatUtils.parseUTCTimestamp("2018-11-02T10:00:04.000000Z"));
            rOrders.putSym(0, "msft");
            rOrders.putDouble(1, 150);
            rOrders.putByte(2, (byte) '1');
            rOrders.append();
            // order googl @ 10.00.05
            rOrders = orders.newRow(TimestampFormatUtils.parseUTCTimestamp("2018-11-02T10:00:05.000000Z"));
            rOrders.putSym(0, "googl");
            rOrders.putDouble(1, 3000);
            rOrders.putByte(2, (byte) '2');
            rOrders.append();
            quotes.commit();
            orders.commit();
        }
    });
    assertQuery("sym\tamount\tside\ttimestamp\tsym1\tbid\task\ttimestamp1\n" + "googl\t2000.0\t49\t2018-11-02T10:00:03.000000Z\tgoogl\t100.2\t100.3\t2018-11-02T10:00:02.000000Z\n" + "msft\t150.0\t49\t2018-11-02T10:00:04.000000Z\tmsft\t183.4\t185.9\t2018-11-02T10:00:02.000002Z\n" + "googl\t3000.0\t50\t2018-11-02T10:00:05.000000Z\tgoogl\t100.2\t100.3\t2018-11-02T10:00:02.000000Z\n", "select * from orders asof join quotes on(sym)", null, "timestamp", false, true, true);
}
Also used : TableWriter(io.questdb.cairo.TableWriter) Test(org.junit.Test)

Example 98 with TableWriter

use of io.questdb.cairo.TableWriter in project questdb by bluestreak01.

the class JoinTest method testSpliceCorrectness.

@Test
public void testSpliceCorrectness() throws Exception {
    assertMemoryLeak(() -> {
        compiler.compile("create table orders (sym SYMBOL, amount DOUBLE, side BYTE, timestamp TIMESTAMP) timestamp(timestamp)", sqlExecutionContext);
        compiler.compile("create table quotes (sym SYMBOL, bid DOUBLE, ask DOUBLE, timestamp TIMESTAMP) timestamp(timestamp)", sqlExecutionContext);
        try (TableWriter orders = engine.getWriter(AllowAllCairoSecurityContext.INSTANCE, "orders", "testing");
            TableWriter quotes = engine.getWriter(AllowAllCairoSecurityContext.INSTANCE, "quotes", "testing")) {
            TableWriter.Row rOrders;
            TableWriter.Row rQuotes;
            // quote googl @ 10:00:02
            rQuotes = quotes.newRow(TimestampFormatUtils.parseUTCTimestamp("2018-11-02T10:00:02.000000Z"));
            rQuotes.putSym(0, "googl");
            rQuotes.putDouble(1, 100.2);
            rQuotes.putDouble(2, 100.3);
            rQuotes.append();
            // quote msft @ 10.00.02.000001
            rQuotes = quotes.newRow(TimestampFormatUtils.parseUTCTimestamp("2018-11-02T10:00:02.000001Z"));
            rQuotes.putSym(0, "msft");
            rQuotes.putDouble(1, 185.9);
            rQuotes.putDouble(2, 187.3);
            rQuotes.append();
            // quote msft @ 10.00.02.000002
            rQuotes = quotes.newRow(TimestampFormatUtils.parseUTCTimestamp("2018-11-02T10:00:02.000002Z"));
            rQuotes.putSym(0, "msft");
            rQuotes.putDouble(1, 186.1);
            rQuotes.putDouble(2, 187.8);
            rQuotes.append();
            // order googl @ 10.00.03
            rOrders = orders.newRow(TimestampFormatUtils.parseUTCTimestamp("2018-11-02T10:00:03.000000Z"));
            rOrders.putSym(0, "googl");
            rOrders.putDouble(1, 2000);
            rOrders.putByte(2, (byte) '1');
            rOrders.append();
            // quote msft @ 10.00.03.000001
            rQuotes = quotes.newRow(TimestampFormatUtils.parseUTCTimestamp("2018-11-02T10:00:02.000002Z"));
            rQuotes.putSym(0, "msft");
            rQuotes.putDouble(1, 183.4);
            rQuotes.putDouble(2, 185.9);
            rQuotes.append();
            // order msft @ 10:00:04
            rOrders = orders.newRow(TimestampFormatUtils.parseUTCTimestamp("2018-11-02T10:00:04.000000Z"));
            rOrders.putSym(0, "msft");
            rOrders.putDouble(1, 150);
            rOrders.putByte(2, (byte) '1');
            rOrders.append();
            // order googl @ 10.00.05
            rOrders = orders.newRow(TimestampFormatUtils.parseUTCTimestamp("2018-11-02T10:00:05.000000Z"));
            rOrders.putSym(0, "googl");
            rOrders.putDouble(1, 3000);
            rOrders.putByte(2, (byte) '2');
            rOrders.append();
            quotes.commit();
            orders.commit();
        }
    });
    assertQuery("sym\tamount\tside\ttimestamp\tsym1\tbid\task\ttimestamp1\n" + "\tNaN\t0\t\tgoogl\t100.2\t100.3\t2018-11-02T10:00:02.000000Z\n" + "\tNaN\t0\t\tmsft\t185.9\t187.3\t2018-11-02T10:00:02.000001Z\n" + "\tNaN\t0\t\tmsft\t186.1\t187.8\t2018-11-02T10:00:02.000002Z\n" + "\tNaN\t0\t\tmsft\t183.4\t185.9\t2018-11-02T10:00:02.000002Z\n" + "googl\t2000.0\t49\t2018-11-02T10:00:03.000000Z\tgoogl\t100.2\t100.3\t2018-11-02T10:00:02.000000Z\n" + "msft\t150.0\t49\t2018-11-02T10:00:04.000000Z\tmsft\t183.4\t185.9\t2018-11-02T10:00:02.000002Z\n" + "googl\t3000.0\t50\t2018-11-02T10:00:05.000000Z\tgoogl\t100.2\t100.3\t2018-11-02T10:00:02.000000Z\n", "select * from orders splice join quotes on(sym)", null, null, false);
}
Also used : TableWriter(io.questdb.cairo.TableWriter) Test(org.junit.Test)

Example 99 with TableWriter

use of io.questdb.cairo.TableWriter in project questdb by bluestreak01.

the class EngineMigrationTest method generateMigrationTables.

private void generateMigrationTables() throws SqlException, NumericException {
    compiler.compile("create table t_none_nts as (" + "select" + commonColumns() + " from long_sequence(30)," + "), index(m)", sqlExecutionContext);
    compiler.compile("create table t_none as (" + "select" + commonColumns() + ", timestamp_sequence(100, 200000000L) ts" + " from long_sequence(30)," + "), index(m) timestamp(ts) partition by NONE", sqlExecutionContext);
    compiler.compile("create table t_day as (" + "select" + commonColumns() + ", timestamp_sequence(200000000L, 2000000000000L) ts" + " from long_sequence(30)," + "), index(m) timestamp(ts) partition by DAY", sqlExecutionContext);
    compiler.compile("create table t_month as (" + "select" + commonColumns() + ", timestamp_sequence(200000000L, 20000000000000L) ts" + " from long_sequence(30)," + "), index(m) timestamp(ts) partition by MONTH", sqlExecutionContext);
    compiler.compile("create table t_year as (" + "select" + commonColumns() + ", timestamp_sequence(200000000L, 200000000000000L) ts" + " from long_sequence(30)," + "), index(m) timestamp(ts) partition by YEAR", sqlExecutionContext);
    compiler.compile("create table t_day_ooo as (" + "select" + commonColumns() + ", timestamp_sequence(16 * 200000000L + 200000000L, 2000000000000L) ts" + " from long_sequence(15)" + "), index(m) timestamp(ts) partition by DAY", sqlExecutionContext);
    compiler.compile("insert into t_day_ooo " + "select " + commonColumns() + ", timestamp_sequence(200000000L, 2000000000000L) ts" + " from long_sequence(15)", sqlExecutionContext);
    compiler.compile("create table t_month_ooo as (" + "select" + commonColumns() + ", timestamp_sequence(16 * 200000000000L + 200000000L, 200000000000L) ts" + " from long_sequence(15)" + "), index(m) timestamp(ts) partition by MONTH", sqlExecutionContext);
    compiler.compile("insert into t_month_ooo " + "select " + commonColumns() + ", timestamp_sequence(200000000L, 200000000000L) ts" + " from long_sequence(15)", sqlExecutionContext);
    compiler.compile("create table t_year_ooo as (" + "select" + commonColumns() + ", timestamp_sequence(200000000L, 20000000000000L) ts" + " from long_sequence(15)," + "), index(m) timestamp(ts) partition by YEAR", sqlExecutionContext);
    compiler.compile("insert into t_year_ooo " + "select " + commonColumns() + ", timestamp_sequence(200000000L, 20000000000000L) ts" + " from long_sequence(15)", sqlExecutionContext);
    compiler.compile("create table o3_0(a string, b binary, t timestamp) timestamp(t) partition by DAY", sqlExecutionContext);
    try (TableWriter w = engine.getWriter(sqlExecutionContext.getCairoSecurityContext(), "o3_0", "test")) {
        TableWriter.Row r;
        // insert day 1
        long t = TimestampFormatUtils.parseTimestamp("2014-09-10T01:00:00.000000Z");
        for (int i = 0; i < 100; i++) {
            r = w.newRow(t);
            r.putStr(0, null);
            r.putBin(1, null);
            r.append();
            t += 100000L;
        }
        // day 2
        t = TimestampFormatUtils.parseTimestamp("2014-09-11T01:00:00.000000Z");
        for (int i = 0; i < 100; i++) {
            r = w.newRow(t);
            r.putStr(0, null);
            r.putBin(1, null);
            r.append();
            t += 100000L;
        }
        // O3
        t = TimestampFormatUtils.parseTimestamp("2014-09-10T01:00:00.000000Z");
        r = w.newRow(t);
        r.putStr(0, null);
        r.putBin(1, null);
        r.append();
        w.commit();
    }
}
Also used : TableWriter(io.questdb.cairo.TableWriter)

Example 100 with TableWriter

use of io.questdb.cairo.TableWriter in project questdb by bluestreak01.

the class AlterTableAlterSymbolColumnCacheFlagTest method testAlterSymbolCacheFlagToTrueCheckOpenReaderWithCursor.

@Test
public void testAlterSymbolCacheFlagToTrueCheckOpenReaderWithCursor() throws Exception {
    final RecordCursorPrinter printer = new SingleColumnRecordCursorPrinter(1);
    assertMemoryLeak(() -> {
        compiler.compile("create table x (i int, sym symbol nocache) ;", sqlExecutionContext);
        executeInsert("insert into x values (1, 'GBP')\"");
        executeInsert("insert into x values (2, 'CHF')\"");
        executeInsert("insert into x values (3, 'GBP')\"");
        executeInsert("insert into x values (4, 'JPY')\"");
        executeInsert("insert into x values (5, 'USD')\"");
        executeInsert("insert into x values (6, 'GBP')\"");
        executeInsert("insert into x values (7, 'GBP')\"");
        executeInsert("insert into x values (8, 'GBP')\"");
        executeInsert("insert into x values (9, 'GBP')\"");
    });
    String expectedOrdered = "sym\n" + "CHF\n" + "GBP\n" + "GBP\n" + "GBP\n" + "GBP\n" + "GBP\n" + "GBP\n" + "JPY\n" + "USD\n";
    String expectedChronological = "sym\n" + "GBP\n" + "CHF\n" + "GBP\n" + "JPY\n" + "USD\n" + "GBP\n" + "GBP\n" + "GBP\n" + "GBP\n";
    assertMemoryLeak(() -> {
        assertQueryPlain(expectedOrdered, "select sym from x order by sym");
        try (TableReader reader = engine.getReader(sqlExecutionContext.getCairoSecurityContext(), "x")) {
            // check cursor before altering symbol column
            sink.clear();
            printer.print(reader.getCursor(), reader.getMetadata(), true, sink);
            Assert.assertEquals(expectedChronological, sink.toString());
            try (TableWriter writer = engine.getWriter(sqlExecutionContext.getCairoSecurityContext(), "x", "testing")) {
                writer.changeCacheFlag(1, true);
            }
            // reload reader
            Assert.assertTrue(reader.reload());
            // check cursor after reload
            sink.clear();
            printer.print(reader.getCursor(), reader.getMetadata(), true, sink);
            Assert.assertEquals(expectedChronological, sink.toString());
            try (TableReader reader2 = engine.getReader(sqlExecutionContext.getCairoSecurityContext(), "x")) {
                sink.clear();
                printer.print(reader2.getCursor(), reader2.getMetadata(), true, sink);
                Assert.assertEquals(expectedChronological, sink.toString());
            }
        }
    });
    assertQueryPlain(expectedOrdered, "select sym from x order by 1 asc");
}
Also used : RecordCursorPrinter(io.questdb.cairo.RecordCursorPrinter) TableWriter(io.questdb.cairo.TableWriter) TableReader(io.questdb.cairo.TableReader) Test(org.junit.Test)

Aggregations

TableWriter (io.questdb.cairo.TableWriter)103 Test (org.junit.Test)88 RecordCursor (io.questdb.cairo.sql.RecordCursor)71 AbstractGriffinTest (io.questdb.griffin.AbstractGriffinTest)71 Record (io.questdb.cairo.sql.Record)70 RecordCursorFactory (io.questdb.cairo.sql.RecordCursorFactory)68 Rnd (io.questdb.std.Rnd)23 TableReader (io.questdb.cairo.TableReader)9 CountDownLatch (java.util.concurrent.CountDownLatch)9 EntryUnavailableException (io.questdb.cairo.EntryUnavailableException)7 ServerDisconnectException (io.questdb.network.ServerDisconnectException)7 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)7 CairoConfiguration (io.questdb.cairo.CairoConfiguration)3 CairoEngine (io.questdb.cairo.CairoEngine)3 DefaultCairoConfiguration (io.questdb.cairo.DefaultCairoConfiguration)3 SqlCompiler (io.questdb.griffin.SqlCompiler)3 SqlExecutionContextImpl (io.questdb.griffin.SqlExecutionContextImpl)3 RecordCursorPrinter (io.questdb.cairo.RecordCursorPrinter)2 Path (io.questdb.std.str.Path)2 CyclicBarrier (java.util.concurrent.CyclicBarrier)2