diff --git hcatalog/src/test/e2e/templeton/tests/ddl.conf hcatalog/src/test/e2e/templeton/tests/ddl.conf index 3c19404..a51fe36 100644 --- hcatalog/src/test/e2e/templeton/tests/ddl.conf +++ hcatalog/src/test/e2e/templeton/tests/ddl.conf @@ -1113,7 +1113,60 @@ $cfg = ] } - +, + { + 'name' => 'TEST_VIEW', + 'tests' => + [ + { + 'num' => 1, + 'method' => 'POST', + 'url' => ':TEMPLETON_URL:/templeton/v1/ddl?user.name=:UNAME:', + 'status_code' => 200, + 'post_options' => ['exec=DROP VIEW url_table_view;'], + 'json_field_substr_match' => {'stderr' => 'OK', 'exitcode' => '^0$'} + }, + { + 'num' => 2, + 'method' => 'DELETE', + 'url' => ':TEMPLETON_URL:/templeton/v1/ddl/database/default/table/url_table?user.name=:UNAME:&ifExists=true', + 'status_code' => 200, + 'json_field_substr_match' => {'database' => 'default', 'table' => 'url_table'}, + }, + { + #create table + 'num' => 3, + 'method' => 'PUT', + 'url' => ':TEMPLETON_URL:/templeton/v1/ddl/database/default/table/url_table?user.name=:UNAME:', + 'format_header' => 'Content-Type: application/json', + 'post_options' => ['{ + "columns": [ + { "name" : "count", "type" : "int" }, + { "name" : "page_url", "type" : "string"} + ], + "format" : { "storedAs" : "SEQUENCEFILE"} + }'], + 'status_code' => 200, + 'json_field_substr_match' => {'database' => 'default', 'table' => 'url_table'}, + + }, + { + #create view + 'num' => 4, + 'method' => 'POST', + 'url' => ':TEMPLETON_URL:/templeton/v1/ddl?user.name=:UNAME:', + 'status_code' => 200, + 'post_options' => ['exec=CREATE VIEW url_table_view(url) as SELECT DISTINCT page_url from url_table;'], + 'json_field_substr_match' => {'stderr' => 'OK', 'exitcode' => '^0$'} + }, + { + 'num' => 5, + 'method' => 'GET', + 'url' => ':TEMPLETON_URL:/templeton/v1/ddl/database/default/table/url_table_view?user.name=:UNAME:&format=extended', + 'status_code' => 200, + } + ] + } diff --git ql/src/java/org/apache/hadoop/hive/ql/metadata/formatting/JsonMetaDataFormatter.java ql/src/java/org/apache/hadoop/hive/ql/metadata/formatting/JsonMetaDataFormatter.java index 96cba25..ee35857 100644 --- ql/src/java/org/apache/hadoop/hive/ql/metadata/formatting/JsonMetaDataFormatter.java +++ ql/src/java/org/apache/hadoop/hive/ql/metadata/formatting/JsonMetaDataFormatter.java @@ -35,6 +35,7 @@ import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; import org.apache.hadoop.hive.conf.HiveConf; +import org.apache.hadoop.hive.metastore.TableType; import org.apache.hadoop.hive.metastore.api.FieldSchema; import org.apache.hadoop.hive.ql.metadata.Hive; import org.apache.hadoop.hive.ql.metadata.HiveException; @@ -189,9 +190,11 @@ public void showTableStatus(DataOutputStream out, Hive db, HiveConf conf, if (tbl.isPartitioned()) { builder.put("partitionColumns", makeColsUnformatted(tbl.getPartCols())); } - - putFileSystemsStats(builder, makeTableStatusLocations(tbl, db, par), + if(tbl.getTableType() != TableType.VIRTUAL_VIEW) { + //tbl.getPath() is null for views + putFileSystemsStats(builder, makeTableStatusLocations(tbl, db, par), conf, tbl.getPath()); + } return builder.build(); } @@ -222,6 +225,10 @@ public void showTableStatus(DataOutputStream out, Hive db, HiveConf conf, return locations; } + /** + * @param tblPath not NULL + * @throws IOException + */ // Duplicates logic in TextMetaDataFormatter private void putFileSystemsStats(MapBuilder builder, List locations, HiveConf conf, Path tblPath)