Skip to content

Commit

Permalink
HIVE-22009 : CTLV with user specified location is not honoured. ( Nar…
Browse files Browse the repository at this point in the history
…esh P R reviewed by Mahesh Kumar Behera)

Signed-off-by: Mahesh Kumar Behera <mahesh@apache.org>
  • Loading branch information
nareshpr authored and maheshk114 committed Jul 24, 2019
1 parent 959ebeb commit 10554ae
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1676,4 +1676,25 @@ static String getDetailedTableDescription(Statement stmt, String table) throws S
}
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));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ private Table createViewLikeTable(Table oldTable) throws HiveException {
setExternalProperties(table);
}

setUserSpecifiedLocation(table);

table.setFields(oldTable.getCols());
table.setPartCols(oldTable.getPartCols());

Expand All @@ -114,11 +116,7 @@ private Table createTableLikeTable(Table table) throws SemanticException, HiveEx
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);

Expand All @@ -138,6 +136,14 @@ private Table createTableLikeTable(Table table) throws SemanticException, HiveEx
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>();

Expand Down

0 comments on commit 10554ae

Please sign in to comment.