[ 
https://issues.apache.org/jira/browse/HIVE-22010?focusedWorklogId=280797&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-280797
 ]

ASF GitHub Bot logged work on HIVE-22010:
-----------------------------------------

                Author: ASF GitHub Bot
            Created on: 23/Jul/19 04:12
            Start Date: 23/Jul/19 04:12
    Worklog Time Spent: 10m 
      Work Description: jcamachor commented on pull request #732: HIVE-22010 - 
Clean up ShowCreateTableOperation
URL: https://github.com/apache/hive/pull/732#discussion_r306120864
 
 

 ##########
 File path: 
ql/src/java/org/apache/hadoop/hive/ql/ddl/table/creation/ShowCreateTableOperation.java
 ##########
 @@ -73,198 +82,207 @@ public ShowCreateTableOperation(DDLOperationContext 
context, ShowCreateTableDesc
   public int execute() throws HiveException {
     // get the create table statement for the table and populate the output
     try (DataOutputStream outStream = DDLUtils.getOutputStream(new 
Path(desc.getResFile()), context)) {
-      return showCreateTable(outStream);
+      Table table = context.getDb().getTable(desc.getTableName(), false);
+      String command = table.isView() ?
+          getCreateViewCommand(table) :
+          getCreateTableCommand(table);
+      outStream.write(command.getBytes(StandardCharsets.UTF_8));
+      return 0;
+    } catch (IOException e) {
+      LOG.info("show create table: ", e);
+      return 1;
     } catch (Exception e) {
       throw new HiveException(e);
     }
   }
 
-  private int showCreateTable(DataOutputStream outStream) throws HiveException 
{
-    boolean needsLocation = true;
-    StringBuilder createTabCommand = new StringBuilder();
+  private static final String CREATE_VIEW_COMMAND = "CREATE VIEW `%s` AS %s";
 
-    Table tbl = context.getDb().getTable(desc.getTableName(), false);
-    List<String> duplicateProps = new ArrayList<String>();
-    try {
-      needsLocation = CreateTableOperation.doesTableNeedLocation(tbl);
+  private String getCreateViewCommand(Table table) {
+    return String.format(CREATE_VIEW_COMMAND, desc.getTableName(), 
table.getViewExpandedText());
+  }
 
-      if (tbl.isView()) {
-        String createTabStmt = "CREATE VIEW `" + desc.getTableName() + "` AS " 
+ tbl.getViewExpandedText();
-        outStream.write(createTabStmt.getBytes(StandardCharsets.UTF_8));
-        return 0;
-      }
+  private static final String CREATE_TABLE_TEMPLATE =
+      "CREATE <" + TEMPORARY + "><" + EXTERNAL + ">TABLE `<" + NAME + ">`(\n" +
+      "<" + LIST_COLUMNS + ">)\n" +
+      "<" + COMMENT + ">\n" +
+      "<" + PARTITIONS + ">\n" +
+      "<" + BUCKETS + ">\n" +
+      "<" + SKEWED + ">\n" +
+      "<" + ROW_FORMAT + ">\n" +
+      "<" + LOCATION_BLOCK + ">" +
+      "TBLPROPERTIES (\n" +
+      "<" + PROPERTIES + ">)\n";
 
-      createTabCommand.append("CREATE <" + TEMPORARY + "><" + EXTERNAL + 
">TABLE `");
-      createTabCommand.append(desc.getTableName() + "`(\n");
-      createTabCommand.append("<" + LIST_COLUMNS + ">)\n");
-      createTabCommand.append("<" + TBL_COMMENT + ">\n");
 
 Review comment:
   It seems we have removed some of the information we were printing, e.g., 
`TBL_COMMENT` or `TBL_LOCATION`. Is this because they will be included in the 
table properties?
 
----------------------------------------------------------------
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: 280797)
    Time Spent: 20m  (was: 10m)

> Clean up ShowCreateTableOperation
> ---------------------------------
>
>                 Key: HIVE-22010
>                 URL: https://issues.apache.org/jira/browse/HIVE-22010
>             Project: Hive
>          Issue Type: Sub-task
>          Components: Hive
>            Reporter: Miklos Gergely
>            Assignee: Miklos Gergely
>            Priority: Major
>              Labels: pull-request-available, refactor-ddl
>         Attachments: HIVE-22010.01.patch, HIVE-22010.02.patch
>
>          Time Spent: 20m
>  Remaining Estimate: 0h
>




--
This message was sent by Atlassian JIRA
(v7.6.14#76016)

Reply via email to