return 1;
}
return 0;
}
descTableDesc descTbl = work.getDescTblDesc();
if (descTbl != null) {
// describe the table - populate the output stream
Table tbl = db.getTable(descTbl.getTableName(), false);
Partition part = null;
try {
if(tbl == null) {
DataOutput outStream = (DataOutput)fs.open(descTbl.getResFile());
String errMsg = "Table " + descTbl.getTableName() + " does not exist";
outStream.write(errMsg.getBytes("UTF-8"));
((FSDataOutputStream)outStream).close();
return 0;
}
if(descTbl.getPartSpec() != null) {
part = db.getPartition(tbl, descTbl.getPartSpec(), false);
if(part == null) {
DataOutput outStream = (DataOutput)fs.open(descTbl.getResFile());
String errMsg = "Partition " + descTbl.getPartSpec() + " for table " + descTbl.getTableName() + " does not exist";
outStream.write(errMsg.getBytes("UTF-8"));
((FSDataOutputStream)outStream).close();
return 0;
}
}
} catch (FileNotFoundException e) {
LOG.info("describe table: " + StringUtils.stringifyException(e));
return 1;
}
catch (IOException e) {
LOG.info("describe table: " + StringUtils.stringifyException(e));
return 1;
}
try {
LOG.info("DDLTask: got data for " + tbl.getName());
// write the results in the file
DataOutput os = (DataOutput)fs.create(descTbl.getResFile());
List<FieldSchema> cols = tbl.getCols();
if(part != null) {
cols = part.getTPartition().getSd().getCols();
}
Iterator<FieldSchema> iterCols = cols.iterator();
boolean firstCol = true;
while (iterCols.hasNext())
{
if (!firstCol)
os.write(terminator);
FieldSchema col = iterCols.next();
os.write(col.getName().getBytes("UTF-8"));
os.write(separator);
os.write(col.getType().getBytes("UTF-8"));
if (col.getComment() != null)
{
os.write(separator);
os.write(col.getComment().getBytes("UTF-8"));
}
firstCol = false;
}
// also return the partitioning columns
List<FieldSchema> partCols = tbl.getPartCols();
Iterator<FieldSchema> iterPartCols = partCols.iterator();
while (iterPartCols.hasNext())
{
os.write(terminator);
FieldSchema col = iterPartCols.next();
os.write(col.getName().getBytes("UTF-8"));
os.write(separator);
os.write(col.getType().getBytes("UTF-8"));
if (col.getComment() != null)
{
os.write(separator);
os.write(col.getComment().getBytes("UTF-8"));
}
}
// if extended desc table then show the complete details of the table
if(descTbl.isExt()) {
if(part != null) {
// show partition informatio
os.write("\n\nDetailed Partition Information:\n".getBytes("UTF-8"));
os.write(part.getTPartition().toString().getBytes("UTF-8"));
} else {