当前位置: 首页>>代码示例>>Java>>正文


Java HiveParser.TOK_FUNCTION属性代码示例

本文整理汇总了Java中org.apache.hadoop.hive.ql.parse.HiveParser.TOK_FUNCTION属性的典型用法代码示例。如果您正苦于以下问题:Java HiveParser.TOK_FUNCTION属性的具体用法?Java HiveParser.TOK_FUNCTION怎么用?Java HiveParser.TOK_FUNCTION使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在org.apache.hadoop.hive.ql.parse.HiveParser的用法示例。


在下文中一共展示了HiveParser.TOK_FUNCTION属性的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: updateOuterHavingAST

/**
 * Update outer havingAST with proper alias name projected.
 *
 * @param node
 * @return
 */
private ASTNode updateOuterHavingAST(ASTNode node) {
  if (node.getToken().getType() == HiveParser.TOK_FUNCTION
      && (HQLParser.isAggregateAST(node))) {
    if (innerToOuterSelectASTs.containsKey(new HQLParser.HashableASTNode(node))
        || innerToOuterHavingASTs.containsKey(new HQLParser.HashableASTNode(node))) {
      ASTNode expr = innerToOuterSelectASTs.containsKey(new HQLParser.HashableASTNode(node))
          ? innerToOuterSelectASTs.get(new HQLParser.HashableASTNode(node))
          : innerToOuterHavingASTs.get(new HQLParser.HashableASTNode(node));
      if (node.getChildCount() > 1) {
        node.replaceChildren(1, 1, expr.getChild(1));
      } else {
        node.replaceChildren(0, 0, expr);
      }
    }
  }
  for (int i = 0; i < node.getChildCount(); i++) {
    ASTNode child = (ASTNode) node.getChild(i);
    updateOuterHavingAST(child);
  }
  return node;
}
 
开发者ID:apache,项目名称:lens,代码行数:27,代码来源:UnionQueryWriter.java

示例2: getAggregateColumns

/**
 * Gets the aggregate columns.
 *
 * @param node the node
 * @return the aggregate columns
 */
public ArrayList<String> getAggregateColumns(ASTNode node, MutableInt count) {

  StringBuilder aggmeasures = new StringBuilder();
  if (HQLParser.isAggregateAST(node)) {
    if (node.getToken().getType() == HiveParser.TOK_FUNCTION || node.getToken().getType() == HiveParser.DOT) {

      ASTNode right = (ASTNode) node.getChild(1);
      String aggCol = HQLParser.getString(right);

      String funident = HQLParser.findNodeByPath(node, Identifier).toString();
      String measure = funident.concat("(").concat(aggCol).concat(")");
      count.add(1);
      String alias = "alias" + String.valueOf(count);
      String allaggmeasures = aggmeasures.append(measure).append(" as ").append(alias).toString();
      String aggColAlias = funident + "(" + alias + ")";
      String measureRegex = "\\s*" + Pattern.quote(funident)
        + "\\s*\\(\\s*\\Q" + aggCol.replaceAll("\\s+", "\\\\E\\\\s+\\\\Q") + "\\E\\s*\\)\\s*";
      mapAggTabAlias.put(measureRegex, aggColAlias);
      if (!aggColumn.contains(allaggmeasures)) {
        aggColumn.add(allaggmeasures);
      }
    }
  }

  for (int i = 0; i < node.getChildCount(); i++) {
    ASTNode child = (ASTNode) node.getChild(i);
    getAggregateColumns(child, count);
  }
  return (ArrayList<String>) aggColumn;
}
 
开发者ID:apache,项目名称:lens,代码行数:36,代码来源:ColumnarSQLRewriter.java

示例3: getAggregateChildrenInNode

/**
 * Gets all aggreage nodes used in having
 *
 * @param node
 * @param havingClauses
 * @return
 */
private Set<ASTNode> getAggregateChildrenInNode(ASTNode node, Set<ASTNode> havingClauses) {
  if (node.getToken().getType() == HiveParser.TOK_FUNCTION && (HQLParser.isAggregateAST(node))) {
    havingClauses.add(node);
  }
  for (int i = 0; i < node.getChildCount(); i++) {
    ASTNode child = (ASTNode) node.getChild(i);
    getAggregateChildrenInNode(child, havingClauses);
  }
  return havingClauses;
}
 
开发者ID:apache,项目名称:lens,代码行数:17,代码来源:UnionQueryWriter.java

示例4: generate

@Override
public boolean generate(ASTNode hiveRoot, CommonTree sqlRoot, ASTNode currentHiveNode,
    CommonTree currentSqlNode, TranslateContext context) throws SqlXlateException {
  ASTNode ret = super.newHiveASTNode(HiveParser.TOK_FUNCTION, "TOK_FUNCTION");

  super.attachHiveNode(hiveRoot, currentHiveNode, ret);
  currentHiveNode = ret;
  ret = super.newHiveASTNode(HiveParser.KW_IN, "in");
  super.attachHiveNode(hiveRoot, currentHiveNode, ret);
  return super.generateChildren(hiveRoot, sqlRoot, currentHiveNode, currentSqlNode, context);
}
 
开发者ID:adrian-wang,项目名称:project-panthera-skin,代码行数:11,代码来源:InGenerator.java

示例5: generate

@Override
public boolean generate(ASTNode hiveRoot, CommonTree sqlRoot, ASTNode currentHiveNode,
    CommonTree currentSqlNode, TranslateContext context) throws SqlXlateException {

  ASTNode tokFunc = super.newHiveASTNode(HiveParser.TOK_FUNCTION, "TOK_FUNCTION");
  ASTNode funcName = super.newHiveASTNode(HiveParser.Identifier, "concat");

  super.attachHiveNode(hiveRoot, currentHiveNode, tokFunc);
  super.attachHiveNode(hiveRoot, tokFunc, funcName);
  return generateTreeInOrder(hiveRoot, sqlRoot, tokFunc, currentSqlNode, context);
}
 
开发者ID:adrian-wang,项目名称:project-panthera-skin,代码行数:11,代码来源:ConcatenationOpGenerator.java

示例6: processOrderbyExpression

private ASTNode processOrderbyExpression(ASTNode astNode) throws LensException {
  if (astNode == null) {
    return null;
  }
  ASTNode outerExpression = new ASTNode(astNode);
  // sample orderby AST looks the following :
  /*
  TOK_ORDERBY
 TOK_TABSORTCOLNAMEDESC
    TOK_NULLS_LAST
       .
          TOK_TABLE_OR_COL
             testcube
          cityid
 TOK_TABSORTCOLNAMEASC
    TOK_NULLS_FIRST
       .
          TOK_TABLE_OR_COL
             testcube
          stateid
 TOK_TABSORTCOLNAMEASC
    TOK_NULLS_FIRST
       .
          TOK_TABLE_OR_COL
             testcube
          zipcode
   */
  for (Node node : astNode.getChildren()) {
    ASTNode child = (ASTNode) node;
    ASTNode outerOrderby = new ASTNode(child);
    ASTNode tokNullsChild = (ASTNode) child.getChild(0);
    ASTNode outerTokNullsChild = new ASTNode(tokNullsChild);
    if (((ASTNode) tokNullsChild.getChild(0)).getToken().getType() == HiveParser.DOT
        || ((ASTNode) tokNullsChild.getChild(0)).getToken().getType() == HiveParser.TOK_FUNCTION) {
      outerTokNullsChild.addChild(innerToOuterSelectASTs.get(new HQLParser.HashableASTNode((ASTNode) tokNullsChild)));
    } else {
      outerTokNullsChild.addChild(tokNullsChild);
    }
    outerOrderby.addChild(outerTokNullsChild);
    outerExpression.addChild(outerOrderby);
  }
  return outerExpression;
}
 
开发者ID:apache,项目名称:lens,代码行数:43,代码来源:UnionQueryWriter.java

示例7: wrapAggregate

private ASTNode wrapAggregate(CubeQueryContext cubeql, ASTNode node) throws LensException {

    String tabname = null;
    String colname;

    if (node.getToken().getType() == HiveParser.TOK_TABLE_OR_COL) {
      colname = node.getChild(0).getText();
    } else {
      // node in 'alias.column' format
      ASTNode tabident = HQLParser.findNodeByPath(node, TOK_TABLE_OR_COL, Identifier);
      ASTNode colIdent = (ASTNode) node.getChild(1);

      colname = colIdent.getText().toLowerCase();
      tabname = tabident.getText().toLowerCase();
    }

    String msrname = StringUtils.isBlank(tabname) ? colname : tabname + "." + colname;

    if (cubeql.isCubeMeasure(msrname)) {
      if (cubeql.getQueriedExprs().contains(colname)) {
        String alias = cubeql.getAliasForTableName(cubeql.getCube().getName());
        for (ExprSpecContext esc : cubeql.getExprCtx().getExpressionContext(colname, alias).getAllExprs()) {
          ASTNode transformedNode = transform(cubeql, null, esc.getFinalAST(), 0);
          esc.setFinalAST(transformedNode);
        }
        return node;
      } else {
        CubeMeasure measure = cubeql.getCube().getMeasureByName(colname);
        String aggregateFn = measure.getAggregate();

        if (StringUtils.isBlank(aggregateFn)) {
          throw new LensException(LensCubeErrorCode.NO_DEFAULT_AGGREGATE.getLensErrorInfo(), colname);
        }
        ASTNode fnroot = new ASTNode(new CommonToken(HiveParser.TOK_FUNCTION, "TOK_FUNCTION"));
        ASTNode fnIdentNode = new ASTNode(new CommonToken(HiveParser.Identifier, aggregateFn));
        fnroot.addChild(fnIdentNode);
        fnroot.addChild(node);
        return fnroot;
      }
    } else {
      return node;
    }
  }
 
开发者ID:apache,项目名称:lens,代码行数:43,代码来源:AggregateResolver.java

示例8: generate

@Override
public boolean generate(ASTNode hiveRoot, CommonTree sqlRoot, ASTNode currentHiveNode,
    CommonTree currentSqlNode, TranslateContext context) throws SqlXlateException {
  ASTNode ret = super.newHiveASTNode(HiveParser.TOK_FUNCTION, "TOK_FUNCTION");
  super.attachHiveNode(hiveRoot, currentHiveNode, ret);
  //transfer to standard CASE WHEN expression THEN compval [WHEN expression THEN compval]* [ELSE result] END
  ASTNode whenNode = super.newHiveASTNode(HiveParser.KW_WHEN, "when");
  super.attachHiveNode(hiveRoot, ret, whenNode);
  if (!(currentSqlNode.getChildCount() >= 2)) {
    throw new SqlXlateException(currentSqlNode, "Parameters error in simple case expression.");
  }
  for (int i = 1; i < currentSqlNode.getChildCount();i++) {
    CommonTree node = (CommonTree) currentSqlNode.getChild(i);
    if (node.getChildCount()==1) {
      //else clause
      HiveASTGenerator generator = GeneratorFactory.getGenerator(node);
      if (generator == null) {
        throw new SqlXlateException(node, "Untransformed sql AST node:" + node.getText());
      }
      if (!generator.generateHiveAST(hiveRoot, sqlRoot,
          ret, node, context)) {
        return false;
      }
    } else {
      //when-then clause
      ASTNode equal = SqlXlateUtil.newASTNode(HiveParser.EQUAL_NS, "<=>");
      ret.addChild(equal);
      HiveASTGenerator generatorL = GeneratorFactory.getGenerator((CommonTree) currentSqlNode.getChild(0));
      if (generatorL == null) {
        throw new SqlXlateException((CommonTree) currentSqlNode.getChild(0),
            "Untransformed SQL AST node:" + currentSqlNode.getChild(0).getText());
      }
      if (!generatorL.generateHiveAST(hiveRoot, sqlRoot,
          equal, (CommonTree) currentSqlNode.getChild(0), context)) {
        return false;
      }
      HiveASTGenerator generatorR = GeneratorFactory.getGenerator((CommonTree)node.getChild(0));
      if (generatorR == null) {
        throw new SqlXlateException((CommonTree) node.getChild(0), "Untransformed SQL AST node:" + node.getChild(0).getText());
      }
      if (!generatorR.generateHiveAST(hiveRoot, sqlRoot,
          equal, (CommonTree)node.getChild(0), context)) {
        return false;
      }
      HiveASTGenerator resultgen = GeneratorFactory.getGenerator((CommonTree)node.getChild(1));
      if (resultgen == null) {
        throw new SqlXlateException((CommonTree) node.getChild(1), "Untransformed SQL AST node:" + node.getChild(1).getText());
      }
      if (!resultgen.generateHiveAST(hiveRoot, sqlRoot,
          ret, (CommonTree)node.getChild(1), context)) {
        return false;
      }
    }
  }
  return true;
}
 
开发者ID:adrian-wang,项目名称:project-panthera-skin,代码行数:56,代码来源:SimpleCaseGenerator.java


注:本文中的org.apache.hadoop.hive.ql.parse.HiveParser.TOK_FUNCTION属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。