miklosgergely commented on a change in pull request #732: HIVE-22010 - Clean up 
ShowCreateTableOperation
URL: https://github.com/apache/hive/pull/732#discussion_r306674949
 
 

 ##########
 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:
   They are still there, just removed the unnecessary TBL_ prefix - they are 
all for the table :)
   

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to