Search in sources :

Example 6 with ColumnNamesOptions

use of org.apache.drill.exec.metastore.ColumnNamesOptions in project drill by apache.

the class MetastoreAnalyzeTableHandler method getPlan.

@Override
public PhysicalPlan getPlan(SqlNode sqlNode) throws ValidationException, RelConversionException, IOException, ForemanSetupException {
    if (!context.getOptions().getOption(ExecConstants.METASTORE_ENABLED_VALIDATOR)) {
        throw UserException.validationError().message("Running ANALYZE TABLE REFRESH METADATA command when Metastore is disabled (`metastore.enabled` is set to false)").build(logger);
    }
    // disables during analyze to prevent using data about locations from the Metastore
    context.getOptions().setLocalOption(ExecConstants.METASTORE_ENABLED, false);
    SqlMetastoreAnalyzeTable sqlAnalyzeTable = unwrap(sqlNode, SqlMetastoreAnalyzeTable.class);
    SqlNode tableRef = sqlAnalyzeTable.getTableRef();
    DrillTableInfo drillTableInfo = DrillTableInfo.getTableInfoHolder(tableRef, config);
    AnalyzeInfoProvider analyzeInfoProvider = drillTableInfo.drillTable().getGroupScan().getAnalyzeInfoProvider();
    if (analyzeInfoProvider == null) {
        throw UserException.validationError().message("ANALYZE is not supported for group scan [%s]", drillTableInfo.drillTable().getGroupScan()).build(logger);
    }
    ColumnNamesOptions columnNamesOptions = new ColumnNamesOptions(context.getOptions());
    // creates select with DYNAMIC_STAR column and analyze specific columns to obtain corresponding table scan
    SqlSelect scanSql = new SqlSelect(SqlParserPos.ZERO, SqlNodeList.EMPTY, getColumnList(analyzeInfoProvider.getProjectionFields(drillTableInfo.drillTable(), getMetadataType(sqlAnalyzeTable), columnNamesOptions)), tableRef, null, null, null, null, null, null, null);
    ConvertedRelNode convertedRelNode = validateAndConvert(rewrite(scanSql));
    RelDataType validatedRowType = convertedRelNode.getValidatedRowType();
    RelNode relScan = convertedRelNode.getConvertedNode();
    DrillRel drel = convertToDrel(relScan, sqlAnalyzeTable, drillTableInfo);
    Prel prel = convertToPrel(drel, validatedRowType);
    logAndSetTextPlan("Drill Physical", prel, logger);
    PhysicalOperator pop = convertToPop(prel);
    PhysicalPlan plan = convertToPlan(pop);
    log("Drill Plan", plan, logger);
    return plan;
}
Also used : PhysicalPlan(org.apache.drill.exec.physical.PhysicalPlan) AnalyzeInfoProvider(org.apache.drill.exec.metastore.analyze.AnalyzeInfoProvider) RelDataType(org.apache.calcite.rel.type.RelDataType) Prel(org.apache.drill.exec.planner.physical.Prel) SqlSelect(org.apache.calcite.sql.SqlSelect) RelNode(org.apache.calcite.rel.RelNode) SqlMetastoreAnalyzeTable(org.apache.drill.exec.planner.sql.parser.SqlMetastoreAnalyzeTable) PhysicalOperator(org.apache.drill.exec.physical.base.PhysicalOperator) ColumnNamesOptions(org.apache.drill.exec.metastore.ColumnNamesOptions) DrillRel(org.apache.drill.exec.planner.logical.DrillRel) SqlNode(org.apache.calcite.sql.SqlNode)

Aggregations

ColumnNamesOptions (org.apache.drill.exec.metastore.ColumnNamesOptions)6 RelNode (org.apache.calcite.rel.RelNode)4 IOException (java.io.IOException)3 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 SchemaPath (org.apache.drill.common.expression.SchemaPath)3 MetadataAggregateContext (org.apache.drill.exec.metastore.analyze.MetadataAggregateContext)3 MetastoreAnalyzeConstants (org.apache.drill.exec.metastore.analyze.MetastoreAnalyzeConstants)3 PlannerSettings (org.apache.drill.exec.planner.physical.PlannerSettings)3 FormatSelection (org.apache.drill.exec.store.dfs.FormatSelection)3 Collection (java.util.Collection)2 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 Function (java.util.function.Function)2 IntFunction (java.util.function.IntFunction)2 IntStream (java.util.stream.IntStream)2 RelOptRule (org.apache.calcite.plan.RelOptRule)2 RelOptRuleCall (org.apache.calcite.plan.RelOptRuleCall)2 RelDataType (org.apache.calcite.rel.type.RelDataType)2 SqlNode (org.apache.calcite.sql.SqlNode)2