[
https://issues.apache.org/jira/browse/HIVE-22010?focusedWorklogId=281565&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-281565
]
ASF GitHub Bot logged work on HIVE-22010:
-----------------------------------------
Author: ASF GitHub Bot
Created on: 24/Jul/19 07:58
Start Date: 24/Jul/19 07:58
Worklog Time Spent: 10m
Work Description: miklosgergely commented on 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]
Issue Time Tracking
-------------------
Worklog Id: (was: 281565)
Time Spent: 1h 20m (was: 1h 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,
> HIVE-22010.03.patch
>
> Time Spent: 1h 20m
> Remaining Estimate: 0h
>
--
This message was sent by Atlassian JIRA
(v7.6.14#76016)