use of com.hazelcast.jet.sql.impl.SqlPlanImpl.DmlPlan in project hazelcast by hazelcast.
the class CalciteSqlOptimizer method toCreateJobPlan.
private SqlPlan toCreateJobPlan(PlanKey planKey, QueryParseResult parseResult, OptimizerContext context, String query) {
SqlCreateJob sqlCreateJob = (SqlCreateJob) parseResult.getNode();
SqlNode source = sqlCreateJob.dmlStatement();
QueryParseResult dmlParseResult = new QueryParseResult(source, parseResult.getParameterMetadata(), false);
QueryConvertResult dmlConvertedResult = context.convert(dmlParseResult.getNode());
SqlPlanImpl dmlPlan = toPlan(null, parseResult.getParameterMetadata(), dmlConvertedResult.getRel(), dmlConvertedResult.getFieldNames(), context, dmlParseResult.isInfiniteRows(), true, query);
assert dmlPlan instanceof DmlPlan && ((DmlPlan) dmlPlan).getOperation() == Operation.INSERT;
return new CreateJobPlan(planKey, sqlCreateJob.jobConfig(), sqlCreateJob.ifNotExists(), (DmlPlan) dmlPlan, query, parseResult.isInfiniteRows(), planExecutor);
}
use of com.hazelcast.jet.sql.impl.SqlPlanImpl.DmlPlan in project hazelcast by hazelcast.
the class CalciteSqlOptimizer method toPlan.
private SqlPlanImpl toPlan(PlanKey planKey, QueryParameterMetadata parameterMetadata, RelNode rel, List<String> fieldNames, OptimizerContext context, boolean isInfiniteRows, boolean isCreateJob, String query) {
PhysicalRel physicalRel = optimize(parameterMetadata, rel, context, isCreateJob);
List<Permission> permissions = extractPermissions(physicalRel);
if (physicalRel instanceof SelectByKeyMapPhysicalRel) {
assert !isCreateJob;
SelectByKeyMapPhysicalRel select = (SelectByKeyMapPhysicalRel) physicalRel;
SqlRowMetadata rowMetadata = createRowMetadata(fieldNames, physicalRel.schema(parameterMetadata).getTypes(), rel.getRowType().getFieldList());
return new IMapSelectPlan(planKey, select.objectKey(), parameterMetadata, select.mapName(), select.keyCondition(parameterMetadata), select.rowProjectorSupplier(parameterMetadata), rowMetadata, planExecutor, permissions);
} else if (physicalRel instanceof InsertMapPhysicalRel) {
assert !isCreateJob;
InsertMapPhysicalRel insert = (InsertMapPhysicalRel) physicalRel;
return new IMapInsertPlan(planKey, insert.objectKey(), parameterMetadata, insert.mapName(), insert.entriesFn(), planExecutor, permissions);
} else if (physicalRel instanceof SinkMapPhysicalRel) {
assert !isCreateJob;
SinkMapPhysicalRel sink = (SinkMapPhysicalRel) physicalRel;
return new IMapSinkPlan(planKey, sink.objectKey(), parameterMetadata, sink.mapName(), sink.entriesFn(), planExecutor, permissions);
} else if (physicalRel instanceof UpdateByKeyMapPhysicalRel) {
assert !isCreateJob;
UpdateByKeyMapPhysicalRel update = (UpdateByKeyMapPhysicalRel) physicalRel;
return new IMapUpdatePlan(planKey, update.objectKey(), parameterMetadata, update.mapName(), update.keyCondition(parameterMetadata), update.updaterSupplier(parameterMetadata), planExecutor, permissions);
} else if (physicalRel instanceof DeleteByKeyMapPhysicalRel) {
assert !isCreateJob;
DeleteByKeyMapPhysicalRel delete = (DeleteByKeyMapPhysicalRel) physicalRel;
return new IMapDeletePlan(planKey, delete.objectKey(), parameterMetadata, delete.mapName(), delete.keyCondition(parameterMetadata), planExecutor, permissions);
} else if (physicalRel instanceof TableModify) {
checkDmlOperationWithView(physicalRel);
Operation operation = ((TableModify) physicalRel).getOperation();
CreateDagVisitor visitor = traverseRel(physicalRel, parameterMetadata);
return new DmlPlan(operation, planKey, parameterMetadata, visitor.getObjectKeys(), visitor.getDag(), query, isInfiniteRows, planExecutor, permissions);
} else {
CreateDagVisitor visitor = traverseRel(new RootRel(physicalRel), parameterMetadata);
SqlRowMetadata rowMetadata = createRowMetadata(fieldNames, physicalRel.schema(parameterMetadata).getTypes(), rel.getRowType().getFieldList());
return new SelectPlan(planKey, parameterMetadata, visitor.getObjectKeys(), visitor.getDag(), query, isInfiniteRows, rowMetadata, planExecutor, permissions);
}
}
use of com.hazelcast.jet.sql.impl.SqlPlanImpl.DmlPlan in project hazelcast by hazelcast.
the class PlanExecutorTest method test_insertExecution.
@Test
public void test_insertExecution() {
// given
QueryId queryId = QueryId.create(UuidUtil.newSecureUUID());
DmlPlan plan = new DmlPlan(Operation.INSERT, planKey(), QueryParameterMetadata.EMPTY, emptySet(), dag, null, false, planExecutor, Collections.emptyList());
given(hazelcastInstance.getJet()).willReturn(jet);
given(jet.newLightJob(eq(dag), isA(JobConfig.class))).willReturn(job);
// when
SqlResult result = planExecutor.execute(plan, queryId, emptyList(), 0L);
// then
assertThat(result.updateCount()).isEqualTo(0);
verify(job).join();
}
Aggregations