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


Java ASTNode.setChild方法代码示例

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


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

示例1: getMockedCubeContext

import org.apache.hadoop.hive.ql.parse.ASTNode; //导入方法依赖的package包/类
/**
 * Gets the mocked cube context.
 *
 * @param ast the ast
 * @return the mocked cube context
 * @throws ParseException    the parse exception
 * @throws LensException  the lens exception
 */
private CubeQueryContext getMockedCubeContext(ASTNode ast) throws ParseException, LensException {
  CubeQueryContext context = Mockito.mock(CubeQueryContext.class);
  if (ast.getToken().getType() == HiveParser.TOK_QUERY) {
    if (((ASTNode) ast.getChild(0)).getToken().getType() == HiveParser.KW_CUBE) {
      // remove cube child from AST
      for (int i = 0; i < ast.getChildCount() - 1; i++) {
        ast.setChild(i, ast.getChild(i + 1));
      }
      ast.deleteChild(ast.getChildCount() - 1);
    }
  }
  StringBuilder builder = new StringBuilder();
  HQLParser.toInfixString(ast, builder);
  Mockito.when(context.toHQL()).thenReturn(builder.toString());
  Mockito.when(context.toAST(Matchers.any(Context.class))).thenReturn(ast);
  return context;
}
 
开发者ID:apache,项目名称:lens,代码行数:26,代码来源:TestRewriting.java

示例2: updateOuterASTDuplicateAliases

import org.apache.hadoop.hive.ql.parse.ASTNode; //导入方法依赖的package包/类
private void updateOuterASTDuplicateAliases(ASTNode node, Map<String, List<String>> aliasMap) {
  if (node.getToken().getType() == HiveParser.DOT) {
    String col = node.getChild(1).toString();
    for (Map.Entry<String, List<String>> entry : aliasMap.entrySet()) {
      if (entry.getValue().contains(col)) {
        try {
          node.setChild(1, HQLParser.parseExpr(entry.getKey()));
        } catch (LensException e) {
          log.error("Unable to parse select expression: {}.", entry.getKey());
        }
      }

    }
  }
  for (int i = 0; i < node.getChildCount(); i++) {
    ASTNode child = (ASTNode) node.getChild(i);
    updateOuterASTDuplicateAliases(child, aliasMap);
  }
}
 
开发者ID:apache,项目名称:lens,代码行数:20,代码来源:UnionQueryWriter.java

示例3: transform

import org.apache.hadoop.hive.ql.parse.ASTNode; //导入方法依赖的package包/类
private ASTNode transform(CubeQueryContext cubeql, ASTNode parent, ASTNode node, int nodePos) throws LensException {
  if (node == null) {
    return node;
  }
  int nodeType = node.getToken().getType();

  if (!(HQLParser.isAggregateAST(node))) {
    if (nodeType == HiveParser.TOK_TABLE_OR_COL || nodeType == HiveParser.DOT) {
      // Leaf node
      ASTNode wrapped = wrapAggregate(cubeql, node);
      if (wrapped != node) {
        if (parent != null) {
          parent.setChild(nodePos, wrapped);
        } else {
          return wrapped;
        }
      }
    } else {
      // Dig deeper in non-leaf nodes
      for (int i = 0; i < node.getChildCount(); i++) {
        transform(cubeql, node, (ASTNode) node.getChild(i), i);
      }
    }
  }
  return node;
}
 
开发者ID:apache,项目名称:lens,代码行数:27,代码来源:AggregateResolver.java

示例4: setDefaultValueInExprForAggregateNodes

import org.apache.hadoop.hive.ql.parse.ASTNode; //导入方法依赖的package包/类
/**
 * Set the default value "0" in the non answerable aggreagte expressions.
 * @param node
 * @param sc
 * @return
 * @throws LensException
 */
private ASTNode setDefaultValueInExprForAggregateNodes(ASTNode node, StorageCandidate sc) throws LensException {
  if (HQLParser.isAggregateAST(node)) {
    node.setChild(1, getSelectExpr(null, null, true));
  }
  for (int i = 0; i < node.getChildCount(); i++) {
    ASTNode child = (ASTNode) node.getChild(i);
    setDefaultValueInExprForAggregateNodes(child, sc);
  }
  return node;
}
 
开发者ID:apache,项目名称:lens,代码行数:18,代码来源:UnionQueryWriter.java

示例5: getDefaultExpr

import org.apache.hadoop.hive.ql.parse.ASTNode; //导入方法依赖的package包/类
private  ASTNode getDefaultExpr(ASTNode node) {
  if (HQLParser.isAggregateAST(node)) {
    node.setChild(1, new ASTNode(new CommonToken(HiveParser.Identifier, "0")));
  }
  for (int i = 0; i < node.getChildCount(); i++) {
    ASTNode child = (ASTNode) node.getChild(i);
    getDefaultExpr(child);
  }
  return node;
}
 
开发者ID:apache,项目名称:lens,代码行数:11,代码来源:ExpressionResolver.java

示例6: processSelectAST

import org.apache.hadoop.hive.ql.parse.ASTNode; //导入方法依赖的package包/类
List<String> processSelectAST(ASTNode selectAST)
  throws LensException {
  // iterate over children
  for (int i = 0; i < selectAST.getChildCount(); i++) {
    ASTNode selectExprNode = (ASTNode) selectAST.getChild(i);
    ASTNode child = (ASTNode) selectExprNode.getChild(0);
    if (hasBridgeCol(child, tableAlias)) {
      selectExprNode.setChild(0, getDotASTForExprAST(child));
    }
  }
  return selectedBridgeExprs;
}
 
开发者ID:apache,项目名称:lens,代码行数:13,代码来源:BridgeTableJoinContext.java

示例7: processGroupbyAST

import org.apache.hadoop.hive.ql.parse.ASTNode; //导入方法依赖的package包/类
void processGroupbyAST(ASTNode ast)
  throws LensException {
  if (ast == null) {
    return;
  }
  // iterate over children
  for (int i = 0; i < ast.getChildCount(); i++) {
    ASTNode exprNode = (ASTNode) ast.getChild(i);
    if (hasBridgeCol(exprNode, tableAlias)) {
      ast.setChild(i, getDotASTForExprAST(exprNode));
    }
  }
}
 
开发者ID:apache,项目名称:lens,代码行数:14,代码来源:BridgeTableJoinContext.java

示例8: processOrderbyAST

import org.apache.hadoop.hive.ql.parse.ASTNode; //导入方法依赖的package包/类
void processOrderbyAST(ASTNode ast)
  throws LensException {
  if (ast == null) {
    return;
  }
  // iterate over children
  for (int i = 0; i < ast.getChildCount(); i++) {
    ASTNode exprNode = (ASTNode) ast.getChild(i);
    ASTNode child = (ASTNode) exprNode.getChild(0);
    if (hasBridgeCol(child, tableAlias)) {
      exprNode.setChild(0, getDotASTForExprAST(child));
    }
  }
}
 
开发者ID:apache,项目名称:lens,代码行数:15,代码来源:BridgeTableJoinContext.java

示例9: addChildAtIndex

import org.apache.hadoop.hive.ql.parse.ASTNode; //导入方法依赖的package包/类
private void addChildAtIndex(int index, ASTNode parent, ASTNode child) {
  // add the last child
  int count = parent.getChildCount();
  Tree lastchild = parent.getChild(count - 1);
  parent.addChild(lastchild);

  // move all the children from last upto index
  for (int i = count - 2; i >= index; i--) {
    Tree ch = parent.getChild(i);
    parent.setChild(i + 1, ch);
  }
  parent.setChild(index, child);
}
 
开发者ID:apache,项目名称:lens,代码行数:14,代码来源:GroupbyResolver.java

示例10: replaceAliases

import org.apache.hadoop.hive.ql.parse.ASTNode; //导入方法依赖的package包/类
static ASTNode replaceAliases(ASTNode node, int nodePos, Map<String, String> colToTableAlias) {
  if (node == null) {
    return node;
  }

  int nodeType = node.getToken().getType();
  if (nodeType == HiveParser.TOK_TABLE_OR_COL || nodeType == HiveParser.DOT) {
    String colName = HQLParser.getColName(node);
    String newAlias = colToTableAlias.get(colName.toLowerCase());

    if (StringUtils.isBlank(newAlias)) {
      return node;
    }

    if (nodeType == HiveParser.DOT) {
      // No need to create a new node, just replace the table name ident
      ASTNode aliasNode = (ASTNode) node.getChild(0);
      ASTNode newAliasIdent = new ASTNode(new CommonToken(HiveParser.Identifier, newAlias));
      aliasNode.setChild(0, newAliasIdent);
    } else {
      // Just a column ref, we need to make it alias.col
      // '.' will become the parent node
      ASTNode dot = new ASTNode(new CommonToken(HiveParser.DOT, "."));
      ASTNode aliasIdentNode = new ASTNode(new CommonToken(HiveParser.Identifier, newAlias));
      ASTNode tabRefNode = new ASTNode(new CommonToken(HiveParser.TOK_TABLE_OR_COL, "TOK_TABLE_OR_COL"));

      tabRefNode.addChild(aliasIdentNode);
      dot.addChild(tabRefNode);

      ASTNode colIdentNode = new ASTNode(new CommonToken(HiveParser.Identifier, colName));
      dot.addChild(colIdentNode);

      ASTNode parent = (ASTNode) node.getParent();
      if (parent != null) {
        parent.setChild(nodePos, dot);
      } else {
        return dot;
      }
    }
  } else {
    // recurse down
    for (int i = 0; i < node.getChildCount(); i++) {
      ASTNode child = (ASTNode) node.getChild(i);
      replaceAliases(child, i, colToTableAlias);
    }
  }
  return node;
}
 
开发者ID:apache,项目名称:lens,代码行数:49,代码来源:AliasReplacer.java


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