use of io.questdb.cairo.security.CairoSecurityContextImpl in project questdb by bluestreak01.
the class SecurityTest method testTreeResizesWithImplicitGroupBy.
@Test
public void testTreeResizesWithImplicitGroupBy() throws Exception {
SqlExecutionContext readOnlyExecutionContext = new SqlExecutionContextImpl(engine, 1).with(new CairoSecurityContextImpl(false), bindVariableService, null, -1, null);
assertMemoryLeak(() -> {
sqlExecutionContext.getRandom().reset();
compiler.compile("create table tb1 as (select" + " rnd_symbol(4,4,4,20000) sym1," + " rnd_symbol(2,2,2,20000) sym2," + " rnd_double(2) d," + " timestamp_sequence(0, 1000000000) ts" + " from long_sequence(2000)) timestamp(ts)", sqlExecutionContext);
assertQuery(memoryRestrictedCompiler, "sym2\tcount\nGZ\t1040\nRX\t960\n", "select sym2, count() from tb1 order by sym2", null, true, readOnlyExecutionContext, true);
try {
assertQuery(memoryRestrictedCompiler, "sym1\tcount\nPEHN\t265\nCPSW\t231\nHYRX\t262\nVTJW\t242\n", "select sym1, count() from tb1 order by sym1", null, readOnlyExecutionContext, true, true, true);
Assert.fail();
} catch (Exception ex) {
Assert.assertTrue(ex.toString().contains("Maximum number of pages (2) breached"));
}
});
}
use of io.questdb.cairo.security.CairoSecurityContextImpl in project questdb by bluestreak01.
the class SecurityTest method testMemoryResizesWithImplicitGroupBy.
@Test
public void testMemoryResizesWithImplicitGroupBy() throws Exception {
SqlExecutionContext readOnlyExecutionContext = new SqlExecutionContextImpl(engine, 1).with(new CairoSecurityContextImpl(false), bindVariableService, null, -1, null);
assertMemoryLeak(() -> {
sqlExecutionContext.getRandom().reset();
compiler.compile("create table tb1 as (select" + " rnd_symbol(4,4,4,20000) sym1," + " rnd_symbol(2,2,2,20000) sym2," + " rnd_double(2) d," + " timestamp_sequence(0, 1000000000) ts" + " from long_sequence(1000)) timestamp(ts)", sqlExecutionContext);
assertQuery(memoryRestrictedCompiler, "sym2\td\nGZ\t0.006817672510656014\nGZ\t0.0014986299883373855\nGZ\t0.007868356216637062\nGZ\t0.007985454958725269\nGZ\t0.0011075361080621349\nRX\t4.016718301054212E-4\nRX\t0.006651203432318287\nRX\t6.503932953429992E-4\nRX\t0.0072398675350549\nRX\t0.0016532800623808575\n", "select sym2, d from tb1 where d < 0.01 order by sym2", null, true, readOnlyExecutionContext);
try {
assertQuery(memoryRestrictedCompiler, "", "select sym2, d from tb1 order by sym2", null, true, readOnlyExecutionContext);
Assert.fail();
} catch (Exception ex) {
Assert.assertTrue(ex.toString().contains("Maximum number of pages (11) breached"));
}
});
}
use of io.questdb.cairo.security.CairoSecurityContextImpl in project questdb by bluestreak01.
the class SecurityTest method setUpReadOnlyExecutionContext.
@BeforeClass
public static void setUpReadOnlyExecutionContext() {
CairoConfiguration readOnlyConfiguration = new DefaultCairoConfiguration(root) {
@Override
public int getSqlMapPageSize() {
return 64;
}
@Override
public int getSqlMapMaxResizes() {
return 2;
}
@Override
public long getSqlSortKeyPageSize() {
return 64;
}
@Override
public int getSqlSortKeyMaxPages() {
return 2;
}
@Override
public int getSqlJoinMetadataPageSize() {
return 64;
}
@Override
public int getSqlJoinMetadataMaxResizes() {
return 10;
}
@Override
public long getSqlSortLightValuePageSize() {
return 1024;
}
@Override
public int getSqlSortLightValueMaxPages() {
return 11;
}
};
memoryRestrictedEngine = new CairoEngine(readOnlyConfiguration);
SqlExecutionInterruptor dummyInterruptor = () -> {
int nCalls = nCheckInterruptedCalls.incrementAndGet();
int max = maxNCheckInterruptedCalls;
if (nCalls > max) {
throw CairoException.instance(0).put("Interrupting SQL processing, max calls is ").put(max);
}
};
readOnlyExecutionContext = new SqlExecutionContextImpl(memoryRestrictedEngine, 1).with(new CairoSecurityContextImpl(false), bindVariableService, null, -1, dummyInterruptor);
memoryRestrictedCompiler = new SqlCompiler(memoryRestrictedEngine);
}
Aggregations