Search in sources :

Example 1 with RowResolver

use of org.apache.hadoop.hive.ql.parse.RowResolver in project SQLWindowing by hbutani.

the class WindowingTypeCheckProcFactory method processGByExpr.

/**
	 * Function to do groupby subexpression elimination. This is called by all
	 * the processors initially. As an example, consider the query select a+b,
	 * count(1) from T group by a+b; Then a+b is already precomputed in the
	 * group by operators key, so we substitute a+b in the select list with the
	 * internal column name of the a+b expression that appears in the in input
	 * row resolver.
	 * 
	 * @param nd
	 *            The node that is being inspected.
	 * @param procCtx
	 *            The processor context.
	 * 
	 * @return exprNodeColumnDesc.
	 */
public static ExprNodeDesc processGByExpr(Node nd, Object procCtx) throws SemanticException {
    // We recursively create the exprNodeDesc. Base cases: when we encounter
    // a column ref, we convert that into an exprNodeColumnDesc; when we
    // encounter
    // a constant, we convert that into an exprNodeConstantDesc. For others
    // we
    // just
    // build the exprNodeFuncDesc with recursively built children.
    ASTNode expr = (ASTNode) nd;
    TypeCheckCtx ctx = (TypeCheckCtx) procCtx;
    RowResolver input = ctx.getInputRR();
    ExprNodeDesc desc = null;
    // If the current subExpression is pre-calculated, as in Group-By etc.
    ColumnInfo colInfo = input.getExpression(expr);
    if (colInfo != null) {
        desc = new ExprNodeColumnDesc(colInfo.getType(), colInfo.getInternalName(), colInfo.getTabAlias(), colInfo.getIsVirtualCol());
        //			}
        return desc;
    }
    return desc;
}
Also used : TypeCheckCtx(org.apache.hadoop.hive.ql.parse.TypeCheckCtx) ASTNode(org.apache.hadoop.hive.ql.parse.ASTNode) ExprNodeColumnDesc(org.apache.hadoop.hive.ql.plan.ExprNodeColumnDesc) ColumnInfo(org.apache.hadoop.hive.ql.exec.ColumnInfo) RowResolver(org.apache.hadoop.hive.ql.parse.RowResolver) ExprNodeDesc(org.apache.hadoop.hive.ql.plan.ExprNodeDesc)

Example 2 with RowResolver

use of org.apache.hadoop.hive.ql.parse.RowResolver in project SQLWindowing by hbutani.

the class QueryOutputPrinter method getQueryOutputRowSchema.

RowSchema getQueryOutputRowSchema(QueryDef qry, JobConf jcfg) throws WindowingException {
    String tabAlias = qry.getOutput().getSpec().getHiveTable();
    StructObjectInspector rowObjectInspector = qry.getSelectList().getOI();
    RowResolver rr = HiveUtils.getRowResolver(tabAlias, rowObjectInspector);
    return rr.getRowSchema();
}
Also used : RowResolver(org.apache.hadoop.hive.ql.parse.RowResolver) StructObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector)

Example 3 with RowResolver

use of org.apache.hadoop.hive.ql.parse.RowResolver in project SQLWindowing by hbutani.

the class MRUtils method initialize.

/**
	 * Construct the data structures containing ExprNodeDesc for partition
	 * columns and order columns. Use the input definition to construct the list
	 * of output columns for the ReduceSinkOperator
	 * 
	 * @throws WindowingException
	 */
public void initialize() throws WindowingException {
    TableFuncDef tabDef = RuntimeUtils.getFirstTableFunction(qdef);
    hiveTableDef = tabDef.getHiveTableDef();
    InputInfo inputInfo;
    ArrayList<ColumnDef> partColList = tabDef.getWindow().getPartDef().getColumns();
    TableFunctionEvaluator tEval = tabDef.getFunction();
    /*
		 * If the query has a map phase, the inputInfo is retrieved from the map
		 * output info of the table function definition. This is constructed
		 * using the map output oi of the table function definition. If the
		 * query does not have a map phase, the inputInfo is retrieved from the
		 * QueryInputDef (either HiveTableDef or HiveQueryDef) of the query.
		 */
    if (tEval.isTransformsRawInput()) {
        inputInfo = qdef.getTranslationInfo().getMapInputInfo(tabDef);
    } else {
        inputInfo = qdef.getTranslationInfo().getInputInfo(hiveTableDef);
    }
    for (ColumnDef colDef : partColList) {
        partCols.add(colDef.getExprNode());
    }
    ArrayList<OrderColumnDef> orderColList = tabDef.getWindow().getOrderDef().getColumns();
    for (OrderColumnDef colDef : orderColList) {
        Order order = colDef.getOrder();
        if (order.name().equals("ASC")) {
            orderString.append('+');
        } else {
            orderString.append('-');
        }
        orderCols.add(colDef.getExprNode());
        outputColumnNames.add(colDef.getAlias());
    }
    RowResolver rr = inputInfo.getRowResolver();
    ArrayList<ColumnInfo> colInfoList = rr.getColumnInfos();
    for (ColumnInfo colInfo : colInfoList) {
        String internalName = colInfo.getInternalName();
        TypeInfo type = colInfo.getType();
        valueCols.add(TranslateUtils.getExprDesc(internalName, type));
        outputColumnNames.add(internalName);
    }
}
Also used : Order(com.sap.hadoop.metadata.Order) OrderColumnDef(com.sap.hadoop.windowing.query2.definition.OrderColumnDef) ColumnDef(com.sap.hadoop.windowing.query2.definition.ColumnDef) OrderColumnDef(com.sap.hadoop.windowing.query2.definition.OrderColumnDef) ColumnInfo(org.apache.hadoop.hive.ql.exec.ColumnInfo) RowResolver(org.apache.hadoop.hive.ql.parse.RowResolver) TypeInfo(org.apache.hadoop.hive.serde2.typeinfo.TypeInfo) TableFuncDef(com.sap.hadoop.windowing.query2.definition.TableFuncDef) InputInfo(com.sap.hadoop.windowing.query2.translate.QueryTranslationInfo.InputInfo) TableFunctionEvaluator(com.sap.hadoop.windowing.functions2.TableFunctionEvaluator)

Example 4 with RowResolver

use of org.apache.hadoop.hive.ql.parse.RowResolver in project hive by apache.

the class MatchPath method createSelectListRR.

/*
   * add array<struct> to the list of columns
   */
protected static RowResolver createSelectListRR(MatchPath evaluator, PTFInputDef inpDef) throws SemanticException {
    RowResolver rr = new RowResolver();
    RowResolver inputRR = inpDef.getOutputShape().getRr();
    evaluator.inputColumnNamesMap = new HashMap<String, String>();
    ArrayList<String> inputColumnNames = new ArrayList<String>();
    ArrayList<ObjectInspector> inpColOIs = new ArrayList<ObjectInspector>();
    for (ColumnInfo inpCInfo : inputRR.getColumnInfos()) {
        ColumnInfo cInfo = new ColumnInfo(inpCInfo);
        String colAlias = cInfo.getAlias();
        String[] tabColAlias = inputRR.reverseLookup(inpCInfo.getInternalName());
        if (tabColAlias != null) {
            colAlias = tabColAlias[1];
        }
        ASTNode inExpr = null;
        inExpr = PTFTranslator.getASTNode(inpCInfo, inputRR);
        if (inExpr != null) {
            rr.putExpression(inExpr, cInfo);
            colAlias = inExpr.toStringTree().toLowerCase();
        } else {
            colAlias = colAlias == null ? cInfo.getInternalName() : colAlias;
            rr.put(cInfo.getTabAlias(), colAlias, cInfo);
        }
        evaluator.inputColumnNamesMap.put(cInfo.getInternalName(), colAlias);
        inputColumnNames.add(colAlias);
        inpColOIs.add(cInfo.getObjectInspector());
    }
    StandardListObjectInspector pathAttrOI = ObjectInspectorFactory.getStandardListObjectInspector(ObjectInspectorFactory.getStandardStructObjectInspector(inputColumnNames, inpColOIs));
    ColumnInfo pathColumn = new ColumnInfo(PATHATTR_NAME, TypeInfoUtils.getTypeInfoFromObjectInspector(pathAttrOI), null, false, false);
    rr.put(null, PATHATTR_NAME, pathColumn);
    return rr;
}
Also used : PrimitiveObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector) ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) StandardListObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.StandardListObjectInspector) StructObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector) ConstantObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ConstantObjectInspector) ArrayList(java.util.ArrayList) ASTNode(org.apache.hadoop.hive.ql.parse.ASTNode) ColumnInfo(org.apache.hadoop.hive.ql.exec.ColumnInfo) StandardListObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.StandardListObjectInspector) RowResolver(org.apache.hadoop.hive.ql.parse.RowResolver)

Example 5 with RowResolver

use of org.apache.hadoop.hive.ql.parse.RowResolver in project hive by apache.

the class HiveOpConverter method genPTF.

private OpAttr genPTF(OpAttr inputOpAf, WindowingSpec wSpec) throws SemanticException {
    Operator<?> input = inputOpAf.inputs.get(0);
    wSpec.validateAndMakeEffective();
    WindowingComponentizer groups = new WindowingComponentizer(wSpec);
    RowResolver rr = new RowResolver();
    for (ColumnInfo ci : input.getSchema().getSignature()) {
        rr.put(inputOpAf.tabAlias, ci.getInternalName(), ci);
    }
    while (groups.hasNext()) {
        wSpec = groups.next(hiveConf, semanticAnalyzer, unparseTranslator, rr);
        // 1. Create RS and backtrack Select operator on top
        ArrayList<ExprNodeDesc> keyCols = new ArrayList<ExprNodeDesc>();
        ArrayList<ExprNodeDesc> partCols = new ArrayList<ExprNodeDesc>();
        StringBuilder order = new StringBuilder();
        StringBuilder nullOrder = new StringBuilder();
        for (PartitionExpression partCol : wSpec.getQueryPartitionSpec().getExpressions()) {
            ExprNodeDesc partExpr = semanticAnalyzer.genExprNodeDesc(partCol.getExpression(), rr);
            if (ExprNodeDescUtils.indexOf(partExpr, partCols) < 0) {
                keyCols.add(partExpr);
                partCols.add(partExpr);
                order.append('+');
                nullOrder.append('a');
            }
        }
        if (wSpec.getQueryOrderSpec() != null) {
            for (OrderExpression orderCol : wSpec.getQueryOrderSpec().getExpressions()) {
                ExprNodeDesc orderExpr = semanticAnalyzer.genExprNodeDesc(orderCol.getExpression(), rr);
                char orderChar = orderCol.getOrder() == PTFInvocationSpec.Order.ASC ? '+' : '-';
                char nullOrderChar = orderCol.getNullOrder() == PTFInvocationSpec.NullOrder.NULLS_FIRST ? 'a' : 'z';
                int index = ExprNodeDescUtils.indexOf(orderExpr, keyCols);
                if (index >= 0) {
                    order.setCharAt(index, orderChar);
                    nullOrder.setCharAt(index, nullOrderChar);
                    continue;
                }
                keyCols.add(orderExpr);
                order.append(orderChar);
                nullOrder.append(nullOrderChar);
            }
        }
        SelectOperator selectOp = genReduceSinkAndBacktrackSelect(input, keyCols.toArray(new ExprNodeDesc[keyCols.size()]), 0, partCols, order.toString(), nullOrder.toString(), -1, Operation.NOT_ACID, hiveConf);
        // 2. Finally create PTF
        PTFTranslator translator = new PTFTranslator();
        PTFDesc ptfDesc = translator.translate(wSpec, semanticAnalyzer, hiveConf, rr, unparseTranslator);
        RowResolver ptfOpRR = ptfDesc.getFuncDef().getOutputShape().getRr();
        Operator<?> ptfOp = OperatorFactory.getAndMakeChild(ptfDesc, new RowSchema(ptfOpRR.getColumnInfos()), selectOp);
        if (LOG.isDebugEnabled()) {
            LOG.debug("Generated " + ptfOp + " with row schema: [" + ptfOp.getSchema() + "]");
        }
        // 3. Prepare for next iteration (if any)
        rr = ptfOpRR;
        input = ptfOp;
    }
    return inputOpAf.clone(input);
}
Also used : RowSchema(org.apache.hadoop.hive.ql.exec.RowSchema) OrderExpression(org.apache.hadoop.hive.ql.parse.PTFInvocationSpec.OrderExpression) ArrayList(java.util.ArrayList) PTFTranslator(org.apache.hadoop.hive.ql.parse.PTFTranslator) ColumnInfo(org.apache.hadoop.hive.ql.exec.ColumnInfo) RowResolver(org.apache.hadoop.hive.ql.parse.RowResolver) SelectOperator(org.apache.hadoop.hive.ql.exec.SelectOperator) PartitionExpression(org.apache.hadoop.hive.ql.parse.PTFInvocationSpec.PartitionExpression) PTFDesc(org.apache.hadoop.hive.ql.plan.PTFDesc) ExprNodeDesc(org.apache.hadoop.hive.ql.plan.ExprNodeDesc) WindowingComponentizer(org.apache.hadoop.hive.ql.parse.WindowingComponentizer)

Aggregations

RowResolver (org.apache.hadoop.hive.ql.parse.RowResolver)8 ColumnInfo (org.apache.hadoop.hive.ql.exec.ColumnInfo)7 ArrayList (java.util.ArrayList)4 StructObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector)4 WindowingException (com.sap.hadoop.windowing.WindowingException)2 FieldSchema (org.apache.hadoop.hive.metastore.api.FieldSchema)2 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)2 HiveException (org.apache.hadoop.hive.ql.metadata.HiveException)2 ASTNode (org.apache.hadoop.hive.ql.parse.ASTNode)2 ExprNodeDesc (org.apache.hadoop.hive.ql.plan.ExprNodeDesc)2 Order (com.sap.hadoop.metadata.Order)1 TableFunctionEvaluator (com.sap.hadoop.windowing.functions2.TableFunctionEvaluator)1 ColumnDef (com.sap.hadoop.windowing.query2.definition.ColumnDef)1 OrderColumnDef (com.sap.hadoop.windowing.query2.definition.OrderColumnDef)1 TableFuncDef (com.sap.hadoop.windowing.query2.definition.TableFuncDef)1 InputInfo (com.sap.hadoop.windowing.query2.translate.QueryTranslationInfo.InputInfo)1 HashSet (java.util.HashSet)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 DruidSchema (org.apache.calcite.adapter.druid.DruidSchema)1 DruidTable (org.apache.calcite.adapter.druid.DruidTable)1