Search in sources :

Example 1 with DmlPlan

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);
}
Also used : SqlCreateJob(com.hazelcast.jet.sql.impl.parse.SqlCreateJob) DmlPlan(com.hazelcast.jet.sql.impl.SqlPlanImpl.DmlPlan) QueryConvertResult(com.hazelcast.jet.sql.impl.parse.QueryConvertResult) CreateJobPlan(com.hazelcast.jet.sql.impl.SqlPlanImpl.CreateJobPlan) QueryParseResult(com.hazelcast.jet.sql.impl.parse.QueryParseResult) SqlNode(org.apache.calcite.sql.SqlNode)

Example 2 with DmlPlan

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);
    }
}
Also used : IMapDeletePlan(com.hazelcast.jet.sql.impl.SqlPlanImpl.IMapDeletePlan) IMapSinkPlan(com.hazelcast.jet.sql.impl.SqlPlanImpl.IMapSinkPlan) Operation(org.apache.calcite.rel.core.TableModify.Operation) RootRel(com.hazelcast.jet.sql.impl.opt.physical.RootRel) InsertMapPhysicalRel(com.hazelcast.jet.sql.impl.opt.physical.InsertMapPhysicalRel) SelectByKeyMapPhysicalRel(com.hazelcast.jet.sql.impl.opt.physical.SelectByKeyMapPhysicalRel) DmlPlan(com.hazelcast.jet.sql.impl.SqlPlanImpl.DmlPlan) IMapUpdatePlan(com.hazelcast.jet.sql.impl.SqlPlanImpl.IMapUpdatePlan) CreateDagVisitor(com.hazelcast.jet.sql.impl.opt.physical.CreateDagVisitor) SelectByKeyMapPhysicalRel(com.hazelcast.jet.sql.impl.opt.physical.SelectByKeyMapPhysicalRel) SinkMapPhysicalRel(com.hazelcast.jet.sql.impl.opt.physical.SinkMapPhysicalRel) DeleteByKeyMapPhysicalRel(com.hazelcast.jet.sql.impl.opt.physical.DeleteByKeyMapPhysicalRel) InsertMapPhysicalRel(com.hazelcast.jet.sql.impl.opt.physical.InsertMapPhysicalRel) UpdateByKeyMapPhysicalRel(com.hazelcast.jet.sql.impl.opt.physical.UpdateByKeyMapPhysicalRel) PhysicalRel(com.hazelcast.jet.sql.impl.opt.physical.PhysicalRel) Permission(java.security.Permission) MapPermission(com.hazelcast.security.permission.MapPermission) IMapSelectPlan(com.hazelcast.jet.sql.impl.SqlPlanImpl.IMapSelectPlan) SelectPlan(com.hazelcast.jet.sql.impl.SqlPlanImpl.SelectPlan) IMapSelectPlan(com.hazelcast.jet.sql.impl.SqlPlanImpl.IMapSelectPlan) SinkMapPhysicalRel(com.hazelcast.jet.sql.impl.opt.physical.SinkMapPhysicalRel) DeleteByKeyMapPhysicalRel(com.hazelcast.jet.sql.impl.opt.physical.DeleteByKeyMapPhysicalRel) SqlRowMetadata(com.hazelcast.sql.SqlRowMetadata) TableModify(org.apache.calcite.rel.core.TableModify) IMapInsertPlan(com.hazelcast.jet.sql.impl.SqlPlanImpl.IMapInsertPlan) UpdateByKeyMapPhysicalRel(com.hazelcast.jet.sql.impl.opt.physical.UpdateByKeyMapPhysicalRel)

Example 3 with DmlPlan

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();
}
Also used : DmlPlan(com.hazelcast.jet.sql.impl.SqlPlanImpl.DmlPlan) SqlResult(com.hazelcast.sql.SqlResult) QueryId(com.hazelcast.sql.impl.QueryId) JobConfig(com.hazelcast.jet.config.JobConfig) Test(org.junit.Test)

Aggregations

DmlPlan (com.hazelcast.jet.sql.impl.SqlPlanImpl.DmlPlan)3 JobConfig (com.hazelcast.jet.config.JobConfig)1 CreateJobPlan (com.hazelcast.jet.sql.impl.SqlPlanImpl.CreateJobPlan)1 IMapDeletePlan (com.hazelcast.jet.sql.impl.SqlPlanImpl.IMapDeletePlan)1 IMapInsertPlan (com.hazelcast.jet.sql.impl.SqlPlanImpl.IMapInsertPlan)1 IMapSelectPlan (com.hazelcast.jet.sql.impl.SqlPlanImpl.IMapSelectPlan)1 IMapSinkPlan (com.hazelcast.jet.sql.impl.SqlPlanImpl.IMapSinkPlan)1 IMapUpdatePlan (com.hazelcast.jet.sql.impl.SqlPlanImpl.IMapUpdatePlan)1 SelectPlan (com.hazelcast.jet.sql.impl.SqlPlanImpl.SelectPlan)1 CreateDagVisitor (com.hazelcast.jet.sql.impl.opt.physical.CreateDagVisitor)1 DeleteByKeyMapPhysicalRel (com.hazelcast.jet.sql.impl.opt.physical.DeleteByKeyMapPhysicalRel)1 InsertMapPhysicalRel (com.hazelcast.jet.sql.impl.opt.physical.InsertMapPhysicalRel)1 PhysicalRel (com.hazelcast.jet.sql.impl.opt.physical.PhysicalRel)1 RootRel (com.hazelcast.jet.sql.impl.opt.physical.RootRel)1 SelectByKeyMapPhysicalRel (com.hazelcast.jet.sql.impl.opt.physical.SelectByKeyMapPhysicalRel)1 SinkMapPhysicalRel (com.hazelcast.jet.sql.impl.opt.physical.SinkMapPhysicalRel)1 UpdateByKeyMapPhysicalRel (com.hazelcast.jet.sql.impl.opt.physical.UpdateByKeyMapPhysicalRel)1 QueryConvertResult (com.hazelcast.jet.sql.impl.parse.QueryConvertResult)1 QueryParseResult (com.hazelcast.jet.sql.impl.parse.QueryParseResult)1 SqlCreateJob (com.hazelcast.jet.sql.impl.parse.SqlCreateJob)1