saihemanth-cloudera commented on a change in pull request #2442:
URL: https://github.com/apache/hive/pull/2442#discussion_r697702962



##########
File path: ql/src/java/org/apache/hadoop/hive/ql/parse/TaskCompiler.java
##########
@@ -472,6 +474,32 @@ private void setLoadFileLocation(
       loc = cmv.getLocation();
     }
     Path location = (loc == null) ? getDefaultCtasLocation(pCtx) : new 
Path(loc);
+    boolean isExternal = false;
+    boolean isAcid = false;
+    if (pCtx.getQueryProperties().isCTAS()) {
+      isExternal = pCtx.getCreateTable().isExternal();
+      isAcid = pCtx.getCreateTable().getTblProps().getOrDefault(
+              hive_metastoreConstants.TABLE_IS_TRANSACTIONAL, 
"false").equalsIgnoreCase("true") ||
+              
pCtx.getCreateTable().getTblProps().containsKey(hive_metastoreConstants.TABLE_TRANSACTIONAL_PROPERTIES);
+      if ((HiveConf.getBoolVar(conf, 
HiveConf.ConfVars.CREATE_TABLE_AS_EXTERNAL) || (isExternal || !isAcid))) {
+        CreateTableDesc ctd = pCtx.getCreateTable();
+        ctd.getTblProps().put(hive_metastoreConstants.TABLE_IS_TRANSACTIONAL, 
"false"); // create as external table
+        try {
+          Table table = ctd.toTable(conf);
+          table = db.getCTASQueryDryrun(table.getTTable());
+          org.apache.hadoop.hive.metastore.api.Table tTable = 
table.getTTable();
+          if (tTable.getSd() != null  && tTable.getSd().getLocation() != null) 
{
+            location = new Path(tTable.getSd().getLocation());
+            ctd.setLocation(location.toString());
+          }
+          
ctd.setExternal(TableType.EXTERNAL_TABLE.toString().equals(tTable.getTableType()));
+          ctd.setTblProps(tTable.getParameters());

Review comment:
       Sure. Will do the change.




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