Search in sources :

Example 91 with StringSink

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

the class FunctionFactoryDescriptor method replaceSignatureNameAndSwapArgs.

public static String replaceSignatureNameAndSwapArgs(String name, String signature) throws SqlException {
    int openBraceIndex = validateSignatureAndGetNameSeparator(signature);
    StringSink signatureBuilder = Misc.getThreadLocalBuilder();
    signatureBuilder.put(name);
    signatureBuilder.put('(');
    for (int i = signature.length() - 2; i > openBraceIndex; i--) {
        char curr = signature.charAt(i);
        if (curr == '[') {
            signatureBuilder.put("[]");
        } else if (curr != ']') {
            signatureBuilder.put(curr);
        }
    }
    signatureBuilder.put(')');
    return signatureBuilder.toString();
}
Also used : StringSink(io.questdb.std.str.StringSink)

Example 92 with StringSink

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

the class LineTcpMeasurementScheduler method getTableUpdateDetailsFromSharedArea.

private TableUpdateDetails getTableUpdateDetailsFromSharedArea(@NotNull NetworkIOJob netIoJob, @NotNull LineTcpParser parser) {
    final DirectByteCharSequence tableNameUtf8 = parser.getMeasurementName();
    final StringSink tableNameUtf16 = tableNameSinks[netIoJob.getWorkerId()];
    tableNameUtf16.clear();
    Chars.utf8Decode(tableNameUtf8.getLo(), tableNameUtf8.getHi(), tableNameUtf16);
    tableUpdateDetailsLock.writeLock().lock();
    try {
        TableUpdateDetails tab;
        final int tudKeyIndex = tableUpdateDetailsUtf16.keyIndex(tableNameUtf16);
        if (tudKeyIndex < 0) {
            tab = tableUpdateDetailsUtf16.valueAt(tudKeyIndex);
        } else {
            int status = engine.getStatus(securityContext, path, tableNameUtf16, 0, tableNameUtf16.length());
            if (status != TableUtils.TABLE_EXISTS) {
                // validate that parser entities do not contain NULLs
                TableStructureAdapter tsa = tableStructureAdapter.of(tableNameUtf16, parser);
                for (int i = 0, n = tsa.getColumnCount(); i < n; i++) {
                    if (tsa.getColumnType(i) == LineTcpParser.ENTITY_TYPE_NULL) {
                        throw CairoException.instance(0).put("unknown column type [columnName=").put(tsa.getColumnName(i)).put(']');
                    }
                }
                LOG.info().$("creating table [tableName=").$(tableNameUtf16).$(']').$();
                engine.createTable(securityContext, ddlMem, path, tsa);
            }
            final int idleTudKeyIndex = idleTableUpdateDetailsUtf16.keyIndex(tableNameUtf16);
            if (idleTudKeyIndex < 0) {
                tab = idleTableUpdateDetailsUtf16.valueAt(idleTudKeyIndex);
                LOG.info().$("idle table going active [tableName=").$(tab.getTableNameUtf16()).I$();
                if (tab.getWriter() == null) {
                    tab.closeNoLock();
                    // Use actual table name from the "details" to avoid case mismatches in the
                    // WriterPool. There was an error in the LineTcpReceiverFuzzTest, which helped
                    // to identify the cause
                    tab = unsafeAssignTableToWriterThread(tudKeyIndex, tab.getTableNameUtf16());
                } else {
                    idleTableUpdateDetailsUtf16.removeAt(idleTudKeyIndex);
                    tableUpdateDetailsUtf16.putAt(tudKeyIndex, tab.getTableNameUtf16(), tab);
                }
            } else {
                TelemetryTask.doStoreTelemetry(engine, Telemetry.SYSTEM_ILP_RESERVE_WRITER, Telemetry.ORIGIN_ILP_TCP);
                tab = unsafeAssignTableToWriterThread(tudKeyIndex, tableNameUtf16);
            }
        }
        // here we need to create a string image (mangled) of utf8 char sequence
        // deliberately not decoding UTF8, store bytes as chars each
        tableNameUtf16.clear();
        tableNameUtf16.put(tableNameUtf8);
        // at this point this is not UTF16 string
        netIoJob.addTableUpdateDetails(tableNameUtf16.toString(), tab);
        return tab;
    } finally {
        tableUpdateDetailsLock.writeLock().unlock();
    }
}
Also used : DirectByteCharSequence(io.questdb.std.str.DirectByteCharSequence) StringSink(io.questdb.std.str.StringSink)

Example 93 with StringSink

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

the class TextException method $.

public static TextException $(CharSequence message) {
    TextException te = tlException.get();
    StringSink sink = te.message;
    sink.clear();
    sink.put(message);
    return te;
}
Also used : StringSink(io.questdb.std.str.StringSink)

Example 94 with StringSink

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

the class TableReaderMetadataTimestampTest method assertThat.

private void assertThat(String expected, int expectedInitialTimestampIndex) throws Exception {
    int columnCount = 11;
    TestUtils.assertMemoryLeak(() -> {
        try (Path path = new Path().of(root).concat("all")) {
            try (TableReaderMetadata metadata = new TableReaderMetadata(FilesFacadeImpl.INSTANCE, path.concat(TableUtils.META_FILE_NAME).$())) {
                Assert.assertEquals(12, metadata.getColumnCount());
                Assert.assertEquals(expectedInitialTimestampIndex, metadata.getTimestampIndex());
                long structureVersion;
                try (TableWriter writer = new TableWriter(configuration, "all", metrics)) {
                    writer.removeColumn("timestamp");
                    structureVersion = writer.getStructureVersion();
                }
                long pTransitionIndex = metadata.createTransitionIndex(structureVersion);
                StringSink sink = new StringSink();
                try {
                    metadata.applyTransitionIndex();
                    Assert.assertEquals(columnCount, metadata.getColumnCount());
                    for (int i = 0; i < columnCount; i++) {
                        sink.put(metadata.getColumnName(i)).put(':').put(ColumnType.nameOf(metadata.getColumnType(i))).put('\n');
                    }
                    TestUtils.assertEquals(expected, sink);
                    Assert.assertEquals(-1, metadata.getTimestampIndex());
                } finally {
                    TableUtils.freeTransitionIndex(pTransitionIndex);
                }
            }
        }
    });
}
Also used : Path(io.questdb.std.str.Path) StringSink(io.questdb.std.str.StringSink)

Example 95 with StringSink

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

the class TableReaderTest method testReadLong256Four.

@Test
public void testReadLong256Four() {
    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", metrics)) {
        for (int i = 0; i < N; i++) {
            TableWriter.Row row = writer.newRow(timestamp);
            row.putLong256(0, "0x" + padHexLong(rnd.nextLong()) + padHexLong(rnd.nextLong()) + padHexLong(rnd.nextLong()) + 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()) + padHexLong(rnd.nextLong()) + padHexLong(rnd.nextLong()) + 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)

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