use of org.apache.drill.common.logical.FormatPluginConfig in project drill by apache.
the class AnalyzeTableHandler method getPlan.
@Override
public PhysicalPlan getPlan(SqlNode sqlNode) throws ValidationException, RelConversionException, IOException, ForemanSetupException {
final SqlAnalyzeTable sqlAnalyzeTable = unwrap(sqlNode, SqlAnalyzeTable.class);
verifyNoUnsupportedFunctions(sqlAnalyzeTable);
SqlNode tableRef = sqlAnalyzeTable.getTableRef();
SqlSelect scanSql = new SqlSelect(SqlParserPos.ZERO, /* position */
SqlNodeList.EMPTY, /* keyword list */
getColumnList(sqlAnalyzeTable), /* select list */
tableRef, /* from */
null, /* where */
null, /* group by */
null, /* having */
null, /* windowDecls */
null, /* orderBy */
null, /* offset */
null);
ConvertedRelNode convertedRelNode = validateAndConvert(rewrite(scanSql));
RelDataType validatedRowType = convertedRelNode.getValidatedRowType();
RelNode relScan = convertedRelNode.getConvertedNode();
DrillTableInfo drillTableInfo = DrillTableInfo.getTableInfoHolder(sqlAnalyzeTable.getTableRef(), config);
String tableName = drillTableInfo.tableName();
AbstractSchema drillSchema = SchemaUtilites.resolveToDrillSchema(config.getConverter().getDefaultSchema(), drillTableInfo.schemaPath());
Table table = SqlHandlerUtil.getTableFromSchema(drillSchema, tableName);
if (table == null) {
throw UserException.validationError().message("No table with given name [%s] exists in schema [%s]", tableName, drillSchema.getFullSchemaName()).build(logger);
} else if (!(table instanceof DrillTable)) {
return DrillStatsTable.notSupported(context, tableName);
}
DrillTable drillTable = (DrillTable) table;
final Object selection = drillTable.getSelection();
if (!(selection instanceof FormatSelection)) {
return DrillStatsTable.notSupported(context, tableName);
}
// Do not support non-parquet tables
FormatSelection formatSelection = (FormatSelection) selection;
FormatPluginConfig formatConfig = formatSelection.getFormat();
if (!((formatConfig instanceof ParquetFormatConfig) || ((formatConfig instanceof NamedFormatPluginConfig) && ((NamedFormatPluginConfig) formatConfig).getName().equals("parquet")))) {
return DrillStatsTable.notSupported(context, tableName);
}
FileSystemPlugin plugin = (FileSystemPlugin) drillTable.getPlugin();
DrillFileSystem fs = new DrillFileSystem(plugin.getFormatPlugin(formatSelection.getFormat()).getFsConf());
Path selectionRoot = formatSelection.getSelection().getSelectionRoot();
if (!selectionRoot.toUri().getPath().endsWith(tableName) || !fs.getFileStatus(selectionRoot).isDirectory()) {
return DrillStatsTable.notSupported(context, tableName);
}
// Do not recompute statistics, if stale
Path statsFilePath = new Path(selectionRoot, DotDrillType.STATS.getEnding());
if (fs.exists(statsFilePath) && !isStatsStale(fs, statsFilePath)) {
return DrillStatsTable.notRequired(context, tableName);
}
// Convert the query to Drill Logical plan and insert a writer operator on top.
DrillRel drel = convertToDrel(relScan, drillSchema, tableName, sqlAnalyzeTable.getSamplePercent());
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;
}
Aggregations