use of com.hazelcast.sql.impl.optimizer.SqlPlan in project hazelcast by hazelcast.
the class CalciteSqlOptimizer method toCreateMappingPlan.
private SqlPlan toCreateMappingPlan(PlanKey planKey, SqlCreateMapping sqlCreateMapping) {
List<MappingField> mappingFields = sqlCreateMapping.columns().map(field -> new MappingField(field.name(), field.type(), field.externalName())).collect(toList());
Mapping mapping = new Mapping(sqlCreateMapping.nameWithoutSchema(), sqlCreateMapping.externalName(), sqlCreateMapping.type(), mappingFields, sqlCreateMapping.options());
return new CreateMappingPlan(planKey, mapping, sqlCreateMapping.getReplace(), sqlCreateMapping.ifNotExists(), planExecutor);
}
use of com.hazelcast.sql.impl.optimizer.SqlPlan in project hazelcast by hazelcast.
the class PlanCacheIntegrationTest method testPlanIsCached.
@Test
public void testPlanIsCached() {
createMapping(mapName, int.class, int.class);
instance().getMap(mapName).put(1, 1);
PlanCache planCache = planCache(instance());
instance().getSql().execute("SELECT * FROM " + mapName);
assertEquals(1, planCache.size());
SqlPlan plan1 = planCache.get(planCache.getPlans().keys().nextElement());
instance().getSql().execute("SELECT * FROM " + mapName);
assertEquals(1, planCache.size());
SqlPlan plan2 = planCache.get(planCache.getPlans().keys().nextElement());
assertSame(plan1, plan2);
}
use of com.hazelcast.sql.impl.optimizer.SqlPlan in project hazelcast by hazelcast.
the class PlanCacheIntegrationTest method testPlanInvalidatedOnIndexAdd.
@Test
public void testPlanInvalidatedOnIndexAdd() {
IMap<Integer, Integer> map = instance().getMap(mapName);
createMapping(mapName, int.class, int.class);
map.put(1, 1);
PlanCache planCache = planCache(instance());
instance().getSql().execute("SELECT * FROM " + mapName + " WHERE this=1");
assertEquals(1, planCache.size());
SqlPlan plan1 = planCache.get(planCache.getPlans().keys().nextElement());
map.addIndex(IndexType.HASH, "this");
assertTrueEventually(() -> {
instance().getSql().execute("SELECT * FROM " + mapName + " WHERE this=1");
assertEquals(1, planCache.size());
SqlPlan plan2 = planCache.get(planCache.getPlans().keys().nextElement());
assertNotSame(plan1, plan2);
});
}
use of com.hazelcast.sql.impl.optimizer.SqlPlan in project hazelcast by hazelcast.
the class PlanCacheTest method testPlanUsageUpdate.
@Test
public void testPlanUsageUpdate() {
PlanCache cache = new PlanCache(10);
PlanKey key = createKey("sql");
SqlPlan plan = createPlan(key, PART_MAP_1);
cache.put(key, plan);
long timestamp1 = plan.getPlanLastUsed();
assertTrue(timestamp1 > 0);
advanceTime();
cache.put(key, plan);
long timestamp2 = plan.getPlanLastUsed();
assertTrue(timestamp2 > timestamp1);
advanceTime();
cache.get(key);
long timestamp3 = plan.getPlanLastUsed();
assertTrue(timestamp3 > timestamp2);
}
Aggregations