hive-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pa...@apache.org
Subject svn commit: r1076105 - in /hive/trunk: jdbc/src/test/org/apache/hadoop/hive/jdbc/ metastore/src/java/org/apache/hadoop/hive/metastore/ ql/src/java/org/apache/hadoop/hive/ql/exec/ ql/src/java/org/apache/hadoop/hive/ql/metadata/ ql/src/java/org/apache/ha...
Date Wed, 02 Mar 2011 05:05:56 GMT
Author: pauly
Date: Wed Mar  2 05:05:55 2011
New Revision: 1076105

URL: http://svn.apache.org/viewvc?rev=1076105&view=rev
Log:
HIVE-1941 support explicit view partitioning (John Sichi via pauly)


Added:
    hive/trunk/ql/src/test/queries/clientnegative/alter_view_failure2.q
    hive/trunk/ql/src/test/queries/clientnegative/alter_view_failure3.q
    hive/trunk/ql/src/test/queries/clientnegative/alter_view_failure4.q
    hive/trunk/ql/src/test/queries/clientnegative/alter_view_failure5.q
    hive/trunk/ql/src/test/queries/clientnegative/alter_view_failure6.q
    hive/trunk/ql/src/test/queries/clientnegative/alter_view_failure7.q
    hive/trunk/ql/src/test/queries/clientnegative/analyze_view.q
    hive/trunk/ql/src/test/queries/clientnegative/create_view_failure6.q
    hive/trunk/ql/src/test/queries/clientnegative/create_view_failure7.q
    hive/trunk/ql/src/test/queries/clientnegative/create_view_failure8.q
    hive/trunk/ql/src/test/queries/clientnegative/create_view_failure9.q
    hive/trunk/ql/src/test/queries/clientpositive/create_view_partitioned.q
    hive/trunk/ql/src/test/results/clientnegative/alter_view_failure2.q.out
    hive/trunk/ql/src/test/results/clientnegative/alter_view_failure3.q.out
    hive/trunk/ql/src/test/results/clientnegative/alter_view_failure4.q.out
    hive/trunk/ql/src/test/results/clientnegative/alter_view_failure5.q.out
    hive/trunk/ql/src/test/results/clientnegative/alter_view_failure6.q.out
    hive/trunk/ql/src/test/results/clientnegative/alter_view_failure7.q.out
    hive/trunk/ql/src/test/results/clientnegative/analyze_view.q.out
    hive/trunk/ql/src/test/results/clientnegative/create_view_failure6.q.out
    hive/trunk/ql/src/test/results/clientnegative/create_view_failure7.q.out
    hive/trunk/ql/src/test/results/clientnegative/create_view_failure8.q.out
    hive/trunk/ql/src/test/results/clientnegative/create_view_failure9.q.out
    hive/trunk/ql/src/test/results/clientpositive/create_view_partitioned.q.out
Modified:
    hive/trunk/jdbc/src/test/org/apache/hadoop/hive/jdbc/TestJdbcDriver.java
    hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/DDLTask.java
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/metadata/Partition.java
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/metadata/Table.java
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/DDLSemanticAnalyzer.java
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/ErrorMsg.java
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/Hive.g
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzerFactory.java
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/plan/AddPartitionDesc.java
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/plan/AlterTableDesc.java
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/plan/CreateViewDesc.java
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/plan/DropTableDesc.java
    hive/trunk/ql/src/test/results/clientnegative/alter_view_failure.q.out

Modified: hive/trunk/jdbc/src/test/org/apache/hadoop/hive/jdbc/TestJdbcDriver.java
URL: http://svn.apache.org/viewvc/hive/trunk/jdbc/src/test/org/apache/hadoop/hive/jdbc/TestJdbcDriver.java?rev=1076105&r1=1076104&r2=1076105&view=diff
==============================================================================
--- hive/trunk/jdbc/src/test/org/apache/hadoop/hive/jdbc/TestJdbcDriver.java (original)
+++ hive/trunk/jdbc/src/test/org/apache/hadoop/hive/jdbc/TestJdbcDriver.java Wed Mar  2 05:05:55 2011
@@ -216,7 +216,8 @@ public class TestJdbcDriver extends Test
 
     // row 1
     assertTrue(res.next());
-    for (int i = 1; i <= meta.getColumnCount(); i++) {
+    // skip the last (partitioning) column since it is always non-null
+    for (int i = 1; i < meta.getColumnCount(); i++) {
       assertNull(res.getObject(i));
     }
 
@@ -291,7 +292,12 @@ public class TestJdbcDriver extends Test
     int i = 0;
 
     ResultSetMetaData meta = res.getMetaData();
-    assertEquals("Unexpected column count", 2, meta.getColumnCount());
+    int expectedColCount = 2;
+    if (tableName.equals(partitionedTableName)) {
+      ++expectedColCount;
+    }
+    assertEquals(
+      "Unexpected column count", expectedColCount, meta.getColumnCount());
 
     boolean moreRow = res.next();
     while (moreRow) {

Modified: hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java
URL: http://svn.apache.org/viewvc/hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java?rev=1076105&r1=1076104&r2=1076105&view=diff
==============================================================================
--- hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java (original)
+++ hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java Wed Mar  2 05:05:55 2011
@@ -1118,6 +1118,10 @@ public class HiveMetaStore extends Thrif
           throw new InvalidObjectException(
               "Unable to add partition because table or database do not exist");
         }
+        if (tbl.getSd().getLocation() == null) {
+            throw new MetaException(
+              "Cannot append a partition to a view");
+        }
 
         part.setSd(tbl.getSd());
         partLocation = new Path(tbl.getSd().getLocation(), Warehouse
@@ -1273,27 +1277,40 @@ public class HiveMetaStore extends Thrif
               "Unable to add partition because table or database do not exist");
         }
 
-        String partLocationStr = part.getSd().getLocation();
+        String partLocationStr = null;
+        if (part.getSd() != null) {
+          partLocationStr = part.getSd().getLocation();
+        }
         if (partLocationStr == null || partLocationStr.isEmpty()) {
-          // set default location if not specified
-          partLocation = new Path(tbl.getSd().getLocation(), Warehouse
+          // set default location if not specified and this is
+          // a physical table partition (not a view)
+          if (tbl.getSd().getLocation() != null) {
+            partLocation = new Path(tbl.getSd().getLocation(), Warehouse
               .makePartName(tbl.getPartitionKeys(), part.getValues()));
+          }
 
         } else {
+          if (tbl.getSd().getLocation() == null) {
+            throw new MetaException(
+              "Cannot specify location for a view partition");
+          }
           partLocation = wh.getDnsPath(new Path(partLocationStr));
         }
 
-        part.getSd().setLocation(partLocation.toString());
+        if (partLocation != null) {
+          part.getSd().setLocation(partLocation.toString());
 
-        // Check to see if the directory already exists before calling mkdirs()
-        // because if the file system is read-only, mkdirs will throw an
-        // exception even if the directory already exists.
-        if (!wh.isDir(partLocation)) {
-          if (!wh.mkdirs(partLocation)) {
-            throw new MetaException(partLocation
+
+          // Check to see if the directory already exists before calling
+          // mkdirs() because if the file system is read-only, mkdirs will
+          // throw an exception even if the directory already exists.
+          if (!wh.isDir(partLocation)) {
+            if (!wh.mkdirs(partLocation)) {
+              throw new MetaException(partLocation
                 + " is not a directory or unable to create one");
+            }
+            madeDir = true;
           }
-          madeDir = true;
         }
 
         // set create time
@@ -1368,14 +1385,13 @@ public class HiveMetaStore extends Thrif
         if (isArchived) {
           archiveParentDir = MetaStoreUtils.getOriginalLocation(part);
         }
-        if (part.getSd() == null || part.getSd().getLocation() == null) {
-          throw new MetaException("Partition metadata is corrupted");
-        }
         if (!ms.dropPartition(db_name, tbl_name, part_vals)) {
           throw new MetaException("Unable to drop partition");
         }
         success = ms.commitTransaction();
-        partPath = new Path(part.getSd().getLocation());
+        if ((part.getSd() != null) && (part.getSd().getLocation() != null)) {
+          partPath = new Path(part.getSd().getLocation());
+        }
         tbl = get_table(db_name, tbl_name);
       } finally {
         if (!success) {

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/DDLTask.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/DDLTask.java?rev=1076105&r1=1076104&r2=1076105&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/DDLTask.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/DDLTask.java Wed Mar  2 05:05:55 2011
@@ -864,7 +864,9 @@ public class DDLTask extends Task<DDLWor
 
     Table tbl = db.getTable(addPartitionDesc.getDbName(), addPartitionDesc.getTableName());
 
-    validateAlterTableType(tbl, AlterTableDesc.AlterTableTypes.ADDPARTITION);
+    validateAlterTableType(
+      tbl, AlterTableDesc.AlterTableTypes.ADDPARTITION,
+      addPartitionDesc.getExpectView());
 
     // If the add partition was created with IF NOT EXISTS, then we should
     // not throw an error if the specified part does exist.
@@ -876,6 +878,9 @@ public class DDLTask extends Task<DDLWor
     if (addPartitionDesc.getLocation() == null) {
       db.createPartition(tbl, addPartitionDesc.getPartSpec());
     } else {
+      if (tbl.isView()) {
+        throw new HiveException("LOCATION clause illegal for view partition");
+      }
       // set partition path relative to table
       db.createPartition(tbl, addPartitionDesc.getPartSpec(), new Path(tbl
           .getPath(), addPartitionDesc.getLocation()));
@@ -1406,16 +1411,32 @@ public class DDLTask extends Task<DDLWor
   }
 
   private void validateAlterTableType(
-    Table tbl, AlterTableDesc.AlterTableTypes alterType)  throws HiveException {
+    Table tbl, AlterTableDesc.AlterTableTypes alterType) throws HiveException {
+
+    validateAlterTableType(tbl, alterType, false);
+  }
+  
+  private void validateAlterTableType(
+    Table tbl, AlterTableDesc.AlterTableTypes alterType,
+    boolean expectView) throws HiveException {
 
     if (tbl.isView()) {
+      if (!expectView) {
+        throw new HiveException("Cannot alter a view with ALTER TABLE");
+      }
       switch (alterType) {
+      case ADDPARTITION:
+      case DROPPARTITION:
       case ADDPROPS:
         // allow this form
         break;
       default:
         throw new HiveException(
-          "Cannot use this form of ALTER TABLE on a view");
+          "Cannot use this form of ALTER on a view");
+      }
+    } else {
+      if (expectView) {
+        throw new HiveException("Cannot alter a base table with ALTER VIEW");
       }
     }
 
@@ -2138,12 +2159,16 @@ public class DDLTask extends Task<DDLWor
         String outputFormattCls = null;
         if (part != null) {
           if (par != null) {
-            tblLoc = par.getDataLocation().toString();
+            if (par.getLocation() != null) {
+              tblLoc = par.getDataLocation().toString();
+            }
             inputFormattCls = par.getInputFormatClass().getName();
             outputFormattCls = par.getOutputFormatClass().getName();
           }
         } else {
-          tblLoc = tbl.getDataLocation().toString();
+          if (tbl.getPath() != null) {
+            tblLoc = tbl.getDataLocation().toString();
+          }
           inputFormattCls = tbl.getInputFormatClass().getName();
           outputFormattCls = tbl.getOutputFormatClass().getName();
         }
@@ -2180,16 +2205,23 @@ public class DDLTask extends Task<DDLWor
         if (isPartitioned) {
           if (par == null) {
             for (Partition curPart : db.getPartitions(tbl)) {
-              locations.add(new Path(curPart.getTPartition().getSd()
-                  .getLocation()));
+              if (curPart.getLocation() != null) {
+                locations.add(new Path(curPart.getLocation()));
+              }
             }
           } else {
-            locations.add(new Path(par.getTPartition().getSd().getLocation()));
+            if (par.getLocation() != null) {
+              locations.add(new Path(par.getLocation()));
+            }
           }
         } else {
-          locations.add(tablLoc);
+          if (tablLoc != null) {
+            locations.add(tablLoc);
+          }
+        }
+        if (!locations.isEmpty()) {
+          writeFileSystemStats(outStream, locations, tablLoc, false, 0);
         }
-        writeFileSystemStats(outStream, locations, tablLoc, false, 0);
 
         outStream.write(terminator);
       }
@@ -2519,17 +2551,7 @@ public class DDLTask extends Task<DDLWor
       }
     }
 
-    validateAlterTableType(tbl, alterTbl.getOp());
-
-    if (tbl.isView()) {
-      if (!alterTbl.getExpectView()) {
-        throw new HiveException("Cannot alter a view with ALTER TABLE");
-      }
-    } else {
-      if (alterTbl.getExpectView()) {
-        throw new HiveException("Cannot alter a base table with ALTER VIEW");
-      }
-    }
+    validateAlterTableType(tbl, alterTbl.getOp(), alterTbl.getExpectView());
 
     Table oldTbl = tbl.copy();
 
@@ -2823,19 +2845,20 @@ public class DDLTask extends Task<DDLWor
       // drop table is idempotent
     }
 
-    if (tbl != null) {
-      if (tbl.isView()) {
-        if (!dropTbl.getExpectView()) {
-          throw new HiveException("Cannot drop a view with DROP TABLE");
-        }
-      } else {
-        if (dropTbl.getExpectView()) {
-          throw new HiveException("Cannot drop a base table with DROP VIEW");
+    if (dropTbl.getPartSpecs() == null) {
+      // This is a true DROP TABLE
+      if (tbl != null) {
+        if (tbl.isView()) {
+          if (!dropTbl.getExpectView()) {
+            throw new HiveException("Cannot drop a view with DROP TABLE");
+          }
+        } else {
+          if (dropTbl.getExpectView()) {
+            throw new HiveException("Cannot drop a base table with DROP VIEW");
+          }
         }
       }
-    }
 
-    if (dropTbl.getPartSpecs() == null) {
       if (tbl != null && !tbl.canDrop()) {
         throw new HiveException("Table " + tbl.getTableName() +
             " is protected from being dropped");
@@ -2859,6 +2882,13 @@ public class DDLTask extends Task<DDLWor
         work.getOutputs().add(new WriteEntity(tbl));
       }
     } else {
+      // This is actually an ALTER TABLE DROP PARTITION
+      if (tbl != null) {
+        validateAlterTableType(
+          tbl, AlterTableDesc.AlterTableTypes.DROPPARTITION,
+          dropTbl.getExpectView());
+      }
+      
       // get all partitions of the table
       List<String> partitionNames =
         db.getPartitionNames(dropTbl.getTableName(), (short) -1);
@@ -3238,6 +3268,10 @@ public class DDLTask extends Task<DDLWor
       tbl.getTTable().getParameters().putAll(crtView.getTblProps());
     }
 
+    if (crtView.getPartCols() != null) {
+      tbl.setPartCols(crtView.getPartCols());
+    }
+
     int rc = setGenericTableAttributes(tbl);
     if (rc != 0) {
       return rc;

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/metadata/Partition.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/metadata/Partition.java?rev=1076105&r1=1076104&r2=1076105&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/metadata/Partition.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/metadata/Partition.java Wed Mar  2 05:05:55 2011
@@ -95,7 +95,9 @@ public class Partition implements Serial
   public Partition(Table tbl) throws HiveException {
     org.apache.hadoop.hive.metastore.api.Partition tPart =
         new org.apache.hadoop.hive.metastore.api.Partition();
-    tPart.setSd(tbl.getTTable().getSd()); // TODO: get a copy
+    if (!tbl.isView()) {
+      tPart.setSd(tbl.getTTable().getSd()); // TODO: get a copy
+    }
     initialize(tbl, tPart);
   }
 
@@ -134,6 +136,11 @@ public class Partition implements Serial
     tpart.setTableName(tbl.getTableName());
     tpart.setValues(pvals);
 
+    if (tbl.isView()) {
+      initialize(tbl, tpart);
+      return;
+    }
+
     StorageDescriptor sd = new StorageDescriptor();
     try {
       // replace with THRIFT-138
@@ -172,15 +179,23 @@ public class Partition implements Serial
 
     this.table = table;
     this.tPartition = tPartition;
-    String partName = "";
 
+    if (table.isView()) {
+      return;
+    }
+    
+    String partName = "";
     if (table.isPartitioned()) {
       try {
         partName = Warehouse.makePartName(table.getPartCols(), tPartition.getValues());
         if (tPartition.getSd().getLocation() == null) {
-          // set default if location is not set
-          Path partPath = new Path(table.getDataLocation().toString(), partName);
-          tPartition.getSd().setLocation(partPath.toString());
+          // set default if location is not set and this is a physical
+          // table partition (not a view partition)
+          if (table.getDataLocation() != null) {
+            Path partPath = new Path(
+              table.getDataLocation().toString(), partName);
+            tPartition.getSd().setLocation(partPath.toString());
+          }
         }
       } catch (MetaException e) {
         throw new HiveException("Invalid partition for table " + table.getTableName(),
@@ -466,7 +481,11 @@ public class Partition implements Serial
   }
 
   public String getLocation() {
-    return tPartition.getSd().getLocation();
+    if (tPartition.getSd() == null) {
+      return null;
+    } else {
+      return tPartition.getSd().getLocation();
+    }
   }
 
   public void setLocation(String location) {

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/metadata/Table.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/metadata/Table.java?rev=1076105&r1=1076104&r2=1076105&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/metadata/Table.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/metadata/Table.java Wed Mar  2 05:05:55 2011
@@ -339,8 +339,9 @@ public class Table implements Serializab
 
     if ((spec == null) || (spec.size() != partCols.size())) {
       throw new HiveException(
-          "table is partitioned but partition spec is not specified or tab: "
-              + spec);
+          "table is partitioned but partition spec is not specified or"
+          + " does not fully match table partitioning: "
+          + spec);
     }
 
     for (FieldSchema field : partCols) {

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/DDLSemanticAnalyzer.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/DDLSemanticAnalyzer.java?rev=1076105&r1=1076104&r2=1076105&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/DDLSemanticAnalyzer.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/DDLSemanticAnalyzer.java Wed Mar  2 05:05:55 2011
@@ -34,6 +34,7 @@ import java.util.Map;
 import java.util.Properties;
 import java.util.Set;
 import java.util.Map.Entry;
+import java.util.regex.Pattern;
 
 import org.antlr.runtime.tree.CommonTree;
 import org.antlr.runtime.tree.Tree;
@@ -48,6 +49,7 @@ import org.apache.hadoop.hive.metastore.
 import org.apache.hadoop.hive.metastore.api.MetaException;
 import org.apache.hadoop.hive.metastore.api.Order;
 import org.apache.hadoop.hive.metastore.api.PrincipalType;
+import org.apache.hadoop.hive.ql.Driver;
 import org.apache.hadoop.hive.ql.exec.FetchTask;
 import org.apache.hadoop.hive.ql.exec.Task;
 import org.apache.hadoop.hive.ql.exec.TaskFactory;
@@ -243,6 +245,16 @@ public class DDLSemanticAnalyzer extends
     case HiveParser.TOK_ALTERVIEW_PROPERTIES:
       analyzeAlterTableProps(ast, true);
       break;
+    case HiveParser.TOK_ALTERVIEW_ADDPARTS:
+      // for ALTER VIEW ADD PARTITION, we wrapped the ADD to discriminate
+      // view from table; unwrap it now
+      analyzeAlterTableAddParts((ASTNode) ast.getChild(0), true);
+      break;
+    case HiveParser.TOK_ALTERVIEW_DROPPARTS:
+      // for ALTER VIEW DROP PARTITION, we wrapped the DROP to discriminate
+      // view from table; unwrap it now
+      analyzeAlterTableDropParts((ASTNode) ast.getChild(0), true);
+      break;
     case HiveParser.TOK_ALTERTABLE_RENAME:
       analyzeAlterTableRename(ast);
       break;
@@ -265,10 +277,10 @@ public class DDLSemanticAnalyzer extends
       analyzeAlterTableRenameCol(ast);
       break;
     case HiveParser.TOK_ALTERTABLE_ADDPARTS:
-      analyzeAlterTableAddParts(ast);
+      analyzeAlterTableAddParts(ast, false);
       break;
     case HiveParser.TOK_ALTERTABLE_DROPPARTS:
-      analyzeAlterTableDropParts(ast);
+      analyzeAlterTableDropParts(ast, false);
       break;
     case HiveParser.TOK_ALTERTABLE_PROPERTIES:
       analyzeAlterTableProps(ast, false);
@@ -1669,11 +1681,14 @@ public class DDLSemanticAnalyzer extends
         alterTblDesc), conf));
   }
 
-  private void analyzeAlterTableDropParts(ASTNode ast) throws SemanticException {
+  private void analyzeAlterTableDropParts(ASTNode ast, boolean expectView)
+    throws SemanticException {
+
     String tblName = getUnescapedName((ASTNode)ast.getChild(0));
     // get table metadata
     List<Map<String, String>> partSpecs = getPartitionSpecs(ast);
-    DropTableDesc dropTblDesc = new DropTableDesc(tblName, partSpecs);
+    DropTableDesc dropTblDesc =
+      new DropTableDesc(tblName, partSpecs, expectView);
 
     try {
       Table tab = db.getTable(db.getCurrentDatabase(), tblName, false);
@@ -1703,17 +1718,24 @@ public class DDLSemanticAnalyzer extends
    *
    * @param ast
    *          The parsed command tree.
+   *
+   * @param expectView
+   *          True for ALTER VIEW, false for ALTER TABLE.
+   *
    * @throws SemanticException
-   *           Parsin failed
+   *           Parsing failed
    */
-  private void analyzeAlterTableAddParts(CommonTree ast)
+  private void analyzeAlterTableAddParts(CommonTree ast, boolean expectView)
       throws SemanticException {
 
     String tblName = getUnescapedName((ASTNode)ast.getChild(0));
+    boolean isView = false;
+    Table tab;
     try {
-      Table tab = db.getTable(db.getCurrentDatabase(), tblName, false);
+      tab = db.getTable(db.getCurrentDatabase(), tblName, false);
       if (tab != null) {
         inputs.add(new ReadEntity(tab));
+        isView = tab.isView();
       }
     } catch (HiveException e) {
       throw new SemanticException(ErrorMsg.INVALID_TABLE.getMsg(tblName));
@@ -1728,6 +1750,7 @@ public class DDLSemanticAnalyzer extends
     String currentLocation = null;
     Map<String, String> currentPart = null;
     boolean ifNotExists = false;
+    List<AddPartitionDesc> partitionDescs = new ArrayList<AddPartitionDesc>();
 
     int numCh = ast.getChildCount();
     for (int num = 1; num < numCh; num++) {
@@ -1741,9 +1764,8 @@ public class DDLSemanticAnalyzer extends
           validatePartitionValues(currentPart);
           AddPartitionDesc addPartitionDesc = new AddPartitionDesc(
               db.getCurrentDatabase(), tblName, currentPart,
-              currentLocation, ifNotExists);
-          rootTasks.add(TaskFactory.get(new DDLWork(getInputs(), getOutputs(),
-              addPartitionDesc), conf));
+              currentLocation, ifNotExists, expectView);
+          partitionDescs.add(addPartitionDesc);
         }
         // create new partition, set values
         currentLocation = null;
@@ -1763,9 +1785,60 @@ public class DDLSemanticAnalyzer extends
       validatePartitionValues(currentPart);
       AddPartitionDesc addPartitionDesc = new AddPartitionDesc(
           db.getCurrentDatabase(), tblName, currentPart,
-          currentLocation, ifNotExists);
+          currentLocation, ifNotExists, expectView);
+      partitionDescs.add(addPartitionDesc);
+    }
+
+    for (AddPartitionDesc addPartitionDesc : partitionDescs) {
       rootTasks.add(TaskFactory.get(new DDLWork(getInputs(), getOutputs(),
-          addPartitionDesc), conf));
+            addPartitionDesc), conf));
+    }
+    
+    if (isView) {
+      // Compile internal query to capture underlying table partition
+      // dependencies
+      StringBuilder cmd = new StringBuilder();
+      cmd.append("SELECT * FROM ");
+      cmd.append(HiveUtils.unparseIdentifier(tblName));
+      cmd.append(" WHERE ");
+      boolean firstOr = true;
+      for (AddPartitionDesc partitionDesc : partitionDescs) {
+        // Perform this check early so that we get a better error message.
+        try {
+          // Note that isValidSpec throws an exception (it never
+          // actually returns false).
+          tab.isValidSpec(partitionDesc.getPartSpec());
+        } catch (HiveException ex) {
+          throw new SemanticException(ex.getMessage(), ex);
+        }
+        if (firstOr) {
+          firstOr = false;
+        } else {
+          cmd.append(" OR ");
+        }
+        boolean firstAnd = true;
+        cmd.append("(");
+        for (Map.Entry<String, String> entry
+               : partitionDesc.getPartSpec().entrySet())
+        {
+          if (firstAnd) {
+            firstAnd = false;
+          } else {
+            cmd.append(" AND ");
+          }
+          cmd.append(HiveUtils.unparseIdentifier(entry.getKey()));
+          cmd.append(" = '");
+          cmd.append(HiveUtils.escapeString(entry.getValue()));
+          cmd.append("'");
+        }
+        cmd.append(")");
+      }
+      Driver driver = new Driver(conf);
+      int rc = driver.compile(cmd.toString());
+      if (rc != 0) {
+        throw new SemanticException(ErrorMsg.NO_VALID_PARTN.getMsg());
+      }
+      inputs.addAll(driver.getPlan().getInputs());
     }
   }
 

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/ErrorMsg.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/ErrorMsg.java?rev=1076105&r1=1076104&r2=1076105&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/ErrorMsg.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/ErrorMsg.java Wed Mar  2 05:05:55 2011
@@ -139,6 +139,9 @@ public enum ErrorMsg {
   VIEW_COL_MISMATCH("The number of columns produced by the SELECT clause does not match the "
       + "number of column names specified by CREATE VIEW"),
   DML_AGAINST_VIEW("A view cannot be used as target table for LOAD or INSERT"),
+  ANALYZE_VIEW("ANALYZE is not supported for views"),
+  VIEW_PARTITION_TOTAL("At least one non-partitioning column must be present in view"),
+  VIEW_PARTITION_MISMATCH("Rightmost columns in view output do not match PARTITIONED ON clause"),
   PARTITION_DYN_STA_ORDER("Dynamic partition cannot be the parent of a static partition"),
   DYNAMIC_PARTITION_DISABLED("Dynamic partition is disabled. Either enable it by setting "
       + "hive.exec.dynamic.partition=true or specify partition column values"),

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/Hive.g
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/Hive.g?rev=1076105&r1=1076104&r2=1076105&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/Hive.g (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/Hive.g Wed Mar  2 05:05:55 2011
@@ -181,6 +181,9 @@ TOK_DROPFUNCTION;
 TOK_CREATEVIEW;
 TOK_DROPVIEW;
 TOK_ALTERVIEW_PROPERTIES;
+TOK_ALTERVIEW_ADDPARTS;
+TOK_ALTERVIEW_DROPPARTS;
+TOK_VIEWPARTCOLS;
 TOK_EXPLAIN;
 TOK_TABLESERIALIZER;
 TOK_TABLEPROPERTIES;
@@ -528,6 +531,10 @@ alterViewStatementSuffix
 @init { msgs.push("alter view statement"); }
 @after { msgs.pop(); }
     : alterViewSuffixProperties
+    | alterStatementSuffixAddPartitions
+        -> ^(TOK_ALTERVIEW_ADDPARTS alterStatementSuffixAddPartitions)
+    | alterStatementSuffixDropPartitions
+        -> ^(TOK_ALTERVIEW_DROPPARTS alterStatementSuffixDropPartitions)
     ;
 
 alterIndexStatementSuffix
@@ -948,18 +955,26 @@ createViewStatement
 }
 @after { msgs.pop(); }
     : KW_CREATE KW_VIEW ifNotExists? name=tableName
-        (LPAREN columnNameCommentList RPAREN)? tableComment?
+        (LPAREN columnNameCommentList RPAREN)? tableComment? viewPartition?
         tablePropertiesPrefixed?
         KW_AS
         selectStatement
     -> ^(TOK_CREATEVIEW $name ifNotExists?
          columnNameCommentList?
          tableComment?
+         viewPartition?
          tablePropertiesPrefixed?
          selectStatement
         )
     ;
 
+viewPartition
+@init { msgs.push("view partition specification"); }
+@after { msgs.pop(); }
+    : KW_PARTITIONED KW_ON LPAREN columnNameList RPAREN
+    -> ^(TOK_VIEWPARTCOLS columnNameList)
+    ;
+
 dropViewStatement
 @init { msgs.push("drop view statement"); }
 @after { msgs.pop(); }

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java?rev=1076105&r1=1076104&r2=1076105&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java Wed Mar  2 05:05:55 2011
@@ -801,6 +801,9 @@ public class SemanticAnalyzer extends Ba
             throw new SemanticException(ErrorMsg.INVALID_TABLE_ALIAS.
                 getMsg("Referencing view from foreign databases is not supported."));
           }
+          if (qb.getParseInfo().isAnalyzeCommand()) {
+            throw new SemanticException(ErrorMsg.ANALYZE_VIEW.getMsg());
+          }
           replaceViewReferenceWithDefinition(qb, tab, tab_name, alias);
           continue;
         }
@@ -6702,6 +6705,52 @@ public class SemanticAnalyzer extends Ba
       expandedText = sb.toString();
     }
 
+    if (createVwDesc.getPartColNames() != null) {
+      // Make sure all partitioning columns referenced actually
+      // exist and are in the correct order at the end
+      // of the list of columns produced by the view.  Also move the field
+      // schema descriptors from derivedSchema to the partitioning key
+      // descriptor.
+      List<String> partColNames = createVwDesc.getPartColNames();
+      if (partColNames.size() > derivedSchema.size()) {
+          throw new SemanticException(
+            ErrorMsg.VIEW_PARTITION_MISMATCH.getMsg());
+      }
+      
+      // Get the partition columns from the end of derivedSchema.
+      List<FieldSchema> partitionColumns = derivedSchema.subList(
+        derivedSchema.size() - partColNames.size(),
+        derivedSchema.size());
+
+      // Verify that the names match the PARTITIONED ON clause.
+      Iterator<String> colNameIter = partColNames.iterator();
+      Iterator<FieldSchema> schemaIter = partitionColumns.iterator();
+      while (colNameIter.hasNext()) {
+        String colName = colNameIter.next();
+        FieldSchema fieldSchema = schemaIter.next();
+        if (!fieldSchema.getName().equals(colName)) {
+          throw new SemanticException(
+            ErrorMsg.VIEW_PARTITION_MISMATCH.getMsg());
+        }
+      }
+
+      // Boundary case:  require at least one non-partitioned column
+      // for consistency with tables.
+      if (partColNames.size() == derivedSchema.size()) {
+          throw new SemanticException(
+            ErrorMsg.VIEW_PARTITION_TOTAL.getMsg());
+      }
+
+      // Now make a copy.
+      createVwDesc.setPartCols(
+        new ArrayList<FieldSchema>(partitionColumns));
+
+      // Finally, remove the partition columns from the end of derivedSchema.
+      // (Clearing the subList writes through to the underlying
+      // derivedSchema ArrayList.)
+      partitionColumns.clear();
+    }
+
     createVwDesc.setSchema(derivedSchema);
     createVwDesc.setViewExpandedText(expandedText);
   }
@@ -6709,7 +6758,7 @@ public class SemanticAnalyzer extends Ba
   private List<FieldSchema> convertRowSchemaToViewSchema(RowResolver rr) {
     List<FieldSchema> fieldSchemas = new ArrayList<FieldSchema>();
     for (ColumnInfo colInfo : rr.getColumnInfos()) {
-      if (colInfo.getIsVirtualCol()) {
+      if (colInfo.isHiddenVirtualCol()) {
         continue;
       }
       String colName = rr.reverseLookup(colInfo.getInternalName())[1];
@@ -7171,6 +7220,7 @@ public class SemanticAnalyzer extends Ba
     String comment = null;
     ASTNode selectStmt = null;
     Map<String, String> tblProps = null;
+    List<String> partColNames = null;
 
     LOG.info("Creating view " + tableName + " position="
         + ast.getCharPositionInLine());
@@ -7193,13 +7243,16 @@ public class SemanticAnalyzer extends Ba
       case HiveParser.TOK_TABLEPROPERTIES:
         tblProps = DDLSemanticAnalyzer.getProps((ASTNode) child.getChild(0));
         break;
+      case HiveParser.TOK_VIEWPARTCOLS:
+        partColNames = getColumnNames((ASTNode) child.getChild(0));
+        break;
       default:
         assert false;
       }
     }
 
     createVwDesc = new CreateViewDesc(
-      tableName, cols, comment, tblProps, ifNotExists);
+      tableName, cols, comment, tblProps, partColNames, ifNotExists);
     unparseTranslator.enable();
     rootTasks.add(TaskFactory.get(new DDLWork(getInputs(), getOutputs(),
         createVwDesc), conf));

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzerFactory.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzerFactory.java?rev=1076105&r1=1076104&r2=1076105&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzerFactory.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzerFactory.java Wed Mar  2 05:05:55 2011
@@ -73,6 +73,8 @@ public final class SemanticAnalyzerFacto
     commandType.put(HiveParser.TOK_ALTERINDEX_REBUILD, HiveOperation.ALTERINDEX_REBUILD);
     commandType.put(HiveParser.TOK_ALTERINDEX_PROPERTIES, HiveOperation.ALTERINDEX_PROPS);
     commandType.put(HiveParser.TOK_ALTERVIEW_PROPERTIES, HiveOperation.ALTERVIEW_PROPERTIES);
+    commandType.put(HiveParser.TOK_ALTERVIEW_ADDPARTS, HiveOperation.ALTERTABLE_ADDPARTS);
+    commandType.put(HiveParser.TOK_ALTERVIEW_DROPPARTS, HiveOperation.ALTERTABLE_DROPPARTS);
     commandType.put(HiveParser.TOK_QUERY, HiveOperation.QUERY);
     commandType.put(HiveParser.TOK_LOCKTABLE, HiveOperation.LOCKTABLE);
     commandType.put(HiveParser.TOK_UNLOCKTABLE, HiveOperation.UNLOCKTABLE);
@@ -137,6 +139,8 @@ public final class SemanticAnalyzerFacto
       case HiveParser.TOK_ALTERINDEX_REBUILD:
       case HiveParser.TOK_ALTERINDEX_PROPERTIES:
       case HiveParser.TOK_ALTERVIEW_PROPERTIES:
+      case HiveParser.TOK_ALTERVIEW_ADDPARTS:
+      case HiveParser.TOK_ALTERVIEW_DROPPARTS:
       case HiveParser.TOK_SHOWDATABASES:
       case HiveParser.TOK_SHOWTABLES:
       case HiveParser.TOK_SHOW_TABLESTATUS:

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/plan/AddPartitionDesc.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/plan/AddPartitionDesc.java?rev=1076105&r1=1076104&r2=1076105&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/plan/AddPartitionDesc.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/plan/AddPartitionDesc.java Wed Mar  2 05:05:55 2011
@@ -33,6 +33,7 @@ public class AddPartitionDesc extends DD
   String dbName;
   String location;
   boolean ifNotExists;
+  boolean expectView;
   LinkedHashMap<String, String> partSpec;
 
   /**
@@ -52,15 +53,19 @@ public class AddPartitionDesc extends DD
    *          partition location, relative to table location.
    * @param ifNotExists 
    *          if true, the partition is only added if it doesn't exist
+   * @param expectView
+   *          true for ALTER VIEW, false for ALTER TABLE
    */
   public AddPartitionDesc(String dbName, String tableName,
-      Map<String, String> partSpec, String location, boolean ifNotExists) {
+      Map<String, String> partSpec, String location, boolean ifNotExists,
+      boolean expectView) {
     super();
     this.dbName = dbName;
     this.tableName = tableName;
     this.partSpec = new LinkedHashMap<String,String>(partSpec);
     this.location = location;
     this.ifNotExists = ifNotExists;
+    this.expectView = expectView;
   }
 
   /**
@@ -137,4 +142,19 @@ public class AddPartitionDesc extends DD
   public void setIfNotExists(boolean ifNotExists) {
     this.ifNotExists = ifNotExists;
   }
+
+  /**
+   * @return whether to expect a view being altered
+   */
+  public boolean getExpectView() {
+    return expectView;
+  }
+
+  /**
+   * @param expectView
+   *          set whether to expect a view being altered
+   */
+  public void setExpectView(boolean expectView) {
+    this.expectView = expectView;
+  }
 }

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/plan/AlterTableDesc.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/plan/AlterTableDesc.java?rev=1076105&r1=1076104&r2=1076105&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/plan/AlterTableDesc.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/plan/AlterTableDesc.java Wed Mar  2 05:05:55 2011
@@ -42,7 +42,8 @@ public class AlterTableDesc extends DDLD
   public static enum AlterTableTypes {
     RENAME, ADDCOLS, REPLACECOLS, ADDPROPS, ADDSERDE, ADDSERDEPROPS,
     ADDFILEFORMAT, ADDCLUSTERSORTCOLUMN, RENAMECOLUMN, ADDPARTITION,
-    TOUCH, ARCHIVE, UNARCHIVE, ALTERPROTECTMODE, ALTERPARTITIONPROTECTMODE, ALTERLOCATION,
+    TOUCH, ARCHIVE, UNARCHIVE, ALTERPROTECTMODE, ALTERPARTITIONPROTECTMODE,
+    ALTERLOCATION, DROPPARTITION
   };
 
   public static enum ProtectModeType {

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/plan/CreateViewDesc.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/plan/CreateViewDesc.java?rev=1076105&r1=1076104&r2=1076105&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/plan/CreateViewDesc.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/plan/CreateViewDesc.java Wed Mar  2 05:05:55 2011
@@ -38,6 +38,8 @@ public class CreateViewDesc extends DDLD
   private String expandedText;
   private List<FieldSchema> schema;
   private Map<String, String> tblProps;
+  private List<String> partColNames;
+  private List<FieldSchema> partCols;
   private String comment;
   private boolean ifNotExists;
 
@@ -48,11 +50,13 @@ public class CreateViewDesc extends DDLD
   }
   
   public CreateViewDesc(String viewName, List<FieldSchema> schema,
-      String comment, Map<String, String> tblProps, boolean ifNotExists) {
+      String comment, Map<String, String> tblProps,
+      List<String> partColNames, boolean ifNotExists) {
     this.viewName = viewName;
     this.schema = schema;
     this.comment = comment;
     this.tblProps = tblProps;
+    this.partColNames = partColNames;
     this.ifNotExists = ifNotExists;
   }
 
@@ -96,6 +100,27 @@ public class CreateViewDesc extends DDLD
     this.schema = schema;
   }
 
+  @Explain(displayName = "partition columns")
+  public List<String> getPartColsString() {
+    return Utilities.getFieldSchemaString(partCols);
+  }
+
+  public List<FieldSchema> getPartCols() {
+    return partCols;
+  }
+
+  public void setPartCols(List<FieldSchema> partCols) {
+    this.partCols = partCols;
+  }
+
+  public List<String> getPartColNames() {
+    return partColNames;
+  }
+
+  public void setPartColNames(List<String> partColNames) {
+    this.partColNames = partColNames;
+  }
+
   @Explain(displayName = "comment")
   public String getComment() {
     return comment;

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/plan/DropTableDesc.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/plan/DropTableDesc.java?rev=1076105&r1=1076104&r2=1076105&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/plan/DropTableDesc.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/plan/DropTableDesc.java Wed Mar  2 05:05:55 2011
@@ -48,13 +48,13 @@ public class DropTableDesc extends DDLDe
     this.expectView = expectView;
   }
 
-  public DropTableDesc(String tableName, List<? extends Map<String, String>> partSpecs) {
+  public DropTableDesc(String tableName, List<? extends Map<String, String>> partSpecs, boolean expectView) {
     this.tableName = tableName;
     this.partSpecs = new ArrayList<LinkedHashMap<String, String>>(partSpecs.size());
     for (int i = 0; i < partSpecs.size(); i++) {
       this.partSpecs.add(new LinkedHashMap<String, String>(partSpecs.get(i)));
     }
-    expectView = false;
+    this.expectView = expectView;
   }
 
   /**

Added: hive/trunk/ql/src/test/queries/clientnegative/alter_view_failure2.q
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/queries/clientnegative/alter_view_failure2.q?rev=1076105&view=auto
==============================================================================
--- hive/trunk/ql/src/test/queries/clientnegative/alter_view_failure2.q (added)
+++ hive/trunk/ql/src/test/queries/clientnegative/alter_view_failure2.q Wed Mar  2 05:05:55 2011
@@ -0,0 +1,8 @@
+DROP VIEW xxx4;
+CREATE VIEW xxx4 
+PARTITIONED ON (value)
+AS 
+SELECT * FROM src;
+
+-- should fail:  need to use ALTER VIEW, not ALTER TABLE
+ALTER TABLE xxx4 ADD PARTITION (value='val_86');

Added: hive/trunk/ql/src/test/queries/clientnegative/alter_view_failure3.q
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/queries/clientnegative/alter_view_failure3.q?rev=1076105&view=auto
==============================================================================
--- hive/trunk/ql/src/test/queries/clientnegative/alter_view_failure3.q (added)
+++ hive/trunk/ql/src/test/queries/clientnegative/alter_view_failure3.q Wed Mar  2 05:05:55 2011
@@ -0,0 +1,2 @@
+-- should fail:  can't use ALTER VIEW on a table
+ALTER VIEW srcpart ADD PARTITION (ds='2012-12-31', hr='23');

Added: hive/trunk/ql/src/test/queries/clientnegative/alter_view_failure4.q
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/queries/clientnegative/alter_view_failure4.q?rev=1076105&view=auto
==============================================================================
--- hive/trunk/ql/src/test/queries/clientnegative/alter_view_failure4.q (added)
+++ hive/trunk/ql/src/test/queries/clientnegative/alter_view_failure4.q Wed Mar  2 05:05:55 2011
@@ -0,0 +1,8 @@
+DROP VIEW xxx5;
+CREATE VIEW xxx5
+PARTITIONED ON (value)
+AS 
+SELECT * FROM src;
+
+-- should fail:  LOCATION clause is illegal
+ALTER VIEW xxx5 ADD PARTITION (value='val_86') LOCATION '/foo/bar/baz';

Added: hive/trunk/ql/src/test/queries/clientnegative/alter_view_failure5.q
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/queries/clientnegative/alter_view_failure5.q?rev=1076105&view=auto
==============================================================================
--- hive/trunk/ql/src/test/queries/clientnegative/alter_view_failure5.q (added)
+++ hive/trunk/ql/src/test/queries/clientnegative/alter_view_failure5.q Wed Mar  2 05:05:55 2011
@@ -0,0 +1,8 @@
+DROP VIEW xxx6;
+CREATE VIEW xxx6
+PARTITIONED ON (value)
+AS 
+SELECT * FROM src;
+
+-- should fail:  partition column name does not match
+ALTER VIEW xxx6 ADD PARTITION (v='val_86');

Added: hive/trunk/ql/src/test/queries/clientnegative/alter_view_failure6.q
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/queries/clientnegative/alter_view_failure6.q?rev=1076105&view=auto
==============================================================================
--- hive/trunk/ql/src/test/queries/clientnegative/alter_view_failure6.q (added)
+++ hive/trunk/ql/src/test/queries/clientnegative/alter_view_failure6.q Wed Mar  2 05:05:55 2011
@@ -0,0 +1,11 @@
+DROP VIEW xxx7;
+CREATE VIEW xxx7
+PARTITIONED ON (key)
+AS 
+SELECT hr,key FROM srcpart;
+
+SET hive.mapred.mode=strict;
+
+-- strict mode should cause this to fail since view partition
+-- predicate does not correspond to an underlying table partition predicate
+ALTER VIEW xxx7 ADD PARTITION (key=10);

Added: hive/trunk/ql/src/test/queries/clientnegative/alter_view_failure7.q
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/queries/clientnegative/alter_view_failure7.q?rev=1076105&view=auto
==============================================================================
--- hive/trunk/ql/src/test/queries/clientnegative/alter_view_failure7.q (added)
+++ hive/trunk/ql/src/test/queries/clientnegative/alter_view_failure7.q Wed Mar  2 05:05:55 2011
@@ -0,0 +1,8 @@
+DROP VIEW xxx8;
+CREATE VIEW xxx8
+PARTITIONED ON (ds,hr)
+AS 
+SELECT key,ds,hr FROM srcpart;
+
+-- should fail:  need to fill in all partition columns
+ALTER VIEW xxx8 ADD PARTITION (ds='2011-01-01');

Added: hive/trunk/ql/src/test/queries/clientnegative/analyze_view.q
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/queries/clientnegative/analyze_view.q?rev=1076105&view=auto
==============================================================================
--- hive/trunk/ql/src/test/queries/clientnegative/analyze_view.q (added)
+++ hive/trunk/ql/src/test/queries/clientnegative/analyze_view.q Wed Mar  2 05:05:55 2011
@@ -0,0 +1,6 @@
+DROP VIEW av;
+
+CREATE VIEW av AS SELECT * FROM src;
+
+-- should fail:  can't analyze a view...yet
+ANALYZE TABLE av COMPUTE STATISTICS;

Added: hive/trunk/ql/src/test/queries/clientnegative/create_view_failure6.q
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/queries/clientnegative/create_view_failure6.q?rev=1076105&view=auto
==============================================================================
--- hive/trunk/ql/src/test/queries/clientnegative/create_view_failure6.q (added)
+++ hive/trunk/ql/src/test/queries/clientnegative/create_view_failure6.q Wed Mar  2 05:05:55 2011
@@ -0,0 +1,6 @@
+DROP VIEW xxx15;
+
+-- should fail:  baz is not a column
+CREATE VIEW xxx15
+PARTITIONED ON (baz)
+AS SELECT key FROM src;

Added: hive/trunk/ql/src/test/queries/clientnegative/create_view_failure7.q
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/queries/clientnegative/create_view_failure7.q?rev=1076105&view=auto
==============================================================================
--- hive/trunk/ql/src/test/queries/clientnegative/create_view_failure7.q (added)
+++ hive/trunk/ql/src/test/queries/clientnegative/create_view_failure7.q Wed Mar  2 05:05:55 2011
@@ -0,0 +1,6 @@
+DROP VIEW xxx16;
+
+-- should fail:  must have at least one non-partitioning column
+CREATE VIEW xxx16
+PARTITIONED ON (key)
+AS SELECT key FROM src;

Added: hive/trunk/ql/src/test/queries/clientnegative/create_view_failure8.q
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/queries/clientnegative/create_view_failure8.q?rev=1076105&view=auto
==============================================================================
--- hive/trunk/ql/src/test/queries/clientnegative/create_view_failure8.q (added)
+++ hive/trunk/ql/src/test/queries/clientnegative/create_view_failure8.q Wed Mar  2 05:05:55 2011
@@ -0,0 +1,6 @@
+DROP VIEW xxx17;
+
+-- should fail:  partitioning key must be at end
+CREATE VIEW xxx17
+PARTITIONED ON (key)
+AS SELECT key,value FROM src;

Added: hive/trunk/ql/src/test/queries/clientnegative/create_view_failure9.q
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/queries/clientnegative/create_view_failure9.q?rev=1076105&view=auto
==============================================================================
--- hive/trunk/ql/src/test/queries/clientnegative/create_view_failure9.q (added)
+++ hive/trunk/ql/src/test/queries/clientnegative/create_view_failure9.q Wed Mar  2 05:05:55 2011
@@ -0,0 +1,6 @@
+DROP VIEW xxx18;
+
+-- should fail:  partitioning columns out of order
+CREATE VIEW xxx18
+PARTITIONED ON (value,key)
+AS SELECT key+1 as k2,key,value FROM src;

Added: hive/trunk/ql/src/test/queries/clientpositive/create_view_partitioned.q
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/queries/clientpositive/create_view_partitioned.q?rev=1076105&view=auto
==============================================================================
--- hive/trunk/ql/src/test/queries/clientpositive/create_view_partitioned.q (added)
+++ hive/trunk/ql/src/test/queries/clientpositive/create_view_partitioned.q Wed Mar  2 05:05:55 2011
@@ -0,0 +1,83 @@
+DROP VIEW vp1;
+DROP VIEW vp2;
+DROP VIEW vp3;
+
+-- test partitioned view definition
+-- (underlying table is not actually partitioned)
+CREATE VIEW vp1
+PARTITIONED ON (value)
+AS
+SELECT key, value
+FROM src
+WHERE key=86;
+DESCRIBE EXTENDED vp1;
+DESCRIBE FORMATTED vp1;
+
+SELECT * FROM vp1;
+
+SELECT key FROM vp1;
+
+SELECT value FROM vp1;
+
+ALTER VIEW vp1
+ADD PARTITION (value='val_86') PARTITION (value='val_xyz');
+
+-- should work since we use IF NOT EXISTS
+ALTER VIEW vp1
+ADD IF NOT EXISTS PARTITION (value='val_xyz');
+
+SHOW PARTITIONS vp1;
+
+SHOW PARTITIONS vp1 PARTITION(value='val_86');
+
+SHOW TABLE EXTENDED LIKE vp1;
+
+SHOW TABLE EXTENDED LIKE vp1 PARTITION(value='val_86');
+
+ALTER VIEW vp1
+DROP PARTITION (value='val_xyz');
+
+SET hive.exec.drop.ignorenonexistent=false;
+
+-- should work since we use IF EXISTS
+ALTER VIEW vp1
+DROP IF EXISTS PARTITION (value='val_xyz');
+
+SHOW PARTITIONS vp1;
+
+SET hive.mapred.mode=strict;
+
+-- Even though no partition predicate is specified in the next query,
+-- the WHERE clause inside of the view should satisfy strict mode.
+-- In other words, strict only applies to underlying tables
+-- (regardless of whether or not the view is partitioned).
+SELECT * FROM vp1;
+
+SET hive.mapred.mode=nonstrict;
+
+-- test a partitioned view on top of an underlying partitioned table,
+-- but with only a suffix of the partitioning columns
+CREATE VIEW vp2
+PARTITIONED ON (hr)
+AS SELECT * FROM srcpart WHERE key < 10;
+DESCRIBE FORMATTED vp2;
+
+ALTER VIEW vp2 ADD PARTITION (hr='11') PARTITION (hr='12');
+SELECT key FROM vp2 WHERE hr='12' ORDER BY key;
+
+-- test a partitioned view where the PARTITIONED ON clause references
+-- an imposed column name
+CREATE VIEW vp3(k,v)
+PARTITIONED ON (v)
+AS
+SELECT key, value
+FROM src
+WHERE key=86;
+DESCRIBE FORMATTED vp3;
+
+ALTER VIEW vp3
+ADD PARTITION (v='val_86');
+
+DROP VIEW vp1;
+DROP VIEW vp2;
+DROP VIEW vp3;

Modified: hive/trunk/ql/src/test/results/clientnegative/alter_view_failure.q.out
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/results/clientnegative/alter_view_failure.q.out?rev=1076105&r1=1076104&r2=1076105&view=diff
==============================================================================
--- hive/trunk/ql/src/test/results/clientnegative/alter_view_failure.q.out (original)
+++ hive/trunk/ql/src/test/results/clientnegative/alter_view_failure.q.out Wed Mar  2 05:05:55 2011
@@ -4,14 +4,14 @@ POSTHOOK: query: DROP VIEW xxx3
 POSTHOOK: type: DROPVIEW
 PREHOOK: query: CREATE VIEW xxx3 AS SELECT * FROM src
 PREHOOK: type: CREATEVIEW
-PREHOOK: Output: file:/tmp/njain/hive_2010-08-16_23-08-10_293_51772665808484032/-mr-10000
+PREHOOK: Output: file:/var/folders/7P/7PeC14kXFIWq0PIYyexGbmKuXUk/-Tmp-/jsichi/hive_2011-02-03_16-14-26_185_7721791068067207339/-mr-10000
 POSTHOOK: query: CREATE VIEW xxx3 AS SELECT * FROM src
 POSTHOOK: type: CREATEVIEW
-POSTHOOK: Output: file:/tmp/njain/hive_2010-08-16_23-08-10_293_51772665808484032/-mr-10000
 POSTHOOK: Output: default@xxx3
+POSTHOOK: Output: file:/var/folders/7P/7PeC14kXFIWq0PIYyexGbmKuXUk/-Tmp-/jsichi/hive_2011-02-03_16-14-26_185_7721791068067207339/-mr-10000
 PREHOOK: query: ALTER TABLE xxx3 REPLACE COLUMNS (xyz int)
 PREHOOK: type: ALTERTABLE_REPLACECOLS
 PREHOOK: Input: default@xxx3
 PREHOOK: Output: default@xxx3
-FAILED: Error in metadata: Cannot use this form of ALTER TABLE on a view
+FAILED: Error in metadata: Cannot alter a view with ALTER TABLE
 FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask

Added: hive/trunk/ql/src/test/results/clientnegative/alter_view_failure2.q.out
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/results/clientnegative/alter_view_failure2.q.out?rev=1076105&view=auto
==============================================================================
--- hive/trunk/ql/src/test/results/clientnegative/alter_view_failure2.q.out (added)
+++ hive/trunk/ql/src/test/results/clientnegative/alter_view_failure2.q.out Wed Mar  2 05:05:55 2011
@@ -0,0 +1,24 @@
+PREHOOK: query: DROP VIEW xxx4
+PREHOOK: type: DROPVIEW
+POSTHOOK: query: DROP VIEW xxx4
+POSTHOOK: type: DROPVIEW
+PREHOOK: query: CREATE VIEW xxx4 
+PARTITIONED ON (value)
+AS 
+SELECT * FROM src
+PREHOOK: type: CREATEVIEW
+PREHOOK: Output: file:/var/folders/7P/7PeC14kXFIWq0PIYyexGbmKuXUk/-Tmp-/jsichi/hive_2011-02-10_12-58-02_930_3490345072474460874/-mr-10000
+POSTHOOK: query: CREATE VIEW xxx4 
+PARTITIONED ON (value)
+AS 
+SELECT * FROM src
+POSTHOOK: type: CREATEVIEW
+POSTHOOK: Output: default@xxx4
+POSTHOOK: Output: file:/var/folders/7P/7PeC14kXFIWq0PIYyexGbmKuXUk/-Tmp-/jsichi/hive_2011-02-10_12-58-02_930_3490345072474460874/-mr-10000
+PREHOOK: query: -- should fail:  need to use ALTER VIEW, not ALTER TABLE
+ALTER TABLE xxx4 ADD PARTITION (value='val_86')
+PREHOOK: type: QUERY
+PREHOOK: Input: default@src
+PREHOOK: Input: default@xxx4
+FAILED: Error in metadata: Cannot alter a view with ALTER TABLE
+FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask

Added: hive/trunk/ql/src/test/results/clientnegative/alter_view_failure3.q.out
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/results/clientnegative/alter_view_failure3.q.out?rev=1076105&view=auto
==============================================================================
--- hive/trunk/ql/src/test/results/clientnegative/alter_view_failure3.q.out (added)
+++ hive/trunk/ql/src/test/results/clientnegative/alter_view_failure3.q.out Wed Mar  2 05:05:55 2011
@@ -0,0 +1,6 @@
+PREHOOK: query: -- should fail:  can't use ALTER VIEW on a table
+ALTER VIEW srcpart ADD PARTITION (ds='2012-12-31', hr='23')
+PREHOOK: type: ALTERTABLE_ADDPARTS
+PREHOOK: Input: default@srcpart
+FAILED: Error in metadata: Cannot alter a base table with ALTER VIEW
+FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask

Added: hive/trunk/ql/src/test/results/clientnegative/alter_view_failure4.q.out
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/results/clientnegative/alter_view_failure4.q.out?rev=1076105&view=auto
==============================================================================
--- hive/trunk/ql/src/test/results/clientnegative/alter_view_failure4.q.out (added)
+++ hive/trunk/ql/src/test/results/clientnegative/alter_view_failure4.q.out Wed Mar  2 05:05:55 2011
@@ -0,0 +1,24 @@
+PREHOOK: query: DROP VIEW xxx5
+PREHOOK: type: DROPVIEW
+POSTHOOK: query: DROP VIEW xxx5
+POSTHOOK: type: DROPVIEW
+PREHOOK: query: CREATE VIEW xxx5
+PARTITIONED ON (value)
+AS 
+SELECT * FROM src
+PREHOOK: type: CREATEVIEW
+PREHOOK: Output: file:/var/folders/7P/7PeC14kXFIWq0PIYyexGbmKuXUk/-Tmp-/jsichi/hive_2011-02-10_12-59-39_789_5581361064099423922/-mr-10000
+POSTHOOK: query: CREATE VIEW xxx5
+PARTITIONED ON (value)
+AS 
+SELECT * FROM src
+POSTHOOK: type: CREATEVIEW
+POSTHOOK: Output: default@xxx5
+POSTHOOK: Output: file:/var/folders/7P/7PeC14kXFIWq0PIYyexGbmKuXUk/-Tmp-/jsichi/hive_2011-02-10_12-59-39_789_5581361064099423922/-mr-10000
+PREHOOK: query: -- should fail:  LOCATION clause is illegal
+ALTER VIEW xxx5 ADD PARTITION (value='val_86') LOCATION '/foo/bar/baz'
+PREHOOK: type: QUERY
+PREHOOK: Input: default@src
+PREHOOK: Input: default@xxx5
+FAILED: Error in metadata: LOCATION clause illegal for view partition
+FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask

Added: hive/trunk/ql/src/test/results/clientnegative/alter_view_failure5.q.out
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/results/clientnegative/alter_view_failure5.q.out?rev=1076105&view=auto
==============================================================================
--- hive/trunk/ql/src/test/results/clientnegative/alter_view_failure5.q.out (added)
+++ hive/trunk/ql/src/test/results/clientnegative/alter_view_failure5.q.out Wed Mar  2 05:05:55 2011
@@ -0,0 +1,18 @@
+PREHOOK: query: DROP VIEW xxx6
+PREHOOK: type: DROPVIEW
+POSTHOOK: query: DROP VIEW xxx6
+POSTHOOK: type: DROPVIEW
+PREHOOK: query: CREATE VIEW xxx6
+PARTITIONED ON (value)
+AS 
+SELECT * FROM src
+PREHOOK: type: CREATEVIEW
+PREHOOK: Output: file:/var/folders/7P/7PeC14kXFIWq0PIYyexGbmKuXUk/-Tmp-/jsichi/hive_2011-02-10_16-32-17_470_5386519951595960232/-mr-10000
+POSTHOOK: query: CREATE VIEW xxx6
+PARTITIONED ON (value)
+AS 
+SELECT * FROM src
+POSTHOOK: type: CREATEVIEW
+POSTHOOK: Output: default@xxx6
+POSTHOOK: Output: file:/var/folders/7P/7PeC14kXFIWq0PIYyexGbmKuXUk/-Tmp-/jsichi/hive_2011-02-10_16-32-17_470_5386519951595960232/-mr-10000
+FAILED: Error in semantic analysis: value not found in table's partition spec: {v=val_86}

Added: hive/trunk/ql/src/test/results/clientnegative/alter_view_failure6.q.out
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/results/clientnegative/alter_view_failure6.q.out?rev=1076105&view=auto
==============================================================================
--- hive/trunk/ql/src/test/results/clientnegative/alter_view_failure6.q.out (added)
+++ hive/trunk/ql/src/test/results/clientnegative/alter_view_failure6.q.out Wed Mar  2 05:05:55 2011
@@ -0,0 +1,19 @@
+PREHOOK: query: DROP VIEW xxx7
+PREHOOK: type: DROPVIEW
+POSTHOOK: query: DROP VIEW xxx7
+POSTHOOK: type: DROPVIEW
+PREHOOK: query: CREATE VIEW xxx7
+PARTITIONED ON (key)
+AS 
+SELECT hr,key FROM srcpart
+PREHOOK: type: CREATEVIEW
+PREHOOK: Output: file:/var/folders/7P/7PeC14kXFIWq0PIYyexGbmKuXUk/-Tmp-/jsichi/hive_2011-02-08_18-38-11_186_2914437704768475613/-mr-10000
+POSTHOOK: query: CREATE VIEW xxx7
+PARTITIONED ON (key)
+AS 
+SELECT hr,key FROM srcpart
+POSTHOOK: type: CREATEVIEW
+POSTHOOK: Output: default@xxx7
+POSTHOOK: Output: file:/var/folders/7P/7PeC14kXFIWq0PIYyexGbmKuXUk/-Tmp-/jsichi/hive_2011-02-08_18-38-11_186_2914437704768475613/-mr-10000
+FAILED: Error in semantic analysis: No Partition Predicate Found for Alias "xxx7:srcpart" Table "srcpart"
+FAILED: Error in semantic analysis: The query does not reference any valid partition. To run this query, set hive.mapred.mode=nonstrict

Added: hive/trunk/ql/src/test/results/clientnegative/alter_view_failure7.q.out
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/results/clientnegative/alter_view_failure7.q.out?rev=1076105&view=auto
==============================================================================
--- hive/trunk/ql/src/test/results/clientnegative/alter_view_failure7.q.out (added)
+++ hive/trunk/ql/src/test/results/clientnegative/alter_view_failure7.q.out Wed Mar  2 05:05:55 2011
@@ -0,0 +1,18 @@
+PREHOOK: query: DROP VIEW xxx8
+PREHOOK: type: DROPVIEW
+POSTHOOK: query: DROP VIEW xxx8
+POSTHOOK: type: DROPVIEW
+PREHOOK: query: CREATE VIEW xxx8
+PARTITIONED ON (ds,hr)
+AS 
+SELECT key,ds,hr FROM srcpart
+PREHOOK: type: CREATEVIEW
+PREHOOK: Output: file:/var/folders/7P/7PeC14kXFIWq0PIYyexGbmKuXUk/-Tmp-/jsichi/hive_2011-02-10_17-23-35_264_1200860254018763/-mr-10000
+POSTHOOK: query: CREATE VIEW xxx8
+PARTITIONED ON (ds,hr)
+AS 
+SELECT key,ds,hr FROM srcpart
+POSTHOOK: type: CREATEVIEW
+POSTHOOK: Output: default@xxx8
+POSTHOOK: Output: file:/var/folders/7P/7PeC14kXFIWq0PIYyexGbmKuXUk/-Tmp-/jsichi/hive_2011-02-10_17-23-35_264_1200860254018763/-mr-10000
+FAILED: Error in semantic analysis: table is partitioned but partition spec is not specified or does not fully match table partitioning: {ds=2011-01-01}

Added: hive/trunk/ql/src/test/results/clientnegative/analyze_view.q.out
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/results/clientnegative/analyze_view.q.out?rev=1076105&view=auto
==============================================================================
--- hive/trunk/ql/src/test/results/clientnegative/analyze_view.q.out (added)
+++ hive/trunk/ql/src/test/results/clientnegative/analyze_view.q.out Wed Mar  2 05:05:55 2011
@@ -0,0 +1,12 @@
+PREHOOK: query: DROP VIEW av
+PREHOOK: type: DROPVIEW
+POSTHOOK: query: DROP VIEW av
+POSTHOOK: type: DROPVIEW
+PREHOOK: query: CREATE VIEW av AS SELECT * FROM src
+PREHOOK: type: CREATEVIEW
+PREHOOK: Output: file:/var/folders/7P/7PeC14kXFIWq0PIYyexGbmKuXUk/-Tmp-/jsichi/hive_2011-02-01_17-50-22_779_44083551773069928/-mr-10000
+POSTHOOK: query: CREATE VIEW av AS SELECT * FROM src
+POSTHOOK: type: CREATEVIEW
+POSTHOOK: Output: default@av
+POSTHOOK: Output: file:/var/folders/7P/7PeC14kXFIWq0PIYyexGbmKuXUk/-Tmp-/jsichi/hive_2011-02-01_17-50-22_779_44083551773069928/-mr-10000
+FAILED: Error in semantic analysis: ANALYZE is not supported for views

Added: hive/trunk/ql/src/test/results/clientnegative/create_view_failure6.q.out
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/results/clientnegative/create_view_failure6.q.out?rev=1076105&view=auto
==============================================================================
--- hive/trunk/ql/src/test/results/clientnegative/create_view_failure6.q.out (added)
+++ hive/trunk/ql/src/test/results/clientnegative/create_view_failure6.q.out Wed Mar  2 05:05:55 2011
@@ -0,0 +1,5 @@
+PREHOOK: query: DROP VIEW xxx15
+PREHOOK: type: DROPVIEW
+POSTHOOK: query: DROP VIEW xxx15
+POSTHOOK: type: DROPVIEW
+FAILED: Error in semantic analysis: Rightmost columns in view output do not match PARTITIONED ON clause

Added: hive/trunk/ql/src/test/results/clientnegative/create_view_failure7.q.out
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/results/clientnegative/create_view_failure7.q.out?rev=1076105&view=auto
==============================================================================
--- hive/trunk/ql/src/test/results/clientnegative/create_view_failure7.q.out (added)
+++ hive/trunk/ql/src/test/results/clientnegative/create_view_failure7.q.out Wed Mar  2 05:05:55 2011
@@ -0,0 +1,5 @@
+PREHOOK: query: DROP VIEW xxx16
+PREHOOK: type: DROPVIEW
+POSTHOOK: query: DROP VIEW xxx16
+POSTHOOK: type: DROPVIEW
+FAILED: Error in semantic analysis: At least one non-partitioning column must be present in view

Added: hive/trunk/ql/src/test/results/clientnegative/create_view_failure8.q.out
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/results/clientnegative/create_view_failure8.q.out?rev=1076105&view=auto
==============================================================================
--- hive/trunk/ql/src/test/results/clientnegative/create_view_failure8.q.out (added)
+++ hive/trunk/ql/src/test/results/clientnegative/create_view_failure8.q.out Wed Mar  2 05:05:55 2011
@@ -0,0 +1,5 @@
+PREHOOK: query: DROP VIEW xxx17
+PREHOOK: type: DROPVIEW
+POSTHOOK: query: DROP VIEW xxx17
+POSTHOOK: type: DROPVIEW
+FAILED: Error in semantic analysis: Rightmost columns in view output do not match PARTITIONED ON clause

Added: hive/trunk/ql/src/test/results/clientnegative/create_view_failure9.q.out
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/results/clientnegative/create_view_failure9.q.out?rev=1076105&view=auto
==============================================================================
--- hive/trunk/ql/src/test/results/clientnegative/create_view_failure9.q.out (added)
+++ hive/trunk/ql/src/test/results/clientnegative/create_view_failure9.q.out Wed Mar  2 05:05:55 2011
@@ -0,0 +1,5 @@
+PREHOOK: query: DROP VIEW xxx18
+PREHOOK: type: DROPVIEW
+POSTHOOK: query: DROP VIEW xxx18
+POSTHOOK: type: DROPVIEW
+FAILED: Error in semantic analysis: Rightmost columns in view output do not match PARTITIONED ON clause

Added: hive/trunk/ql/src/test/results/clientpositive/create_view_partitioned.q.out
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/results/clientpositive/create_view_partitioned.q.out?rev=1076105&view=auto
==============================================================================
--- hive/trunk/ql/src/test/results/clientpositive/create_view_partitioned.q.out (added)
+++ hive/trunk/ql/src/test/results/clientpositive/create_view_partitioned.q.out Wed Mar  2 05:05:55 2011
@@ -0,0 +1,412 @@
+PREHOOK: query: DROP VIEW vp1
+PREHOOK: type: DROPVIEW
+POSTHOOK: query: DROP VIEW vp1
+POSTHOOK: type: DROPVIEW
+PREHOOK: query: DROP VIEW vp2
+PREHOOK: type: DROPVIEW
+POSTHOOK: query: DROP VIEW vp2
+POSTHOOK: type: DROPVIEW
+PREHOOK: query: DROP VIEW vp3
+PREHOOK: type: DROPVIEW
+POSTHOOK: query: DROP VIEW vp3
+POSTHOOK: type: DROPVIEW
+PREHOOK: query: -- test partitioned view definition
+-- (underlying table is not actually partitioned)
+CREATE VIEW vp1
+PARTITIONED ON (value)
+AS
+SELECT key, value
+FROM src
+WHERE key=86
+PREHOOK: type: CREATEVIEW
+PREHOOK: Output: file:/var/folders/7P/7PeC14kXFIWq0PIYyexGbmKuXUk/-Tmp-/jsichi/hive_2011-02-09_12-39-20_202_459725770522554343/-mr-10000
+POSTHOOK: query: -- test partitioned view definition
+-- (underlying table is not actually partitioned)
+CREATE VIEW vp1
+PARTITIONED ON (value)
+AS
+SELECT key, value
+FROM src
+WHERE key=86
+POSTHOOK: type: CREATEVIEW
+POSTHOOK: Output: default@vp1
+POSTHOOK: Output: file:/var/folders/7P/7PeC14kXFIWq0PIYyexGbmKuXUk/-Tmp-/jsichi/hive_2011-02-09_12-39-20_202_459725770522554343/-mr-10000
+PREHOOK: query: DESCRIBE EXTENDED vp1
+PREHOOK: type: DESCTABLE
+POSTHOOK: query: DESCRIBE EXTENDED vp1
+POSTHOOK: type: DESCTABLE
+key	string	
+value	string	
+	 	 
+Detailed Table Information	Table(tableName:vp1, dbName:default, owner:jsichi, createTime:1297283960, lastAccessTime:0, retention:0, sd:StorageDescriptor(cols:[FieldSchema(name:key, type:string, comment:null), FieldSchema(name:value, type:string, comment:null)], location:null, inputFormat:org.apache.hadoop.mapred.SequenceFileInputFormat, outputFormat:org.apache.hadoop.hive.ql.io.HiveSequenceFileOutputFormat, compressed:false, numBuckets:-1, serdeInfo:SerDeInfo(name:null, serializationLib:null, parameters:{}), bucketCols:[], sortCols:[], parameters:{}), partitionKeys:[FieldSchema(name:value, type:string, comment:null)], parameters:{transient_lastDdlTime=1297283960}, viewOriginalText:SELECT key, value	 
+FROM src	 	 
+WHERE key=86, viewExpandedText:SELECT `src`.`key`, `src`.`value`	 	 
+FROM `src`	 	 
+WHERE `src`.`key`=86, tableType:VIRTUAL_VIEW)		 
+PREHOOK: query: DESCRIBE FORMATTED vp1
+PREHOOK: type: DESCTABLE
+POSTHOOK: query: DESCRIBE FORMATTED vp1
+POSTHOOK: type: DESCTABLE
+# col_name            	data_type           	comment             
+	 	 
+key                 	string              	None                
+	 	 
+# Partition Information	 	 
+# col_name            	data_type           	comment             
+	 	 
+value               	string              	None                
+	 	 
+# Detailed Table Information	 	 
+Database:           	default             	 
+Owner:              	jsichi              	 
+CreateTime:         	Wed Feb 09 12:39:20 PST 2011	 
+LastAccessTime:     	UNKNOWN             	 
+Protect Mode:       	None                	 
+Retention:          	0                   	 
+Table Type:         	VIRTUAL_VIEW        	 
+Table Parameters:	 	 
+	transient_lastDdlTime	1297283960          
+	 	 
+# Storage Information	 	 
+SerDe Library:      	null                	 
+InputFormat:        	org.apache.hadoop.mapred.SequenceFileInputFormat	 
+OutputFormat:       	org.apache.hadoop.hive.ql.io.HiveSequenceFileOutputFormat	 
+Compressed:         	No                  	 
+Num Buckets:        	-1                  	 
+Bucket Columns:     	[]                  	 
+Sort Columns:       	[]                  	 
+	 	 
+# View Information	 	 
+View Original Text: 	SELECT key, value	 
+FROM src	 	 
+WHERE key=86	 	 
+View Expanded Text: 	SELECT `src`.`key`, `src`.`value`	 
+FROM `src`	 	 
+WHERE `src`.`key`=86	 	 
+PREHOOK: query: SELECT * FROM vp1
+PREHOOK: type: QUERY
+PREHOOK: Input: default@src
+PREHOOK: Output: file:/var/folders/7P/7PeC14kXFIWq0PIYyexGbmKuXUk/-Tmp-/jsichi/hive_2011-02-09_12-39-20_956_4791033359314261882/-mr-10000
+POSTHOOK: query: SELECT * FROM vp1
+POSTHOOK: type: QUERY
+POSTHOOK: Input: default@src
+POSTHOOK: Output: file:/var/folders/7P/7PeC14kXFIWq0PIYyexGbmKuXUk/-Tmp-/jsichi/hive_2011-02-09_12-39-20_956_4791033359314261882/-mr-10000
+86	val_86
+PREHOOK: query: SELECT key FROM vp1
+PREHOOK: type: QUERY
+PREHOOK: Input: default@src
+PREHOOK: Output: file:/var/folders/7P/7PeC14kXFIWq0PIYyexGbmKuXUk/-Tmp-/jsichi/hive_2011-02-09_12-39-28_000_2791859544795907188/-mr-10000
+POSTHOOK: query: SELECT key FROM vp1
+POSTHOOK: type: QUERY
+POSTHOOK: Input: default@src
+POSTHOOK: Output: file:/var/folders/7P/7PeC14kXFIWq0PIYyexGbmKuXUk/-Tmp-/jsichi/hive_2011-02-09_12-39-28_000_2791859544795907188/-mr-10000
+86
+PREHOOK: query: SELECT value FROM vp1
+PREHOOK: type: QUERY
+PREHOOK: Input: default@src
+PREHOOK: Output: file:/var/folders/7P/7PeC14kXFIWq0PIYyexGbmKuXUk/-Tmp-/jsichi/hive_2011-02-09_12-39-34_032_4697733201868315411/-mr-10000
+POSTHOOK: query: SELECT value FROM vp1
+POSTHOOK: type: QUERY
+POSTHOOK: Input: default@src
+POSTHOOK: Output: file:/var/folders/7P/7PeC14kXFIWq0PIYyexGbmKuXUk/-Tmp-/jsichi/hive_2011-02-09_12-39-34_032_4697733201868315411/-mr-10000
+val_86
+PREHOOK: query: ALTER VIEW vp1
+ADD PARTITION (value='val_86') PARTITION (value='val_xyz')
+PREHOOK: type: QUERY
+PREHOOK: Input: default@src
+PREHOOK: Input: default@vp1
+POSTHOOK: query: ALTER VIEW vp1
+ADD PARTITION (value='val_86') PARTITION (value='val_xyz')
+POSTHOOK: type: QUERY
+POSTHOOK: Input: default@src
+POSTHOOK: Input: default@vp1
+POSTHOOK: Output: default@vp1@value=val_86
+POSTHOOK: Output: default@vp1@value=val_xyz
+PREHOOK: query: -- should work since we use IF NOT EXISTS
+ALTER VIEW vp1
+ADD IF NOT EXISTS PARTITION (value='val_xyz')
+PREHOOK: type: QUERY
+PREHOOK: Input: default@src
+PREHOOK: Input: default@vp1
+PREHOOK: Output: default@vp1@value=val_xyz
+POSTHOOK: query: -- should work since we use IF NOT EXISTS
+ALTER VIEW vp1
+ADD IF NOT EXISTS PARTITION (value='val_xyz')
+POSTHOOK: type: QUERY
+POSTHOOK: Input: default@src
+POSTHOOK: Input: default@vp1
+POSTHOOK: Output: default@vp1@value=val_xyz
+PREHOOK: query: SHOW PARTITIONS vp1
+PREHOOK: type: SHOWPARTITIONS
+POSTHOOK: query: SHOW PARTITIONS vp1
+POSTHOOK: type: SHOWPARTITIONS
+value=val_86
+value=val_xyz
+PREHOOK: query: SHOW PARTITIONS vp1 PARTITION(value='val_86')
+PREHOOK: type: SHOWPARTITIONS
+POSTHOOK: query: SHOW PARTITIONS vp1 PARTITION(value='val_86')
+POSTHOOK: type: SHOWPARTITIONS
+value=val_86
+PREHOOK: query: SHOW TABLE EXTENDED LIKE vp1
+PREHOOK: type: SHOW_TABLESTATUS
+POSTHOOK: query: SHOW TABLE EXTENDED LIKE vp1
+POSTHOOK: type: SHOW_TABLESTATUS
+tableName:vp1
+owner:jsichi
+location:null
+inputformat:org.apache.hadoop.mapred.SequenceFileInputFormat
+outputformat:org.apache.hadoop.hive.ql.io.HiveSequenceFileOutputFormat
+columns:struct columns { string key}
+partitioned:true
+partitionColumns:struct partition_columns { string value}
+
+PREHOOK: query: SHOW TABLE EXTENDED LIKE vp1 PARTITION(value='val_86')
+PREHOOK: type: SHOW_TABLESTATUS
+POSTHOOK: query: SHOW TABLE EXTENDED LIKE vp1 PARTITION(value='val_86')
+POSTHOOK: type: SHOW_TABLESTATUS
+tableName:vp1
+owner:jsichi
+location:null
+inputformat:org.apache.hadoop.mapred.SequenceFileInputFormat
+outputformat:org.apache.hadoop.hive.ql.io.HiveSequenceFileOutputFormat
+columns:struct columns { string key}
+partitioned:true
+partitionColumns:struct partition_columns { string value}
+
+PREHOOK: query: ALTER VIEW vp1
+DROP PARTITION (value='val_xyz')
+PREHOOK: type: ALTERTABLE_DROPPARTS
+PREHOOK: Input: default@vp1
+PREHOOK: Output: default@vp1@value=val_xyz
+POSTHOOK: query: ALTER VIEW vp1
+DROP PARTITION (value='val_xyz')
+POSTHOOK: type: ALTERTABLE_DROPPARTS
+POSTHOOK: Input: default@vp1
+POSTHOOK: Output: default@vp1@value=val_xyz
+PREHOOK: query: -- should work since we use IF EXISTS
+ALTER VIEW vp1
+DROP IF EXISTS PARTITION (value='val_xyz')
+PREHOOK: type: ALTERTABLE_DROPPARTS
+PREHOOK: Input: default@vp1
+POSTHOOK: query: -- should work since we use IF EXISTS
+ALTER VIEW vp1
+DROP IF EXISTS PARTITION (value='val_xyz')
+POSTHOOK: type: ALTERTABLE_DROPPARTS
+POSTHOOK: Input: default@vp1
+PREHOOK: query: SHOW PARTITIONS vp1
+PREHOOK: type: SHOWPARTITIONS
+POSTHOOK: query: SHOW PARTITIONS vp1
+POSTHOOK: type: SHOWPARTITIONS
+value=val_86
+PREHOOK: query: -- Even though no partition predicate is specified in the next query,
+-- the WHERE clause inside of the view should satisfy strict mode.
+-- In other words, strict only applies to underlying tables
+-- (regardless of whether or not the view is partitioned).
+SELECT * FROM vp1
+PREHOOK: type: QUERY
+PREHOOK: Input: default@src
+PREHOOK: Output: file:/var/folders/7P/7PeC14kXFIWq0PIYyexGbmKuXUk/-Tmp-/jsichi/hive_2011-02-09_12-39-41_066_3753395059950041338/-mr-10000
+POSTHOOK: query: -- Even though no partition predicate is specified in the next query,
+-- the WHERE clause inside of the view should satisfy strict mode.
+-- In other words, strict only applies to underlying tables
+-- (regardless of whether or not the view is partitioned).
+SELECT * FROM vp1
+POSTHOOK: type: QUERY
+POSTHOOK: Input: default@src
+POSTHOOK: Output: file:/var/folders/7P/7PeC14kXFIWq0PIYyexGbmKuXUk/-Tmp-/jsichi/hive_2011-02-09_12-39-41_066_3753395059950041338/-mr-10000
+86	val_86
+PREHOOK: query: -- test a partitioned view on top of an underlying partitioned table,
+-- but with only a suffix of the partitioning columns
+CREATE VIEW vp2
+PARTITIONED ON (hr)
+AS SELECT * FROM srcpart WHERE key < 10
+PREHOOK: type: CREATEVIEW
+PREHOOK: Output: file:/var/folders/7P/7PeC14kXFIWq0PIYyexGbmKuXUk/-Tmp-/jsichi/hive_2011-02-09_12-39-46_912_6988747758977470257/-mr-10000
+POSTHOOK: query: -- test a partitioned view on top of an underlying partitioned table,
+-- but with only a suffix of the partitioning columns
+CREATE VIEW vp2
+PARTITIONED ON (hr)
+AS SELECT * FROM srcpart WHERE key < 10
+POSTHOOK: type: CREATEVIEW
+POSTHOOK: Output: default@vp2
+POSTHOOK: Output: file:/var/folders/7P/7PeC14kXFIWq0PIYyexGbmKuXUk/-Tmp-/jsichi/hive_2011-02-09_12-39-46_912_6988747758977470257/-mr-10000
+PREHOOK: query: DESCRIBE FORMATTED vp2
+PREHOOK: type: DESCTABLE
+POSTHOOK: query: DESCRIBE FORMATTED vp2
+POSTHOOK: type: DESCTABLE
+# col_name            	data_type           	comment             
+	 	 
+key                 	string              	None                
+value               	string              	None                
+ds                  	string              	None                
+	 	 
+# Partition Information	 	 
+# col_name            	data_type           	comment             
+	 	 
+hr                  	string              	None                
+	 	 
+# Detailed Table Information	 	 
+Database:           	default             	 
+Owner:              	jsichi              	 
+CreateTime:         	Wed Feb 09 12:39:46 PST 2011	 
+LastAccessTime:     	UNKNOWN             	 
+Protect Mode:       	None                	 
+Retention:          	0                   	 
+Table Type:         	VIRTUAL_VIEW        	 
+Table Parameters:	 	 
+	transient_lastDdlTime	1297283986          
+	 	 
+# Storage Information	 	 
+SerDe Library:      	null                	 
+InputFormat:        	org.apache.hadoop.mapred.SequenceFileInputFormat	 
+OutputFormat:       	org.apache.hadoop.hive.ql.io.HiveSequenceFileOutputFormat	 
+Compressed:         	No                  	 
+Num Buckets:        	-1                  	 
+Bucket Columns:     	[]                  	 
+Sort Columns:       	[]                  	 
+	 	 
+# View Information	 	 
+View Original Text: 	SELECT * FROM srcpart WHERE key < 10	 
+View Expanded Text: 	SELECT `srcpart`.`key`, `srcpart`.`value`, `srcpart`.`ds`, `srcpart`.`hr` FROM `srcpart` WHERE `srcpart`.`key` < 10	 
+PREHOOK: query: ALTER VIEW vp2 ADD PARTITION (hr='11') PARTITION (hr='12')
+PREHOOK: type: QUERY
+PREHOOK: Input: default@srcpart@ds=2008-04-08/hr=11
+PREHOOK: Input: default@srcpart@ds=2008-04-08/hr=12
+PREHOOK: Input: default@srcpart@ds=2008-04-09/hr=11
+PREHOOK: Input: default@srcpart@ds=2008-04-09/hr=12
+PREHOOK: Input: default@vp2
+POSTHOOK: query: ALTER VIEW vp2 ADD PARTITION (hr='11') PARTITION (hr='12')
+POSTHOOK: type: QUERY
+POSTHOOK: Input: default@srcpart@ds=2008-04-08/hr=11
+POSTHOOK: Input: default@srcpart@ds=2008-04-08/hr=12
+POSTHOOK: Input: default@srcpart@ds=2008-04-09/hr=11
+POSTHOOK: Input: default@srcpart@ds=2008-04-09/hr=12
+POSTHOOK: Input: default@vp2
+POSTHOOK: Output: default@vp2@hr=11
+POSTHOOK: Output: default@vp2@hr=12
+PREHOOK: query: SELECT key FROM vp2 WHERE hr='12' ORDER BY key
+PREHOOK: type: QUERY
+PREHOOK: Input: default@srcpart@ds=2008-04-08/hr=12
+PREHOOK: Input: default@srcpart@ds=2008-04-09/hr=12
+PREHOOK: Output: file:/var/folders/7P/7PeC14kXFIWq0PIYyexGbmKuXUk/-Tmp-/jsichi/hive_2011-02-09_12-39-47_562_328778258675461955/-mr-10000
+POSTHOOK: query: SELECT key FROM vp2 WHERE hr='12' ORDER BY key
+POSTHOOK: type: QUERY
+POSTHOOK: Input: default@srcpart@ds=2008-04-08/hr=12
+POSTHOOK: Input: default@srcpart@ds=2008-04-09/hr=12
+POSTHOOK: Output: file:/var/folders/7P/7PeC14kXFIWq0PIYyexGbmKuXUk/-Tmp-/jsichi/hive_2011-02-09_12-39-47_562_328778258675461955/-mr-10000
+0
+0
+0
+0
+0
+0
+2
+2
+4
+4
+5
+5
+5
+5
+5
+5
+8
+8
+9
+9
+PREHOOK: query: -- test a partitioned view where the PARTITIONED ON clause references
+-- an imposed column name
+CREATE VIEW vp3(k,v)
+PARTITIONED ON (v)
+AS
+SELECT key, value
+FROM src
+WHERE key=86
+PREHOOK: type: CREATEVIEW
+PREHOOK: Output: file:/var/folders/7P/7PeC14kXFIWq0PIYyexGbmKuXUk/-Tmp-/jsichi/hive_2011-02-09_12-39-55_502_5144513026720493384/-mr-10000
+POSTHOOK: query: -- test a partitioned view where the PARTITIONED ON clause references
+-- an imposed column name
+CREATE VIEW vp3(k,v)
+PARTITIONED ON (v)
+AS
+SELECT key, value
+FROM src
+WHERE key=86
+POSTHOOK: type: CREATEVIEW
+POSTHOOK: Output: default@vp3
+POSTHOOK: Output: file:/var/folders/7P/7PeC14kXFIWq0PIYyexGbmKuXUk/-Tmp-/jsichi/hive_2011-02-09_12-39-55_502_5144513026720493384/-mr-10000
+PREHOOK: query: DESCRIBE FORMATTED vp3
+PREHOOK: type: DESCTABLE
+POSTHOOK: query: DESCRIBE FORMATTED vp3
+POSTHOOK: type: DESCTABLE
+# col_name            	data_type           	comment             
+	 	 
+k                   	string              	None                
+	 	 
+# Partition Information	 	 
+# col_name            	data_type           	comment             
+	 	 
+v                   	string              	None                
+	 	 
+# Detailed Table Information	 	 
+Database:           	default             	 
+Owner:              	jsichi              	 
+CreateTime:         	Wed Feb 09 12:39:55 PST 2011	 
+LastAccessTime:     	UNKNOWN             	 
+Protect Mode:       	None                	 
+Retention:          	0                   	 
+Table Type:         	VIRTUAL_VIEW        	 
+Table Parameters:	 	 
+	transient_lastDdlTime	1297283995          
+	 	 
+# Storage Information	 	 
+SerDe Library:      	null                	 
+InputFormat:        	org.apache.hadoop.mapred.SequenceFileInputFormat	 
+OutputFormat:       	org.apache.hadoop.hive.ql.io.HiveSequenceFileOutputFormat	 
+Compressed:         	No                  	 
+Num Buckets:        	-1                  	 
+Bucket Columns:     	[]                  	 
+Sort Columns:       	[]                  	 
+	 	 
+# View Information	 	 
+View Original Text: 	SELECT key, value	 
+FROM src	 	 
+WHERE key=86	 	 
+View Expanded Text: 	SELECT `key` AS `k`, `value` AS `v` FROM (SELECT `src`.`key`, `src`.`value`	 
+FROM `src`	 	 
+WHERE `src`.`key`=86) `vp3`	 	 
+PREHOOK: query: ALTER VIEW vp3
+ADD PARTITION (v='val_86')
+PREHOOK: type: QUERY
+PREHOOK: Input: default@src
+PREHOOK: Input: default@vp3
+POSTHOOK: query: ALTER VIEW vp3
+ADD PARTITION (v='val_86')
+POSTHOOK: type: QUERY
+POSTHOOK: Input: default@src
+POSTHOOK: Input: default@vp3
+POSTHOOK: Output: default@vp3@v=val_86
+PREHOOK: query: DROP VIEW vp1
+PREHOOK: type: DROPVIEW
+PREHOOK: Input: default@vp1
+PREHOOK: Output: default@vp1
+POSTHOOK: query: DROP VIEW vp1
+POSTHOOK: type: DROPVIEW
+POSTHOOK: Input: default@vp1
+POSTHOOK: Output: default@vp1
+PREHOOK: query: DROP VIEW vp2
+PREHOOK: type: DROPVIEW
+PREHOOK: Input: default@vp2
+PREHOOK: Output: default@vp2
+POSTHOOK: query: DROP VIEW vp2
+POSTHOOK: type: DROPVIEW
+POSTHOOK: Input: default@vp2
+POSTHOOK: Output: default@vp2
+PREHOOK: query: DROP VIEW vp3
+PREHOOK: type: DROPVIEW
+PREHOOK: Input: default@vp3
+PREHOOK: Output: default@vp3
+POSTHOOK: query: DROP VIEW vp3
+POSTHOOK: type: DROPVIEW
+POSTHOOK: Input: default@vp3
+POSTHOOK: Output: default@vp3



Mime
View raw message