use of com.hazelcast.sql.impl.optimizer.PlanKey in project hazelcast by hazelcast.
the class PlanCacheTest method testBasicOperations.
@Test
public void testBasicOperations() {
PlanCache cache = new PlanCache(10);
PlanKey key = createKey("sql");
// Put plan
SqlPlan plan1 = createPlan(key, PART_MAP_1);
cache.put(key, plan1);
assertEquals(1, cache.size());
assertSame(plan1, cache.get(key));
// Overwrite plan
SqlPlan plan2 = createPlan(key, PART_MAP_2);
cache.put(key, plan2);
assertEquals(1, cache.size());
assertSame(plan2, cache.get(key));
// Invalidate the plan that is no longer cached
cache.invalidate(plan1);
assertEquals(1, cache.size());
assertSame(plan2, cache.get(key));
// Invalidate cache plan
cache.invalidate(plan2);
assertEquals(0, cache.size());
assertNull(cache.get(key));
// Clear
cache.put(key, plan1);
assertEquals(1, cache.size());
assertSame(plan1, cache.get(key));
cache.clear();
assertEquals(0, cache.size());
assertNull(cache.get(key));
}
use of com.hazelcast.sql.impl.optimizer.PlanKey in project hazelcast by hazelcast.
the class SqlServiceImpl method prepare.
private SqlPlan prepare(String schema, String sql, List<Object> arguments, SqlExpectedResultType expectedResultType) {
List<List<String>> searchPaths = prepareSearchPaths(schema);
PlanKey planKey = new PlanKey(searchPaths, sql);
SqlPlan plan = planCache.get(planKey);
if (plan == null) {
SqlCatalog catalog = new SqlCatalog(optimizer.tableResolvers());
plan = optimizer.prepare(new OptimizationTask(sql, arguments, searchPaths, catalog));
if (plan.isCacheable()) {
planCache.put(planKey, plan);
}
}
checkReturnType(plan, expectedResultType);
return plan;
}
use of com.hazelcast.sql.impl.optimizer.PlanKey in project hazelcast by hazelcast.
the class PlanKeyTest method testEquals.
@Test
public void testEquals() {
PlanKey key = new PlanKey(singletonList(singletonList("schema1")), "sql1");
checkEquals(key, new PlanKey(singletonList(singletonList("schema1")), "sql1"), true);
checkEquals(key, new PlanKey(singletonList(singletonList("schema2")), "sql1"), false);
checkEquals(key, new PlanKey(singletonList(singletonList("schema1")), "sql2"), false);
}
use of com.hazelcast.sql.impl.optimizer.PlanKey in project hazelcast by hazelcast.
the class CalciteSqlOptimizer method createPlan.
@SuppressWarnings("checkstyle:returncount")
private SqlPlan createPlan(OptimizationTask task, QueryParseResult parseResult, OptimizerContext context) {
// TODO [sasha] : refactor this.
SqlNode node = parseResult.getNode();
PlanKey planKey = new PlanKey(task.getSearchPaths(), task.getSql());
if (node instanceof SqlCreateMapping) {
return toCreateMappingPlan(planKey, (SqlCreateMapping) node);
} else if (node instanceof SqlDropMapping) {
return toDropMappingPlan(planKey, (SqlDropMapping) node);
} else if (node instanceof SqlCreateIndex) {
return toCreateIndexPlan(planKey, (SqlCreateIndex) node);
} else if (node instanceof SqlDropIndex) {
return toDropIndexPlan(planKey, (SqlDropIndex) node);
} else if (node instanceof SqlCreateJob) {
return toCreateJobPlan(planKey, parseResult, context, task.getSql());
} else if (node instanceof SqlAlterJob) {
return toAlterJobPlan(planKey, (SqlAlterJob) node);
} else if (node instanceof SqlDropJob) {
return toDropJobPlan(planKey, (SqlDropJob) node);
} else if (node instanceof SqlCreateSnapshot) {
return toCreateSnapshotPlan(planKey, (SqlCreateSnapshot) node);
} else if (node instanceof SqlDropSnapshot) {
return toDropSnapshotPlan(planKey, (SqlDropSnapshot) node);
} else if (node instanceof SqlCreateView) {
return toCreateViewPlan(planKey, context, (SqlCreateView) node);
} else if (node instanceof SqlDropView) {
return toDropViewPlan(planKey, (SqlDropView) node);
} else if (node instanceof SqlShowStatement) {
return toShowStatementPlan(planKey, (SqlShowStatement) node);
} else if (node instanceof SqlExplainStatement) {
return toExplainStatementPlan(planKey, context, parseResult);
} else {
QueryConvertResult convertResult = context.convert(parseResult.getNode());
return toPlan(planKey, parseResult.getParameterMetadata(), convertResult.getRel(), convertResult.getFieldNames(), context, parseResult.isInfiniteRows(), false, task.getSql());
}
}
use of com.hazelcast.sql.impl.optimizer.PlanKey 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);
}
Aggregations