Search in sources :

Example 6 with QueryDef

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

the class WindowSpecTranslation method translatePartition.

static PartitionDef translatePartition(QueryDef qDef, InputInfo iInfo, PartitionSpec spec) throws WindowingException {
    if (spec == null || spec.getColumns() == null || spec.getColumns().size() == 0)
        return null;
    PartitionDef pDef = new PartitionDef(spec);
    for (ColumnSpec colSpec : spec.getColumns()) {
        ColumnDef cDef = translatePartitionColumn(qDef, iInfo, colSpec);
        pDef.addColumn(cDef);
    }
    return pDef;
}
Also used : OrderColumnSpec(com.sap.hadoop.windowing.query2.specification.OrderColumnSpec) ColumnSpec(com.sap.hadoop.windowing.query2.specification.ColumnSpec) PartitionDef(com.sap.hadoop.windowing.query2.definition.PartitionDef) OrderColumnDef(com.sap.hadoop.windowing.query2.definition.OrderColumnDef) ColumnDef(com.sap.hadoop.windowing.query2.definition.ColumnDef)

Example 7 with QueryDef

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

the class WindowSpecTranslation method translateWindowFrame.

static WindowFrameDef translateWindowFrame(QueryDef qDef, WindowFrameSpec wfSpec, InputInfo iInfo) throws WindowingException {
    if (wfSpec == null) {
        return null;
    }
    BoundarySpec s = wfSpec.getStart();
    BoundarySpec e = wfSpec.getEnd();
    WindowFrameDef wfDef = new WindowFrameDef(wfSpec);
    wfDef.setStart(translateBoundary(qDef, s, iInfo));
    wfDef.setEnd(translateBoundary(qDef, e, iInfo));
    int cmp = s.compareTo(e);
    if (cmp > 0) {
        throw new WindowingException(sprintf("Window range invalid, start boundary is greater than end boundary: %s", wfSpec));
    }
    return wfDef;
}
Also used : WindowFrameDef(com.sap.hadoop.windowing.query2.definition.WindowFrameDef) WindowingException(com.sap.hadoop.windowing.WindowingException) ValueBoundarySpec(com.sap.hadoop.windowing.query2.specification.WindowFrameSpec.ValueBoundarySpec) RangeBoundarySpec(com.sap.hadoop.windowing.query2.specification.WindowFrameSpec.RangeBoundarySpec) BoundarySpec(com.sap.hadoop.windowing.query2.specification.WindowFrameSpec.BoundarySpec)

Example 8 with QueryDef

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

the class Executor method executeChain.

/**
	 * For all the table functions to be applied to the input 
	 * hive table or query, push them on a stack. 
	 * For each table function popped out of the stack, 
	 * execute the function on the input partition 
	 * and return an output partition.
	 * @param qDef
	 * @param part
	 * @return
	 * @throws WindowingException
	 */
public static Partition executeChain(QueryDef qDef, Partition part) throws WindowingException {
    Stack<TableFuncDef> fnDefs = new Stack<TableFuncDef>();
    QueryInputDef iDef = qDef.getInput();
    while (true) {
        if (iDef instanceof TableFuncDef) {
            fnDefs.push((TableFuncDef) iDef);
            iDef = ((TableFuncDef) iDef).getInput();
        } else {
            break;
        }
    }
    TableFuncDef currFnDef;
    while (!fnDefs.isEmpty()) {
        currFnDef = fnDefs.pop();
        part = currFnDef.getFunction().execute(part);
    }
    return part;
}
Also used : QueryInputDef(com.sap.hadoop.windowing.query2.definition.QueryInputDef) Stack(java.util.Stack) TableFuncDef(com.sap.hadoop.windowing.query2.definition.TableFuncDef)

Example 9 with QueryDef

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

the class RuntimeUtils method connectLeadLagFunctionsToPartition.

public static void connectLeadLagFunctionsToPartition(QueryDef qDef, PartitionIterator<Object> pItr) throws WindowingException {
    QueryTranslationInfo tInfo = qDef.getTranslationInfo();
    List<ExprNodeGenericFuncDesc> llFnDescs = tInfo.getLLInfo().getLeadLagExprs();
    if (llFnDescs == null)
        return;
    for (ExprNodeGenericFuncDesc llFnDesc : llFnDescs) {
        GenericUDFLeadLag llFn = (GenericUDFLeadLag) llFnDesc.getGenericUDF();
        llFn.setpItr(pItr);
    }
}
Also used : GenericUDFLeadLag(com.sap.hadoop.windowing.functions2.GenericUDFLeadLag) ExprNodeGenericFuncDesc(org.apache.hadoop.hive.ql.plan.ExprNodeGenericFuncDesc) QueryTranslationInfo(com.sap.hadoop.windowing.query2.translate.QueryTranslationInfo)

Example 10 with QueryDef

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

the class RuntimeUtils method getFirstTableFunction.

/**
	 * Iterate the list of the query input definitions in reverse order 
	 * Return the first table function definition in the chain.
	 * This table function is the first one to be executed on the 
	 * input hive table. 
	 * @param qDef
	 * @return
	 */
public static TableFuncDef getFirstTableFunction(QueryDef qDef) {
    TableFuncDef tabDef = null;
    Iterator<QueryInputDef> it = TranslateUtils.iterateInputDefs(qDef, true);
    while (it.hasNext()) {
        QueryInputDef qIn = it.next();
        if (qIn instanceof TableFuncDef) {
            tabDef = (TableFuncDef) qIn;
            break;
        }
    }
    return tabDef;
}
Also used : QueryInputDef(com.sap.hadoop.windowing.query2.definition.QueryInputDef) TableFuncDef(com.sap.hadoop.windowing.query2.definition.TableFuncDef)

Aggregations

WindowingException (com.sap.hadoop.windowing.WindowingException)15 QueryDef (com.sap.hadoop.windowing.query2.definition.QueryDef)7 TableFuncDef (com.sap.hadoop.windowing.query2.definition.TableFuncDef)7 InputInfo (com.sap.hadoop.windowing.query2.translate.QueryTranslationInfo.InputInfo)7 ColumnDef (com.sap.hadoop.windowing.query2.definition.ColumnDef)6 QueryInputDef (com.sap.hadoop.windowing.query2.definition.QueryInputDef)6 ExprNodeEvaluator (org.apache.hadoop.hive.ql.exec.ExprNodeEvaluator)6 ObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)6 OrderColumnDef (com.sap.hadoop.windowing.query2.definition.OrderColumnDef)5 QuerySpec (com.sap.hadoop.windowing.query2.specification.QuerySpec)5 ExprNodeDesc (org.apache.hadoop.hive.ql.plan.ExprNodeDesc)5 TableFunctionEvaluator (com.sap.hadoop.windowing.functions2.TableFunctionEvaluator)4 ArgDef (com.sap.hadoop.windowing.query2.definition.ArgDef)4 OrderDef (com.sap.hadoop.windowing.query2.definition.OrderDef)4 LocalExecutorTest (com.sap.hadoop.windowing.testutils.LocalExecutorTest)4 Test (org.junit.Test)4 HiveQueryDef (com.sap.hadoop.windowing.query2.definition.HiveQueryDef)3 HiveTableDef (com.sap.hadoop.windowing.query2.definition.HiveTableDef)3 HiveTableSpec (com.sap.hadoop.windowing.query2.specification.HiveTableSpec)3 ArrayList (java.util.ArrayList)3