use of com.sap.hadoop.windowing.query2.definition.QueryOutputDef in project SQLWindowing by hbutani.
the class OutputTranslation method setupOutputSerDe.
@SuppressWarnings("unchecked")
public static void setupOutputSerDe(HiveConf hCfg, SelectDef selectDef, QueryOutputDef oDef) throws WindowingException {
String serDeClassName = oDef.getSpec().getSerDeClass();
Properties serDeProps = oDef.getSpec().getSerDeProps();
Class<? extends SerDe> serDeClass;
SerDe serde;
try {
serDeClass = (Class<? extends SerDe>) Class.forName(serDeClassName);
serde = serDeClass.newInstance();
} catch (Exception e) {
throw new WindowingException("Internal error, initializing output SerDe", e);
}
StringBuilder colNames = new StringBuilder();
StringBuilder colTypes = new StringBuilder();
boolean first = true;
for (ColumnDef cDef : selectDef.getColumns()) {
if (!first) {
colNames.append(",");
colTypes.append(",");
} else
first = false;
colNames.append(cDef.getAlias());
colTypes.append(TypeInfoUtils.getTypeInfoFromObjectInspector(cDef.getOI()).getTypeName());
}
serDeProps.setProperty(org.apache.hadoop.hive.serde.Constants.LIST_COLUMNS, colNames.toString());
serDeProps.setProperty(org.apache.hadoop.hive.serde.Constants.LIST_COLUMN_TYPES, colTypes.toString());
try {
serde.initialize(hCfg, serDeProps);
} catch (SerDeException se) {
throw new WindowingException("Failed to initialize output SerDe", se);
}
oDef.setSerDe(serde);
}
use of com.sap.hadoop.windowing.query2.definition.QueryOutputDef in project SQLWindowing by hbutani.
the class OutputTranslation method translate.
public static void translate(QueryDef qDef) throws WindowingException {
QueryTranslationInfo tInfo = qDef.getTranslationInfo();
translateSelectExprs(qDef);
validateOutputSpec(qDef);
QueryOutputDef oDef = new QueryOutputDef();
oDef.setOutputSpec(qDef.getSpec().getOutput());
qDef.setOutput(oDef);
setupOutputSerDe(tInfo.getHiveCfg(), qDef.getSelectList(), oDef);
}
use of com.sap.hadoop.windowing.query2.definition.QueryOutputDef in project SQLWindowing by hbutani.
the class MRExecutor method createOutputTableDesc.
/**
* Use the settings on the QueryOutputDef to define the
* properties for the output table in hive.
* @param qDef
* @return
* @throws WindowingException
*/
static TableDesc createOutputTableDesc(QueryDef qDef) throws WindowingException {
QueryOutputDef oDef = qDef.getOutput();
Class<? extends SerDe> serDeClass = oDef.getSerDe().getClass();
Properties p = oDef.getSpec().getSerDeProps();
String columnNamesList = p.getProperty(Constants.LIST_COLUMNS);
String columnTypesList = p.getProperty(Constants.LIST_COLUMN_TYPES);
String fieldSeparator = p.getProperty(Constants.FIELD_DELIM, Integer.toString(Utilities.ctrlaCode));
return PlanUtils.getTableDesc(serDeClass, fieldSeparator, columnNamesList, columnTypesList, false);
}
Aggregations