private void buildSelectListEvaluators() throws SemanticException, HiveException { resultExprInfo = new ResultExprInfo(); resultExprInfo.resultExprEvals = new ArrayList<ExprNodeEvaluator>(); resultExprInfo.resultExprNames = new ArrayList<String>(); resultExprInfo.resultExprNodes = new ArrayList<ExprNodeDesc>(); // result ArrayList<ObjectInspector> selectListExprOIs = new ArrayList<ObjectInspector>(); int i = 0; for (WindowExpressionSpec expr : selectSpec) { String selectColName = expr.getAlias(); ASTNode selectColumnNode = expr.getExpression(); ExprNodeDesc selectColumnExprNode = ResultExpressionParser.buildExprNode(selectColumnNode, selectListInputTypeCheckCtx); ExprNodeEvaluator selectColumnExprEval = ExprNodeEvaluatorFactory.get(selectColumnExprNode); ObjectInspector selectColumnOI = null; selectColumnOI = selectColumnExprEval.initialize(selectListInputOI); selectColName = getColumnName(selectColName, selectColumnExprNode, i); resultExprInfo.resultExprEvals.add(selectColumnExprEval); selectListExprOIs.add(selectColumnOI); resultExprInfo.resultExprNodes.add(selectColumnExprNode); resultExprInfo.resultExprNames.add(selectColName); i++; } resultExprInfo.resultOI = ObjectInspectorFactory.getStandardStructObjectInspector( resultExprInfo.resultExprNames, selectListExprOIs); }
private static ExprNodeConstantDesc foldConstant(ExprNodeGenericFuncDesc func) { GenericUDF udf = func.getGenericUDF(); if (!FunctionRegistry.isDeterministic(udf) || FunctionRegistry.isStateful(udf)) { return null; } try { // If the UDF depends on any external resources, we can't fold because the // resources may not be available at compile time. if (udf instanceof GenericUDFBridge) { UDF internal = ReflectionUtils.newInstance(((GenericUDFBridge) udf).getUdfClass(), null); if (internal.getRequiredFiles() != null || internal.getRequiredJars() != null) { return null; } } else { if (udf.getRequiredFiles() != null || udf.getRequiredJars() != null) { return null; } } if (func.getChildren() != null) { for (ExprNodeDesc child : func.getChildren()) { if (child instanceof ExprNodeConstantDesc) { continue; } if (child instanceof ExprNodeGenericFuncDesc) { if (foldConstant((ExprNodeGenericFuncDesc) child) != null) { continue; } } return null; } } ExprNodeEvaluator evaluator = ExprNodeEvaluatorFactory.get(func); ObjectInspector output = evaluator.initialize(null); Object constant = evaluator.evaluate(null); Object java = ObjectInspectorUtils.copyToStandardJavaObject(constant, output); return new ExprNodeConstantDesc(java); } catch (Exception e) { return null; } }
@Override public void initializeOutputOI() throws HiveException { try { MatchPath evaluator = (MatchPath) getEvaluator(); PartitionedTableFunctionDef tDef = evaluator.getTableDef(); List<PTFExpressionDef> args = tDef.getArgs(); int argsNum = args.size(); validateAndSetupPatternStr(evaluator, args); validateAndSetupSymbolInfo(evaluator, args, argsNum); validateAndSetupResultExprStr(evaluator, args, argsNum); setupSymbolFunctionChain(evaluator); /* * setup OI for input to resultExpr select list */ StructObjectInspector selectListInputOI = MatchPath.createSelectListOI(evaluator, tDef.getInput()); ResultExprInfo resultExprInfo = evaluator.resultExprInfo; ArrayList<ObjectInspector> selectListExprOIs = new ArrayList<ObjectInspector>(); resultExprInfo.resultExprEvals = new ArrayList<ExprNodeEvaluator>(); for (int i = 0; i < resultExprInfo.resultExprNodes.size(); i++) { ExprNodeDesc selectColumnExprNode = resultExprInfo.resultExprNodes.get(i); ExprNodeEvaluator selectColumnExprEval = ExprNodeEvaluatorFactory.get(selectColumnExprNode); ObjectInspector selectColumnOI = selectColumnExprEval.initialize(selectListInputOI); resultExprInfo.resultExprEvals.add(selectColumnExprEval); selectListExprOIs.add(selectColumnOI); } resultExprInfo.resultOI = ObjectInspectorFactory.getStandardStructObjectInspector( resultExprInfo.resultExprNames, selectListExprOIs); setOutputOI(resultExprInfo.resultOI); } catch (SemanticException se) { throw new HiveException(se); } }