Search in sources :

Example 1 with WhereDef

use of com.sap.hadoop.windowing.query2.definition.WhereDef in project SQLWindowing by hbutani.

the class Executor method executeSelectList.

/**
 * For each row in the partition:
 * 1. evaluate the where condition if applicable.
 * 2. evaluate the value for each column retrieved
 *    from the select list
 * 3. Forward the writable value or object based on the
 * 	  implementation of the ForwardSink
 * @param qDef
 * @param oPart
 * @param rS
 * @throws WindowingException
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
public static void executeSelectList(QueryDef qDef, Partition oPart, ForwardSink rS) throws WindowingException {
    ArrayList<ColumnDef> cols = qDef.getSelectList().getColumns();
    ObjectInspector selectOI = qDef.getSelectList().getOI();
    SerDe oSerDe = qDef.getOutput().getSerDe();
    Object[] output = new Object[cols.size()];
    WhereDef whDef = qDef.getWhere();
    boolean applyWhere = whDef != null;
    Converter whConverter = !applyWhere ? null : ObjectInspectorConverters.getConverter(whDef.getOI(), PrimitiveObjectInspectorFactory.javaBooleanObjectInspector);
    ExprNodeEvaluator whCondEval = !applyWhere ? null : whDef.getExprEvaluator();
    Writable value = null;
    PartitionIterator<Object> pItr = oPart.iterator();
    RuntimeUtils.connectLeadLagFunctionsToPartition(qDef, pItr);
    while (pItr.hasNext()) {
        int colCnt = 0;
        ArrayList selectList = new ArrayList();
        Object oRow = pItr.next();
        if (applyWhere) {
            Object whCond = null;
            try {
                whCond = whCondEval.evaluate(oRow);
                whCond = whConverter.convert(whCond);
            } catch (HiveException he) {
                throw new WindowingException(he);
            }
            if (whCond == null || !((Boolean) whCond).booleanValue()) {
                continue;
            }
        }
        for (ColumnDef cDef : cols) {
            try {
                Object newCol = cDef.getExprEvaluator().evaluate(oRow);
                output[colCnt++] = newCol;
                selectList.add(newCol);
            } catch (HiveException he) {
                throw new WindowingException(he);
            }
        }
        // else collect the writable key-value pairs for outstream
        if (rS.acceptObject()) {
            rS.collectOutput(output);
        } else {
            try {
                value = oSerDe.serialize(selectList, selectOI);
            } catch (SerDeException se) {
                throw new WindowingException(se);
            }
            rS.collectOutput(NullWritable.get(), value);
        }
    }
}
Also used : SerDe(org.apache.hadoop.hive.serde2.SerDe) ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) WhereDef(com.sap.hadoop.windowing.query2.definition.WhereDef) HiveException(org.apache.hadoop.hive.ql.metadata.HiveException) ExprNodeEvaluator(org.apache.hadoop.hive.ql.exec.ExprNodeEvaluator) ArrayList(java.util.ArrayList) ColumnDef(com.sap.hadoop.windowing.query2.definition.ColumnDef) NullWritable(org.apache.hadoop.io.NullWritable) Writable(org.apache.hadoop.io.Writable) WindowingException(com.sap.hadoop.windowing.WindowingException) Converter(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorConverters.Converter) SerDeException(org.apache.hadoop.hive.serde2.SerDeException)

Example 2 with WhereDef

use of com.sap.hadoop.windowing.query2.definition.WhereDef in project SQLWindowing by hbutani.

the class WhereTranslation method translate.

public static void translate(QueryDef qDef) throws WindowingException {
    QueryTranslationInfo tInfo = qDef.getTranslationInfo();
    QuerySpec spec = qDef.getSpec();
    ASTNode wExpr = spec.getWhereExpr();
    if (wExpr == null)
        return;
    WhereDef whDef = new WhereDef();
    whDef.setExpression(wExpr);
    QueryInputDef iDef = qDef.getInput();
    InputInfo iInfo = tInfo.getInputInfo(iDef);
    ExprNodeDesc exprNode = TranslateUtils.buildExprNode(wExpr, iInfo.getTypeCheckCtx());
    ExprNodeEvaluator exprEval = WindowingExprNodeEvaluatorFactory.get(tInfo, exprNode);
    ObjectInspector oi = TranslateUtils.initExprNodeEvaluator(qDef, exprNode, exprEval, iInfo);
    try {
        ObjectInspectorConverters.getConverter(oi, PrimitiveObjectInspectorFactory.javaBooleanObjectInspector);
    } catch (Throwable t) {
        throw new WindowingException("Where Expr must be convertible to a boolean value", t);
    }
    whDef.setExprNode(exprNode);
    whDef.setExprEvaluator(exprEval);
    whDef.setOI(oi);
    qDef.setWhere(whDef);
}
Also used : ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) WhereDef(com.sap.hadoop.windowing.query2.definition.WhereDef) InputInfo(com.sap.hadoop.windowing.query2.translate.QueryTranslationInfo.InputInfo) QueryInputDef(com.sap.hadoop.windowing.query2.definition.QueryInputDef) ASTNode(org.apache.hadoop.hive.ql.parse.ASTNode) ExprNodeEvaluator(org.apache.hadoop.hive.ql.exec.ExprNodeEvaluator) WindowingException(com.sap.hadoop.windowing.WindowingException) ExprNodeDesc(org.apache.hadoop.hive.ql.plan.ExprNodeDesc) QuerySpec(com.sap.hadoop.windowing.query2.specification.QuerySpec)

Aggregations

WindowingException (com.sap.hadoop.windowing.WindowingException)2 WhereDef (com.sap.hadoop.windowing.query2.definition.WhereDef)2 ExprNodeEvaluator (org.apache.hadoop.hive.ql.exec.ExprNodeEvaluator)2 ObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)2 ColumnDef (com.sap.hadoop.windowing.query2.definition.ColumnDef)1 QueryInputDef (com.sap.hadoop.windowing.query2.definition.QueryInputDef)1 QuerySpec (com.sap.hadoop.windowing.query2.specification.QuerySpec)1 InputInfo (com.sap.hadoop.windowing.query2.translate.QueryTranslationInfo.InputInfo)1 ArrayList (java.util.ArrayList)1 HiveException (org.apache.hadoop.hive.ql.metadata.HiveException)1 ASTNode (org.apache.hadoop.hive.ql.parse.ASTNode)1 ExprNodeDesc (org.apache.hadoop.hive.ql.plan.ExprNodeDesc)1 SerDe (org.apache.hadoop.hive.serde2.SerDe)1 SerDeException (org.apache.hadoop.hive.serde2.SerDeException)1 Converter (org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorConverters.Converter)1 NullWritable (org.apache.hadoop.io.NullWritable)1 Writable (org.apache.hadoop.io.Writable)1