You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by ma...@apache.org on 2019/07/24 05:15:11 UTC
[hive] branch master updated: HIVE-22009 : CTLV with user specified location is not honoured. ( Naresh P R reviewed by Mahesh Kumar Behera)
This is an automated email from the ASF dual-hosted git repository.
mahesh pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hive.git
The following commit(s) were added to refs/heads/master by this push:
new 10554ae HIVE-22009 : CTLV with user specified location is not honoured. ( Naresh P R reviewed by Mahesh Kumar Behera)
10554ae is described below
commit 10554ae8fa3d44b611a716e05a9e9fdda26a44f2
Author: Naresh P R <pr...@gmail.com>
AuthorDate: Wed Jul 24 10:44:29 2019 +0530
HIVE-22009 : CTLV with user specified location is not honoured. ( Naresh P R reviewed by Mahesh Kumar Behera)
Signed-off-by: Mahesh Kumar Behera <ma...@apache.org>
---
.../org/apache/hive/jdbc/TestJdbcWithMiniHS2.java | 21 +++++++++++++++++++++
.../table/creation/CreateTableLikeOperation.java | 16 +++++++++++-----
2 files changed, 32 insertions(+), 5 deletions(-)
diff --git a/itests/hive-unit/src/test/java/org/apache/hive/jdbc/TestJdbcWithMiniHS2.java b/itests/hive-unit/src/test/java/org/apache/hive/jdbc/TestJdbcWithMiniHS2.java
index 2e151ec..03a1926 100644
--- a/itests/hive-unit/src/test/java/org/apache/hive/jdbc/TestJdbcWithMiniHS2.java
+++ b/itests/hive-unit/src/test/java/org/apache/hive/jdbc/TestJdbcWithMiniHS2.java
@@ -1676,4 +1676,25 @@ public class TestJdbcWithMiniHS2 {
}
return extendedDescription;
}
+
+ @Test
+ public void testCustomPathsForCTLV() throws Exception {
+ try (Statement stmt = conTestDb.createStatement()) {
+ // Initialize
+ stmt.execute("CREATE TABLE emp_table (id int, name string, salary int)");
+ stmt.execute("insert into emp_table values(1,'aaaaa',20000)");
+ stmt.execute("CREATE VIEW emp_view AS SELECT * FROM emp_table WHERE salary>10000");
+ String customPath = System.getProperty("test.tmp.dir") + "/custom";
+
+ //Test External CTLV
+ String extPath = customPath + "/emp_ext_table";
+ stmt.execute("CREATE EXTERNAL TABLE emp_ext_table like emp_view STORED AS PARQUET LOCATION '" + extPath + "'");
+ assertTrue(getDetailedTableDescription(stmt, "emp_ext_table").contains(extPath));
+
+ //Test Managed CTLV
+ String mndPath = customPath + "/emp_mm_table";
+ stmt.execute("CREATE TABLE emp_mm_table like emp_view STORED AS ORC LOCATION '" + mndPath + "'");
+ assertTrue(getDetailedTableDescription(stmt, "emp_mm_table").contains(mndPath));
+ }
+ }
}
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/ddl/table/creation/CreateTableLikeOperation.java b/ql/src/java/org/apache/hadoop/hive/ql/ddl/table/creation/CreateTableLikeOperation.java
index 4837d44..8a11261 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/ddl/table/creation/CreateTableLikeOperation.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/ddl/table/creation/CreateTableLikeOperation.java
@@ -94,6 +94,8 @@ public class CreateTableLikeOperation extends DDLOperation<CreateTableLikeDesc>
setExternalProperties(table);
}
+ setUserSpecifiedLocation(table);
+
table.setFields(oldTable.getCols());
table.setPartCols(oldTable.getPartCols());
@@ -114,11 +116,7 @@ public class CreateTableLikeOperation extends DDLOperation<CreateTableLikeDesc>
table.setTableName(names[1]);
table.setOwner(SessionState.getUserFromAuthenticator());
- if (desc.getLocation() != null) {
- table.setDataLocation(new Path(desc.getLocation()));
- } else {
- table.unsetDataLocation();
- }
+ setUserSpecifiedLocation(table);
setTableParameters(table);
@@ -138,6 +136,14 @@ public class CreateTableLikeOperation extends DDLOperation<CreateTableLikeDesc>
return table;
}
+ private void setUserSpecifiedLocation(Table table) {
+ if (desc.getLocation() != null) {
+ table.setDataLocation(new Path(desc.getLocation()));
+ } else {
+ table.unsetDataLocation();
+ }
+ }
+
private void setTableParameters(Table tbl) throws HiveException {
Set<String> retainer = new HashSet<String>();