Search in sources :

Example 1 with SelectPlan

use of com.hazelcast.jet.sql.impl.SqlPlanImpl.SelectPlan 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)

Aggregations

DmlPlan (com.hazelcast.jet.sql.impl.SqlPlanImpl.DmlPlan)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 MapPermission (com.hazelcast.security.permission.MapPermission)1 SqlRowMetadata (com.hazelcast.sql.SqlRowMetadata)1 Permission (java.security.Permission)1 TableModify (org.apache.calcite.rel.core.TableModify)1 Operation (org.apache.calcite.rel.core.TableModify.Operation)1