use of io.questdb.std.Long256 in project questdb by bluestreak01.
the class TelemetryJob method updateTelemetryConfig.
private TableWriter updateTelemetryConfig(SqlCompiler compiler, SqlExecutionContextImpl sqlExecutionContext, boolean enabled) throws SqlException {
final TableWriter configWriter = compiler.getEngine().getWriter(AllowAllCairoSecurityContext.INSTANCE, configTableName, WRITER_LOCK_REASON);
final CompiledQuery cc = compiler.compile(configTableName + " LIMIT -1", sqlExecutionContext);
try (final RecordCursor cursor = cc.getRecordCursorFactory().getCursor(sqlExecutionContext)) {
if (cursor.hasNext()) {
final Record record = cursor.getRecord();
final boolean _enabled = record.getBool(1);
Long256 l256 = record.getLong256A(0);
final CharSequence lastVersion = record.getSym(2);
// we need to update the table to reflect that
if (enabled != _enabled || !configuration.getBuildInformation().getQuestDbVersion().equals(lastVersion)) {
appendConfigRow(compiler, configWriter, l256, enabled);
LOG.info().$("instance config changes [id=").$256(l256.getLong0(), l256.getLong1(), 0, 0).$(", enabled=").$(enabled).$(']').$();
} else {
LOG.error().$("instance [id=").$256(l256.getLong0(), l256.getLong1(), 0, 0).$(", enabled=").$(enabled).$(']').$();
}
} else {
// if there are no record for telemetry id we need to create one using clocks
appendConfigRow(compiler, configWriter, null, enabled);
}
}
return configWriter;
}
use of io.questdb.std.Long256 in project questdb by bluestreak01.
the class InsertTest method testBindVariableInsert.
private void testBindVariableInsert(int partitionBy, TimestampFunction timestampFunction, boolean initBindVariables, boolean columnSet) throws Exception {
assertMemoryLeak(() -> {
CairoTestUtils.createAllTableWithNewTypes(configuration, partitionBy);
// this is BLOB
byte[] blob = new byte[500];
TestBinarySequence bs = new TestBinarySequence();
bs.of(blob);
Rnd rnd = new Rnd();
if (initBindVariables) {
// this is type declaration to have query compile correctly
bindVariableService.setInt(0, 0);
bindVariableService.setShort(1, (short) 10);
bindVariableService.setByte(2, (byte) 91);
bindVariableService.setDouble(3, 9.2);
bindVariableService.setFloat(4, 5.6f);
bindVariableService.setLong(5, 99901);
bindVariableService.setStr(6, "hello kitty");
bindVariableService.setStr(7, "sym?");
bindVariableService.setBoolean(8, true);
bindVariableService.setBin(9, bs);
bindVariableService.setDate(10, 1234L);
bindVariableService.setLong256(11, 1, 2, 3, 4);
bindVariableService.setChar(12, 'A');
bindVariableService.setTimestamp(13, timestampFunction.getTimestamp());
}
final String sql;
if (columnSet) {
sql = "insert into all2 (" + "int, " + "short, " + "byte, " + "double, " + "float, " + "long, " + "str, " + "sym, " + "bool, " + "bin, " + "date, " + "long256, " + "chr, " + "timestamp" + ") values (" + "$1, " + "$2, " + "$3, " + "$4, " + "$5, " + "$6, " + "$7, " + "$8, " + "$9, " + "$10, " + "$11, " + "$12, " + "$13, " + "$14)";
} else {
sql = "insert into all2 values (" + "$1, " + "$2, " + "$3, " + "$4, " + "$5, " + "$6, " + "$7, " + "$8, " + "$9, " + "$10, " + "$11, " + "$12, " + "$13, " + "$14)";
}
final CompiledQuery cq = compiler.compile(sql, sqlExecutionContext);
Assert.assertEquals(CompiledQuery.INSERT, cq.getType());
InsertStatement insert = cq.getInsertStatement();
try (InsertMethod method = insert.createMethod(sqlExecutionContext)) {
for (int i = 0; i < 10_000; i++) {
bindVariableService.setInt(0, rnd.nextInt());
bindVariableService.setShort(1, rnd.nextShort());
bindVariableService.setByte(2, rnd.nextByte());
bindVariableService.setDouble(3, rnd.nextDouble());
bindVariableService.setFloat(4, rnd.nextFloat());
bindVariableService.setLong(5, rnd.nextLong());
bindVariableService.setStr(6, rnd.nextChars(6));
bindVariableService.setStr(7, rnd.nextChars(1));
bindVariableService.setBoolean(8, rnd.nextBoolean());
rnd.nextBytes(blob);
bindVariableService.setBin(9, bs);
bindVariableService.setDate(10, rnd.nextLong());
bindVariableService.setLong256(11, rnd.nextLong(), rnd.nextLong(), rnd.nextLong(), rnd.nextLong());
bindVariableService.setChar(12, rnd.nextChar());
bindVariableService.setTimestamp(13, timestampFunction.getTimestamp());
method.execute();
}
method.commit();
}
rnd.reset();
try (TableReader reader = engine.getReader(sqlExecutionContext.getCairoSecurityContext(), "all2")) {
final TableReaderRecordCursor cursor = reader.getCursor();
final Record record = cursor.getRecord();
while (cursor.hasNext()) {
Assert.assertEquals(rnd.nextInt(), record.getInt(0));
Assert.assertEquals(rnd.nextShort(), record.getShort(1));
Assert.assertEquals(rnd.nextByte(), record.getByte(2));
Assert.assertEquals(rnd.nextDouble(), record.getDouble(3), 0.0001);
Assert.assertEquals(rnd.nextFloat(), record.getFloat(4), 0.000001);
Assert.assertEquals(rnd.nextLong(), record.getLong(5));
TestUtils.assertEquals(rnd.nextChars(6), record.getStr(6));
TestUtils.assertEquals(rnd.nextChars(1), record.getSym(7));
Assert.assertEquals(rnd.nextBoolean(), record.getBool(8));
rnd.nextBytes(blob);
BinarySequence binarySequence = record.getBin(9);
Assert.assertEquals(blob.length, binarySequence.length());
for (int j = 0, m = blob.length; j < m; j++) {
Assert.assertEquals(blob[j], binarySequence.byteAt(j));
}
Assert.assertEquals(rnd.nextLong(), record.getDate(10));
Long256 long256 = record.getLong256A(11);
Assert.assertEquals(rnd.nextLong(), long256.getLong0());
Assert.assertEquals(rnd.nextLong(), long256.getLong1());
Assert.assertEquals(rnd.nextLong(), long256.getLong2());
Assert.assertEquals(rnd.nextLong(), long256.getLong3());
Assert.assertEquals(rnd.nextChar(), record.getChar(12));
}
}
});
}
Aggregations