use of io.questdb.std.str.StringSink in project questdb by questdb.
the class BindVariableServiceImplTest method testNamedSetLong256ToLong256NoDefine.
@Test
public void testNamedSetLong256ToLong256NoDefine() throws SqlException {
bindVariableService.setLong256("x", 888, 777, 6666, 5555);
StringSink sink = new StringSink();
bindVariableService.getFunction(":x").getLong256(null, sink);
TestUtils.assertEquals("0x15b30000000000001a0a00000000000003090000000000000378", sink);
}
use of io.questdb.std.str.StringSink in project questdb by questdb.
the class BindVariableServiceImplTest method testNamedSetLong256ToLong256AsObj.
@Test
public void testNamedSetLong256ToLong256AsObj() throws SqlException {
final Long256Impl long256 = new Long256Impl();
long256.setAll(888, 999, 777, 111);
bindVariableService.setLong256("x");
bindVariableService.setLong256("x", long256);
final StringSink sink = new StringSink();
bindVariableService.getFunction(":x").getLong256(null, sink);
TestUtils.assertEquals("0x6f000000000000030900000000000003e70000000000000378", sink);
}
use of io.questdb.std.str.StringSink in project questdb by questdb.
the class StrConstantTest method testConstant.
@Test
public void testConstant() {
StrConstant constant = new StrConstant("abc");
Assert.assertTrue(constant.isConstant());
TestUtils.assertEquals("abc", constant.getStr(null));
TestUtils.assertEquals("abc", constant.getStrB(null));
Assert.assertEquals(3, constant.getStrLen(null));
CharSink sink = new StringSink();
constant.getStr(null, sink);
TestUtils.assertEquals("abc", (CharSequence) sink);
}
use of io.questdb.std.str.StringSink in project questdb by questdb.
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;
}
}
use of io.questdb.std.str.StringSink in project questdb by questdb.
the class PageFrameCursorTest method testVarColumnWithColumnTop.
@Test
public void testVarColumnWithColumnTop() throws Exception {
assertMemoryLeak(() -> {
compiler.compile("create table x as (select" + " rnd_int() a," + " rnd_str() b," + " timestamp_sequence(to_timestamp('2022-01-13T00:00:00', 'yyyy-MM-ddTHH:mm:ss'), 100000L) t" + " from long_sequence(10)" + ") timestamp (t) partition by DAY", sqlExecutionContext);
compiler.compile("alter table x add column c string", sqlExecutionContext).execute(null).await();
compiler.compile("insert into x " + "select" + " rnd_int() a," + " rnd_str() b," + " timestamp_sequence(to_timestamp('2022-01-13T00:00:01', 'yyyy-MM-ddTHH:mm:ss'), 100000L) t," + " rnd_str() c" + " from long_sequence(10)", sqlExecutionContext);
TestUtils.printSql(compiler, sqlExecutionContext, "select b from x", sink);
final StringSink actualSink = new StringSink();
// header
actualSink.put("b\n");
try (RecordCursorFactory factory = compiler.compile("x", sqlExecutionContext).getRecordCursorFactory()) {
// test that we can read string column without using index
try (PageFrameCursor pageFrameCursor = factory.getPageFrameCursor(sqlExecutionContext)) {
PageFrame frame;
while ((frame = pageFrameCursor.next()) != null) {
long size = frame.getPageSize(1);
long topOfVarAddress = frame.getPageAddress(1);
long fixAddress = frame.getIndexPageAddress(1);
long count = frame.getPartitionHi() - frame.getPartitionLo();
while (count > 0) {
// validate that index column has correct offsets
final long offset = Unsafe.getUnsafe().getLong(fixAddress);
Assert.assertTrue(offset >= 0 && offset < size);
fixAddress += 8;
long varAddress = topOfVarAddress + offset;
// string len
int len = Unsafe.getUnsafe().getInt(varAddress);
varAddress += 4;
if (len != -1) {
for (int i = 0; i < len; i++) {
actualSink.put(Unsafe.getUnsafe().getChar(varAddress + i * 2L));
}
}
actualSink.put('\n');
count--;
}
}
TestUtils.assertEquals(sink, actualSink);
}
}
});
}
Aggregations