[ https://issues.apache.org/jira/browse/HIVE-24596?focusedWorklogId=590192&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-590192 ]
ASF GitHub Bot logged work on HIVE-24596: ----------------------------------------- Author: ASF GitHub Bot Created on: 28/Apr/21 07:41 Start Date: 28/Apr/21 07:41 Worklog Time Spent: 10m Work Description: rbalamohan commented on a change in pull request #2033: URL: https://github.com/apache/hive/pull/2033#discussion_r621898378 ########## File path: ql/src/java/org/apache/hadoop/hive/ql/exec/ExplainTask.java ########## @@ -422,6 +430,92 @@ private JSONObject getLocks(PrintStream out, ExplainWork work) { return jsonObject; } + public void addCreateTableStatement(Table table, List<String> tableCreateStmt , DDLPlanUtils ddlPlanUtils){ + tableCreateStmt.add(ddlPlanUtils.getCreateTableCommand(table, false) + ";"); + } + + public void addPKandBasicStats(Table tbl, List<String> basicDef, DDLPlanUtils ddlPlanUtils){ + String primaryKeyStmt = ddlPlanUtils.getAlterTableStmtPrimaryKeyConstraint(tbl.getPrimaryKeyInfo()); + if (primaryKeyStmt != null) { + basicDef.add(primaryKeyStmt); + } + basicDef.add(ddlPlanUtils.getAlterTableStmtTableStatsBasic(tbl)); + } + + public void addConstraints(Table tbl, List<String> constraints, Set<String> allTableNames, + DDLPlanUtils ddlPlanUtils){ + constraints.addAll(ddlPlanUtils.populateConstraints(tbl, allTableNames)); + } + + public void addStats(Table table,List<String> alterTableStmt ,Map<String, List<Partition>> tablePartitionsMap, + DDLPlanUtils ddlPlanUtils) + throws HiveException, MetaException{ + PerfLogger perfLogger = PerfLogger.getPerfLogger(conf, false); + perfLogger.perfLogBegin(ExplainTask.class.getName(), PerfLogger.HIVE_GET_TABLE_COLUMN_STATS); + if (table.isPartitioned()) { + alterTableStmt.addAll(ddlPlanUtils.getDDLPlanForPartitionWithStats(table, tablePartitionsMap)); + } else { + alterTableStmt.addAll(ddlPlanUtils.getAlterTableStmtTableStatsColsAll(table)); + } + perfLogger.perfLogEnd(ExplainTask.class.getName(), PerfLogger.HIVE_GET_TABLE_COLUMN_STATS); + } + + public void addExplain(String sql , List<String> explainStmt, DDLPlanUtils ddlPlanUtils){ + explainStmt.addAll(ddlPlanUtils.addExplainPlans(sql)); + return; + } + + public void getDDLPlan(PrintStream out) throws HiveException, MetaException { + DDLPlanUtils ddlPlanUtils = new DDLPlanUtils(); + Set<String> createDatabase = new TreeSet<String>(); + List<String> tableCreateStmt = new LinkedList<String>(); + List<String> tableBasicDef = new LinkedList<String>(); + List<String> createViewList = new LinkedList<String>(); + List<String> alterTableStmt = new LinkedList<String>(); + List<String> explainStmt = new LinkedList<String>(); + Map<String, Table> tableMap = new HashMap<>(); + Map<String, List<Partition>> tablePartitionsMap = new HashMap<>(); + for (ReadEntity ent : work.getInputs()) { + switch (ent.getType()) { + // Views are also covered in table + case TABLE: + Table tbl = ent.getTable(); + createDatabase.add(tbl.getDbName()); + tableMap.put(tbl.getTableName(), tbl); + tablePartitionsMap.putIfAbsent(tbl.getTableName(), new ArrayList<Partition>()); + break; + case PARTITION: + tablePartitionsMap.get(ent.getTable().getTableName()).add(ent.getPartition()); + break; + default: + break; + } + } + //process the databases + List<String> createDatabaseStmt = ddlPlanUtils.getCreateDatabaseStmt(createDatabase); + //process the tables + for (String tableName : tableMap.keySet()) { + Table table = tableMap.get(tableName); + if (table.isView()) { + createViewList.add(ddlPlanUtils.getCreateViewStmt(table)); + continue; + } else { + addCreateTableStatement(table, tableCreateStmt, ddlPlanUtils); + addPKandBasicStats(table, tableBasicDef, ddlPlanUtils); + addConstraints(table, alterTableStmt, tableMap.keySet(), ddlPlanUtils); + addStats(table, alterTableStmt, tablePartitionsMap, ddlPlanUtils); + } + } + addExplain(conf.getQueryString(), explainStmt, ddlPlanUtils); Review comment: This may end up adding "explain cbo <query>". But will not print the output of 'explain cbo query'. Can you fix it? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org Issue Time Tracking ------------------- Worklog Id: (was: 590192) Time Spent: 2.5h (was: 2h 20m) > Explain ddl for debugging > ------------------------- > > Key: HIVE-24596 > URL: https://issues.apache.org/jira/browse/HIVE-24596 > Project: Hive > Issue Type: Improvement > Reporter: Rajesh Balamohan > Assignee: Harshit Gupta > Priority: Major > Labels: pull-request-available > Attachments: output, query, table_definitions > > Time Spent: 2.5h > Remaining Estimate: 0h > > For debugging query issues, basic details like table schema, statistics, > partition details, query plans are needed. > It would be good to have "explain ddl" support, which can generate these > details. This can help in recreating the schema and planner issues without > sample data. > -- This message was sent by Atlassian Jira (v8.3.4#803005)