Search in sources :

Example 11 with ColumnDef

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

the class PTFOperator method setupKeysWrapper.

protected void setupKeysWrapper(ObjectInspector inputOI) throws HiveException {
    PartitionDef pDef = RuntimeUtils.getFirstTableFunction(qDef).getWindow().getPartDef();
    ArrayList<ColumnDef> cols = pDef.getColumns();
    int numCols = cols.size();
    ExprNodeEvaluator[] keyFields = new ExprNodeEvaluator[numCols];
    ObjectInspector[] keyOIs = new ObjectInspector[numCols];
    ObjectInspector[] currentKeyOIs = new ObjectInspector[numCols];
    for (int i = 0; i < numCols; i++) {
        ColumnDef cDef = cols.get(i);
        /*
			 * Why cannot we just use the ExprNodeEvaluator on the column?
			 * - because on the reduce-side it is initialized based on the rowOI of the HiveTable 
			 *   and not the OI of the ExtractOp ( the parent of this Operator on the reduce-side)
			 */
        keyFields[i] = ExprNodeEvaluatorFactory.get(cDef.getExprNode());
        keyOIs[i] = keyFields[i].initialize(inputOI);
        currentKeyOIs[i] = ObjectInspectorUtils.getStandardObjectInspector(keyOIs[i], ObjectInspectorCopyOption.WRITABLE);
    }
    keyWrapperFactory = new WindowingKeyWrapperFactory(keyFields, keyOIs, currentKeyOIs);
    newKeys = keyWrapperFactory.getWindowingKeyWrapper();
}
Also used : ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) PartitionDef(com.sap.hadoop.windowing.query2.definition.PartitionDef) ExprNodeEvaluator(org.apache.hadoop.hive.ql.exec.ExprNodeEvaluator) ColumnDef(com.sap.hadoop.windowing.query2.definition.ColumnDef)

Example 12 with ColumnDef

use of com.sap.hadoop.windowing.query2.definition.ColumnDef 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)

Aggregations

ColumnDef (com.sap.hadoop.windowing.query2.definition.ColumnDef)12 OrderColumnDef (com.sap.hadoop.windowing.query2.definition.OrderColumnDef)7 ObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)4 WindowingException (com.sap.hadoop.windowing.WindowingException)3 PartitionDef (com.sap.hadoop.windowing.query2.definition.PartitionDef)3 ArrayList (java.util.ArrayList)3 ExprNodeEvaluator (org.apache.hadoop.hive.ql.exec.ExprNodeEvaluator)3 OrderDef (com.sap.hadoop.windowing.query2.definition.OrderDef)2 OrderColumnSpec (com.sap.hadoop.windowing.query2.specification.OrderColumnSpec)2 InputInfo (com.sap.hadoop.windowing.query2.translate.QueryTranslationInfo.InputInfo)2 HiveException (org.apache.hadoop.hive.ql.metadata.HiveException)2 SerDe (org.apache.hadoop.hive.serde2.SerDe)2 SerDeException (org.apache.hadoop.hive.serde2.SerDeException)2 Order (com.sap.hadoop.metadata.Order)1 TableFunctionEvaluator (com.sap.hadoop.windowing.functions2.TableFunctionEvaluator)1 QueryInputDef (com.sap.hadoop.windowing.query2.definition.QueryInputDef)1 SelectDef (com.sap.hadoop.windowing.query2.definition.SelectDef)1 TableFuncDef (com.sap.hadoop.windowing.query2.definition.TableFuncDef)1 WhereDef (com.sap.hadoop.windowing.query2.definition.WhereDef)1 WindowFrameDef (com.sap.hadoop.windowing.query2.definition.WindowFrameDef)1