Index: ql/src/java/org/apache/hadoop/hive/ql/parse/HiveParser.g =================================================================== --- ql/src/java/org/apache/hadoop/hive/ql/parse/HiveParser.g (revision 1460536) +++ ql/src/java/org/apache/hadoop/hive/ql/parse/HiveParser.g (working copy) @@ -1857,7 +1857,7 @@ @init { msgs.push("destination specification"); } @after { msgs.pop(); } : - KW_LOCAL KW_DIRECTORY StringLiteral -> ^(TOK_LOCAL_DIR StringLiteral) + KW_LOCAL KW_DIRECTORY StringLiteral tableRowFormat? -> ^(TOK_LOCAL_DIR StringLiteral tableRowFormat?) | KW_DIRECTORY StringLiteral -> ^(TOK_DIR StringLiteral) | KW_TABLE tableOrPartition -> tableOrPartition ; Index: ql/src/java/org/apache/hadoop/hive/ql/parse/QB.java =================================================================== --- ql/src/java/org/apache/hadoop/hive/ql/parse/QB.java (revision 1460536) +++ ql/src/java/org/apache/hadoop/hive/ql/parse/QB.java (working copy) @@ -27,6 +27,7 @@ import org.apache.commons.logging.LogFactory; import org.apache.hadoop.hive.ql.metadata.Table; import org.apache.hadoop.hive.ql.plan.CreateTableDesc; +import org.apache.hadoop.hive.ql.plan.LoadFileDesc; /** * Implementation of the query block. @@ -51,6 +52,7 @@ private boolean isQuery; private boolean isAnalyzeRewrite; private CreateTableDesc tblDesc = null; // table descriptor of the final + private LoadFileDesc loadFileDesc = null ; // results @@ -215,6 +217,14 @@ tblDesc = desc; } + public LoadFileDesc getLoadFileDesc() { + return loadFileDesc; + } + + public void setLoadFileDesc(LoadFileDesc loadFileDesc) { + this.loadFileDesc = loadFileDesc; + } + /** * Whether this QB is for a CREATE-TABLE-AS-SELECT. */ Index: ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java =================================================================== --- ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java (revision 1460536) +++ ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java (working copy) @@ -1087,6 +1087,8 @@ } } + RowFormatParams rowFormatParams = new RowFormatParams(); + AnalyzeCreateCommonVars shared = new AnalyzeCreateCommonVars(); LOG.info("Get metadata for destination tables"); // Go over all the destination structures and populate the related // metadata @@ -1174,6 +1176,16 @@ } qb.getMetaData().setDestForAlias(name, fname, (ast.getToken().getType() == HiveParser.TOK_DIR)); + if (ast.getChild(1) != null && ast.getChild(1).getType() == HiveParser.TOK_TABLEROWFORMAT) { + rowFormatParams.analyzeRowFormat(shared, (ASTNode)ast.getChild(1)); + LoadFileDesc loadFileDesc = new LoadFileDesc(); + loadFileDesc.setFieldDelim(rowFormatParams.fieldDelim); + loadFileDesc.setLineDelim(rowFormatParams.lineDelim); + loadFileDesc.setCollItemDelim(rowFormatParams.collItemDelim); + loadFileDesc.setMapKeyDelim(rowFormatParams.mapKeyDelim); + loadFileDesc.setFieldEscape(rowFormatParams.fieldEscape); + qb.setLoadFileDesc(loadFileDesc); + } break; } default: @@ -5056,8 +5068,7 @@ String fileFormat = HiveConf.getVar(conf, HiveConf.ConfVars.HIVEQUERYRESULTFILEFORMAT); table_desc = PlanUtils.getDefaultQueryOutputTableDesc(cols, colTypes, fileFormat); } else { - table_desc = PlanUtils.getDefaultTableDesc(Integer - .toString(Utilities.ctrlaCode), cols, colTypes, false); + table_desc = PlanUtils.getDefaultTableDesc(qb.getLoadFileDesc(), cols, colTypes); } } else { table_desc = PlanUtils.getTableDesc(tblDesc, cols, colTypes); Index: ql/src/java/org/apache/hadoop/hive/ql/plan/LoadFileDesc.java =================================================================== --- ql/src/java/org/apache/hadoop/hive/ql/plan/LoadFileDesc.java (revision 1460536) +++ ql/src/java/org/apache/hadoop/hive/ql/plan/LoadFileDesc.java (working copy) @@ -20,6 +20,8 @@ import java.io.Serializable; +import org.apache.hadoop.hive.ql.exec.Utilities; + /** * LoadFileDesc. * @@ -32,6 +34,11 @@ private String columns; private String columnTypes; private String destinationCreateTable; + private String fieldDelim = Integer.toString(Utilities.ctrlaCode); + private String fieldEscape; + private String collItemDelim; + private String mapKeyDelim; + private String lineDelim; public LoadFileDesc() { } @@ -112,4 +119,52 @@ public String getDestinationCreateTable(){ return destinationCreateTable; } + + public String getFieldEscape() { + return fieldEscape; + } + + public void setFieldEscape(String fieldEscape) { + this.fieldEscape = fieldEscape; + } + + public String getMapKeyDelim() { + return mapKeyDelim; + } + + public void setMapKeyDelim(String mapKeyDelim) { + this.mapKeyDelim = mapKeyDelim; + } + + public String getLineDelim() { + return lineDelim; + } + + public void setLineDelim(String lineDelim) { + this.lineDelim = lineDelim; + } + + public String getFieldDelim() { + return fieldDelim; + } + + public void setDfsDir(boolean isDfsDir) { + this.isDfsDir = isDfsDir; + } + + public void setDestinationCreateTable(String destinationCreateTable) { + this.destinationCreateTable = destinationCreateTable; + } + + public void setFieldDelim(String fieldDelim) { + this.fieldDelim = fieldDelim; + } + + public String getCollItemDelim() { + return collItemDelim; + } + + public void setCollItemDelim(String collItemDelim) { + this.collItemDelim = collItemDelim; + } } Index: ql/src/java/org/apache/hadoop/hive/ql/plan/PlanUtils.java =================================================================== --- ql/src/java/org/apache/hadoop/hive/ql/plan/PlanUtils.java (revision 1460536) +++ ql/src/java/org/apache/hadoop/hive/ql/plan/PlanUtils.java (working copy) @@ -99,6 +99,31 @@ } } + public static TableDesc getDefaultTableDesc(LoadFileDesc loadFileDesc, String cols, String colTypes ) { + TableDesc tableDesc = getDefaultTableDesc(Integer.toString(Utilities.ctrlaCode), cols, + colTypes, false);; + if (loadFileDesc == null) { + return tableDesc; + } + if (loadFileDesc.getFieldDelim() != null) { + tableDesc.getProperties().setProperty(serdeConstants.FIELD_DELIM, loadFileDesc.getFieldDelim()); + tableDesc.getProperties().setProperty(serdeConstants.SERIALIZATION_FORMAT, loadFileDesc.getFieldDelim()); + } + if (loadFileDesc.getLineDelim() != null) { + tableDesc.getProperties().setProperty(serdeConstants.LINE_DELIM, loadFileDesc.getLineDelim()); + } + if (loadFileDesc.getCollItemDelim() != null) { + tableDesc.getProperties().setProperty(serdeConstants.COLLECTION_DELIM, loadFileDesc.getCollItemDelim()); + } + if (loadFileDesc.getMapKeyDelim() != null) { + tableDesc.getProperties().setProperty(serdeConstants.MAPKEY_DELIM, loadFileDesc.getMapKeyDelim()); + } + if (loadFileDesc.getFieldEscape() !=null) { + tableDesc.getProperties().setProperty(serdeConstants.ESCAPE_CHAR, loadFileDesc.getFieldEscape()); + } + return tableDesc; + } + /** * Generate the table descriptor of MetadataTypedColumnsetSerDe with the * separatorCode and column names (comma separated string).