本文整理汇总了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;
}
示例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);
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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));
}
}
}
示例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));
}
}
}
示例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);
}
示例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;
}