hadoop-hive-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From na...@apache.org
Subject svn commit: r820771 [1/3] - in /hadoop/hive/trunk: ./ ql/src/java/org/apache/hadoop/hive/ql/exec/ ql/src/java/org/apache/hadoop/hive/ql/parse/ ql/src/java/org/apache/hadoop/hive/ql/plan/ ql/src/test/queries/clientnegative/ ql/src/test/queries/clientpos...
Date Thu, 01 Oct 2009 20:07:00 GMT
Author: namit
Date: Thu Oct  1 20:06:57 2009
New Revision: 820771

URL: http://svn.apache.org/viewvc?rev=820771&view=rev
Log:
HIVE-861. NumberFormatException in sum and average
(Zheng Shao via namit)


Added:
    hadoop/hive/trunk/ql/src/test/queries/clientnegative/ctas.q
    hadoop/hive/trunk/ql/src/test/queries/clientpositive/ctas.q
    hadoop/hive/trunk/ql/src/test/results/clientnegative/ctas.q.out
    hadoop/hive/trunk/ql/src/test/results/clientpositive/ctas.q.out
Modified:
    hadoop/hive/trunk/CHANGES.txt
    hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/ColumnInfo.java
    hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/BaseSemanticAnalyzer.java
    hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/DDLSemanticAnalyzer.java
    hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/ErrorMsg.java
    hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/Hive.g
    hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/QB.java
    hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java
    hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzerFactory.java
    hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/plan/PlanUtils.java
    hadoop/hive/trunk/ql/src/test/results/clientpositive/create_1.q.out
    hadoop/hive/trunk/ql/src/test/results/clientpositive/create_like.q.out
    hadoop/hive/trunk/ql/src/test/results/compiler/plan/cast1.q.xml
    hadoop/hive/trunk/ql/src/test/results/compiler/plan/groupby2.q.xml
    hadoop/hive/trunk/ql/src/test/results/compiler/plan/groupby3.q.xml
    hadoop/hive/trunk/ql/src/test/results/compiler/plan/groupby4.q.xml
    hadoop/hive/trunk/ql/src/test/results/compiler/plan/groupby5.q.xml
    hadoop/hive/trunk/ql/src/test/results/compiler/plan/groupby6.q.xml
    hadoop/hive/trunk/ql/src/test/results/compiler/plan/input20.q.xml
    hadoop/hive/trunk/ql/src/test/results/compiler/plan/input3.q.xml
    hadoop/hive/trunk/ql/src/test/results/compiler/plan/input8.q.xml
    hadoop/hive/trunk/ql/src/test/results/compiler/plan/input_part1.q.xml
    hadoop/hive/trunk/ql/src/test/results/compiler/plan/input_testxpath.q.xml
    hadoop/hive/trunk/ql/src/test/results/compiler/plan/input_testxpath2.q.xml
    hadoop/hive/trunk/ql/src/test/results/compiler/plan/join4.q.xml
    hadoop/hive/trunk/ql/src/test/results/compiler/plan/join5.q.xml
    hadoop/hive/trunk/ql/src/test/results/compiler/plan/join6.q.xml
    hadoop/hive/trunk/ql/src/test/results/compiler/plan/join7.q.xml
    hadoop/hive/trunk/ql/src/test/results/compiler/plan/join8.q.xml
    hadoop/hive/trunk/ql/src/test/results/compiler/plan/sample1.q.xml
    hadoop/hive/trunk/ql/src/test/results/compiler/plan/subq.q.xml
    hadoop/hive/trunk/ql/src/test/results/compiler/plan/udf1.q.xml
    hadoop/hive/trunk/ql/src/test/results/compiler/plan/udf4.q.xml
    hadoop/hive/trunk/ql/src/test/results/compiler/plan/udf6.q.xml
    hadoop/hive/trunk/ql/src/test/results/compiler/plan/udf_case.q.xml
    hadoop/hive/trunk/ql/src/test/results/compiler/plan/udf_when.q.xml
    hadoop/hive/trunk/ql/src/test/results/compiler/plan/union.q.xml

Modified: hadoop/hive/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/CHANGES.txt?rev=820771&r1=820770&r2=820771&view=diff
==============================================================================
--- hadoop/hive/trunk/CHANGES.txt (original)
+++ hadoop/hive/trunk/CHANGES.txt Thu Oct  1 20:06:57 2009
@@ -51,6 +51,9 @@
     HIVE-853. Provide hints for controlling join order
     (Emil Ibrishimov via namit)
 
+    HIVE-31. Support Create Table As Select
+    (Ning Zhang via namit)
+
   IMPROVEMENTS
 
     HIVE-760. Add version info to META-INF/MANIFEST.MF.

Modified: hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/ColumnInfo.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/ColumnInfo.java?rev=820771&r1=820770&r2=820771&view=diff
==============================================================================
--- hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/ColumnInfo.java (original)
+++ hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/ColumnInfo.java Thu Oct  1 20:06:57 2009
@@ -35,6 +35,8 @@
   private static final long serialVersionUID = 1L;
 
   private String internalName;
+  
+  private String alias = null; // [optional] alias of the column (external name as seen by the users) 
 
   /**
    * Store the alias of the table where available.
@@ -96,4 +98,13 @@
   public String toString() {
     return internalName + ": " + type;
   }
+  
+  public void setAlias(String col_alias) {
+    alias = col_alias;
+  }
+  
+  public String getAlias() {
+    return alias;
+  }
+  
 }

Modified: hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/BaseSemanticAnalyzer.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/BaseSemanticAnalyzer.java?rev=820771&r1=820770&r2=820771&view=diff
==============================================================================
--- hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/BaseSemanticAnalyzer.java (original)
+++ hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/BaseSemanticAnalyzer.java Thu Oct  1 20:06:57 2009
@@ -37,6 +37,10 @@
 import org.apache.hadoop.hive.ql.hooks.ReadEntity;
 import org.apache.hadoop.hive.ql.hooks.WriteEntity;
 
+import org.apache.hadoop.hive.metastore.api.FieldSchema;
+import org.apache.hadoop.hive.metastore.api.Order;
+import org.apache.hadoop.hive.serde.Constants;
+
 public abstract class BaseSemanticAnalyzer {
   protected final Hive db;
   protected final HiveConf conf;
@@ -253,6 +257,92 @@
     return outputs;
   }
 
+  /**
+   *  Get the list of FieldSchema out of the ASTNode. 
+   */
+  protected List<FieldSchema> getColumns(ASTNode ast) throws SemanticException
+  {
+    List<FieldSchema> colList = new ArrayList<FieldSchema>();
+    int numCh = ast.getChildCount();
+    for (int i = 0; i < numCh; i++) {
+      FieldSchema col = new FieldSchema();
+      ASTNode child = (ASTNode)ast.getChild(i);
+      
+      // child 0 is the name of the column
+      col.setName(unescapeIdentifier(child.getChild(0).getText()));
+      // child 1 is the type of the column
+      ASTNode typeChild = (ASTNode)(child.getChild(1));
+      col.setType(getTypeStringFromAST(typeChild));
+       
+      // child 2 is the optional comment of the column
+      if (child.getChildCount() == 3)
+        col.setComment(unescapeSQLString(child.getChild(2).getText()));
+      colList.add(col);
+    }
+    return colList;
+  }
+  
+  protected List<String> getColumnNames(ASTNode ast)
+  {
+    List<String> colList = new ArrayList<String>();
+    int numCh = ast.getChildCount();
+    for (int i = 0; i < numCh; i++) {
+      ASTNode child = (ASTNode)ast.getChild(i);
+      colList.add(unescapeIdentifier(child.getText()));
+    }
+    return colList;
+  }
+  
+  protected List<Order> getColumnNamesOrder(ASTNode ast)
+  {
+    List<Order> colList = new ArrayList<Order>();
+    int numCh = ast.getChildCount();
+    for (int i = 0; i < numCh; i++) {
+      ASTNode child = (ASTNode)ast.getChild(i);
+      if (child.getToken().getType() == HiveParser.TOK_TABSORTCOLNAMEASC)
+        colList.add(new Order(unescapeIdentifier(child.getChild(0).getText()), 1));
+      else
+        colList.add(new Order(unescapeIdentifier(child.getChild(0).getText()), 0));
+    }
+    return colList;
+  }
+  
+  protected static String getTypeStringFromAST(ASTNode typeNode) throws SemanticException {
+    switch (typeNode.getType()) {
+    case HiveParser.TOK_LIST:
+      return Constants.LIST_TYPE_NAME + "<"
+        + getTypeStringFromAST((ASTNode)typeNode.getChild(0)) + ">";
+    case HiveParser.TOK_MAP:
+      return Constants.MAP_TYPE_NAME + "<"
+        + getTypeStringFromAST((ASTNode)typeNode.getChild(0)) + ","
+        + getTypeStringFromAST((ASTNode)typeNode.getChild(1)) + ">";
+    case HiveParser.TOK_STRUCT:
+      return getStructTypeStringFromAST(typeNode);
+    default:
+      return DDLSemanticAnalyzer.getTypeName(typeNode.getType());
+    }
+  }
+  
+  private static String getStructTypeStringFromAST(ASTNode typeNode)
+      throws SemanticException {
+    String typeStr = Constants.STRUCT_TYPE_NAME + "<";
+    typeNode = (ASTNode) typeNode.getChild(0);
+    int children = typeNode.getChildCount();
+    if(children <= 0)
+      throw new SemanticException("empty struct not allowed.");
+    for (int i = 0; i < children; i++) {
+      ASTNode child = (ASTNode) typeNode.getChild(i);
+      typeStr += unescapeIdentifier(child.getChild(0).getText()) + ":";
+      typeStr += getTypeStringFromAST((ASTNode) child.getChild(1));
+      if (i < children - 1)
+        typeStr += ",";
+    }
+      
+    typeStr += ">";
+    return typeStr;
+  }
+ 
+ 
   public static class tableSpec {
     public String tableName;
     public Table tableHandle;

Modified: hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/DDLSemanticAnalyzer.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/DDLSemanticAnalyzer.java?rev=820771&r1=820770&r2=820771&view=diff
==============================================================================
--- hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/DDLSemanticAnalyzer.java (original)
+++ hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/DDLSemanticAnalyzer.java Thu Oct  1 20:06:57 2009
@@ -40,17 +40,12 @@
 import org.apache.hadoop.hive.metastore.api.Order;
 import org.apache.hadoop.hive.ql.exec.Task;
 import org.apache.hadoop.hive.ql.exec.TaskFactory;
-import org.apache.hadoop.hive.ql.io.HiveFileFormatUtils;
 import org.apache.hadoop.hive.ql.io.HiveOutputFormat;
 import org.apache.hadoop.hive.ql.io.IgnoreKeyTextOutputFormat;
-import org.apache.hadoop.hive.ql.io.RCFileInputFormat;
-import org.apache.hadoop.hive.ql.io.RCFileOutputFormat;
 import org.apache.hadoop.hive.ql.plan.AddPartitionDesc;
 import org.apache.hadoop.hive.ql.plan.DDLWork;
 import org.apache.hadoop.hive.ql.plan.MsckDesc;
 import org.apache.hadoop.hive.ql.plan.alterTableDesc;
-import org.apache.hadoop.hive.ql.plan.createTableDesc;
-import org.apache.hadoop.hive.ql.plan.createTableLikeDesc;
 import org.apache.hadoop.hive.ql.plan.descFunctionDesc;
 import org.apache.hadoop.hive.ql.plan.descTableDesc;
 import org.apache.hadoop.hive.ql.plan.dropTableDesc;
@@ -62,11 +57,7 @@
 import org.apache.hadoop.hive.ql.plan.tableDesc;
 import org.apache.hadoop.hive.ql.plan.alterTableDesc.alterTableTypes;
 import org.apache.hadoop.hive.serde.Constants;
-import org.apache.hadoop.hive.serde2.SerDeUtils;
-import org.apache.hadoop.hive.serde2.columnar.ColumnarSerDe;
 import org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe;
-import org.apache.hadoop.mapred.SequenceFileInputFormat;
-import org.apache.hadoop.mapred.SequenceFileOutputFormat;
 import org.apache.hadoop.mapred.TextInputFormat;
 
 public class DDLSemanticAnalyzer extends BaseSemanticAnalyzer {
@@ -85,14 +76,6 @@
     TokenToTypeName.put(HiveParser.TOK_DATETIME, Constants.DATETIME_TYPE_NAME);
     TokenToTypeName.put(HiveParser.TOK_TIMESTAMP, Constants.TIMESTAMP_TYPE_NAME);
   }
-  private static final String TEXTFILE_INPUT = TextInputFormat.class.getName();
-  private static final String TEXTFILE_OUTPUT = IgnoreKeyTextOutputFormat.class.getName();
-  private static final String SEQUENCEFILE_INPUT = SequenceFileInputFormat.class.getName();
-  private static final String SEQUENCEFILE_OUTPUT = SequenceFileOutputFormat.class.getName();
-  private static final String RCFILE_INPUT = RCFileInputFormat.class.getName();
-  private static final String RCFILE_OUTPUT = RCFileOutputFormat.class.getName();
-
-  private static final String COLUMNAR_SERDE = ColumnarSerDe.class.getName();
 
   public static String getTypeName(int token) {
     return TokenToTypeName.get(token);
@@ -104,9 +87,7 @@
 
   @Override
   public void analyzeInternal(ASTNode ast) throws SemanticException {
-    if (ast.getToken().getType() == HiveParser.TOK_CREATETABLE)
-       analyzeCreateTable(ast);
-    else if (ast.getToken().getType() == HiveParser.TOK_DROPTABLE)
+    if (ast.getToken().getType() == HiveParser.TOK_DROPTABLE)
        analyzeDropTable(ast);
     else if (ast.getToken().getType() == HiveParser.TOK_DESCTABLE)
     {
@@ -155,245 +136,7 @@
     }
   }
 
-  private void analyzeCreateTable(ASTNode ast)
-    throws SemanticException {
-    String            tableName     = unescapeIdentifier(ast.getChild(0).getText());
-    String            likeTableName = null;
-    List<FieldSchema> cols          = null;
-    List<FieldSchema> partCols      = null;
-    List<String>      bucketCols    = null;
-    List<Order>       sortCols      = null;
-    int               numBuckets    = -1;
-    String            fieldDelim    = null;
-    String            fieldEscape   = null;
-    String            collItemDelim = null;
-    String            mapKeyDelim   = null;
-    String            lineDelim     = null;
-    String            comment       = null;
-    String            inputFormat   = TEXTFILE_INPUT;
-    String            outputFormat  = TEXTFILE_OUTPUT;
-    String            location      = null;
-    String            serde         = null;
-    Map<String, String> mapProp     = null;
-    boolean           ifNotExists   = false;
-    boolean           isExt         = false;
-
-    if ("SequenceFile".equalsIgnoreCase(conf.getVar(HiveConf.ConfVars.HIVEDEFAULTFILEFORMAT))) {
-      inputFormat = SEQUENCEFILE_INPUT;
-      outputFormat = SEQUENCEFILE_OUTPUT;
-    }
-
-    LOG.info("Creating table" + tableName);
-    int numCh = ast.getChildCount();
-    for (int num = 1; num < numCh; num++)
-    {
-      ASTNode child = (ASTNode)ast.getChild(num);
-      switch (child.getToken().getType()) {
-        case HiveParser.TOK_IFNOTEXISTS:
-          ifNotExists = true;
-          break;
-        case HiveParser.KW_EXTERNAL:
-          isExt = true;
-          break;
-        case HiveParser.TOK_LIKETABLE:
-          if (child.getChildCount() > 0) {
-            likeTableName = unescapeIdentifier(child.getChild(0).getText());
-          }
-          break;
-        case HiveParser.TOK_TABCOLLIST:
-          cols = getColumns(child);
-          break;
-        case HiveParser.TOK_TABLECOMMENT:
-          comment = unescapeSQLString(child.getChild(0).getText());
-          break;
-        case HiveParser.TOK_TABLEPARTCOLS:
-          partCols = getColumns((ASTNode)child.getChild(0));
-          break;
-        case HiveParser.TOK_TABLEBUCKETS:
-          bucketCols = getColumnNames((ASTNode)child.getChild(0));
-          if (child.getChildCount() == 2)
-            numBuckets = (Integer.valueOf(child.getChild(1).getText())).intValue();
-          else
-          {
-            sortCols = getColumnNamesOrder((ASTNode)child.getChild(1));
-            numBuckets = (Integer.valueOf(child.getChild(2).getText())).intValue();
-          }
-          break;
-        case HiveParser.TOK_TABLEROWFORMAT:
-
-          child = (ASTNode)child.getChild(0);
-          int numChildRowFormat = child.getChildCount();
-          for (int numC = 0; numC < numChildRowFormat; numC++)
-          {
-            ASTNode rowChild = (ASTNode)child.getChild(numC);
-            switch (rowChild.getToken().getType()) {
-              case HiveParser.TOK_TABLEROWFORMATFIELD:
-                fieldDelim = unescapeSQLString(rowChild.getChild(0).getText());
-                if (rowChild.getChildCount()>=2) {
-                  fieldEscape = unescapeSQLString(rowChild.getChild(1).getText());
-                }
-                break;
-              case HiveParser.TOK_TABLEROWFORMATCOLLITEMS:
-                collItemDelim = unescapeSQLString(rowChild.getChild(0).getText());
-                break;
-              case HiveParser.TOK_TABLEROWFORMATMAPKEYS:
-                mapKeyDelim = unescapeSQLString(rowChild.getChild(0).getText());
-                break;
-              case HiveParser.TOK_TABLEROWFORMATLINES:
-                lineDelim = unescapeSQLString(rowChild.getChild(0).getText());
-                break;
-              default: assert false;
-            }
-          }
-          break;
-        case HiveParser.TOK_TABLESERIALIZER:
-
-          child = (ASTNode)child.getChild(0);
-          serde = unescapeSQLString(child.getChild(0).getText());
-          if (child.getChildCount() == 2) {
-            mapProp = new HashMap<String, String>();
-            ASTNode prop = (ASTNode)((ASTNode)child.getChild(1)).getChild(0);
-            for (int propChild = 0; propChild < prop.getChildCount(); propChild++) {
-              String key = unescapeSQLString(prop.getChild(propChild).getChild(0).getText());
-              String value = unescapeSQLString(prop.getChild(propChild).getChild(1).getText());
-              mapProp.put(key,value);
-            }
-          }
-          break;
-        case HiveParser.TOK_TBLSEQUENCEFILE:
-          inputFormat = SEQUENCEFILE_INPUT;
-          outputFormat = SEQUENCEFILE_OUTPUT;
-          break;
-        case HiveParser.TOK_TBLTEXTFILE:
-          inputFormat = TEXTFILE_INPUT;
-          outputFormat = TEXTFILE_OUTPUT;
-          break;
-        case HiveParser.TOK_TBLRCFILE:
-          inputFormat = RCFILE_INPUT;
-          outputFormat = RCFILE_OUTPUT;
-          serde = COLUMNAR_SERDE;
-          break;
-        case HiveParser.TOK_TABLEFILEFORMAT:
-          inputFormat = unescapeSQLString(child.getChild(0).getText());
-          outputFormat = unescapeSQLString(child.getChild(1).getText());
-          break;
-        case HiveParser.TOK_TABLELOCATION:
-          location = unescapeSQLString(child.getChild(0).getText());
-          break;
-        default: assert false;
-      }
-    }
-    if (likeTableName == null) {
-      createTableDesc crtTblDesc =
-        new createTableDesc(tableName, isExt, cols, partCols, bucketCols,
-                            sortCols, numBuckets,
-                            fieldDelim, fieldEscape,
-                            collItemDelim, mapKeyDelim, lineDelim,
-                            comment, inputFormat, outputFormat, location, serde,
-                            mapProp, ifNotExists);
-
-      validateCreateTable(crtTblDesc);
-      rootTasks.add(TaskFactory.get(new DDLWork(getInputs(), getOutputs(), crtTblDesc), conf));
-    } else {
-      createTableLikeDesc crtTblLikeDesc =
-        new createTableLikeDesc(tableName, isExt, location, ifNotExists, likeTableName);
-      rootTasks.add(TaskFactory.get(new DDLWork(getInputs(), getOutputs(), crtTblLikeDesc), conf));
-    }
-
-  }
-
-  private void validateCreateTable(createTableDesc crtTblDesc) throws SemanticException {
-    // no duplicate column names
-    // currently, it is a simple n*n algorithm - this can be optimized later if need be
-    // but it should not be a major bottleneck as the number of columns are anyway not so big
-
-    if((crtTblDesc.getCols() == null) || (crtTblDesc.getCols().size() == 0)) {
-      // for now make sure that serde exists
-      if(StringUtils.isEmpty(crtTblDesc.getSerName()) || SerDeUtils.isNativeSerDe(crtTblDesc.getSerName())) {
-        throw new SemanticException(ErrorMsg.INVALID_TBL_DDL_SERDE.getMsg());
-      }
-      return;
-    }
-
-    try {
-      Class<?> origin = Class.forName(crtTblDesc.getOutputFormat(), true, JavaUtils.getClassLoader());
-      Class<? extends HiveOutputFormat> replaced = HiveFileFormatUtils.getOutputFormatSubstitute(origin);
-      if(replaced == null)
-        throw new SemanticException(ErrorMsg.INVALID_OUTPUT_FORMAT_TYPE.getMsg());
-    } catch (ClassNotFoundException e) {
-      throw new SemanticException(ErrorMsg.INVALID_OUTPUT_FORMAT_TYPE.getMsg());
-    }
-
-    Iterator<FieldSchema> iterCols = crtTblDesc.getCols().iterator();
-    List<String> colNames = new ArrayList<String>();
-    while (iterCols.hasNext()) {
-      String colName = iterCols.next().getName();
-      Iterator<String> iter = colNames.iterator();
-      while (iter.hasNext()) {
-        String oldColName = iter.next();
-        if (colName.equalsIgnoreCase(oldColName))
-          throw new SemanticException(ErrorMsg.DUPLICATE_COLUMN_NAMES.getMsg());
-      }
-      colNames.add(colName);
-    }
-
-    if (crtTblDesc.getBucketCols() != null)
-    {
-      // all columns in cluster and sort are valid columns
-      Iterator<String> bucketCols = crtTblDesc.getBucketCols().iterator();
-      while (bucketCols.hasNext()) {
-        String bucketCol = bucketCols.next();
-        boolean found = false;
-        Iterator<String> colNamesIter = colNames.iterator();
-        while (colNamesIter.hasNext()) {
-          String colName = colNamesIter.next();
-          if (bucketCol.equalsIgnoreCase(colName)) {
-            found = true;
-            break;
-          }
-        }
-        if (!found)
-          throw new SemanticException(ErrorMsg.INVALID_COLUMN.getMsg());
-      }
-    }
-
-    if (crtTblDesc.getSortCols() != null)
-    {
-      // all columns in cluster and sort are valid columns
-      Iterator<Order> sortCols = crtTblDesc.getSortCols().iterator();
-      while (sortCols.hasNext()) {
-        String sortCol = sortCols.next().getCol();
-        boolean found = false;
-        Iterator<String> colNamesIter = colNames.iterator();
-        while (colNamesIter.hasNext()) {
-          String colName = colNamesIter.next();
-          if (sortCol.equalsIgnoreCase(colName)) {
-            found = true;
-            break;
-          }
-        }
-        if (!found)
-          throw new SemanticException(ErrorMsg.INVALID_COLUMN.getMsg());
-      }
-    }
-
-    if (crtTblDesc.getPartCols() != null)
-    {
-      // there is no overlap between columns and partitioning columns
-      Iterator<FieldSchema> partColsIter = crtTblDesc.getPartCols().iterator();
-      while (partColsIter.hasNext()) {
-        String partCol = partColsIter.next().getName();
-        Iterator<String> colNamesIter = colNames.iterator();
-        while (colNamesIter.hasNext()) {
-          String colName = unescapeIdentifier(colNamesIter.next());
-          if (partCol.equalsIgnoreCase(colName))
-            throw new SemanticException(ErrorMsg.COLUMN_REPEATED_IN_PARTITIONING_COLS.getMsg());
-        }
-      }
-    }
-  }
-
-  private void analyzeDropTable(ASTNode ast)
+  private void analyzeDropTable(ASTNode ast) 
     throws SemanticException {
     String tableName = unescapeIdentifier(ast.getChild(0).getText());
     dropTableDesc dropTblDesc = new dropTableDesc(tableName);
@@ -441,84 +184,6 @@
     return mapProp;
   }
 
-  private static String getTypeStringFromAST(ASTNode typeNode) throws SemanticException {
-    switch (typeNode.getType()) {
-    case HiveParser.TOK_LIST:
-      return Constants.LIST_TYPE_NAME + "<"
-        + getTypeStringFromAST((ASTNode)typeNode.getChild(0)) + ">";
-    case HiveParser.TOK_MAP:
-      return Constants.MAP_TYPE_NAME + "<"
-        + getTypeStringFromAST((ASTNode)typeNode.getChild(0)) + ","
-        + getTypeStringFromAST((ASTNode)typeNode.getChild(1)) + ">";
-    case HiveParser.TOK_STRUCT:
-      return getStructTypeStringFromAST(typeNode);
-    default:
-      return getTypeName(typeNode.getType());
-    }
-  }
-
-  private static String getStructTypeStringFromAST(ASTNode typeNode)
-      throws SemanticException {
-    String typeStr = Constants.STRUCT_TYPE_NAME + "<";
-    typeNode = (ASTNode) typeNode.getChild(0);
-    int children = typeNode.getChildCount();
-    if(children <= 0)
-      throw new SemanticException("empty struct not allowed.");
-    for (int i = 0; i < children; i++) {
-      ASTNode child = (ASTNode) typeNode.getChild(i);
-      typeStr += unescapeIdentifier(child.getChild(0).getText()) + ":";
-      typeStr += getTypeStringFromAST((ASTNode) child.getChild(1));
-      if (i < children - 1)
-        typeStr += ",";
-    }
-
-    typeStr += ">";
-    return typeStr;
-  }
-
-  private List<FieldSchema> getColumns(ASTNode ast) throws SemanticException
-  {
-    List<FieldSchema> colList = new ArrayList<FieldSchema>();
-    int numCh = ast.getChildCount();
-    for (int i = 0; i < numCh; i++) {
-      FieldSchema col = new FieldSchema();
-      ASTNode child = (ASTNode)ast.getChild(i);
-      col.setName(unescapeIdentifier(child.getChild(0).getText()));
-      ASTNode typeChild = (ASTNode)(child.getChild(1));
-      col.setType(getTypeStringFromAST(typeChild));
-
-      if (child.getChildCount() == 3)
-        col.setComment(unescapeSQLString(child.getChild(2).getText()));
-      colList.add(col);
-    }
-    return colList;
-  }
-
-  private List<String> getColumnNames(ASTNode ast)
-  {
-    List<String> colList = new ArrayList<String>();
-    int numCh = ast.getChildCount();
-    for (int i = 0; i < numCh; i++) {
-      ASTNode child = (ASTNode)ast.getChild(i);
-      colList.add(unescapeIdentifier(child.getText()));
-    }
-    return colList;
-  }
-
-  private List<Order> getColumnNamesOrder(ASTNode ast)
-  {
-    List<Order> colList = new ArrayList<Order>();
-    int numCh = ast.getChildCount();
-    for (int i = 0; i < numCh; i++) {
-      ASTNode child = (ASTNode)ast.getChild(i);
-      if (child.getToken().getType() == HiveParser.TOK_TABSORTCOLNAMEASC)
-        colList.add(new Order(unescapeIdentifier(child.getChild(0).getText()), 1));
-      else
-        colList.add(new Order(unescapeIdentifier(child.getChild(0).getText()), 0));
-    }
-    return colList;
-  }
-
   /**
    * Get the fully qualified name in the ast. e.g. the ast of the form ^(DOT ^(DOT a b) c)
    * will generate a name of the form a.b.c

Modified: hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/ErrorMsg.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/ErrorMsg.java?rev=820771&r1=820770&r2=820771&view=diff
==============================================================================
--- hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/ErrorMsg.java (original)
+++ hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/ErrorMsg.java Thu Oct  1 20:06:57 2009
@@ -96,8 +96,16 @@
   INVALID_MAPJOIN_HINT("neither table specified as map-table"),
   INVALID_MAPJOIN_TABLE("result of a union cannot be a map table"),
   NON_BUCKETED_TABLE("Sampling Expression Needed for Non-Bucketed Table"),
-  NEED_PARTITION_ERROR("need to specify partition columns because the destination table is partitioned.");
-
+  NEED_PARTITION_ERROR("need to specify partition columns because the destination table is partitioned."),
+  CTAS_CTLT_COEXISTENCE("Create table command does not allow LIKE and AS-SELECT in the same command"),
+  CTAS_COLLST_COEXISTENCE("Create table as select command cannot specify the list of columns for the target table."),
+  CTLT_COLLST_COEXISTENCE("Create table like command cannot specify the list of columns for the target table."),
+  INVALID_SELECT_SCHEMA("Cannot derive schema from the select-clause."),
+  CTAS_PARCOL_COEXISTENCE("CREATE-TABLE-AS-SELECT does not support partitioning in the target table."),
+  CTAS_MULTI_LOADFILE("CREATE-TABLE-AS-SELECT results in multiple file load."),
+  CTAS_EXTTBL_COEXISTENCE("CREATE-TABLE-AS-SELECT cannot create external table."),
+  TABLE_ALREADY_EXISTS("Table already exists:", "42S02");
+  
   private String mesg;
   private String SQLState;
 

Modified: hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/Hive.g
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/Hive.g?rev=820771&r1=820770&r2=820771&view=diff
==============================================================================
--- hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/Hive.g (original)
+++ hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/Hive.g Thu Oct  1 20:06:57 2009
@@ -215,8 +215,28 @@
 @init { msgs.push("create statement"); }
 @after { msgs.pop(); }
     : KW_CREATE (ext=KW_EXTERNAL)? KW_TABLE ifNotExists? name=Identifier
-      ( like=KW_LIKE likeName=Identifier | (LPAREN columnNameTypeList RPAREN)? tableComment? tablePartition? tableBuckets? tableRowFormat? tableFileFormat? ) tableLocation?
-    -> ^(TOK_CREATETABLE $name $ext? ifNotExists? ^(TOK_LIKETABLE $likeName?) columnNameTypeList? tableComment? tablePartition? tableBuckets? tableRowFormat? tableFileFormat? tableLocation?)
+      (  like=KW_LIKE likeName=Identifier
+         tableLocation?
+       | (LPAREN columnNameTypeList RPAREN)? 
+         tableComment? 
+         tablePartition? 
+         tableBuckets? 
+         tableRowFormat? 
+         tableFileFormat? 
+         tableLocation?
+         (KW_AS selectStatement)?
+      )
+    -> ^(TOK_CREATETABLE $name $ext? ifNotExists? 
+         ^(TOK_LIKETABLE $likeName?) 
+         columnNameTypeList? 
+         tableComment? 
+         tablePartition? 
+         tableBuckets? 
+         tableRowFormat? 
+         tableFileFormat? 
+         tableLocation?
+         selectStatement?
+        )
     ;
 
 dropStatement
@@ -635,6 +655,11 @@
                      selectClause whereClause? groupByClause? orderByClause? clusterByClause?
                      distributeByClause? sortByClause? limitClause?))
    |
+   selectStatement
+   ;
+
+selectStatement
+   :
    selectClause
    fromClause
    whereClause?

Modified: hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/QB.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/QB.java?rev=820771&r1=820770&r2=820771&view=diff
==============================================================================
--- hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/QB.java (original)
+++ hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/QB.java Thu Oct  1 20:06:57 2009
@@ -22,6 +22,7 @@
 
 import org.apache.hadoop.hive.ql.parse.QBParseInfo;
 import org.apache.hadoop.hive.ql.parse.QBMetaData;
+import org.apache.hadoop.hive.ql.plan.createTableDesc;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -46,6 +47,7 @@
   private QBJoinTree qbjoin;
   private String id;
   private boolean isQuery;
+  private createTableDesc tblDesc = null;   // table descriptor of the final results
 
   public void print(String msg) {
     LOG.info(msg + "alias=" + qbp.getAlias());
@@ -160,6 +162,21 @@
   }
 
   public boolean isSelectStarQuery() {
-    return qbp.isSelectStarQuery() && aliasToSubq.isEmpty();
+    return qbp.isSelectStarQuery() && aliasToSubq.isEmpty() && !isCTAS();
+  }
+  
+  public createTableDesc getTableDesc() {
+    return tblDesc;
+  }
+
+  public void setTableDesc(createTableDesc desc) {
+    tblDesc = desc;
+  }
+  
+  /**
+   * Whether this QB is for a CREATE-TABLE-AS-SELECT.
+   */
+  public boolean isCTAS() {
+    return tblDesc != null;
   }
 }

Modified: hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java?rev=820771&r1=820770&r2=820771&view=diff
==============================================================================
--- hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java (original)
+++ hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java Thu Oct  1 20:06:57 2009
@@ -143,6 +143,28 @@
 import org.apache.hadoop.hive.ql.hooks.ReadEntity;
 import org.apache.hadoop.hive.ql.hooks.WriteEntity;
 
+import java.util.regex.Pattern;
+import java.util.regex.Matcher;
+import org.apache.hadoop.hive.metastore.api.Order;
+import org.apache.hadoop.mapred.SequenceFileInputFormat;
+import org.apache.hadoop.mapred.SequenceFileOutputFormat;
+import org.apache.hadoop.mapred.TextInputFormat;
+import org.apache.hadoop.hive.ql.io.RCFileInputFormat;
+import org.apache.hadoop.hive.ql.io.RCFileOutputFormat;
+import org.apache.hadoop.hive.serde2.columnar.ColumnarSerDe;
+import org.apache.hadoop.hive.ql.plan.DDLWork;
+import org.apache.hadoop.hive.ql.plan.createTableDesc;
+import org.apache.hadoop.hive.ql.plan.createTableLikeDesc;
+import org.apache.hadoop.hive.ql.Context;
+import org.apache.hadoop.hive.ql.Driver;
+import org.apache.hadoop.hive.serde2.SerDeUtils;
+import org.apache.hadoop.hive.ql.io.HiveFileFormatUtils;
+import org.apache.hadoop.hive.ql.exec.FileSinkOperator;
+import org.apache.hadoop.hive.ql.exec.FetchOperator;
+import java.util.Collection;
+import org.apache.hadoop.hive.metastore.api.StorageDescriptor;
+import org.apache.hadoop.hive.ql.hooks.WriteEntity;
+
 /**
  * Implementation of the semantic analyzer
  */
@@ -162,6 +184,14 @@
   private int destTableId;
   private UnionProcContext uCtx;
   List<MapJoinOperator> listMapJoinOpsNoReducer;
+  
+  private static final String TEXTFILE_INPUT = TextInputFormat.class.getName();
+  private static final String TEXTFILE_OUTPUT = IgnoreKeyTextOutputFormat.class.getName();
+  private static final String SEQUENCEFILE_INPUT = SequenceFileInputFormat.class.getName();
+  private static final String SEQUENCEFILE_OUTPUT = SequenceFileOutputFormat.class.getName();
+  private static final String RCFILE_INPUT = RCFileInputFormat.class.getName();
+  private static final String RCFILE_OUTPUT = RCFileOutputFormat.class.getName();
+  private static final String COLUMNAR_SERDE = ColumnarSerDe.class.getName();
 
   private static class Phase1Ctx {
     String dest;
@@ -450,12 +480,11 @@
             doPhase1GetDistinctFuncExpr(aggregations));
         break;
 
-      case HiveParser.TOK_WHERE: {
+      case HiveParser.TOK_WHERE:
         qbp.setWhrExprForClause(ctx_1.dest, ast);
-      }
         break;
 
-      case HiveParser.TOK_DESTINATION: {
+      case HiveParser.TOK_DESTINATION:
         ctx_1.dest = "insclause-" + ctx_1.nextNum;
         ctx_1.nextNum++;
 
@@ -468,10 +497,9 @@
         }
 
         qbp.setDestForClause(ctx_1.dest, (ASTNode) ast.getChild(0));
-      }
         break;
 
-      case HiveParser.TOK_FROM: {
+      case HiveParser.TOK_FROM:
         int child_count = ast.getChildCount();
         if (child_count != 1)
           throw new SemanticException("Multiple Children " + child_count);
@@ -487,17 +515,15 @@
           processJoin(qb, frm);
           qbp.setJoinExpr(frm);
         }
-      }
         break;
 
-      case HiveParser.TOK_CLUSTERBY: {
+      case HiveParser.TOK_CLUSTERBY:
         // Get the clusterby aliases - these are aliased to the entries in the
         // select list
         qbp.setClusterByExprForClause(ctx_1.dest, ast);
-      }
         break;
 
-      case HiveParser.TOK_DISTRIBUTEBY: {
+      case HiveParser.TOK_DISTRIBUTEBY:
         // Get the distribute by  aliases - these are aliased to the entries in the
         // select list
         qbp.setDistributeByExprForClause(ctx_1.dest, ast);
@@ -507,10 +533,9 @@
         else if (qbp.getOrderByForClause(ctx_1.dest) != null) {
           throw new SemanticException(ErrorMsg.ORDERBY_DISTRIBUTEBY_CONFLICT.getMsg(ast));
         }
-      }
         break;
 
-      case HiveParser.TOK_SORTBY: {
+      case HiveParser.TOK_SORTBY:
         // Get the sort by aliases - these are aliased to the entries in the
         // select list
         qbp.setSortByExprForClause(ctx_1.dest, ast);
@@ -521,20 +546,18 @@
           throw new SemanticException(ErrorMsg.ORDERBY_SORTBY_CONFLICT.getMsg(ast));
         }
 
-      }
         break;
 
-      case HiveParser.TOK_ORDERBY: {
+      case HiveParser.TOK_ORDERBY:
         // Get the order by aliases - these are aliased to the entries in the
         // select list
         qbp.setOrderByExprForClause(ctx_1.dest, ast);
         if (qbp.getClusterByForClause(ctx_1.dest) != null) {
           throw new SemanticException(ErrorMsg.CLUSTERBY_ORDERBY_CONFLICT.getMsg(ast));
         }
-      }
         break;
 
-      case HiveParser.TOK_GROUPBY: {
+      case HiveParser.TOK_GROUPBY:
         // Get the groupby aliases - these are aliased to the entries in the
         // select list
         if (qbp.getSelForClause(ctx_1.dest).getToken().getType() == HiveParser.TOK_SELECTDI) {
@@ -542,13 +565,10 @@
         }
         qbp.setGroupByExprForClause(ctx_1.dest, ast);
         skipRecursion = true;
-      }
         break;
 
       case HiveParser.TOK_LIMIT:
-        {
-          qbp.setDestLimit(ctx_1.dest, new Integer(ast.getChild(0).getText()));
-        }
+        qbp.setDestLimit(ctx_1.dest, new Integer(ast.getChild(0).getText()));
         break;
 
       case HiveParser.TOK_UNION:
@@ -673,7 +693,12 @@
             {
               fname = ctx.getMRTmpFileURI();
               ctx.setResDir(new Path(fname));
-              qb.setIsQuery(true);
+              
+              if ( qb.isCTAS() ) {
+                qb.setIsQuery(false);
+              } else {
+                qb.setIsQuery(true);
+              }
             }
             qb.getMetaData().setDestForAlias(name, fname,
                                              (ast.getToken().getType() == HiveParser.TOK_DIR));
@@ -2578,10 +2603,33 @@
         String cols = new String();
         String colTypes = new String();
         Vector<ColumnInfo> colInfos = inputRR.getColumnInfos();
+        
+        // CTAS case: the file output format and serde are defined by the create table command
+        // rather than taking the default value
+        List<FieldSchema> field_schemas = null;
+        createTableDesc tblDesc = qb.getTableDesc();
+        if ( tblDesc != null )
+          field_schemas = new ArrayList<FieldSchema>();
 
         boolean first = true;
         for (ColumnInfo colInfo:colInfos) {
           String[] nm = inputRR.reverseLookup(colInfo.getInternalName());
+          
+          if ( nm[1] != null ) { // non-null column alias
+            colInfo.setAlias(nm[1]);
+          }
+          
+          if ( field_schemas != null ) {
+            FieldSchema col = new FieldSchema();
+            if ( nm[1] != null ) {
+              col.setName(colInfo.getAlias());
+            } else {
+              col.setName(colInfo.getInternalName());
+            }
+            col.setType(colInfo.getType().getTypeName());
+            field_schemas.add(col);
+          }
+          
           if (!first) {
             cols = cols.concat(",");
             colTypes = colTypes.concat(":");
@@ -2605,6 +2653,10 @@
           else
             colTypes = colTypes.concat(tName);
         }
+        
+        // update the create table descriptor with the resulting schema. 
+        if ( tblDesc != null )
+          tblDesc.setCols(field_schemas);
 
         if (!ctx.isMRTmpFileURI(destStr)) {
           this.idToTableNameMap.put( String.valueOf(this.destTableId), destStr);
@@ -2616,8 +2668,13 @@
         this.loadFileWork.add(new loadFileDesc(queryTmpdir, destStr,
                                                isDfsDir, cols, colTypes));
 
-        table_desc = PlanUtils.getDefaultTableDesc(Integer.toString(Utilities.ctrlaCode),
-                                                   cols, colTypes, false);
+        if ( tblDesc == null ) {
+          table_desc = PlanUtils.getDefaultTableDesc(Integer.toString(Utilities.ctrlaCode),
+                                                     cols, colTypes, false);
+        } else {
+          table_desc = PlanUtils.getTableDesc(tblDesc, cols, colTypes);
+        } 
+         
         outputs.add(new WriteEntity(destStr, !isDfsDir));
         break;
     }
@@ -4322,15 +4379,33 @@
 
       fetchTask = TaskFactory.get(fetch, this.conf);
       setFetchTask(fetchTask);
-    }
-    else {
+    } else {
       // First we generate the move work as this needs to be made dependent on all
       // the tasks that have a file sink operation
       List<moveWork>  mv = new ArrayList<moveWork>();
       for (loadTableDesc ltd : loadTableWork)
         mvTask.add(TaskFactory.get(new moveWork(null, null, ltd, null, false), this.conf));
-      for (loadFileDesc lfd : loadFileWork)
+      
+      boolean oneLoadFile = true;
+      for (loadFileDesc lfd : loadFileWork) {
+        if ( qb.isCTAS() ) {
+          assert(oneLoadFile); // should not have more than 1 load file for CTAS
+          // make the movetask's destination directory the table's destination.
+          String location = qb.getTableDesc().getLocation();
+          if ( location == null ) {
+            // get the table's default location
+            location = conf.getVar(HiveConf.ConfVars.METASTOREWAREHOUSE);
+            assert(location.length() > 0 );
+            if ( location.charAt(location.length()-1) != '/' ) {
+              location += '/';
+            }
+            location += qb.getTableDesc().getTableName();
+          }
+          lfd.setTargetDir(location);
+          oneLoadFile = false;
+        } 
         mvTask.add(TaskFactory.get(new moveWork(null, null, null, lfd, false), this.conf));
+      }
     }
 
     // generate map reduce plans
@@ -4380,7 +4455,52 @@
     if (HiveConf.getBoolVar(conf, HiveConf.ConfVars.HIVEJOBPROGRESS))
       for (Task<? extends Serializable> rootTask: rootTasks)
         generateCountersTask(rootTask);
+    
+    if ( qb.isCTAS() ) {
+      // generate a DDL task and make it a dependent task of the leaf
+      createTableDesc crtTblDesc = qb.getTableDesc();
+
+      validateCreateTable(crtTblDesc);
+          
+      // Clear the output for CTAS since we don't need the output from the mapredWork, the
+      // DDLWork at the tail of the chain will have the output
+      getOutputs().clear(); 
+      
+      Task<? extends Serializable> crtTblTask = 
+        TaskFactory.get(new DDLWork(getInputs(), getOutputs(), crtTblDesc), this.conf);
+        
+      // find all leaf tasks and make the DDLTask as a dependent task of all of them
+      HashSet<Task<? extends Serializable>> leaves = new HashSet<Task<? extends Serializable>>();
+      getLeafTasks(rootTasks, leaves);    
+      assert(leaves.size() > 0);
+      for ( Task<? extends Serializable> task: leaves ) {
+        task.addDependentTask(crtTblTask);
+      }
+    }
+  }
+
+  /**
+   * Find all leaf tasks of the list of root tasks.
+   */
+  private void getLeafTasks(   List<Task<? extends Serializable>> rootTasks,
+                            HashSet<Task<? extends Serializable>> leaves)   {
+
+    for ( Task<? extends Serializable> root : rootTasks ) {
+      getLeafTasks(root, leaves);
+    }
   }
+  
+  private void getLeafTasks(        Task<? extends Serializable> task,
+                            HashSet<Task<? extends Serializable>> leaves) {
+    if ( task.getChildTasks() == null ) {
+      if ( ! leaves.contains(task) ) {
+        leaves.add(task);
+      }
+    } else {
+      getLeafTasks(task.getChildTasks(), leaves);
+    }
+  }
+
 
   // loop over all the tasks recursviely
   private void generateCountersTask(Task<? extends Serializable> task) {
@@ -4496,13 +4616,23 @@
   @SuppressWarnings("nls")
   public void analyzeInternal(ASTNode ast) throws SemanticException {
     reset();
-
+    
     QB qb = new QB(null, null, false);
     this.qb = qb;
     this.ast = ast;
-
+    ASTNode child = ast;
+    
     LOG.info("Starting Semantic Analysis");
-    doPhase1(ast, qb, initPhase1Ctx());
+    
+    // analyze create table command
+    if (ast.getToken().getType() == HiveParser.TOK_CREATETABLE) {
+      // if it is not CTAS, we don't need to go further and just return
+      if ( (child = analyzeCreateTable(ast, qb)) == null )
+         return;
+    }
+
+    // continue analyzing from the child ASTNode. 
+    doPhase1(child, qb, initPhase1Ctx());
     LOG.info("Completed phase 1 of Semantic Analysis");
 
     getMetaData(qb);
@@ -4511,7 +4641,7 @@
     genPlan(qb);
 
 
-    ParseContext pCtx = new ParseContext(conf, qb, ast, opToPartPruner, aliasToSamplePruner, topOps,
+    ParseContext pCtx = new ParseContext(conf, qb, child, opToPartPruner, aliasToSamplePruner, topOps,
                                          topSelOps, opParseCtx, joinContext, topToTable, loadTableWork, loadFileWork,
                                          ctx, idToTableNameMap, destTableId, uCtx, listMapJoinOpsNoReducer);
 
@@ -4652,4 +4782,339 @@
       validate(childTask);
   }
 
+  
+  /**
+   * Get the row resolver given an operator. 
+   */
+  public RowResolver getRowResolver(Operator opt) {
+    return opParseCtx.get(opt).getRR(); 
+  }
+  
+  /**
+   * Analyze the create table command. If it is a regular create-table or create-table-like 
+   * statements, we create a DDLWork and return true. If it is a create-table-as-select, we get the
+   * necessary info such as the SerDe and Storage Format and put it in QB, and return false, indicating
+   * the rest of the semantic analyzer need to deal with the select statement with respect to the
+   * SerDe and Storage Format.
+   */
+  private ASTNode analyzeCreateTable(ASTNode ast, QB qb) 
+    throws SemanticException {
+    String            tableName     = unescapeIdentifier(ast.getChild(0).getText());
+    String            likeTableName = null;
+    List<FieldSchema> cols          = null;
+    List<FieldSchema> partCols      = null;
+    List<String>      bucketCols    = null;
+    List<Order>       sortCols      = null;
+    int               numBuckets    = -1;
+    String            fieldDelim    = null;
+    String            fieldEscape   = null;
+    String            collItemDelim = null;
+    String            mapKeyDelim   = null;
+    String            lineDelim     = null;
+    String            comment       = null;
+    String            inputFormat   = TEXTFILE_INPUT;
+    String            outputFormat  = TEXTFILE_OUTPUT;
+    String            location      = null;
+    String            serde         = null;
+    Map<String, String> mapProp     = null;
+    boolean           ifNotExists   = false;
+    boolean           isExt         = false;
+    ASTNode           selectStmt    = null;
+    final int         CREATE_TABLE  = 0;       // regular CREATE TABLE
+    final int         CTLT          = 1;       // CREATE TABLE LIKE ...      (CTLT)
+    final int         CTAS          = 2;       // CREATE TABLE AS SELECT ... (CTAS)
+    int               command_type  = CREATE_TABLE;
+
+    if ("SequenceFile".equalsIgnoreCase(conf.getVar(HiveConf.ConfVars.HIVEDEFAULTFILEFORMAT))) {
+      inputFormat = SEQUENCEFILE_INPUT;
+      outputFormat = SEQUENCEFILE_OUTPUT;
+    }
+
+    LOG.info("Creating table" + tableName + " positin=" + ast.getCharPositionInLine());    
+    int numCh = ast.getChildCount();
+
+    /* Check the 1st-level children and do simple semantic checks:
+     * 1) CTLT and CTAS should not coexists.
+     * 2) CTLT or CTAS should not coexists with column list (target table schema).
+     * 3) CTAS does not support partitioning (for now).
+     */
+    for (int num = 1; num < numCh; num++)
+    {
+      ASTNode child = (ASTNode)ast.getChild(num);
+      switch (child.getToken().getType()) {
+        case HiveParser.TOK_IFNOTEXISTS:
+          ifNotExists = true;
+          break;
+        case HiveParser.KW_EXTERNAL:
+          isExt = true;
+          break;
+        case HiveParser.TOK_LIKETABLE:
+          if (child.getChildCount() > 0) {
+            likeTableName = unescapeIdentifier(child.getChild(0).getText());
+            if ( likeTableName != null ) {
+              if ( command_type == CTAS ) {
+                throw new SemanticException(ErrorMsg.CTAS_CTLT_COEXISTENCE.getMsg());
+              }
+              if ( cols != null ) {
+                throw new SemanticException(ErrorMsg.CTLT_COLLST_COEXISTENCE.getMsg());
+              }
+            }
+            command_type = CTLT;
+          }
+          break;
+        case HiveParser.TOK_QUERY:         // CTAS
+          if ( command_type == CTLT ) {
+            throw new SemanticException(ErrorMsg.CTAS_CTLT_COEXISTENCE.getMsg());
+          }
+          if ( cols != null ) {
+            throw new SemanticException(ErrorMsg.CTAS_COLLST_COEXISTENCE.getMsg());
+          }
+          // TODO: support partition for CTAS? 
+          if ( partCols != null || bucketCols != null ) {
+            throw new SemanticException(ErrorMsg.CTAS_PARCOL_COEXISTENCE.getMsg());
+          }
+          if ( isExt ) {
+            throw new SemanticException(ErrorMsg.CTAS_EXTTBL_COEXISTENCE.getMsg());
+          }
+          command_type = CTAS; 
+          selectStmt   = child;
+          break;
+        case HiveParser.TOK_TABCOLLIST:
+          cols = getColumns(child);
+          break;
+        case HiveParser.TOK_TABLECOMMENT:
+          comment = unescapeSQLString(child.getChild(0).getText());
+          break;
+        case HiveParser.TOK_TABLEPARTCOLS:
+          partCols = getColumns((ASTNode)child.getChild(0));
+          break;
+        case HiveParser.TOK_TABLEBUCKETS:
+          bucketCols = getColumnNames((ASTNode)child.getChild(0));
+          if (child.getChildCount() == 2)
+            numBuckets = (Integer.valueOf(child.getChild(1).getText())).intValue();
+          else
+          {
+            sortCols = getColumnNamesOrder((ASTNode)child.getChild(1));
+            numBuckets = (Integer.valueOf(child.getChild(2).getText())).intValue();
+          }
+          break;
+        case HiveParser.TOK_TABLEROWFORMAT:
+
+          child = (ASTNode)child.getChild(0);
+          int numChildRowFormat = child.getChildCount();
+          for (int numC = 0; numC < numChildRowFormat; numC++)
+          {
+            ASTNode rowChild = (ASTNode)child.getChild(numC);
+            switch (rowChild.getToken().getType()) {
+              case HiveParser.TOK_TABLEROWFORMATFIELD:
+                fieldDelim = unescapeSQLString(rowChild.getChild(0).getText());
+                if (rowChild.getChildCount()>=2) {
+                  fieldEscape = unescapeSQLString(rowChild.getChild(1).getText());
+                }
+                break;
+              case HiveParser.TOK_TABLEROWFORMATCOLLITEMS:
+                collItemDelim = unescapeSQLString(rowChild.getChild(0).getText());
+                break;
+              case HiveParser.TOK_TABLEROWFORMATMAPKEYS:
+                mapKeyDelim = unescapeSQLString(rowChild.getChild(0).getText());
+                break;
+              case HiveParser.TOK_TABLEROWFORMATLINES:
+                lineDelim = unescapeSQLString(rowChild.getChild(0).getText());
+                break;
+              default: assert false;
+            }
+          }
+          break;
+        case HiveParser.TOK_TABLESERIALIZER:
+          
+          child = (ASTNode)child.getChild(0);
+          serde = unescapeSQLString(child.getChild(0).getText());
+          if (child.getChildCount() == 2) {
+            mapProp = new HashMap<String, String>();
+            ASTNode prop = (ASTNode)((ASTNode)child.getChild(1)).getChild(0);
+            for (int propChild = 0; propChild < prop.getChildCount(); propChild++) {
+              String key = unescapeSQLString(prop.getChild(propChild).getChild(0).getText());
+              String value = unescapeSQLString(prop.getChild(propChild).getChild(1).getText());
+              mapProp.put(key,value);
+            }
+          }
+          break;
+        case HiveParser.TOK_TBLSEQUENCEFILE:
+          inputFormat = SEQUENCEFILE_INPUT;
+          outputFormat = SEQUENCEFILE_OUTPUT;
+          break;
+        case HiveParser.TOK_TBLTEXTFILE:
+          inputFormat = TEXTFILE_INPUT;
+          outputFormat = TEXTFILE_OUTPUT;
+          break;
+        case HiveParser.TOK_TBLRCFILE:
+          inputFormat = RCFILE_INPUT;
+          outputFormat = RCFILE_OUTPUT;
+          serde = COLUMNAR_SERDE;
+          break;
+        case HiveParser.TOK_TABLEFILEFORMAT:
+          inputFormat = unescapeSQLString(child.getChild(0).getText());
+          outputFormat = unescapeSQLString(child.getChild(1).getText());
+          break;
+        case HiveParser.TOK_TABLELOCATION:
+          location = unescapeSQLString(child.getChild(0).getText());
+          break;
+        default: assert false;
+      }
+    }
+    
+    // check for existence of table
+    if ( ifNotExists ) {
+      try {
+        List<String> tables = this.db.getTablesByPattern(tableName);
+        if ( tables != null && tables.size() > 0 ) { // table exists
+          return null;
+        }
+      } catch (HiveException e) {
+        e.printStackTrace();
+      }
+    }
+
+    // Handle different types of CREATE TABLE command
+    createTableDesc crtTblDesc = null;
+    switch ( command_type ) {
+      
+      case CREATE_TABLE: // REGULAR CREATE TABLE DDL
+        crtTblDesc = 
+          new createTableDesc(tableName, isExt, cols, partCols, bucketCols, 
+                              sortCols, numBuckets,
+                              fieldDelim, fieldEscape,
+                              collItemDelim, mapKeyDelim, lineDelim,
+                              comment, inputFormat, outputFormat, location, serde, 
+                              mapProp, ifNotExists);
+        
+        validateCreateTable(crtTblDesc);
+        rootTasks.add(TaskFactory.get(new DDLWork(getInputs(), getOutputs(), crtTblDesc), conf));
+        break;
+        
+      case CTLT: // create table like <tbl_name>
+        createTableLikeDesc crtTblLikeDesc = 
+          new createTableLikeDesc(tableName, isExt, location, ifNotExists, likeTableName);
+        rootTasks.add(TaskFactory.get(new DDLWork(getInputs(), getOutputs(), crtTblLikeDesc), conf));
+        break;
+        
+      case CTAS: // create table as select
+      
+        // check for existence of table. Throw an exception if it exists.
+        try {
+          Table tab = this.db.getTable(MetaStoreUtils.DEFAULT_DATABASE_NAME, tableName, 
+                                       false); // do not throw exception if table does not exist
+          
+          if ( tab != null ) {
+            throw new SemanticException(ErrorMsg.TABLE_ALREADY_EXISTS.getMsg(tableName)); 
+          }
+        } catch (HiveException e) { // may be unable to get meta data
+          throw new SemanticException(e); 
+        }
+                
+        crtTblDesc = 
+          new createTableDesc(tableName, isExt, cols, partCols, bucketCols, 
+                              sortCols, numBuckets,
+                              fieldDelim, fieldEscape,
+                              collItemDelim, mapKeyDelim, lineDelim,
+                              comment, inputFormat, outputFormat, location, serde, 
+                              mapProp, ifNotExists);
+        qb.setTableDesc(crtTblDesc);
+        
+        return selectStmt;
+      default: assert false; // should never be unknown command type
+    }
+    return null;
+  }
+ 
+  private void validateCreateTable(createTableDesc crtTblDesc) throws SemanticException {
+    // no duplicate column names
+    // currently, it is a simple n*n algorithm - this can be optimized later if need be
+    // but it should not be a major bottleneck as the number of columns are anyway not so big
+    
+    if((crtTblDesc.getCols() == null) || (crtTblDesc.getCols().size() == 0)) {
+      // for now make sure that serde exists
+      if(StringUtils.isEmpty(crtTblDesc.getSerName()) || SerDeUtils.isNativeSerDe(crtTblDesc.getSerName())) {
+        throw new SemanticException(ErrorMsg.INVALID_TBL_DDL_SERDE.getMsg());
+      }
+      return;
+    }
+    
+    try {
+      Class<?> origin = Class.forName(crtTblDesc.getOutputFormat(), true, JavaUtils.getClassLoader());
+      Class<? extends HiveOutputFormat> replaced = HiveFileFormatUtils.getOutputFormatSubstitute(origin);
+      if(replaced == null)
+        throw new SemanticException(ErrorMsg.INVALID_OUTPUT_FORMAT_TYPE.getMsg());
+    } catch (ClassNotFoundException e) {
+      throw new SemanticException(ErrorMsg.INVALID_OUTPUT_FORMAT_TYPE.getMsg());
+    }
+    
+    Iterator<FieldSchema> iterCols = crtTblDesc.getCols().iterator();
+    List<String> colNames = new ArrayList<String>();
+    while (iterCols.hasNext()) {
+      String colName = iterCols.next().getName();
+      Iterator<String> iter = colNames.iterator();
+      while (iter.hasNext()) {
+        String oldColName = iter.next();
+        if (colName.equalsIgnoreCase(oldColName)) 
+          throw new SemanticException(ErrorMsg.DUPLICATE_COLUMN_NAMES.getMsg());
+      }
+      colNames.add(colName);
+    }
+
+    if (crtTblDesc.getBucketCols() != null)
+    {    
+      // all columns in cluster and sort are valid columns
+      Iterator<String> bucketCols = crtTblDesc.getBucketCols().iterator();
+      while (bucketCols.hasNext()) {
+        String bucketCol = bucketCols.next();
+        boolean found = false;
+        Iterator<String> colNamesIter = colNames.iterator();
+        while (colNamesIter.hasNext()) {
+          String colName = colNamesIter.next();
+          if (bucketCol.equalsIgnoreCase(colName)) {
+            found = true;
+            break;
+          }
+        }
+        if (!found)
+          throw new SemanticException(ErrorMsg.INVALID_COLUMN.getMsg());
+      }
+    }
+
+    if (crtTblDesc.getSortCols() != null)
+    {
+      // all columns in cluster and sort are valid columns
+      Iterator<Order> sortCols = crtTblDesc.getSortCols().iterator();
+      while (sortCols.hasNext()) {
+        String sortCol = sortCols.next().getCol();
+        boolean found = false;
+        Iterator<String> colNamesIter = colNames.iterator();
+        while (colNamesIter.hasNext()) {
+          String colName = colNamesIter.next();
+          if (sortCol.equalsIgnoreCase(colName)) {
+            found = true;
+            break;
+          }
+        }
+        if (!found)
+          throw new SemanticException(ErrorMsg.INVALID_COLUMN.getMsg());
+      }
+    }
+    
+    if (crtTblDesc.getPartCols() != null)
+    {
+      // there is no overlap between columns and partitioning columns
+      Iterator<FieldSchema> partColsIter = crtTblDesc.getPartCols().iterator();
+      while (partColsIter.hasNext()) {
+        String partCol = partColsIter.next().getName();
+        Iterator<String> colNamesIter = colNames.iterator();
+        while (colNamesIter.hasNext()) {
+          String colName = unescapeIdentifier(colNamesIter.next());
+          if (partCol.equalsIgnoreCase(colName)) 
+            throw new SemanticException(ErrorMsg.COLUMN_REPEATED_IN_PARTITIONING_COLS.getMsg());
+        }
+      }
+    }
+  }
 }

Modified: hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzerFactory.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzerFactory.java?rev=820771&r1=820770&r2=820771&view=diff
==============================================================================
--- hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzerFactory.java (original)
+++ hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzerFactory.java Thu Oct  1 20:06:57 2009
@@ -62,8 +62,7 @@
       switch (tree.getToken().getType()) {
       case HiveParser.TOK_EXPLAIN: return new ExplainSemanticAnalyzer(conf);
       case HiveParser.TOK_LOAD: return new LoadSemanticAnalyzer(conf);
-      case HiveParser.TOK_CREATETABLE:
-      case HiveParser.TOK_DROPTABLE:
+      case HiveParser.TOK_DROPTABLE: 
       case HiveParser.TOK_DESCTABLE:
       case HiveParser.TOK_DESCFUNCTION:
       case HiveParser.TOK_MSCK:

Modified: hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/plan/PlanUtils.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/plan/PlanUtils.java?rev=820771&r1=820770&r2=820771&view=diff
==============================================================================
--- hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/plan/PlanUtils.java (original)
+++ hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/plan/PlanUtils.java Thu Oct  1 20:06:57 2009
@@ -38,9 +38,15 @@
 import org.apache.hadoop.mapred.SequenceFileOutputFormat;
 import org.apache.hadoop.mapred.TextInputFormat;
 import org.apache.hadoop.hive.serde2.Deserializer;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.hadoop.mapred.InputFormat;
+import org.apache.hadoop.hive.ql.io.HiveOutputFormat;
 
 public class PlanUtils {
-
+  
+  protected final static Log LOG = LogFactory.getLog("org.apache.hadoop.hive.ql.plan.PlanUtils");
+  
   public static enum ExpressionTypes {FIELD, JEXL};
 
   @SuppressWarnings("nls")
@@ -141,6 +147,42 @@
       properties);    
   }
   
+  /**
+   * Generate a table descriptor from a createTableDesc.
+   */
+  public static tableDesc getTableDesc(createTableDesc crtTblDesc, String cols, String colTypes) {
+    
+    Class<? extends Deserializer> serdeClass = LazySimpleSerDe.class;
+    String separatorCode                     = Integer.toString(Utilities.ctrlaCode);
+    String columns                           = cols;
+    String columnTypes                       = colTypes;
+    boolean lastColumnTakesRestOfTheLine     = false;
+    tableDesc ret;
+
+    try {
+      if ( crtTblDesc.getSerName() != null ) {
+        Class c = Class.forName(crtTblDesc.getSerName());
+        serdeClass = c;
+      }
+    
+      ret = getTableDesc(serdeClass, separatorCode, columns, columnTypes, 
+                                   lastColumnTakesRestOfTheLine, false);
+      
+      // replace the default input & output file format with those found in crtTblDesc
+      Class c1 = Class.forName(crtTblDesc.getInputFormat());
+      Class c2 = Class.forName(crtTblDesc.getOutputFormat());
+      Class<? extends InputFormat>      in_class  = c1;
+      Class<? extends HiveOutputFormat> out_class = c2;
+    
+      ret.setInputFileFormatClass(in_class);
+      ret.setOutputFileFormatClass(out_class);
+    } catch (ClassNotFoundException e) {
+      e.printStackTrace();
+      return null;
+    }
+    return ret;
+  }
+  
   /** 
    * Generate the table descriptor of MetadataTypedColumnsetSerDe with the separatorCode.
    * MetaDataTypedColumnsetSerDe is used because LazySimpleSerDe does not support a table
@@ -382,6 +424,7 @@
     return getReduceSinkDesc(keyCols, valueCols, outputColumnNames, includeKey, tag, partitionCols, order.toString(),
          numReducers);
   }
+  
 
 }
   

Added: hadoop/hive/trunk/ql/src/test/queries/clientnegative/ctas.q
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/ql/src/test/queries/clientnegative/ctas.q?rev=820771&view=auto
==============================================================================
--- hadoop/hive/trunk/ql/src/test/queries/clientnegative/ctas.q (added)
+++ hadoop/hive/trunk/ql/src/test/queries/clientnegative/ctas.q Thu Oct  1 20:06:57 2009
@@ -0,0 +1,5 @@
+drop table nzhang_ctas4;
+
+create external table nzhang_ctas4 as select key, value from src;
+
+drop table nzhang_ctas4;

Added: hadoop/hive/trunk/ql/src/test/queries/clientpositive/ctas.q
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/ql/src/test/queries/clientpositive/ctas.q?rev=820771&view=auto
==============================================================================
--- hadoop/hive/trunk/ql/src/test/queries/clientpositive/ctas.q (added)
+++ hadoop/hive/trunk/ql/src/test/queries/clientpositive/ctas.q Thu Oct  1 20:06:57 2009
@@ -0,0 +1,34 @@
+drop table nzhang_ctas1;
+drop table nzhang_ctas2;
+drop table nzhang_ctas3;
+
+explain create table nzhang_ctas1 as select key k, value from src sort by k, value limit 10;
+
+create table nzhang_ctas1 as select key k, value from src sort by k, value limit 10;
+
+select * from nzhang_ctas1;
+
+
+explain create table nzhang_ctas2 as select * from src sort by key, value limit 10;
+
+create table nzhang_ctas2 as select * from src sort by key, value limit 10;
+
+select * from nzhang_ctas2;
+
+
+explain create table nzhang_ctas3 row format serde "org.apache.hadoop.hive.serde2.columnar.ColumnarSerDe" stored as RCFile as select key/2 half_key, concat(value, "_con") conb  from src sort by half_key, conb limit 10;
+
+create table nzhang_ctas3 row format serde "org.apache.hadoop.hive.serde2.columnar.ColumnarSerDe" stored as RCFile as select key/2 half_key, concat(value, "_con") conb  from src sort by half_key, conb limit 10;
+
+select * from nzhang_ctas3;
+
+
+explain create table if not exists nzhang_ctas3 as select key, value from src sort by key, value limit 2;
+
+create table if not exists nzhang_ctas3 as select key, value from src sort by key, value limit 2;
+
+select * from nzhang_ctas3;
+
+drop table nzhang_ctas1;
+drop table nzhang_ctas2;
+drop table nzhang_ctas3;

Added: hadoop/hive/trunk/ql/src/test/results/clientnegative/ctas.q.out
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/ql/src/test/results/clientnegative/ctas.q.out?rev=820771&view=auto
==============================================================================
--- hadoop/hive/trunk/ql/src/test/results/clientnegative/ctas.q.out (added)
+++ hadoop/hive/trunk/ql/src/test/results/clientnegative/ctas.q.out Thu Oct  1 20:06:57 2009
@@ -0,0 +1,5 @@
+PREHOOK: query: drop table nzhang_ctas4
+PREHOOK: type: DROPTABLE
+POSTHOOK: query: drop table nzhang_ctas4
+POSTHOOK: type: DROPTABLE
+FAILED: Error in semantic analysis: CREATE-TABLE-AS-SELECT cannot create external table.

Modified: hadoop/hive/trunk/ql/src/test/results/clientpositive/create_1.q.out
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/ql/src/test/results/clientpositive/create_1.q.out?rev=820771&r1=820770&r2=820771&view=diff
==============================================================================
--- hadoop/hive/trunk/ql/src/test/results/clientpositive/create_1.q.out (original)
+++ hadoop/hive/trunk/ql/src/test/results/clientpositive/create_1.q.out Thu Oct  1 20:06:57 2009
@@ -28,12 +28,11 @@
 a	string	
 b	string	
 	 	 
-Detailed Table Information	Table(tableName:table1, dbName:default, owner:njain, createTime:1253779809, lastAccessTime:0, retention:0, sd:StorageDescriptor(cols:[FieldSchema(name:a, type:string, comment:null), FieldSchema(name:b, type:string, comment:null)], location:file:/data/users/njain/hive5/hive5/build/ql/test/data/warehouse/table1, inputFormat:org.apache.hadoop.mapred.TextInputFormat, outputFormat:org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat, compressed:false, numBuckets:-1, serdeInfo:SerDeInfo(name:null, serializationLib:org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe, parameters:{serialization.format=1}), bucketCols:[], sortCols:[], parameters:{}), partitionKeys:[], parameters:{})	
+Detailed Table Information	Table(tableName:table1, dbName:default, owner:nzhang, createTime:1254242350, lastAccessTime:0, retention:0, sd:StorageDescriptor(cols:[FieldSchema(name:a, type:string, comment:null), FieldSchema(name:b, type:string, comment:null)], location:file:/data/users/nzhang/work/31/apache-hive-trunk/build/ql/test/data/warehouse/table1, inputFormat:org.apache.hadoop.mapred.TextInputFormat, outputFormat:org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat, compressed:false, numBuckets:-1, serdeInfo:SerDeInfo(name:null, serializationLib:org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe, parameters:{serialization.format=1}), bucketCols:[], sortCols:[], parameters:{}), partitionKeys:[], parameters:{})	
 PREHOOK: query: CREATE TABLE IF NOT EXISTS table1 (a STRING, b STRING) STORED AS TEXTFILE
 PREHOOK: type: CREATETABLE
 POSTHOOK: query: CREATE TABLE IF NOT EXISTS table1 (a STRING, b STRING) STORED AS TEXTFILE
 POSTHOOK: type: CREATETABLE
-POSTHOOK: Output: default@table1
 PREHOOK: query: CREATE TABLE IF NOT EXISTS table2 (a STRING, b INT) STORED AS TEXTFILE
 PREHOOK: type: CREATETABLE
 POSTHOOK: query: CREATE TABLE IF NOT EXISTS table2 (a STRING, b INT) STORED AS TEXTFILE
@@ -52,7 +51,7 @@
 a	string	
 b	int	
 	 	 
-Detailed Table Information	Table(tableName:table2, dbName:default, owner:njain, createTime:1253779809, lastAccessTime:0, retention:0, sd:StorageDescriptor(cols:[FieldSchema(name:a, type:string, comment:null), FieldSchema(name:b, type:int, comment:null)], location:file:/data/users/njain/hive5/hive5/build/ql/test/data/warehouse/table2, inputFormat:org.apache.hadoop.mapred.TextInputFormat, outputFormat:org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat, compressed:false, numBuckets:-1, serdeInfo:SerDeInfo(name:null, serializationLib:org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe, parameters:{serialization.format=1}), bucketCols:[], sortCols:[], parameters:{}), partitionKeys:[], parameters:{})	
+Detailed Table Information	Table(tableName:table2, dbName:default, owner:nzhang, createTime:1254242351, lastAccessTime:0, retention:0, sd:StorageDescriptor(cols:[FieldSchema(name:a, type:string, comment:null), FieldSchema(name:b, type:int, comment:null)], location:file:/data/users/nzhang/work/31/apache-hive-trunk/build/ql/test/data/warehouse/table2, inputFormat:org.apache.hadoop.mapred.TextInputFormat, outputFormat:org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat, compressed:false, numBuckets:-1, serdeInfo:SerDeInfo(name:null, serializationLib:org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe, parameters:{serialization.format=1}), bucketCols:[], sortCols:[], parameters:{}), partitionKeys:[], parameters:{})	
 PREHOOK: query: CREATE TABLE table3 (a STRING, b STRING)
 ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t'
 STORED AS TEXTFILE
@@ -75,7 +74,7 @@
 a	string	
 b	string	
 	 	 
-Detailed Table Information	Table(tableName:table3, dbName:default, owner:njain, createTime:1253779810, lastAccessTime:0, retention:0, sd:StorageDescriptor(cols:[FieldSchema(name:a, type:string, comment:null), FieldSchema(name:b, type:string, comment:null)], location:file:/data/users/njain/hive5/hive5/build/ql/test/data/warehouse/table3, inputFormat:org.apache.hadoop.mapred.TextInputFormat, outputFormat:org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat, compressed:false, numBuckets:-1, serdeInfo:SerDeInfo(name:null, serializationLib:org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe, parameters:{serialization.format=9,field.delim=	}), bucketCols:[], sortCols:[], parameters:{}), partitionKeys:[], parameters:{})
+Detailed Table Information	Table(tableName:table3, dbName:default, owner:nzhang, createTime:1254242351, lastAccessTime:0, retention:0, sd:StorageDescriptor(cols:[FieldSchema(name:a, type:string, comment:null), FieldSchema(name:b, type:string, comment:null)], location:file:/data/users/nzhang/work/31/apache-hive-trunk/build/ql/test/data/warehouse/table3, inputFormat:org.apache.hadoop.mapred.TextInputFormat, outputFormat:org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat, compressed:false, numBuckets:-1, serdeInfo:SerDeInfo(name:null, serializationLib:org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe, parameters:{serialization.format=9,field.delim=	}), bucketCols:[], sortCols:[], parameters:{}), partitionKeys:[], parameters:{})
 PREHOOK: query: DROP TABLE table1
 PREHOOK: type: DROPTABLE
 POSTHOOK: query: DROP TABLE table1

Modified: hadoop/hive/trunk/ql/src/test/results/clientpositive/create_like.q.out
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/ql/src/test/results/clientpositive/create_like.q.out?rev=820771&r1=820770&r2=820771&view=diff
==============================================================================
--- hadoop/hive/trunk/ql/src/test/results/clientpositive/create_like.q.out (original)
+++ hadoop/hive/trunk/ql/src/test/results/clientpositive/create_like.q.out Thu Oct  1 20:06:57 2009
@@ -28,7 +28,7 @@
 a	string	
 b	string	
 	 	 
-Detailed Table Information	Table(tableName:table1, dbName:default, owner:njain, createTime:1253779841, lastAccessTime:0, retention:0, sd:StorageDescriptor(cols:[FieldSchema(name:a, type:string, comment:null), FieldSchema(name:b, type:string, comment:null)], location:file:/data/users/njain/hive5/hive5/build/ql/test/data/warehouse/table1, inputFormat:org.apache.hadoop.mapred.TextInputFormat, outputFormat:org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat, compressed:false, numBuckets:-1, serdeInfo:SerDeInfo(name:null, serializationLib:org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe, parameters:{serialization.format=1}), bucketCols:[], sortCols:[], parameters:{}), partitionKeys:[], parameters:{})	
+Detailed Table Information	Table(tableName:table1, dbName:default, owner:nzhang, createTime:1254243861, lastAccessTime:0, retention:0, sd:StorageDescriptor(cols:[FieldSchema(name:a, type:string, comment:null), FieldSchema(name:b, type:string, comment:null)], location:file:/data/users/nzhang/work/31/apache-hive-trunk/build/ql/test/data/warehouse/table1, inputFormat:org.apache.hadoop.mapred.TextInputFormat, outputFormat:org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat, compressed:false, numBuckets:-1, serdeInfo:SerDeInfo(name:null, serializationLib:org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe, parameters:{serialization.format=1}), bucketCols:[], sortCols:[], parameters:{}), partitionKeys:[], parameters:{})	
 PREHOOK: query: CREATE TABLE table2 LIKE table1
 PREHOOK: type: CREATETABLE
 POSTHOOK: query: CREATE TABLE table2 LIKE table1
@@ -47,17 +47,15 @@
 a	string	
 b	string	
 	 	 
-Detailed Table Information	Table(tableName:table2, dbName:default, owner:njain, createTime:1253779841, lastAccessTime:0, retention:0, sd:StorageDescriptor(cols:[FieldSchema(name:a, type:string, comment:null), FieldSchema(name:b, type:string, comment:null)], location:file:/data/users/njain/hive5/hive5/build/ql/test/data/warehouse/table2, inputFormat:org.apache.hadoop.mapred.TextInputFormat, outputFormat:org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat, compressed:false, numBuckets:-1, serdeInfo:SerDeInfo(name:null, serializationLib:org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe, parameters:{serialization.format=1}), bucketCols:[], sortCols:[], parameters:{}), partitionKeys:[], parameters:{EXTERNAL=FALSE})	
+Detailed Table Information	Table(tableName:table2, dbName:default, owner:nzhang, createTime:1254243861, lastAccessTime:0, retention:0, sd:StorageDescriptor(cols:[FieldSchema(name:a, type:string, comment:null), FieldSchema(name:b, type:string, comment:null)], location:file:/data/users/nzhang/work/31/apache-hive-trunk/build/ql/test/data/warehouse/table2, inputFormat:org.apache.hadoop.mapred.TextInputFormat, outputFormat:org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat, compressed:false, numBuckets:-1, serdeInfo:SerDeInfo(name:null, serializationLib:org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe, parameters:{serialization.format=1}), bucketCols:[], sortCols:[], parameters:{}), partitionKeys:[], parameters:{EXTERNAL=FALSE})	
 PREHOOK: query: CREATE TABLE IF NOT EXISTS table2 LIKE table1
 PREHOOK: type: CREATETABLE
 POSTHOOK: query: CREATE TABLE IF NOT EXISTS table2 LIKE table1
 POSTHOOK: type: CREATETABLE
-POSTHOOK: Output: default@table2
 PREHOOK: query: CREATE EXTERNAL TABLE IF NOT EXISTS table2 LIKE table1
 PREHOOK: type: CREATETABLE
 POSTHOOK: query: CREATE EXTERNAL TABLE IF NOT EXISTS table2 LIKE table1
 POSTHOOK: type: CREATETABLE
-POSTHOOK: Output: default@table2
 PREHOOK: query: CREATE EXTERNAL TABLE IF NOT EXISTS table3 LIKE table1
 PREHOOK: type: CREATETABLE
 POSTHOOK: query: CREATE EXTERNAL TABLE IF NOT EXISTS table3 LIKE table1
@@ -76,7 +74,7 @@
 a	string	
 b	string	
 	 	 
-Detailed Table Information	Table(tableName:table3, dbName:default, owner:njain, createTime:1253779841, lastAccessTime:0, retention:0, sd:StorageDescriptor(cols:[FieldSchema(name:a, type:string, comment:null), FieldSchema(name:b, type:string, comment:null)], location:file:/data/users/njain/hive5/hive5/build/ql/test/data/warehouse/table3, inputFormat:org.apache.hadoop.mapred.TextInputFormat, outputFormat:org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat, compressed:false, numBuckets:-1, serdeInfo:SerDeInfo(name:null, serializationLib:org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe, parameters:{serialization.format=1}), bucketCols:[], sortCols:[], parameters:{}), partitionKeys:[], parameters:{EXTERNAL=TRUE})	
+Detailed Table Information	Table(tableName:table3, dbName:default, owner:nzhang, createTime:1254243861, lastAccessTime:0, retention:0, sd:StorageDescriptor(cols:[FieldSchema(name:a, type:string, comment:null), FieldSchema(name:b, type:string, comment:null)], location:file:/data/users/nzhang/work/31/apache-hive-trunk/build/ql/test/data/warehouse/table3, inputFormat:org.apache.hadoop.mapred.TextInputFormat, outputFormat:org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat, compressed:false, numBuckets:-1, serdeInfo:SerDeInfo(name:null, serializationLib:org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe, parameters:{serialization.format=1}), bucketCols:[], sortCols:[], parameters:{}), partitionKeys:[], parameters:{EXTERNAL=TRUE})	
 PREHOOK: query: INSERT OVERWRITE TABLE table1 SELECT key, value FROM src WHERE key = 86
 PREHOOK: type: QUERY
 PREHOOK: Input: default@src
@@ -96,20 +94,20 @@
 PREHOOK: query: SELECT * FROM table1
 PREHOOK: type: QUERY
 PREHOOK: Input: default@table1
-PREHOOK: Output: file:/data/users/njain/hive5/hive5/build/ql/tmp/20199794/10000
+PREHOOK: Output: file:/data/users/nzhang/work/31/apache-hive-trunk/build/ql/tmp/1104038861/10000
 POSTHOOK: query: SELECT * FROM table1
 POSTHOOK: type: QUERY
 POSTHOOK: Input: default@table1
-POSTHOOK: Output: file:/data/users/njain/hive5/hive5/build/ql/tmp/20199794/10000
+POSTHOOK: Output: file:/data/users/nzhang/work/31/apache-hive-trunk/build/ql/tmp/1104038861/10000
 86	val_86
 PREHOOK: query: SELECT * FROM table2
 PREHOOK: type: QUERY
 PREHOOK: Input: default@table2
-PREHOOK: Output: file:/data/users/njain/hive5/hive5/build/ql/tmp/1027337637/10000
+PREHOOK: Output: file:/data/users/nzhang/work/31/apache-hive-trunk/build/ql/tmp/1673347492/10000
 POSTHOOK: query: SELECT * FROM table2
 POSTHOOK: type: QUERY
 POSTHOOK: Input: default@table2
-POSTHOOK: Output: file:/data/users/njain/hive5/hive5/build/ql/tmp/1027337637/10000
+POSTHOOK: Output: file:/data/users/nzhang/work/31/apache-hive-trunk/build/ql/tmp/1673347492/10000
 100	val_100
 100	val_100
 PREHOOK: query: DROP TABLE table1



Mime
View raw message