use of com.sap.hadoop.windowing.query2.definition.SelectDef in project SQLWindowing by hbutani.
the class QueryDefWalker method walk.
/**
* Visit all the columns in the select list
* to setup their OIs and evaluators
* @param select
* @throws WindowingException
*/
protected void walk(SelectDef select) throws WindowingException {
ArrayList<ColumnDef> cols = select.getColumns();
if (cols != null) {
for (ColumnDef col : cols) {
visitor.visit(col);
}
}
visitor.visit(select);
}
use of com.sap.hadoop.windowing.query2.definition.SelectDef 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.SelectDef in project SQLWindowing by hbutani.
the class OutputTranslation method translateSelectExprs.
public static void translateSelectExprs(QueryDef qDef) throws WindowingException {
QueryTranslationInfo tInfo = qDef.getTranslationInfo();
QueryInputDef iDef = qDef.getInput();
InputInfo iInfo = tInfo.getInputInfo(iDef);
SelectDef selectDef = qDef.getSelectList();
SelectSpec selectSpec = qDef.getSpec().getSelectList();
Iterator<Object> selectExprsAndAliases = selectSpec.getColumnListAndAlias();
int i = 0;
ColumnDef cDef = null;
while (selectExprsAndAliases.hasNext()) {
Object[] o = (Object[]) selectExprsAndAliases.next();
boolean isWnFn = ((Boolean) o[0]).booleanValue();
if (isWnFn) {
cDef = translateWindowFnAlias(qDef, iInfo, i++, (String) o[1]);
} else {
cDef = translateSelectExpr(qDef, iInfo, i++, (String) o[1], (ASTNode) o[2]);
}
selectDef.addColumn(cDef);
}
TranslateUtils.setupSelectOI(selectDef);
}
use of com.sap.hadoop.windowing.query2.definition.SelectDef in project SQLWindowing by hbutani.
the class TranslateUtils method setupSelectOI.
/**
* Use the column aliases and OIs on each ColumnDef
* to recreate the OI on the select list
* @param sDef
*/
public static void setupSelectOI(SelectDef sDef) {
ArrayList<ColumnDef> selColDefs = sDef.getColumns();
ArrayList<String> colAliases = new ArrayList<String>();
ArrayList<ObjectInspector> colOIs = new ArrayList<ObjectInspector>();
for (ColumnDef colDef : selColDefs) {
colAliases.add(colDef.getAlias());
colOIs.add(colDef.getOI());
}
sDef.setOI(ObjectInspectorFactory.getStandardStructObjectInspector(colAliases, colOIs));
}
Aggregations