deniskuzZ commented on code in PR #3281:
URL: https://github.com/apache/hive/pull/3281#discussion_r885441938


##########
ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java:
##########
@@ -7940,6 +7970,46 @@ protected Operator genFileSinkPlan(String dest, QB qb, 
Operator input)
     return output;
   }
 
+  private Path getCTASDestinationTableLocation(CreateTableDesc tblDesc, 
boolean enableSuffixing) throws SemanticException {
+    Path location;
+    String suffix = "";
+    try {
+      // When location is specified, suffix is not added
+      if (tblDesc.getLocation() == null) {
+        String protoName = tblDesc.getDbTableName();
+        String[] names = Utilities.getDbTableName(protoName);
+        if (enableSuffixing) {
+          long txnId = ctx.getHiveTxnManager().getCurrentTxnId();
+          suffix = SOFT_DELETE_PATH_SUFFIX + String.format(DELTA_DIGITS, 
txnId);
+        }
+        if (!db.databaseExists(names[0])) {
+          throw new SemanticException("ERROR: The database " + names[0] + " 
does not exist.");
+        }
+
+        Warehouse wh = new Warehouse(conf);
+        location = wh.getDefaultTablePath(db.getDatabase(names[0]), names[1] + 
suffix, false);
+      } else {
+        location = new Path(tblDesc.getLocation());
+      }
+
+      // Handle table translation
+      // Property modifications of the table is handled later.
+      // We are interested in the location if it has changed
+      // due to table translation.
+      Table tbl = tblDesc.toTable(conf);
+      tbl = db.getTranslateTableDryrun(tbl.getTTable());

Review Comment:
   shouldn't we pass through the transformers first and do the location check 
after?
   ````
   tbl = db.getTranslateTableDryrun(tbl.getTTable());
   if (tbl.getSd().getLocation() == null
               || tbl.getSd().getLocation().isEmpty()) {
        location = wh.getDefaultTablePath(db.getDatabase(names[0]), names[1], 
false);
   } else {
       location = wh.getDnsPath(new Path(tbl.getSd().getLocation()));
   }
   //add the suffix here
   location = new Path(location + getTableSuffix(tbl));
   tbl.getSd().setLocation(location.toString());
   ```` 



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


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

Reply via email to