Search in sources :

Example 1 with PhysicalRel

use of com.hazelcast.jet.sql.impl.opt.physical.PhysicalRel in project hazelcast by hazelcast.

the class OptimizerTestSupport method optimizePhysicalInternal.

private static Result optimizePhysicalInternal(String sql, OptimizerContext context) {
    LogicalRel logicalRel = optimizeLogicalInternal(sql, context);
    PhysicalRel physicalRel = (PhysicalRel) context.optimize(logicalRel, PhysicalRules.getRuleSet(), OptUtils.toPhysicalConvention(logicalRel.getTraitSet()));
    return new Result(logicalRel, physicalRel);
}
Also used : PhysicalRel(com.hazelcast.jet.sql.impl.opt.physical.PhysicalRel) LogicalRel(com.hazelcast.jet.sql.impl.opt.logical.LogicalRel) QueryParseResult(com.hazelcast.jet.sql.impl.parse.QueryParseResult)

Example 2 with PhysicalRel

use of com.hazelcast.jet.sql.impl.opt.physical.PhysicalRel in project hazelcast by hazelcast.

the class CalciteSqlOptimizer method toExplainStatementPlan.

private SqlPlan toExplainStatementPlan(PlanKey planKey, OptimizerContext context, QueryParseResult parseResult) {
    SqlNode node = parseResult.getNode();
    assert node instanceof SqlExplainStatement;
    QueryConvertResult convertResult = context.convert(((SqlExplainStatement) node).getExplicandum());
    PhysicalRel physicalRel = optimize(parseResult.getParameterMetadata(), convertResult.getRel(), context, false);
    return new ExplainStatementPlan(planKey, physicalRel, planExecutor);
}
Also used : QueryConvertResult(com.hazelcast.jet.sql.impl.parse.QueryConvertResult) ExplainStatementPlan(com.hazelcast.jet.sql.impl.SqlPlanImpl.ExplainStatementPlan) 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) SqlExplainStatement(com.hazelcast.jet.sql.impl.parse.SqlExplainStatement) SqlNode(org.apache.calcite.sql.SqlNode)

Example 3 with PhysicalRel

use of com.hazelcast.jet.sql.impl.opt.physical.PhysicalRel in project hazelcast by hazelcast.

the class CalciteSqlOptimizer method optimize.

private PhysicalRel optimize(QueryParameterMetadata parameterMetadata, RelNode rel, OptimizerContext context, boolean isCreateJob) {
    context.setParameterMetadata(parameterMetadata);
    context.setRequiresJob(isCreateJob);
    boolean fineLogOn = logger.isFineEnabled();
    if (fineLogOn) {
        logger.fine("Before logical opt:\n" + RelOptUtil.toString(rel));
    }
    LogicalRel logicalRel = optimizeLogical(context, rel);
    if (fineLogOn) {
        logger.fine("After logical opt:\n" + RelOptUtil.toString(logicalRel));
    }
    detectStandaloneImposeOrder(logicalRel);
    PhysicalRel physicalRel = optimizePhysical(context, logicalRel);
    if (fineLogOn) {
        logger.fine("After physical opt:\n" + RelOptUtil.toString(physicalRel));
    }
    return physicalRel;
}
Also used : 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) LogicalRel(com.hazelcast.jet.sql.impl.opt.logical.LogicalRel)

Example 4 with PhysicalRel

use of com.hazelcast.jet.sql.impl.opt.physical.PhysicalRel 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

PhysicalRel (com.hazelcast.jet.sql.impl.opt.physical.PhysicalRel)4 DeleteByKeyMapPhysicalRel (com.hazelcast.jet.sql.impl.opt.physical.DeleteByKeyMapPhysicalRel)3 InsertMapPhysicalRel (com.hazelcast.jet.sql.impl.opt.physical.InsertMapPhysicalRel)3 SelectByKeyMapPhysicalRel (com.hazelcast.jet.sql.impl.opt.physical.SelectByKeyMapPhysicalRel)3 SinkMapPhysicalRel (com.hazelcast.jet.sql.impl.opt.physical.SinkMapPhysicalRel)3 UpdateByKeyMapPhysicalRel (com.hazelcast.jet.sql.impl.opt.physical.UpdateByKeyMapPhysicalRel)3 LogicalRel (com.hazelcast.jet.sql.impl.opt.logical.LogicalRel)2 DmlPlan (com.hazelcast.jet.sql.impl.SqlPlanImpl.DmlPlan)1 ExplainStatementPlan (com.hazelcast.jet.sql.impl.SqlPlanImpl.ExplainStatementPlan)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 RootRel (com.hazelcast.jet.sql.impl.opt.physical.RootRel)1 QueryConvertResult (com.hazelcast.jet.sql.impl.parse.QueryConvertResult)1 QueryParseResult (com.hazelcast.jet.sql.impl.parse.QueryParseResult)1 SqlExplainStatement (com.hazelcast.jet.sql.impl.parse.SqlExplainStatement)1