Search in sources :

Example 21 with ExprNodeEvaluator

use of org.apache.hadoop.hive.ql.exec.ExprNodeEvaluator in project hive by apache.

the class DynamicValueRegistryTez method init.

@Override
public void init(RegistryConf conf) throws Exception {
    RegistryConfTez rct = (RegistryConfTez) conf;
    for (String inputSourceName : rct.baseWork.getInputSourceToRuntimeValuesInfo().keySet()) {
        LOG.info("Runtime value source: " + inputSourceName);
        LogicalInput runtimeValueInput = rct.inputs.get(inputSourceName);
        RuntimeValuesInfo runtimeValuesInfo = rct.baseWork.getInputSourceToRuntimeValuesInfo().get(inputSourceName);
        // Setup deserializer/obj inspectors for the incoming data source
        Deserializer deserializer = ReflectionUtils.newInstance(runtimeValuesInfo.getTableDesc().getDeserializerClass(), null);
        deserializer.initialize(rct.conf, runtimeValuesInfo.getTableDesc().getProperties());
        ObjectInspector inspector = deserializer.getObjectInspector();
        // Set up col expressions for the dynamic values using this input
        List<ExprNodeEvaluator> colExprEvaluators = new ArrayList<ExprNodeEvaluator>();
        for (ExprNodeDesc expr : runtimeValuesInfo.getColExprs()) {
            ExprNodeEvaluator exprEval = ExprNodeEvaluatorFactory.get(expr, null);
            exprEval.initialize(inspector);
            colExprEvaluators.add(exprEval);
        }
        runtimeValueInput.start();
        List<Input> inputList = new ArrayList<Input>();
        inputList.add(runtimeValueInput);
        rct.processorContext.waitForAllInputsReady(inputList);
        KeyValueReader kvReader = (KeyValueReader) runtimeValueInput.getReader();
        long rowCount = 0;
        while (kvReader.next()) {
            Object row = deserializer.deserialize((Writable) kvReader.getCurrentValue());
            rowCount++;
            for (int colIdx = 0; colIdx < colExprEvaluators.size(); ++colIdx) {
                // Read each expression and save it to the value registry
                ExprNodeEvaluator eval = colExprEvaluators.get(colIdx);
                Object val = eval.evaluate(row);
                setValue(runtimeValuesInfo.getDynamicValueIDs().get(colIdx), val);
            }
        }
        // For now, expecting a single row (min/max, aggregated bloom filter), or no rows
        if (rowCount == 0) {
            LOG.debug("No input rows from " + inputSourceName + ", filling dynamic values with nulls");
            for (int colIdx = 0; colIdx < colExprEvaluators.size(); ++colIdx) {
                ExprNodeEvaluator eval = colExprEvaluators.get(colIdx);
                setValue(runtimeValuesInfo.getDynamicValueIDs().get(colIdx), null);
            }
        } else if (rowCount > 1) {
            throw new IllegalStateException("Expected 0 or 1 rows from " + inputSourceName + ", got " + rowCount);
        }
    }
}
Also used : ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) StructObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector) KeyValueReader(org.apache.tez.runtime.library.api.KeyValueReader) ArrayList(java.util.ArrayList) ExprNodeEvaluator(org.apache.hadoop.hive.ql.exec.ExprNodeEvaluator) RuntimeValuesInfo(org.apache.hadoop.hive.ql.parse.RuntimeValuesInfo) LogicalInput(org.apache.tez.runtime.api.LogicalInput) Input(org.apache.tez.runtime.api.Input) Deserializer(org.apache.hadoop.hive.serde2.Deserializer) LogicalInput(org.apache.tez.runtime.api.LogicalInput) ExprNodeDesc(org.apache.hadoop.hive.ql.plan.ExprNodeDesc)

Example 22 with ExprNodeEvaluator

use of org.apache.hadoop.hive.ql.exec.ExprNodeEvaluator in project SQLWindowing by hbutani.

the class NPath method execute.

@Override
public void execute(PartitionIterator<Object> pItr, Partition outP) throws WindowingException {
    while (pItr.hasNext()) {
        Object iRow = pItr.next();
        SymbolFunctionResult syFnRes = SymbolFunction.match(syFn, iRow, pItr);
        if (syFnRes.matches) {
            int sz = syFnRes.nextRow - (pItr.getIndex() - 1);
            Object selectListInput = NPathUtils.getSelectListInput(iRow, tDef.getInput().getOI(), pItr, sz);
            ArrayList<Object> oRow = new ArrayList<Object>();
            for (ExprNodeEvaluator resExprEval : resultExprEvals) {
                try {
                    oRow.add(resExprEval.evaluate(selectListInput));
                } catch (HiveException he) {
                    throw new WindowingException(he);
                }
            }
            outP.append(oRow);
        }
    }
}
Also used : SymbolFunctionResult(com.sap.hadoop.windowing.functions2.table.npath.SymbolFunction.SymbolFunctionResult) HiveException(org.apache.hadoop.hive.ql.metadata.HiveException) ArrayList(java.util.ArrayList) ExprNodeEvaluator(org.apache.hadoop.hive.ql.exec.ExprNodeEvaluator) WindowingException(com.sap.hadoop.windowing.WindowingException)

Example 23 with ExprNodeEvaluator

use of org.apache.hadoop.hive.ql.exec.ExprNodeEvaluator in project SQLWindowing by hbutani.

the class ResultExpressionParser method buildSelectListEvaluators.

private void buildSelectListEvaluators() throws WindowingException {
    selectListExprEvaluators = new ArrayList<ExprNodeEvaluator>();
    selectListExprOIs = new ArrayList<ObjectInspector>();
    ArrayList<String> selectListExprNames = new ArrayList<String>();
    int i = 0;
    Iterator<Object> it = selectSpec.getColumnListAndAlias();
    while (it.hasNext()) {
        Object[] selectColDetails = (Object[]) it.next();
        String selectColName = (String) selectColDetails[1];
        ASTNode selectColumnNode = (ASTNode) selectColDetails[2];
        ExprNodeDesc selectColumnExprNode = TranslateUtils.buildExprNode(selectColumnNode, selectListInputTypeCheckCtx);
        ExprNodeEvaluator selectColumnExprEval = ExprNodeEvaluatorFactory.get(selectColumnExprNode);
        ObjectInspector selectColumnOI = null;
        try {
            selectColumnOI = selectColumnExprEval.initialize(selectListInputOI);
        } catch (HiveException he) {
            throw new WindowingException(he);
        }
        selectColName = getColumnName(selectColName, selectColumnExprNode, i);
        selectListExprEvaluators.add(selectColumnExprEval);
        selectListExprOIs.add(selectColumnOI);
        selectListExprNames.add(selectColName);
        i++;
    }
    selectListOutputOI = ObjectInspectorFactory.getStandardStructObjectInspector(selectListExprNames, selectListExprOIs);
}
Also used : StructObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector) ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) HiveException(org.apache.hadoop.hive.ql.metadata.HiveException) ExprNodeEvaluator(org.apache.hadoop.hive.ql.exec.ExprNodeEvaluator) ArrayList(java.util.ArrayList) ASTNode(org.apache.hadoop.hive.ql.parse.ASTNode) WindowingException(com.sap.hadoop.windowing.WindowingException) ExprNodeDesc(org.apache.hadoop.hive.ql.plan.ExprNodeDesc)

Example 24 with ExprNodeEvaluator

use of org.apache.hadoop.hive.ql.exec.ExprNodeEvaluator in project SQLWindowing by hbutani.

the class SymbolParser method parse.

public void parse() throws WindowingException {
    symbols = patternStr.split("\\.");
    symbolFunctions = new ArrayList<SymbolFunction>();
    for (String symbol : symbols) {
        boolean isStar = symbol.endsWith("*");
        boolean isPlus = symbol.endsWith("+");
        symbol = (isStar || isPlus) ? symbol.substring(0, symbol.length() - 1) : symbol;
        Object[] symbolDetails = symbolExprEvalMap.get(symbol.toLowerCase());
        if (symbolDetails == null) {
            throw new WindowingException(sprintf("Unknown Symbol %s", symbol));
        }
        ExprNodeEvaluator symbolExprEval = (ExprNodeEvaluator) symbolDetails[0];
        ObjectInspector symbolExprOI = (ObjectInspector) symbolDetails[1];
        SymbolFunction sFn = new Symbol(symbolExprEval, symbolExprOI);
        if (isStar) {
            sFn = new Star(sFn);
        } else if (isPlus) {
            sFn = new Plus(sFn);
        }
        symbolFunctions.add(sFn);
    }
    symbolFnChain = new Chain(symbolFunctions);
}
Also used : Chain(com.sap.hadoop.windowing.functions2.table.npath.SymbolFunction.Chain) ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) Symbol(com.sap.hadoop.windowing.functions2.table.npath.SymbolFunction.Symbol) ExprNodeEvaluator(org.apache.hadoop.hive.ql.exec.ExprNodeEvaluator) Star(com.sap.hadoop.windowing.functions2.table.npath.SymbolFunction.Star) WindowingException(com.sap.hadoop.windowing.WindowingException) Plus(com.sap.hadoop.windowing.functions2.table.npath.SymbolFunction.Plus)

Example 25 with ExprNodeEvaluator

use of org.apache.hadoop.hive.ql.exec.ExprNodeEvaluator in project SQLWindowing by hbutani.

the class QueryDefDeserializer method visit.

/*
	 * Recreate the ExprEvaluator, OI using the current inputInfo This is the
	 * inputInfo on the first InputDef in chain if the query does not have a map
	 * phase; else it is the mapInputInfo on the table function definition
	 */
@Override
public void visit(ValueBoundaryDef boundary) throws WindowingException {
    ExprNodeEvaluator exprEval = WindowingExprNodeEvaluatorFactory.get(tInfo, boundary.getExprNode());
    ObjectInspector oi = TranslateUtils.initExprNodeEvaluator(qDef, boundary.getExprNode(), exprEval, inputInfo);
    boundary.setExprEvaluator(exprEval);
    boundary.setOI(oi);
}
Also used : ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) StructObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector) ExprNodeEvaluator(org.apache.hadoop.hive.ql.exec.ExprNodeEvaluator)

Aggregations

ExprNodeEvaluator (org.apache.hadoop.hive.ql.exec.ExprNodeEvaluator)30 ObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)27 StructObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector)18 ExprNodeDesc (org.apache.hadoop.hive.ql.plan.ExprNodeDesc)13 ArrayList (java.util.ArrayList)10 WindowingException (com.sap.hadoop.windowing.WindowingException)8 HiveException (org.apache.hadoop.hive.ql.metadata.HiveException)8 PrimitiveObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector)7 ColumnDef (com.sap.hadoop.windowing.query2.definition.ColumnDef)3 ASTNode (org.apache.hadoop.hive.ql.parse.ASTNode)3 ExprNodeGenericFuncDesc (org.apache.hadoop.hive.ql.plan.ExprNodeGenericFuncDesc)3 ListObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ListObjectInspector)3 WhereDef (com.sap.hadoop.windowing.query2.definition.WhereDef)2 List (java.util.List)2 VectorExpression (org.apache.hadoop.hive.ql.exec.vector.expressions.VectorExpression)2 VectorExpressionWriter (org.apache.hadoop.hive.ql.exec.vector.expressions.VectorExpressionWriter)2 VectorExpressionWriterFactory (org.apache.hadoop.hive.ql.exec.vector.expressions.VectorExpressionWriterFactory)2 Converter (org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorConverters.Converter)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 GenericUDFLeadLag (com.sap.hadoop.windowing.functions2.GenericUDFLeadLag)1