use of io.questdb.cairo.TableWriter in project questdb by bluestreak01.
the class MinLongGroupByFunctionFactoryTest method testSomeNull.
@Test
public void testSomeNull() throws SqlException {
compiler.compile("create table tab (f long)", sqlExecutionContext);
try (TableWriter w = engine.getWriter(sqlExecutionContext.getCairoSecurityContext(), "tab", "testing")) {
for (int i = 100; i > 10; i--) {
TableWriter.Row r = w.newRow();
if (i % 4 == 0) {
r.putLong(0, i);
}
r.append();
}
w.commit();
}
try (RecordCursorFactory factory = compiler.compile("select min(f) from tab", sqlExecutionContext).getRecordCursorFactory()) {
try (RecordCursor cursor = factory.getCursor(sqlExecutionContext)) {
Record record = cursor.getRecord();
Assert.assertEquals(1, cursor.size());
Assert.assertTrue(cursor.hasNext());
Assert.assertEquals(12, record.getLong(0));
}
}
}
use of io.questdb.cairo.TableWriter in project questdb by bluestreak01.
the class MinLongGroupByFunctionFactoryTest method testNonNull.
@Test
public void testNonNull() throws SqlException {
compiler.compile("create table tab (f long)", sqlExecutionContext);
final Rnd rnd = new Rnd();
try (TableWriter w = engine.getWriter(sqlExecutionContext.getCairoSecurityContext(), "tab", "testing")) {
for (int i = 100; i > 10; i--) {
TableWriter.Row r = w.newRow();
r.putLong(0, rnd.nextLong());
r.append();
}
w.commit();
}
try (RecordCursorFactory factory = compiler.compile("select min(f) from tab", sqlExecutionContext).getRecordCursorFactory()) {
try (RecordCursor cursor = factory.getCursor(sqlExecutionContext)) {
Record record = cursor.getRecord();
Assert.assertEquals(1, cursor.size());
Assert.assertTrue(cursor.hasNext());
Assert.assertEquals(-8968886490993754893L, record.getLong(0));
}
}
}
use of io.questdb.cairo.TableWriter in project questdb by bluestreak01.
the class PGJobContextTest method testRollbackDataOnStaleTransaction.
@Test
public void testRollbackDataOnStaleTransaction() throws Exception {
assertMemoryLeak(() -> {
try (final PGWireServer ignored = createPGServer(2)) {
try (final Connection connection = getConnection(false, true)) {
connection.setAutoCommit(false);
connection.prepareStatement("create table xyz(a int)").execute();
connection.prepareStatement("insert into xyz values (100)").execute();
connection.prepareStatement("insert into xyz values (101)").execute();
connection.prepareStatement("insert into xyz values (102)").execute();
connection.prepareStatement("insert into xyz values (103)").execute();
sink.clear();
try (PreparedStatement ps = connection.prepareStatement("xyz");
ResultSet rs = ps.executeQuery()) {
assertResultSet("a[INTEGER]\n", sink, rs);
}
}
// we need to let server process disconnect and release writer
Os.sleep(2000);
try (TableWriter w = engine.getWriter(sqlExecutionContext.getCairoSecurityContext(), "xyz", "testing")) {
w.commit();
}
try (final Connection connection = getConnection(false, true)) {
sink.clear();
try (PreparedStatement ps = connection.prepareStatement("xyz");
ResultSet rs = ps.executeQuery()) {
assertResultSet("a[INTEGER]\n", sink, rs);
}
}
}
});
}
use of io.questdb.cairo.TableWriter in project questdb by bluestreak01.
the class AlterTableRenameColumnTest method testRenameColumnAndCheckOpenReaderWithCursor.
@Test
public void testRenameColumnAndCheckOpenReaderWithCursor() throws Exception {
String expectedBefore = "i\tsym\tamt\ttimestamp\tb\tc\td\te\tf\tg\tik\tj\tk\tl\tm\tn\n" + "1\tmsft\t50.938\t2018-01-01T00:12:00.000000Z\tfalse\tXYZ\t0.4621835429127854\t0.5599\t31\t2015-06-22T18:58:53.562Z\tPEHN\t-4485747798769957016\t1970-01-01T00:00:00.000000Z\t19\t00000000 19 c4 95 94 36 53 49 b4 59 7e 3b 08 a1 1e\tYSBEOUOJSHRUEDRQ\n" + "2\tgoogl\t42.281\t2018-01-01T00:24:00.000000Z\tfalse\tABC\t0.4138164748227684\t0.5522\t493\t2015-04-09T11:42:28.332Z\tHYRX\t-8811278461560712840\t1970-01-01T00:16:40.000000Z\t29\t00000000 53 d0 fb 64 bb 1a d4 f0 2d 40 e2 4b b1 3e e3 f1\t\n" + "3\tgoogl\t17.371\t2018-01-01T00:36:00.000000Z\tfalse\tABC\t0.05384400312338511\t0.0975\t327\t2015-09-26T18:05:10.217Z\tHYRX\t-3214230645884399728\t1970-01-01T00:33:20.000000Z\t28\t00000000 8e e5 61 2f 64 0e 2c 7f d7 6f b8 c9 ae 28\tSUWDSWUGS\n" + "4\tibm\t44.805\t2018-01-01T00:48:00.000000Z\ttrue\tXYZ\t0.14830552335848957\t0.9442\t95\t2015-01-04T19:58:55.654Z\tPEHN\t-5024542231726589509\t1970-01-01T00:50:00.000000Z\t39\t00000000 49 1c f2 3c ed 39 ac a8 3b a6\tOJIPHZEPIHVL\n" + "5\tgoogl\t42.956\t2018-01-01T01:00:00.000000Z\ttrue\t\t0.22895725920713628\t0.9821\t696\t2015-03-18T09:57:14.898Z\tCPSW\t-8757007522346766135\t1970-01-01T01:06:40.000000Z\t23\t\t\n" + "6\tibm\t82.59700000000001\t2018-01-01T01:12:00.000000Z\ttrue\tCDE\t0.021189232728939578\tNaN\t369\t2015-07-21T10:33:47.953Z\tPEHN\t-9147563299122452591\t1970-01-01T01:23:20.000000Z\t48\t00000000 18 93 bd 0b 61 f5 5d d0 eb 67 44 a7 6a\t\n" + "7\tgoogl\t98.59100000000001\t2018-01-01T01:24:00.000000Z\ttrue\tCDE\t0.24642266252221556\t0.2672\t174\t2015-02-20T01:11:53.748Z\t\t2151565237758036093\t1970-01-01T01:40:00.000000Z\t31\t\tHZSQLDGLOGIFO\n" + "8\tgoogl\t57.086\t2018-01-01T01:36:00.000000Z\ttrue\tABC\t0.6707018622395736\t0.0759\t199\t2015-09-12T07:21:40.050Z\t\t-4058426794463997577\t1970-01-01T01:56:40.000000Z\t37\t00000000 ea 4e ea 8b f5 0f 2d b3 14 33\tFFLRBROMNXKUIZ\n" + "9\tgoogl\t81.44200000000001\t2018-01-01T01:48:00.000000Z\tfalse\t\t0.2677326840703891\t0.5425\t1001\t2015-11-14T07:05:22.934Z\tHYRX\t-8793423647053878901\t1970-01-01T02:13:20.000000Z\t33\t00000000 25 c2 20 ff 70 3a c7 8a b3 14 cd 47 0b 0c\tFMQNTOG\n" + "10\tmsft\t3.973\t2018-01-01T02:00:00.000000Z\tfalse\tXYZ\tNaN\tNaN\t828\t2015-06-18T18:07:42.406Z\tPEHN\t-7398902448022205322\t1970-01-01T02:30:00.000000Z\t50\t00000000 fb 2e 42 fa f5 6e 8f 80 e3 54 b8 07 b1 32 57 ff\n" + "00000010 9a ef 88 cb\tCNGTNLEGPUHH\n";
String expectedAfter = "i\tsym\tamt\ttimestamp\tbb\tcc\td\te\tf\tg\tik\tj\tk\tl\tm\tn\n" + "1\tmsft\t50.938\t2018-01-01T00:12:00.000000Z\tfalse\tXYZ\t0.4621835429127854\t0.5599\t31\t2015-06-22T18:58:53.562Z\tPEHN\t-4485747798769957016\t1970-01-01T00:00:00.000000Z\t19\t00000000 19 c4 95 94 36 53 49 b4 59 7e 3b 08 a1 1e\tYSBEOUOJSHRUEDRQ\n" + "2\tgoogl\t42.281\t2018-01-01T00:24:00.000000Z\tfalse\tABC\t0.4138164748227684\t0.5522\t493\t2015-04-09T11:42:28.332Z\tHYRX\t-8811278461560712840\t1970-01-01T00:16:40.000000Z\t29\t00000000 53 d0 fb 64 bb 1a d4 f0 2d 40 e2 4b b1 3e e3 f1\t\n" + "3\tgoogl\t17.371\t2018-01-01T00:36:00.000000Z\tfalse\tABC\t0.05384400312338511\t0.0975\t327\t2015-09-26T18:05:10.217Z\tHYRX\t-3214230645884399728\t1970-01-01T00:33:20.000000Z\t28\t00000000 8e e5 61 2f 64 0e 2c 7f d7 6f b8 c9 ae 28\tSUWDSWUGS\n" + "4\tibm\t44.805\t2018-01-01T00:48:00.000000Z\ttrue\tXYZ\t0.14830552335848957\t0.9442\t95\t2015-01-04T19:58:55.654Z\tPEHN\t-5024542231726589509\t1970-01-01T00:50:00.000000Z\t39\t00000000 49 1c f2 3c ed 39 ac a8 3b a6\tOJIPHZEPIHVL\n" + "5\tgoogl\t42.956\t2018-01-01T01:00:00.000000Z\ttrue\t\t0.22895725920713628\t0.9821\t696\t2015-03-18T09:57:14.898Z\tCPSW\t-8757007522346766135\t1970-01-01T01:06:40.000000Z\t23\t\t\n" + "6\tibm\t82.59700000000001\t2018-01-01T01:12:00.000000Z\ttrue\tCDE\t0.021189232728939578\tNaN\t369\t2015-07-21T10:33:47.953Z\tPEHN\t-9147563299122452591\t1970-01-01T01:23:20.000000Z\t48\t00000000 18 93 bd 0b 61 f5 5d d0 eb 67 44 a7 6a\t\n" + "7\tgoogl\t98.59100000000001\t2018-01-01T01:24:00.000000Z\ttrue\tCDE\t0.24642266252221556\t0.2672\t174\t2015-02-20T01:11:53.748Z\t\t2151565237758036093\t1970-01-01T01:40:00.000000Z\t31\t\tHZSQLDGLOGIFO\n" + "8\tgoogl\t57.086\t2018-01-01T01:36:00.000000Z\ttrue\tABC\t0.6707018622395736\t0.0759\t199\t2015-09-12T07:21:40.050Z\t\t-4058426794463997577\t1970-01-01T01:56:40.000000Z\t37\t00000000 ea 4e ea 8b f5 0f 2d b3 14 33\tFFLRBROMNXKUIZ\n" + "9\tgoogl\t81.44200000000001\t2018-01-01T01:48:00.000000Z\tfalse\t\t0.2677326840703891\t0.5425\t1001\t2015-11-14T07:05:22.934Z\tHYRX\t-8793423647053878901\t1970-01-01T02:13:20.000000Z\t33\t00000000 25 c2 20 ff 70 3a c7 8a b3 14 cd 47 0b 0c\tFMQNTOG\n" + "10\tmsft\t3.973\t2018-01-01T02:00:00.000000Z\tfalse\tXYZ\tNaN\tNaN\t828\t2015-06-18T18:07:42.406Z\tPEHN\t-7398902448022205322\t1970-01-01T02:30:00.000000Z\t50\t00000000 fb 2e 42 fa f5 6e 8f 80 e3 54 b8 07 b1 32 57 ff\n" + "00000010 9a ef 88 cb\tCNGTNLEGPUHH\n";
assertMemoryLeak(() -> {
createX();
try (TableReader reader = engine.getReader(sqlExecutionContext.getCairoSecurityContext(), "x")) {
Assert.assertEquals("b", reader.getMetadata().getColumnName(4));
// check cursor before renaming column
TestUtils.assertReader(expectedBefore, reader, sink);
try (TableWriter writer = engine.getWriter(sqlExecutionContext.getCairoSecurityContext(), "x", "testing")) {
writer.renameColumn("b", "bb");
writer.renameColumn("c", "cc");
Assert.assertEquals("bb", writer.getMetadata().getColumnName(4));
}
// reload reader
Assert.assertTrue(reader.reload());
// check cursor after reload
TestUtils.assertReader(expectedAfter, reader, sink);
assertReader(expectedAfter, "x");
Assert.assertEquals("bb", reader.getMetadata().getColumnName(4));
}
});
}
use of io.questdb.cairo.TableWriter in project questdb by bluestreak01.
the class AlterTableRenameColumnTest method testRenameTimestampColumnAndCheckOpenReaderWithCursor.
@Test
public void testRenameTimestampColumnAndCheckOpenReaderWithCursor() throws Exception {
String expectedBefore = "i\tsym\tamt\ttimestamp\tb\tc\td\te\tf\tg\tik\tj\tk\tl\tm\tn\n" + "1\tmsft\t50.938\t2018-01-01T00:12:00.000000Z\tfalse\tXYZ\t0.4621835429127854\t0.5599\t31\t2015-06-22T18:58:53.562Z\tPEHN\t-4485747798769957016\t1970-01-01T00:00:00.000000Z\t19\t00000000 19 c4 95 94 36 53 49 b4 59 7e 3b 08 a1 1e\tYSBEOUOJSHRUEDRQ\n" + "2\tgoogl\t42.281\t2018-01-01T00:24:00.000000Z\tfalse\tABC\t0.4138164748227684\t0.5522\t493\t2015-04-09T11:42:28.332Z\tHYRX\t-8811278461560712840\t1970-01-01T00:16:40.000000Z\t29\t00000000 53 d0 fb 64 bb 1a d4 f0 2d 40 e2 4b b1 3e e3 f1\t\n" + "3\tgoogl\t17.371\t2018-01-01T00:36:00.000000Z\tfalse\tABC\t0.05384400312338511\t0.0975\t327\t2015-09-26T18:05:10.217Z\tHYRX\t-3214230645884399728\t1970-01-01T00:33:20.000000Z\t28\t00000000 8e e5 61 2f 64 0e 2c 7f d7 6f b8 c9 ae 28\tSUWDSWUGS\n" + "4\tibm\t44.805\t2018-01-01T00:48:00.000000Z\ttrue\tXYZ\t0.14830552335848957\t0.9442\t95\t2015-01-04T19:58:55.654Z\tPEHN\t-5024542231726589509\t1970-01-01T00:50:00.000000Z\t39\t00000000 49 1c f2 3c ed 39 ac a8 3b a6\tOJIPHZEPIHVL\n" + "5\tgoogl\t42.956\t2018-01-01T01:00:00.000000Z\ttrue\t\t0.22895725920713628\t0.9821\t696\t2015-03-18T09:57:14.898Z\tCPSW\t-8757007522346766135\t1970-01-01T01:06:40.000000Z\t23\t\t\n" + "6\tibm\t82.59700000000001\t2018-01-01T01:12:00.000000Z\ttrue\tCDE\t0.021189232728939578\tNaN\t369\t2015-07-21T10:33:47.953Z\tPEHN\t-9147563299122452591\t1970-01-01T01:23:20.000000Z\t48\t00000000 18 93 bd 0b 61 f5 5d d0 eb 67 44 a7 6a\t\n" + "7\tgoogl\t98.59100000000001\t2018-01-01T01:24:00.000000Z\ttrue\tCDE\t0.24642266252221556\t0.2672\t174\t2015-02-20T01:11:53.748Z\t\t2151565237758036093\t1970-01-01T01:40:00.000000Z\t31\t\tHZSQLDGLOGIFO\n" + "8\tgoogl\t57.086\t2018-01-01T01:36:00.000000Z\ttrue\tABC\t0.6707018622395736\t0.0759\t199\t2015-09-12T07:21:40.050Z\t\t-4058426794463997577\t1970-01-01T01:56:40.000000Z\t37\t00000000 ea 4e ea 8b f5 0f 2d b3 14 33\tFFLRBROMNXKUIZ\n" + "9\tgoogl\t81.44200000000001\t2018-01-01T01:48:00.000000Z\tfalse\t\t0.2677326840703891\t0.5425\t1001\t2015-11-14T07:05:22.934Z\tHYRX\t-8793423647053878901\t1970-01-01T02:13:20.000000Z\t33\t00000000 25 c2 20 ff 70 3a c7 8a b3 14 cd 47 0b 0c\tFMQNTOG\n" + "10\tmsft\t3.973\t2018-01-01T02:00:00.000000Z\tfalse\tXYZ\tNaN\tNaN\t828\t2015-06-18T18:07:42.406Z\tPEHN\t-7398902448022205322\t1970-01-01T02:30:00.000000Z\t50\t00000000 fb 2e 42 fa f5 6e 8f 80 e3 54 b8 07 b1 32 57 ff\n" + "00000010 9a ef 88 cb\tCNGTNLEGPUHH\n";
String expectedAfter = "i\tsym\tamt\tts\tb\tc\td\te\tf\tg\tik\tj\tk\tl\tm\tn\n" + "1\tmsft\t50.938\t2018-01-01T00:12:00.000000Z\tfalse\tXYZ\t0.4621835429127854\t0.5599\t31\t2015-06-22T18:58:53.562Z\tPEHN\t-4485747798769957016\t1970-01-01T00:00:00.000000Z\t19\t00000000 19 c4 95 94 36 53 49 b4 59 7e 3b 08 a1 1e\tYSBEOUOJSHRUEDRQ\n" + "2\tgoogl\t42.281\t2018-01-01T00:24:00.000000Z\tfalse\tABC\t0.4138164748227684\t0.5522\t493\t2015-04-09T11:42:28.332Z\tHYRX\t-8811278461560712840\t1970-01-01T00:16:40.000000Z\t29\t00000000 53 d0 fb 64 bb 1a d4 f0 2d 40 e2 4b b1 3e e3 f1\t\n" + "3\tgoogl\t17.371\t2018-01-01T00:36:00.000000Z\tfalse\tABC\t0.05384400312338511\t0.0975\t327\t2015-09-26T18:05:10.217Z\tHYRX\t-3214230645884399728\t1970-01-01T00:33:20.000000Z\t28\t00000000 8e e5 61 2f 64 0e 2c 7f d7 6f b8 c9 ae 28\tSUWDSWUGS\n" + "4\tibm\t44.805\t2018-01-01T00:48:00.000000Z\ttrue\tXYZ\t0.14830552335848957\t0.9442\t95\t2015-01-04T19:58:55.654Z\tPEHN\t-5024542231726589509\t1970-01-01T00:50:00.000000Z\t39\t00000000 49 1c f2 3c ed 39 ac a8 3b a6\tOJIPHZEPIHVL\n" + "5\tgoogl\t42.956\t2018-01-01T01:00:00.000000Z\ttrue\t\t0.22895725920713628\t0.9821\t696\t2015-03-18T09:57:14.898Z\tCPSW\t-8757007522346766135\t1970-01-01T01:06:40.000000Z\t23\t\t\n" + "6\tibm\t82.59700000000001\t2018-01-01T01:12:00.000000Z\ttrue\tCDE\t0.021189232728939578\tNaN\t369\t2015-07-21T10:33:47.953Z\tPEHN\t-9147563299122452591\t1970-01-01T01:23:20.000000Z\t48\t00000000 18 93 bd 0b 61 f5 5d d0 eb 67 44 a7 6a\t\n" + "7\tgoogl\t98.59100000000001\t2018-01-01T01:24:00.000000Z\ttrue\tCDE\t0.24642266252221556\t0.2672\t174\t2015-02-20T01:11:53.748Z\t\t2151565237758036093\t1970-01-01T01:40:00.000000Z\t31\t\tHZSQLDGLOGIFO\n" + "8\tgoogl\t57.086\t2018-01-01T01:36:00.000000Z\ttrue\tABC\t0.6707018622395736\t0.0759\t199\t2015-09-12T07:21:40.050Z\t\t-4058426794463997577\t1970-01-01T01:56:40.000000Z\t37\t00000000 ea 4e ea 8b f5 0f 2d b3 14 33\tFFLRBROMNXKUIZ\n" + "9\tgoogl\t81.44200000000001\t2018-01-01T01:48:00.000000Z\tfalse\t\t0.2677326840703891\t0.5425\t1001\t2015-11-14T07:05:22.934Z\tHYRX\t-8793423647053878901\t1970-01-01T02:13:20.000000Z\t33\t00000000 25 c2 20 ff 70 3a c7 8a b3 14 cd 47 0b 0c\tFMQNTOG\n" + "10\tmsft\t3.973\t2018-01-01T02:00:00.000000Z\tfalse\tXYZ\tNaN\tNaN\t828\t2015-06-18T18:07:42.406Z\tPEHN\t-7398902448022205322\t1970-01-01T02:30:00.000000Z\t50\t00000000 fb 2e 42 fa f5 6e 8f 80 e3 54 b8 07 b1 32 57 ff\n" + "00000010 9a ef 88 cb\tCNGTNLEGPUHH\n";
assertMemoryLeak(() -> {
createX();
try (TableReader reader = engine.getReader(sqlExecutionContext.getCairoSecurityContext(), "x")) {
Assert.assertEquals("timestamp", reader.getMetadata().getColumnName(3));
// check cursor before renaming column
TestUtils.assertReader(expectedBefore, reader, sink);
try (TableWriter writer = engine.getWriter(sqlExecutionContext.getCairoSecurityContext(), "x", "testing")) {
writer.renameColumn("timestamp", "ts");
Assert.assertEquals("ts", writer.getMetadata().getColumnName(3));
}
// reload reader
Assert.assertTrue(reader.reload());
// check cursor after reload
TestUtils.assertReader(expectedAfter, reader, sink);
assertReader(expectedAfter, "x");
Assert.assertEquals("ts", reader.getMetadata().getColumnName(3));
}
});
}
Aggregations