Search in sources :

Example 26 with PhysicalPlan

use of org.apache.drill.exec.physical.PhysicalPlan in project drill by apache.

the class Foreman method parseAndRunLogicalPlan.

private void parseAndRunLogicalPlan(final String json) throws ExecutionSetupException {
    LogicalPlan logicalPlan;
    try {
        logicalPlan = drillbitContext.getPlanReader().readLogicalPlan(json);
    } catch (final IOException e) {
        throw new ForemanException("Failure parsing logical plan.", e);
    }
    if (logicalPlan.getProperties().resultMode == ResultMode.LOGICAL) {
        throw new ForemanException("Failure running plan.  You requested a result mode of LOGICAL and submitted a logical plan.  In this case you're output mode must be PHYSICAL or EXEC.");
    }
    log(logicalPlan);
    final PhysicalPlan physicalPlan = convert(logicalPlan);
    if (logicalPlan.getProperties().resultMode == ResultMode.PHYSICAL) {
        returnPhysical(physicalPlan);
        return;
    }
    log(physicalPlan);
    runPhysicalPlan(physicalPlan);
}
Also used : PhysicalPlan(org.apache.drill.exec.physical.PhysicalPlan) LogicalPlan(org.apache.drill.common.logical.LogicalPlan) IOException(java.io.IOException)

Example 27 with PhysicalPlan

use of org.apache.drill.exec.physical.PhysicalPlan in project drill by apache.

the class Foreman method runSQL.

private void runSQL(final String sql) throws ExecutionSetupException {
    final Pointer<String> textPlan = new Pointer<>();
    final PhysicalPlan plan = DrillSqlWorker.getPlan(queryContext, sql, textPlan);
    queryManager.setPlanText(textPlan.value);
    runPhysicalPlan(plan);
}
Also used : PhysicalPlan(org.apache.drill.exec.physical.PhysicalPlan) Pointer(org.apache.drill.exec.util.Pointer)

Example 28 with PhysicalPlan

use of org.apache.drill.exec.physical.PhysicalPlan in project drill by apache.

the class PlanningBase method testSqlPlan.

protected void testSqlPlan(String sqlCommands) throws Exception {
    final String[] sqlStrings = sqlCommands.split(";");
    final LocalPersistentStoreProvider provider = new LocalPersistentStoreProvider(config);
    provider.start();
    final ScanResult scanResult = ClassPathScanner.fromPrescan(config);
    final LogicalPlanPersistence logicalPlanPersistence = new LogicalPlanPersistence(config, scanResult);
    final SystemOptionManager systemOptions = new SystemOptionManager(logicalPlanPersistence, provider);
    systemOptions.init();
    @SuppressWarnings("resource") final UserSession userSession = UserSession.Builder.newBuilder().withOptionManager(systemOptions).build();
    final SessionOptionManager sessionOptions = (SessionOptionManager) userSession.getOptions();
    final QueryOptionManager queryOptions = new QueryOptionManager(sessionOptions);
    final ExecutionControls executionControls = new ExecutionControls(queryOptions, DrillbitEndpoint.getDefaultInstance());
    new NonStrictExpectations() {

        {
            dbContext.getMetrics();
            result = new MetricRegistry();
            dbContext.getAllocator();
            result = allocator;
            dbContext.getConfig();
            result = config;
            dbContext.getOptionManager();
            result = systemOptions;
            dbContext.getStoreProvider();
            result = provider;
            dbContext.getClasspathScan();
            result = scanResult;
            dbContext.getLpPersistence();
            result = logicalPlanPersistence;
        }
    };
    final StoragePluginRegistry registry = new StoragePluginRegistryImpl(dbContext);
    registry.init();
    final FunctionImplementationRegistry functionRegistry = new FunctionImplementationRegistry(config);
    final DrillOperatorTable table = new DrillOperatorTable(functionRegistry, systemOptions);
    final SchemaPlus root = SimpleCalciteSchema.createRootSchema(false);
    registry.getSchemaFactory().registerSchemas(SchemaConfig.newBuilder("foo", context).build(), root);
    new NonStrictExpectations() {

        {
            context.getNewDefaultSchema();
            result = root;
            context.getLpPersistence();
            result = new LogicalPlanPersistence(config, ClassPathScanner.fromPrescan(config));
            context.getStorage();
            result = registry;
            context.getFunctionRegistry();
            result = functionRegistry;
            context.getSession();
            result = UserSession.Builder.newBuilder().setSupportComplexTypes(true).build();
            context.getCurrentEndpoint();
            result = DrillbitEndpoint.getDefaultInstance();
            context.getActiveEndpoints();
            result = ImmutableList.of(DrillbitEndpoint.getDefaultInstance());
            context.getPlannerSettings();
            result = new PlannerSettings(queryOptions, functionRegistry);
            context.getOptions();
            result = queryOptions;
            context.getConfig();
            result = config;
            context.getDrillOperatorTable();
            result = table;
            context.getAllocator();
            result = allocator;
            context.getExecutionControls();
            result = executionControls;
            dbContext.getLpPersistence();
            result = logicalPlanPersistence;
        }
    };
    for (final String sql : sqlStrings) {
        if (sql.trim().isEmpty()) {
            continue;
        }
        @SuppressWarnings("unused") final PhysicalPlan p = DrillSqlWorker.getPlan(context, sql);
    }
}
Also used : SessionOptionManager(org.apache.drill.exec.server.options.SessionOptionManager) StoragePluginRegistry(org.apache.drill.exec.store.StoragePluginRegistry) ScanResult(org.apache.drill.common.scanner.persistence.ScanResult) PhysicalPlan(org.apache.drill.exec.physical.PhysicalPlan) PlannerSettings(org.apache.drill.exec.planner.physical.PlannerSettings) LocalPersistentStoreProvider(org.apache.drill.exec.store.sys.store.provider.LocalPersistentStoreProvider) SystemOptionManager(org.apache.drill.exec.server.options.SystemOptionManager) QueryOptionManager(org.apache.drill.exec.server.options.QueryOptionManager) MetricRegistry(com.codahale.metrics.MetricRegistry) SchemaPlus(org.apache.calcite.schema.SchemaPlus) LogicalPlanPersistence(org.apache.drill.common.config.LogicalPlanPersistence) ExecutionControls(org.apache.drill.exec.testing.ExecutionControls) UserSession(org.apache.drill.exec.rpc.user.UserSession) StoragePluginRegistryImpl(org.apache.drill.exec.store.StoragePluginRegistryImpl) NonStrictExpectations(mockit.NonStrictExpectations) FunctionImplementationRegistry(org.apache.drill.exec.expr.fn.FunctionImplementationRegistry) DrillOperatorTable(org.apache.drill.exec.planner.sql.DrillOperatorTable)

Example 29 with PhysicalPlan

use of org.apache.drill.exec.physical.PhysicalPlan in project drill by apache.

the class ExplainHandler method getPlan.

@Override
public PhysicalPlan getPlan(SqlNode sqlNode) throws ValidationException, RelConversionException, IOException, ForemanSetupException {
    final ConvertedRelNode convertedRelNode = validateAndConvert(sqlNode);
    final RelDataType validatedRowType = convertedRelNode.getValidatedRowType();
    final RelNode queryRelNode = convertedRelNode.getConvertedNode();
    log("Calcite", queryRelNode, logger, null);
    DrillRel drel = convertToDrel(queryRelNode, validatedRowType);
    if (mode == ResultMode.LOGICAL) {
        LogicalExplain logicalResult = new LogicalExplain(drel, level, context);
        return DirectPlan.createDirectPlan(context, logicalResult);
    }
    Prel prel = convertToPrel(drel);
    logAndSetTextPlan("Drill Physical", prel, logger);
    PhysicalOperator pop = convertToPop(prel);
    PhysicalPlan plan = convertToPlan(pop);
    log("Drill Plan", plan, logger);
    PhysicalExplain physicalResult = new PhysicalExplain(prel, plan, level, context);
    return DirectPlan.createDirectPlan(context, physicalResult);
}
Also used : PhysicalPlan(org.apache.drill.exec.physical.PhysicalPlan) RelNode(org.apache.calcite.rel.RelNode) PhysicalOperator(org.apache.drill.exec.physical.base.PhysicalOperator) DrillRel(org.apache.drill.exec.planner.logical.DrillRel) RelDataType(org.apache.calcite.rel.type.RelDataType) Prel(org.apache.drill.exec.planner.physical.Prel)

Example 30 with PhysicalPlan

use of org.apache.drill.exec.physical.PhysicalPlan in project drill by apache.

the class CreateTableHandler method getPlan.

@Override
public PhysicalPlan getPlan(SqlNode sqlNode) throws ValidationException, RelConversionException, IOException, ForemanSetupException {
    SqlCreateTable sqlCreateTable = unwrap(sqlNode, SqlCreateTable.class);
    String originalTableName = sqlCreateTable.getName();
    final ConvertedRelNode convertedRelNode = validateAndConvert(sqlCreateTable.getQuery());
    final RelDataType validatedRowType = convertedRelNode.getValidatedRowType();
    final RelNode queryRelNode = convertedRelNode.getConvertedNode();
    final RelNode newTblRelNode = SqlHandlerUtil.resolveNewTableRel(false, sqlCreateTable.getFieldNames(), validatedRowType, queryRelNode);
    final DrillConfig drillConfig = context.getConfig();
    final AbstractSchema drillSchema = resolveSchema(sqlCreateTable, config.getConverter().getDefaultSchema(), drillConfig);
    checkDuplicatedObjectExistence(drillSchema, originalTableName, drillConfig, context.getSession());
    final RelNode newTblRelNodeWithPCol = SqlHandlerUtil.qualifyPartitionCol(newTblRelNode, sqlCreateTable.getPartitionColumns());
    log("Calcite", newTblRelNodeWithPCol, logger, null);
    // Convert the query to Drill Logical plan and insert a writer operator on top.
    StorageStrategy storageStrategy = sqlCreateTable.isTemporary() ? StorageStrategy.TEMPORARY : new StorageStrategy(context.getOption(ExecConstants.PERSISTENT_TABLE_UMASK).string_val, false);
    // If we are creating temporary table, initial table name will be replaced with generated table name.
    // Generated table name is unique, UUID.randomUUID() is used for its generation.
    // Original table name is stored in temporary tables cache, so it can be substituted to generated one during querying.
    String newTableName = sqlCreateTable.isTemporary() ? context.getSession().registerTemporaryTable(drillSchema, originalTableName, drillConfig) : originalTableName;
    DrillRel drel = convertToDrel(newTblRelNodeWithPCol, drillSchema, newTableName, sqlCreateTable.getPartitionColumns(), newTblRelNode.getRowType(), storageStrategy);
    Prel prel = convertToPrel(drel, newTblRelNode.getRowType(), sqlCreateTable.getPartitionColumns());
    logAndSetTextPlan("Drill Physical", prel, logger);
    PhysicalOperator pop = convertToPop(prel);
    PhysicalPlan plan = convertToPlan(pop);
    log("Drill Plan", plan, logger);
    String message = String.format("Creating %s table [%s].", sqlCreateTable.isTemporary() ? "temporary" : "persistent", originalTableName);
    logger.info(message);
    return plan;
}
Also used : StorageStrategy(org.apache.drill.exec.store.StorageStrategy) PhysicalPlan(org.apache.drill.exec.physical.PhysicalPlan) RelNode(org.apache.calcite.rel.RelNode) DrillConfig(org.apache.drill.common.config.DrillConfig) AbstractSchema(org.apache.drill.exec.store.AbstractSchema) PhysicalOperator(org.apache.drill.exec.physical.base.PhysicalOperator) DrillRel(org.apache.drill.exec.planner.logical.DrillRel) RelDataType(org.apache.calcite.rel.type.RelDataType) SqlCreateTable(org.apache.drill.exec.planner.sql.parser.SqlCreateTable) WriterPrel(org.apache.drill.exec.planner.physical.WriterPrel) Prel(org.apache.drill.exec.planner.physical.Prel) ProjectAllowDupPrel(org.apache.drill.exec.planner.physical.ProjectAllowDupPrel) ProjectPrel(org.apache.drill.exec.planner.physical.ProjectPrel)

Aggregations

PhysicalPlan (org.apache.drill.exec.physical.PhysicalPlan)58 FunctionImplementationRegistry (org.apache.drill.exec.expr.fn.FunctionImplementationRegistry)43 FragmentContext (org.apache.drill.exec.ops.FragmentContext)41 PhysicalPlanReader (org.apache.drill.exec.planner.PhysicalPlanReader)41 FragmentRoot (org.apache.drill.exec.physical.base.FragmentRoot)39 Test (org.junit.Test)34 SimpleRootExec (org.apache.drill.exec.physical.impl.SimpleRootExec)24 ExecTest (org.apache.drill.exec.ExecTest)16 SchemaPath (org.apache.drill.common.expression.SchemaPath)15 PhysicalOperator (org.apache.drill.exec.physical.base.PhysicalOperator)13 ValueVector (org.apache.drill.exec.vector.ValueVector)8 StoragePluginRegistryImpl (org.apache.drill.exec.store.StoragePluginRegistryImpl)6 BigIntVector (org.apache.drill.exec.vector.BigIntVector)6 IntVector (org.apache.drill.exec.vector.IntVector)6 Ignore (org.junit.Ignore)5 DrillConfig (org.apache.drill.common.config.DrillConfig)4 DrillbitContext (org.apache.drill.exec.server.DrillbitContext)4 IOException (java.io.IOException)3 RelNode (org.apache.calcite.rel.RelNode)3 RelDataType (org.apache.calcite.rel.type.RelDataType)3