use of io.questdb.std.str.StringSink in project questdb by questdb.
the class TableReaderTailRecordCursorTest method testBusyPoll.
private void testBusyPoll(long timestampIncrement, int n, String createStatement) throws Exception {
assertMemoryLeak(() -> {
compiler.compile(createStatement, sqlExecutionContext);
final AtomicInteger errorCount = new AtomicInteger();
final CyclicBarrier barrier = new CyclicBarrier(2);
final CountDownLatch latch = new CountDownLatch(2);
new Thread(() -> {
try (TableWriter writer = engine.getWriter(AllowAllCairoSecurityContext.INSTANCE, "xyz", "testing")) {
barrier.await();
long ts = 0;
long addr = Unsafe.malloc(128, MemoryTag.NATIVE_DEFAULT);
try {
Rnd rnd = new Rnd();
for (int i = 0; i < n; i++) {
if (errorCount.get() > 0) {
// Reader already failed
return;
}
TableWriter.Row row = writer.newRow(ts);
row.putInt(0, i);
for (int k = 0; k < 128; k++) {
Unsafe.getUnsafe().putByte(addr + k, rnd.nextByte());
}
row.putBin(1, addr, 128);
row.putLong(2, rnd.nextLong());
row.append();
writer.commit();
ts += timestampIncrement;
}
} finally {
Unsafe.free(addr, 128, MemoryTag.NATIVE_DEFAULT);
}
} catch (Throwable e) {
e.printStackTrace();
errorCount.incrementAndGet();
} finally {
latch.countDown();
}
}).start();
new Thread(() -> {
try (TableReader reader = engine.getReader(AllowAllCairoSecurityContext.INSTANCE, "xyz", TableUtils.ANY_TABLE_ID, TableUtils.ANY_TABLE_VERSION)) {
Rnd rnd = new Rnd();
int count = 0;
final TableReaderTailRecordCursor cursor = new TableReaderTailRecordCursor();
cursor.of(reader);
final Record record = cursor.getRecord();
barrier.await();
while (count < n) {
if (cursor.reload()) {
while (cursor.hasNext()) {
if (count != record.getInt(0)) {
errorCount.incrementAndGet();
StringSink ss = new StringSink();
ss.put("[");
for (int i = 0; i < reader.getPartitionCount(); i++) {
ss.put(reader.getPartitionRowCount(i));
ss.put(",");
}
ss.put("]:").put(reader.getTxn());
int val = record.getInt(0);
Assert.assertEquals(ss.toString(), count, record.getInt(0));
}
BinarySequence binarySequence = record.getBin(1);
for (int i = 0; i < 128; i++) {
Assert.assertEquals(rnd.nextByte(), binarySequence.byteAt(i));
}
Assert.assertEquals(rnd.nextLong(), record.getLong(2));
count++;
}
}
}
} catch (Throwable e) {
e.printStackTrace();
errorCount.incrementAndGet();
} finally {
latch.countDown();
}
}).start();
Assert.assertTrue(latch.await(600, TimeUnit.SECONDS));
Assert.assertEquals(0, errorCount.get());
Thread.sleep(1000);
});
}
use of io.questdb.std.str.StringSink in project questdb by questdb.
the class CastDoubleToStrFunctionFactory method newInstance.
@Override
public Function newInstance(int position, ObjList<Function> args, IntList argPositions, CairoConfiguration configuration, SqlExecutionContext sqlExecutionContext) {
Function intFunc = args.getQuick(0);
if (intFunc.isConstant()) {
final StringSink sink = Misc.getThreadLocalBuilder();
sink.put(intFunc.getDouble(null), configuration.getDoubleToStrCastScale());
return new StrConstant(Chars.toString(sink));
}
return new Func(args.getQuick(0), configuration.getDoubleToStrCastScale());
}
use of io.questdb.std.str.StringSink in project questdb by questdb.
the class CastDoubleToSymbolFunctionFactory method newInstance.
@Override
public Function newInstance(int position, ObjList<Function> args, IntList argPositions, CairoConfiguration configuration, SqlExecutionContext sqlExecutionContext) {
final Function arg = args.getQuick(0);
if (arg.isConstant()) {
final StringSink sink = Misc.getThreadLocalBuilder();
sink.put(arg.getDouble(null), configuration.getDoubleToStrCastScale());
return SymbolConstant.newInstance(sink);
}
return new Func(arg, configuration.getDoubleToStrCastScale());
}
use of io.questdb.std.str.StringSink in project questdb by questdb.
the class CastDateToStrFunctionFactory method newInstance.
@Override
public Function newInstance(int position, ObjList<Function> args, IntList argPositions, CairoConfiguration configuration, SqlExecutionContext sqlExecutionContext) {
Function func = args.getQuick(0);
if (func.isConstant()) {
StringSink sink = Misc.getThreadLocalBuilder();
sink.put(func.getDate(null));
return new StrConstant(Chars.toString(sink));
}
return new Func(args.getQuick(0));
}
use of io.questdb.std.str.StringSink in project questdb by questdb.
the class CastCharToSymbolFunctionFactory method newInstance.
@Override
public Function newInstance(int position, ObjList<Function> args, IntList argPositions, CairoConfiguration configuration, SqlExecutionContext sqlExecutionContext) {
final Function arg = args.getQuick(0);
if (arg.isConstant()) {
final char value = arg.getChar(null);
if (value == 0) {
return SymbolConstant.NULL;
}
final StringSink sink = Misc.getThreadLocalBuilder();
sink.put(value);
return SymbolConstant.newInstance(Chars.toString(sink));
}
return new Func(arg);
}
Aggregations