Search in sources :

Example 46 with StringSink

use of io.questdb.std.str.StringSink in project questdb by bluestreak01.

the class TimestampSamplerFactoryTest method testMinutes.

@Test
public void testMinutes() throws NumericException, SqlException {
    StringSink sink = new StringSink();
    for (int k = 0; k < 61; k++) {
        sink.clear();
        if (k > 0) {
            sink.put(k).put('m');
        } else {
            sink.put('m');
        }
        TimestampSampler sampler = TimestampSamplerFactory.getInstance(sink, 120);
        Assert.assertNotNull(sampler);
        final long n = Timestamps.MINUTE_MICROS * (k == 0 ? 1 : k);
        long timestamp = TimestampFormatUtils.parseUTCTimestamp("2018-04-15T10:23:00.000000Z");
        timestamp = timestamp - timestamp % n;
        for (int i = 0; i < 60; i++) {
            long actual = sampler.round(timestamp + i * Timestamps.SECOND_MICROS);
            if (timestamp != actual) {
                Assert.fail("Failed at: " + sink + ". Expected: " + Timestamps.toString(timestamp) + ", actual: " + Timestamps.toString(actual));
            }
        }
    }
}
Also used : StringSink(io.questdb.std.str.StringSink) Test(org.junit.Test)

Example 47 with StringSink

use of io.questdb.std.str.StringSink in project questdb by bluestreak01.

the class MetricsRegistryTest method assetNull.

private static void assetNull(Scrapable scrapable) {
    CharSink sink = new StringSink();
    scrapable.scrapeIntoPrometheus(sink);
    TestUtils.assertEquals("", (CharSequence) sink);
}
Also used : CharSink(io.questdb.std.str.CharSink) StringSink(io.questdb.std.str.StringSink)

Example 48 with StringSink

use of io.questdb.std.str.StringSink in project questdb by bluestreak01.

the class TableSyncModel method fromBinary.

public void fromBinary(long mem) {
    long p = mem;
    tableAction = Unsafe.getUnsafe().getInt(p);
    p += 4;
    dataVersion = Unsafe.getUnsafe().getLong(p);
    p += 8;
    maxTimestamp = Unsafe.getUnsafe().getLong(p);
    p += 8;
    int n = Unsafe.getUnsafe().getInt(p);
    p += 4;
    for (int i = 0; i < n; i += SLOTS_PER_COLUMN_TOP) {
        columnTops.add(Unsafe.getUnsafe().getLong(p), Unsafe.getUnsafe().getInt(p + 8), Unsafe.getUnsafe().getLong(p + 12), 0);
        p += 20;
    }
    n = Unsafe.getUnsafe().getInt(p);
    p += 4;
    for (int i = 0; i < n; i += SLOTS_PER_VAR_COLUMN_SIZE) {
        varColumnSizes.add(Unsafe.getUnsafe().getLong(p), Unsafe.getUnsafe().getInt(p + 8), Unsafe.getUnsafe().getLong(p + 12), 0);
        p += 20;
    }
    n = Unsafe.getUnsafe().getInt(p);
    p += 4;
    for (int i = 0; i < n; i += SLOTS_PER_PARTITION) {
        partitions.add(// action
        Unsafe.getUnsafe().getInt(p), // partition timestamp
        Unsafe.getUnsafe().getLong(p + 4), // start row
        Unsafe.getUnsafe().getLong(p + 12), // row count
        Unsafe.getUnsafe().getLong(p + 20), // name txn
        Unsafe.getUnsafe().getLong(p + 28), // data txn
        Unsafe.getUnsafe().getLong(p + 36), 0, 0);
        p += 44;
    }
    n = Unsafe.getUnsafe().getInt(p);
    p += 4;
    final StringSink nameSink = Misc.getThreadLocalBuilder();
    for (int i = 0; i < n; i++) {
        int nameLen = Unsafe.getUnsafe().getInt(p);
        p += 4;
        for (long lim = p + nameLen * 2L; p < lim; p += 2) {
            nameSink.put(Unsafe.getUnsafe().getChar(p));
        }
        int type = Unsafe.getUnsafe().getInt(p);
        p += 4;
        long hash = Unsafe.getUnsafe().getLong(p);
        p += 8;
        boolean indexed = Unsafe.getUnsafe().getByte(p++) == 0;
        int valueBlockCapacity = Unsafe.getUnsafe().getInt(p);
        p += 4;
        addedColumnMetadata.add(new TableColumnMetadata(Chars.toString(nameSink), hash, type, indexed, valueBlockCapacity, true, null));
    }
    n = Unsafe.getUnsafe().getInt(p);
    p += 4;
    for (int i = 0; i < n; i += SLOTS_PER_COLUMN_META_INDEX) {
        columnMetaIndex.add((long) Unsafe.getUnsafe().getInt(p), Unsafe.getUnsafe().getLong(p + 4));
        p += 12;
    }
}
Also used : StringSink(io.questdb.std.str.StringSink)

Example 49 with StringSink

use of io.questdb.std.str.StringSink in project questdb by bluestreak01.

the class PGJobContextTest method testSimpleSimpleQuery.

@Test
public void testSimpleSimpleQuery() throws Exception {
    TestUtils.assertMemoryLeak(() -> {
        try (final PGWireServer ignored = createPGServer(2);
            final Connection connection = getConnection(true, false)) {
            Statement statement = connection.createStatement();
            ResultSet rs = statement.executeQuery("select " + "rnd_str(4,4,4) s, " + "rnd_int(0, 256, 4) i, " + "rnd_double(4) d, " + "timestamp_sequence(0,10000) t, " + "rnd_float(4) f, " + "rnd_short() _short, " + "rnd_long(0, 10000000, 5) l, " + "rnd_timestamp(to_timestamp('2015','yyyy'),to_timestamp('2016','yyyy'),2) ts2, " + "rnd_byte(0,127) bb, " + "rnd_boolean() b, " + "rnd_symbol(4,4,4,2), " + "rnd_date(to_date('2015', 'yyyy'), to_date('2016', 'yyyy'), 2)," + "rnd_bin(10,20,2) " + "from long_sequence(50)");
            final String expected = "s[VARCHAR],i[INTEGER],d[DOUBLE],t[TIMESTAMP],f[REAL],_short[SMALLINT],l[BIGINT],ts2[TIMESTAMP],bb[SMALLINT],b[BIT],rnd_symbol[VARCHAR],rnd_date[TIMESTAMP],rnd_bin[BINARY]\n" + "null,57,0.6254021542412018,1970-01-01 00:00:00.0,0.462,-1593,3425232,null,121,false,PEHN,2015-03-17 04:25:52.765,00000000 19 c4 95 94 36 53 49 b4 59 7e 3b 08 a1 1e\n" + "XYSB,142,0.5793466326862211,1970-01-01 00:00:00.01,0.969,20088,1517490,2015-01-17 20:41:19.480685,100,true,PEHN,2015-06-20 01:10:58.599,00000000 79 5f 8b 81 2b 93 4d 1a 8e 78 b5 b9 11 53 d0 fb\n" + "00000010 64\n" + "OZZV,219,0.16381374773748514,1970-01-01 00:00:00.02,0.659,-12303,9489508,2015-08-13 17:10:19.752521,6,false,null,2015-05-20 01:48:37.418,00000000 2b 4d 5f f6 46 90 c3 b3 59 8e e5 61 2f 64 0e\n" + "OLYX,30,0.7133910271555843,1970-01-01 00:00:00.03,0.655,6610,6504428,2015-08-08 00:42:24.545639,123,false,null,2015-01-03 13:53:03.165,null\n" + "TIQB,42,0.6806873134626418,1970-01-01 00:00:00.04,0.626,-1605,8814086,2015-07-28 15:08:53.462495,28,true,CPSW,null,00000000 3b a6 dc 3b 7d 2b e3 92 fe 69 38 e1 77 9a\n" + "LTOV,137,0.7632615004324503,1970-01-01 00:00:00.05,0.882,9054,null,2015-04-20 05:09:03.580574,106,false,PEHN,2015-01-09 06:57:17.512,null\n" + "ZIMN,125,null,1970-01-01 00:00:00.06,null,11524,8335261,2015-10-26 02:10:50.688394,111,true,PEHN,2015-08-21 15:46:32.624,null\n" + "OPJO,168,0.10459352312331183,1970-01-01 00:00:00.07,0.535,-5920,7080704,2015-07-11 09:15:38.342717,103,false,VTJW,null,null\n" + "GLUO,145,0.5391626621794673,1970-01-01 00:00:00.08,0.767,14242,2499922,2015-11-02 09:01:31.312804,84,false,PEHN,2015-11-14 17:37:36.43,null\n" + "ZVQE,103,0.6729405590773638,1970-01-01 00:00:00.09,null,13727,7875846,2015-12-12 13:16:26.134562,22,true,PEHN,2015-01-20 04:50:34.98,00000000 14 33 80 c9 eb a3 67 7a 1a 79 e4 35 e4 3a dc 5c\n" + "00000010 65 ff\n" + "LIGY,199,0.2836347139481469,1970-01-01 00:00:00.1,null,30426,3215562,2015-08-21 14:55:07.055722,11,false,VTJW,null,00000000 ff 70 3a c7 8a b3 14 cd 47 0b 0c 39 12\n" + "MQNT,43,0.5859332388599638,1970-01-01 00:00:00.11,0.335,27019,null,null,27,true,PEHN,2015-07-12 12:59:47.665,00000000 26 fb 2e 42 fa f5 6e 8f 80 e3 54 b8 07 b1 32 57\n" + "00000010 ff 9a ef\n" + "WWCC,213,0.7665029914376952,1970-01-01 00:00:00.12,0.580,13640,4121923,2015-08-06 02:27:30.469762,73,false,PEHN,2015-04-30 08:18:10.453,00000000 71 a7 d5 af 11 96 37 08 dd 98 ef 54 88 2a a2 ad\n" + "00000010 e7 d4\n" + "VFGP,120,0.8402964708129546,1970-01-01 00:00:00.13,0.773,7223,7241423,2015-12-18 07:32:18.456025,43,false,VTJW,null,00000000 24 4e 44 a8 0d fe 27 ec 53 13 5d b2 15 e7 b8 35\n" + "00000010 67\n" + "RMDG,134,0.11047315214793696,1970-01-01 00:00:00.14,0.043,21227,7155708,2015-07-03 04:12:45.774281,42,true,CPSW,2015-02-24 12:10:43.199,null\n" + "WFOQ,255,null,1970-01-01 00:00:00.15,0.116,31569,6688277,2015-05-19 03:30:45.779999,126,true,PEHN,2015-12-09 09:57:17.78,null\n" + "MXDK,56,0.9997797234031688,1970-01-01 00:00:00.16,0.523,-32372,6884132,null,58,false,null,2015-01-20 06:18:18.583,null\n" + "XMKJ,139,0.8405815493567417,1970-01-01 00:00:00.17,0.306,25856,null,2015-05-18 03:50:22.731437,2,true,VTJW,2015-06-25 10:45:01.14,00000000 00 7c fb 01 19 ca f2 bf 84 5a 6f 38 35\n" + "VIHD,null,null,1970-01-01 00:00:00.18,0.550,22280,9109842,2015-01-25 13:51:38.270583,94,false,CPSW,2015-10-27 02:52:19.935,00000000 2d 16 f3 89 a3 83 64 de d6 fd c4 5b c4 e9\n" + "WPNX,null,0.9469700813926907,1970-01-01 00:00:00.19,0.415,-17933,674261,2015-03-04 15:43:15.213686,43,true,HYRX,2015-12-18 21:28:25.325,00000000 b3 4c 0e 8f f1 0c c5 60 b7 d1\n" + "YPOV,36,0.6741248448728824,1970-01-01 00:00:00.2,0.031,-5888,1375423,2015-12-10 20:50:35.866614,3,true,null,2015-07-23 20:17:04.236,00000000 d4 ab be 30 fa 8d ac 3d 98 a0 ad 9a 5d\n" + "NUHN,null,0.6940917925148332,1970-01-01 00:00:00.21,0.339,-25226,3524748,2015-05-07 04:07:18.152968,39,true,VTJW,2015-04-04 15:23:34.13,00000000 b8 be f8 a1 46 87 28 92 a3 9b e3 cb c2 64 8a b0\n" + "00000010 35 d8\n" + "BOSE,240,0.06001827721556019,1970-01-01 00:00:00.22,0.379,23904,9069339,2015-03-21 03:42:42.643186,84,true,null,null,null\n" + "INKG,124,0.8615841627702753,1970-01-01 00:00:00.23,0.404,-30383,7233542,2015-07-21 16:42:47.012148,99,false,null,2015-08-27 17:25:35.308,00000000 87 fc 92 83 fc 88 f3 32 27 70 c8 01 b0 dc c9 3a\n" + "00000010 5b 7e\n" + "FUXC,52,0.7430101994511517,1970-01-01 00:00:00.24,null,-14729,1042064,2015-08-21 02:10:58.949674,28,true,CPSW,2015-08-29 20:15:51.835,null\n" + "UNYQ,71,0.442095410281938,1970-01-01 00:00:00.25,0.539,-22611,null,2015-12-23 18:41:42.319859,98,true,PEHN,2015-01-26 00:55:50.202,00000000 28 ed 97 99 d8 77 33 3f b2 67 da 98 47 47 bf\n" + "KBMQ,null,0.28019218825051395,1970-01-01 00:00:00.26,null,12240,null,2015-08-16 01:02:55.766622,21,false,null,2015-05-19 00:47:18.698,00000000 6a de 46 04 d3 81 e7 a2 16 22 35 3b 1c\n" + "JSOL,243,null,1970-01-01 00:00:00.27,0.068,-17468,null,null,20,true,null,2015-06-19 10:38:54.483,00000000 3d e0 2d 04 86 e7 ca 29 98 07 69 ca 5b d6 cf 09\n" + "00000010 69\n" + "HNSS,150,null,1970-01-01 00:00:00.28,0.148,14841,5992443,null,25,false,PEHN,null,00000000 14 d6 fc ee 03 22 81 b8 06 c4 06 af\n" + "PZPB,101,0.061646717786158045,1970-01-01 00:00:00.29,null,12237,9878179,2015-09-03 22:13:18.852465,79,false,VTJW,2015-12-17 15:12:54.958,00000000 12 61 3a 9a ad 98 2e 75 52 ad 62 87 88 45 b9 9d\n" + "OYNN,25,0.3393509514000247,1970-01-01 00:00:00.3,0.628,22412,4736378,2015-10-10 12:19:42.528224,106,true,CPSW,2015-07-01 00:23:49.789,00000000 54 13 3f ff b6 7e cd 04 27 66 94 89 db\n" + "null,117,0.5638404775663161,1970-01-01 00:00:00.31,null,-5604,6353018,null,84,false,null,null,00000000 2b ad 25 07 db 62 44 33 6e 00 8e\n" + "HVRI,233,0.22407665790705777,1970-01-01 00:00:00.32,0.425,10469,1715213,null,86,false,null,2015-02-02 05:48:17.373,null\n" + "OYTO,96,0.7407581616916364,1970-01-01 00:00:00.33,0.528,-12239,3499620,2015-02-07 22:35:03.212268,17,false,PEHN,2015-03-29 12:55:11.682,null\n" + "LFCY,63,0.7217315729790722,1970-01-01 00:00:00.34,null,23344,9523982,null,123,false,CPSW,2015-05-18 04:35:27.228,00000000 05 e5 c0 4e cc d6 e3 7b 34 cd 15 35 bb a4\n" + "GHLX,148,0.3057937704964272,1970-01-01 00:00:00.35,0.636,-31457,2322337,2015-10-22 12:06:05.544701,91,true,HYRX,2015-05-21 09:33:18.158,00000000 57 1d 91 72 30 04 b7 02 cb 03\n" + "YTSZ,123,null,1970-01-01 00:00:00.36,0.519,22534,4446236,2015-07-27 07:23:37.233711,53,false,CPSW,2015-01-13 04:37:10.36,null\n" + "SWLU,251,null,1970-01-01 00:00:00.37,0.179,7734,4082475,2015-10-21 18:24:34.400345,69,false,PEHN,2015-04-01 14:33:42.5,null\n" + "TQJL,245,null,1970-01-01 00:00:00.38,0.865,9516,929340,2015-05-28 04:18:18.640567,69,false,VTJW,2015-06-12 20:12:28.881,00000000 6c 3e 51 d7 eb b1 07 71 32 1f af 40 4e 8c 47\n" + "REIJ,94,null,1970-01-01 00:00:00.39,0.130,-29924,null,2015-03-20 22:14:46.204718,113,true,HYRX,2015-12-19 13:58:41.819,null\n" + "HDHQ,94,0.7234181773407536,1970-01-01 00:00:00.4,0.730,19970,654131,2015-01-10 22:56:08.48045,84,true,null,2015-03-05 17:14:48.275,00000000 4f 56 6b 65 a4 53 38 e9 cd c1 a7 ee 86 75 ad a5\n" + "00000010 2d 49\n" + "UMEU,40,0.008444033230580739,1970-01-01 00:00:00.41,0.805,-11623,4599862,2015-11-20 04:02:44.335947,76,false,PEHN,2015-05-17 17:33:20.922,null\n" + "YJIH,184,null,1970-01-01 00:00:00.42,0.383,17614,3101671,2015-01-28 12:05:46.683001,105,true,null,2015-12-07 19:24:36.838,00000000 ec 69 cd 73 bb 9b c5 95 db 61 91 ce\n" + "CYXG,27,0.2917796053045747,1970-01-01 00:00:00.43,0.953,3944,249165,null,67,true,null,2015-03-02 08:19:44.566,00000000 01 48 15 3e 0c 7f 3f 8f e4 b5 ab 34 21 29\n" + "MRTG,143,0.02632531361499113,1970-01-01 00:00:00.44,0.943,-27320,1667842,2015-01-24 19:56:15.973109,11,false,null,2015-01-24 07:15:02.772,null\n" + "DONP,246,0.654226248740447,1970-01-01 00:00:00.45,0.556,27477,4160018,2015-12-14 03:40:05.911839,20,true,PEHN,2015-10-29 14:35:10.167,00000000 07 92 01 f5 6a a1 31 cd cb c2 a2 b4 8e 99\n" + "IQXS,232,0.23075700218038853,1970-01-01 00:00:00.46,0.049,-18113,4005228,2015-06-11 13:00:07.248188,8,true,CPSW,2015-08-16 11:09:24.311,00000000 fa 1f 92 24 b1 b8 67 65 08 b7 f8 41 00\n" + "null,178,null,1970-01-01 00:00:00.47,0.903,-14626,2934570,2015-04-04 08:51:54.068154,88,true,null,2015-07-01 04:32:23.83,00000000 84 36 25 63 2b 63 61 43 1c 47 7d b6 46 ba bb 98\n" + "00000010 ca 08 be a4\n" + "HUWZ,94,0.110401374979613,1970-01-01 00:00:00.48,0.420,-3736,5687514,2015-01-02 17:18:05.627633,74,false,null,2015-03-29 06:39:11.642,null\n" + "SRED,66,0.11274667140915928,1970-01-01 00:00:00.49,0.060,-10543,3669377,2015-10-22 02:53:02.381351,77,true,PEHN,null,00000000 7c 3f d6 88 3a 93 ef 24 a5 e2 bc\n";
            StringSink sink = new StringSink();
            // dump metadata
            assertResultSet(expected, sink, rs);
        }
    });
}
Also used : BaseConnection(org.postgresql.core.BaseConnection) StringSink(io.questdb.std.str.StringSink) AbstractGriffinTest(io.questdb.griffin.AbstractGriffinTest) Test(org.junit.Test)

Example 50 with StringSink

use of io.questdb.std.str.StringSink in project questdb by bluestreak01.

the class PGJobContextTest method testPreparedStatementInsertSelectNullNoDesignatedColumn.

@Test
public void testPreparedStatementInsertSelectNullNoDesignatedColumn() throws Exception {
    TestUtils.assertMemoryLeak(() -> {
        try (final PGWireServer ignored = createPGServer(2);
            final Connection connection = getConnection(false, false);
            final Statement statement = connection.createStatement();
            final PreparedStatement insert = connection.prepareStatement("insert into tab(ts, value) values(?, ?)")) {
            statement.execute("create table tab(ts timestamp, value double)");
            insert.setNull(1, Types.NULL);
            insert.setNull(2, Types.NULL);
            insert.executeUpdate();
            try (ResultSet rs = statement.executeQuery("select null, ts, value from tab where value = null")) {
                StringSink sink = new StringSink();
                String expected = "null[VARCHAR],ts[TIMESTAMP],value[DOUBLE]\n" + "null,null,null\n";
                assertResultSet(expected, sink, rs);
            }
            statement.execute("drop table tab");
        }
    });
}
Also used : BaseConnection(org.postgresql.core.BaseConnection) StringSink(io.questdb.std.str.StringSink) AbstractGriffinTest(io.questdb.griffin.AbstractGriffinTest) Test(org.junit.Test)

Aggregations

StringSink (io.questdb.std.str.StringSink)284 Test (org.junit.Test)167 Function (io.questdb.cairo.sql.Function)38 BaseConnection (org.postgresql.core.BaseConnection)36 UnaryFunction (io.questdb.griffin.engine.functions.UnaryFunction)28 StrConstant (io.questdb.griffin.engine.functions.constants.StrConstant)22 StrFunction (io.questdb.griffin.engine.functions.StrFunction)20 AbstractGriffinTest (io.questdb.griffin.AbstractGriffinTest)16 Path (io.questdb.std.str.Path)16 CountDownLatch (java.util.concurrent.CountDownLatch)15 CyclicBarrier (java.util.concurrent.CyclicBarrier)15 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)13 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)11 SqlCompiler (io.questdb.griffin.SqlCompiler)10 SqlExecutionContextImpl (io.questdb.griffin.SqlExecutionContextImpl)10 SqlException (io.questdb.griffin.SqlException)9 Metrics (io.questdb.Metrics)8 io.questdb.cairo (io.questdb.cairo)8 AllowAllCairoSecurityContext (io.questdb.cairo.security.AllowAllCairoSecurityContext)8 NetUtils (io.questdb.cutlass.NetUtils)8