Ejemplo n.º 1
0
 /*
  * setup SymbolFunction chain.
  */
 private void setupSymbolFunctionChain(MatchPath evaluator) throws SemanticException {
   SymbolParser syP =
       new SymbolParser(
           evaluator.patternStr,
           evaluator.symInfo.symbolExprsNames,
           evaluator.symInfo.symbolExprsEvaluators,
           evaluator.symInfo.symbolExprsOIs);
   syP.parse();
   evaluator.syFn = syP.getSymbolFunction();
 }
Ejemplo n.º 2
0
    @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);
      }
    }
Ejemplo n.º 3
0
    /**
     *
     *
     * <ul>
     *   <li>check structure of Arguments:
     *       <ol>
     *         <li>First arg should be a String
     *         <li>then there should be an even number of Arguments: String, expression; expression
     *             should be Convertible to Boolean.
     *         <li>finally there should be a String.
     *       </ol>
     *   <li>convert pattern into a NNode chain.
     *   <li>convert symbol args into a Symbol Map.
     *   <li>parse selectList into SelectList struct. The inputOI used to translate these
     *       expressions should be based on the columns in the Input, the 'path.attr'
     * </ul>
     */
    @Override
    public void setupOutputOI() throws SemanticException {
      MatchPath evaluator = (MatchPath) getEvaluator();
      PartitionedTableFunctionDef tDef = evaluator.getTableDef();

      List<PTFExpressionDef> args = tDef.getArgs();
      int argsNum = args == null ? 0 : args.size();

      if (argsNum < 4) {
        throwErrorWithSignature("at least 4 arguments required");
      }

      validateAndSetupPatternStr(evaluator, args);
      validateAndSetupSymbolInfo(evaluator, args, argsNum);
      validateAndSetupResultExprStr(evaluator, args, argsNum);
      setupSymbolFunctionChain(evaluator);

      /*
       * setup OI for input to resultExpr select list
       */
      RowResolver selectListInputRR = MatchPath.createSelectListRR(evaluator, tDef.getInput());

      /*
       * parse ResultExpr Str and setup OI.
       */
      ResultExpressionParser resultExprParser =
          new ResultExpressionParser(evaluator.resultExprStr, selectListInputRR);
      try {
        resultExprParser.translate();
      } catch (HiveException he) {
        throw new SemanticException(he);
      }
      evaluator.resultExprInfo = resultExprParser.getResultExprInfo();
      StructObjectInspector OI = evaluator.resultExprInfo.resultOI;

      setOutputOI(OI);
    }
Ejemplo n.º 4
0
    /*
     * validate and setup resultExprStr
     */
    private void validateAndSetupResultExprStr(
        MatchPath evaluator, List<PTFExpressionDef> args, int argsNum) throws SemanticException {
      PTFExpressionDef resultExprArg = args.get(argsNum - 1);
      ObjectInspector resultExprArgOI = resultExprArg.getOI();

      if (!ObjectInspectorUtils.isConstantObjectInspector(resultExprArgOI)
          || (resultExprArgOI.getCategory() != ObjectInspector.Category.PRIMITIVE)
          || ((PrimitiveObjectInspector) resultExprArgOI).getPrimitiveCategory()
              != PrimitiveObjectInspector.PrimitiveCategory.STRING) {
        throwErrorWithSignature("Currently the result Expr parameter must be a Constant String.");
      }

      evaluator.resultExprStr =
          ((ConstantObjectInspector) resultExprArgOI).getWritableConstantValue().toString();
    }
Ejemplo n.º 5
0
    /*
     * validate and setup patternStr
     */
    private void validateAndSetupPatternStr(MatchPath evaluator, List<PTFExpressionDef> args)
        throws SemanticException {
      PTFExpressionDef symboPatternArg = args.get(0);
      ObjectInspector symbolPatternArgOI = symboPatternArg.getOI();

      if (!ObjectInspectorUtils.isConstantObjectInspector(symbolPatternArgOI)
          || (symbolPatternArgOI.getCategory() != ObjectInspector.Category.PRIMITIVE)
          || ((PrimitiveObjectInspector) symbolPatternArgOI).getPrimitiveCategory()
              != PrimitiveObjectInspector.PrimitiveCategory.STRING) {
        throwErrorWithSignature("Currently the symbol Pattern must be a Constant String.");
      }

      evaluator.patternStr =
          ((ConstantObjectInspector) symbolPatternArgOI).getWritableConstantValue().toString();
    }
Ejemplo n.º 6
0
  /*
   * 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;
  }
Ejemplo n.º 7
0
  @Override
  public void execute(PTFPartitionIterator<Object> pItr, PTFPartition outP) throws HiveException {
    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 =
            MatchPath.getSelectListInput(
                iRow, tableDef.getInput().getOutputShape().getOI(), pItr, sz);
        ArrayList<Object> oRow = new ArrayList<Object>();
        for (ExprNodeEvaluator resExprEval : resultExprInfo.resultExprEvals) {
          oRow.add(resExprEval.evaluate(selectListInput));
        }
        outP.append(oRow);
      }
    }
  }
Ejemplo n.º 8
0
    /*
     * validate and setup SymbolInfo
     */
    private void validateAndSetupSymbolInfo(
        MatchPath evaluator, List<PTFExpressionDef> args, int argsNum) throws SemanticException {
      int symbolArgsSz = argsNum - 2;
      if (symbolArgsSz % 2 != 0) {
        throwErrorWithSignature(
            "Symbol Name, Expression need to be specified in pairs: "
                + "there are odd number of symbol args");
      }

      evaluator.symInfo = new SymbolsInfo(symbolArgsSz / 2);
      for (int i = 1; i <= symbolArgsSz; i += 2) {
        PTFExpressionDef symbolNameArg = args.get(i);
        ObjectInspector symbolNameArgOI = symbolNameArg.getOI();

        if (!ObjectInspectorUtils.isConstantObjectInspector(symbolNameArgOI)
            || (symbolNameArgOI.getCategory() != ObjectInspector.Category.PRIMITIVE)
            || ((PrimitiveObjectInspector) symbolNameArgOI).getPrimitiveCategory()
                != PrimitiveObjectInspector.PrimitiveCategory.STRING) {
          throwErrorWithSignature(
              String.format(
                  "Currently a Symbol Name(%s) must be a Constant String",
                  symbolNameArg.getExpressionTreeString()));
        }
        String symbolName =
            ((ConstantObjectInspector) symbolNameArgOI).getWritableConstantValue().toString();

        PTFExpressionDef symolExprArg = args.get(i + 1);
        ObjectInspector symolExprArgOI = symolExprArg.getOI();
        if ((symolExprArgOI.getCategory() != ObjectInspector.Category.PRIMITIVE)
            || ((PrimitiveObjectInspector) symolExprArgOI).getPrimitiveCategory()
                != PrimitiveObjectInspector.PrimitiveCategory.BOOLEAN) {
          throwErrorWithSignature(
              String.format(
                  "Currently a Symbol Expression(%s) " + "must be a boolean expression",
                  symolExprArg.getExpressionTreeString()));
        }
        evaluator.symInfo.add(symbolName, symolExprArg);
      }
    }