Search in sources :

Example 6 with StringSink

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

the class GeoHashesTest method testLatLon.

@Test
public void testLatLon() throws NumericException {
    String expected = "24 -> s\n" + "789 -> sp\n" + "25248 -> sp0\n" + "807941 -> sp05\n" + "25854114 -> sp052\n" + "827331676 -> sp052w\n" + "26474613641 -> sp052w9\n" + "847187636514 -> sp052w92\n" + "27110004368469 -> sp052w92p\n" + "867520139791009 -> sp052w92p1\n" + "27760644473312309 -> sp052w92p1p\n" + "888340623145993896 -> sp052w92p1p8\n";
    final int maxGeoHashSizeChars = 12;
    String[] expectedStr = new String[maxGeoHashSizeChars];
    long[] expectedHash = new long[maxGeoHashSizeChars];
    StringSink everything = new StringSink();
    StringSink sink = Misc.getThreadLocalBuilder();
    for (int precision = 1; precision <= maxGeoHashSizeChars; precision++) {
        int numBits = precision * 5;
        long hash = GeoHashes.fromCoordinatesDeg(39.982, 0.024, numBits);
        sink.clear();
        GeoHashes.appendChars(hash, precision, sink);
        expectedStr[precision - 1] = sink.toString();
        expectedHash[precision - 1] = hash;
        everything.put(expectedHash[precision - 1]).put(" -> ").put(expectedStr[precision - 1]).put('\n');
    }
    for (int i = 0; i < maxGeoHashSizeChars; i++) {
        final long gh = GeoHashes.fromString(expectedStr[i], 0, expectedStr[i].length());
        Assert.assertEquals(expectedHash[i], gh);
        sink.clear();
        GeoHashes.appendChars(gh, expectedStr[i].length(), sink);
        Assert.assertEquals(expectedStr[i], sink.toString());
    }
    Assert.assertEquals(expected, everything.toString());
}
Also used : StringSink(io.questdb.std.str.StringSink) Test(org.junit.Test)

Example 7 with StringSink

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

the class GeoHashesTest method testFromStringIgnoreQuotesTruncateChars.

@Test
public void testFromStringIgnoreQuotesTruncateChars() throws NumericException {
    Assert.assertEquals(807941, GeoHashes.fromString("'sp052w92p1p'", 1, 5));
    StringSink sink = Misc.getThreadLocalBuilder();
    GeoHashes.appendChars(807941, 4, sink);
    Assert.assertEquals("sp05", sink.toString());
}
Also used : StringSink(io.questdb.std.str.StringSink) Test(org.junit.Test)

Example 8 with StringSink

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

the class GeoHashesTest method testToStringInvalidSizeInChars.

@Test
public void testToStringInvalidSizeInChars() {
    boolean assertsEnabled = false;
    // Test only when assertions enabled
    assert assertsEnabled = true;
    if (assertsEnabled) {
        StringSink sink = Misc.getThreadLocalBuilder();
        Assert.assertThrows(AssertionError.class, () -> GeoHashes.appendChars(-0, 0, sink));
        Assert.assertThrows(AssertionError.class, () -> GeoHashes.appendChars(-0, 31, sink));
    }
}
Also used : StringSink(io.questdb.std.str.StringSink) Test(org.junit.Test)

Example 9 with StringSink

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

the class TableReaderTest method testReadLong256One.

@Test
public void testReadLong256One() {
    try (TableModel model = new TableModel(configuration, "w", PartitionBy.DAY).col("l", ColumnType.LONG256).timestamp()) {
        CairoTestUtils.create(model);
    }
    final int N = 1_000_000;
    final Rnd rnd = new Rnd();
    long timestamp = 0;
    try (TableWriter writer = new TableWriter(configuration, "w")) {
        for (int i = 0; i < N; i++) {
            TableWriter.Row row = writer.newRow(timestamp);
            row.putLong256(0, "0x" + padHexLong(rnd.nextLong()));
            row.append();
        }
        writer.commit();
    }
    rnd.reset();
    final StringSink sink = new StringSink();
    try (TableReader reader = new TableReader(configuration, "w")) {
        final RecordCursor cursor = reader.getCursor();
        final Record record = cursor.getRecord();
        int count = 0;
        while (cursor.hasNext()) {
            sink.clear();
            record.getLong256(0, sink);
            TestUtils.assertEquals("0x" + padHexLong(rnd.nextLong()), sink);
            count++;
        }
        Assert.assertEquals(N, count);
    }
}
Also used : RecordCursor(io.questdb.cairo.sql.RecordCursor) StringSink(io.questdb.std.str.StringSink) Record(io.questdb.cairo.sql.Record) Test(org.junit.Test)

Example 10 with StringSink

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

the class GeoHashesTest method testFromStringTruncatingNlIgnoreQuotesTruncateBits1.

@Test
public void testFromStringTruncatingNlIgnoreQuotesTruncateBits1() throws NumericException {
    Assert.assertEquals(807941, GeoHashes.fromStringTruncatingNl("'sp052w92p1p'", 1, 11, 20));
    StringSink sink = Misc.getThreadLocalBuilder();
    GeoHashes.appendChars(807941, 4, sink);
    Assert.assertEquals("sp05", sink.toString());
}
Also used : StringSink(io.questdb.std.str.StringSink) 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