本文整理汇总了Java中org.apache.hadoop.hive.ql.parse.ASTNode.addChild方法的典型用法代码示例。如果您正苦于以下问题:Java ASTNode.addChild方法的具体用法?Java ASTNode.addChild怎么用?Java ASTNode.addChild使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.hadoop.hive.ql.parse.ASTNode
的用法示例。
在下文中一共展示了ASTNode.addChild方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: processAggregate
import org.apache.hadoop.hive.ql.parse.ASTNode; //导入方法依赖的package包/类
private ASTNode processAggregate(ASTNode astNode, ASTNode innerSelectAST,
AliasDecider aliasDecider, boolean isSelectAst) {
ASTNode innerSelectASTWithoutAlias = MetastoreUtil.copyAST(astNode);
ASTNode innerSelectExprAST = new ASTNode(new CommonToken(HiveParser.TOK_SELEXPR, "TOK_SELEXPR"));
innerSelectExprAST.addChild(innerSelectASTWithoutAlias);
String alias = aliasDecider.decideAlias(astNode);
ASTNode aliasNode = new ASTNode(new CommonToken(Identifier, alias));
innerSelectExprAST.addChild(aliasNode);
innerSelectAST.addChild(innerSelectExprAST);
ASTNode dotAST = getDotAST(cubeql.getCube().getName(), alias);
ASTNode outerAST = new ASTNode(new CommonToken(TOK_FUNCTION, "TOK_FUNCTION"));
//TODO: take care or non-transitive aggregate functions
outerAST.addChild(new ASTNode(new CommonToken(Identifier, astNode.getChild(0).getText())));
outerAST.addChild(dotAST);
HashableASTNode innerAST = new HashableASTNode(innerSelectASTWithoutAlias);
if (isSelectAst && !innerToOuterSelectASTs.containsKey(innerAST)) {
innerToOuterSelectASTs.put(innerAST, outerAST);
} else if (!isSelectAst && !innerToOuterHavingASTs.containsKey(innerAST)) {
innerToOuterHavingASTs.put(innerAST, outerAST);
}
return outerAST;
}
示例2: promoteGroupby
import org.apache.hadoop.hive.ql.parse.ASTNode; //导入方法依赖的package包/类
private void promoteGroupby(CubeQueryContext cubeql, List<SelectPhraseContext> selectExprs, List<String> groupByExprs)
throws LensException {
if (!groupbyPromotionEnabled) {
return;
}
if (selectExprs.size() > 0) {
log.info("Not promoting groupby expression to select, since there are expression projected");
return;
}
int index = 0;
for (String expr : groupByExprs) {
if (!contains(selectExprs, expr)) {
ASTNode exprAST = HQLParser.parseExpr(expr, cubeql.getConf());
ASTNode parent = new ASTNode(new CommonToken(HiveParser.TOK_SELEXPR, "TOK_SELEXPR"));
parent.addChild(exprAST);
exprAST.setParent(parent);
addChildAtIndex(index, cubeql.getSelectAST(), parent);
updateSelectPhrase(cubeql, index, parent);
index++;
}
}
}
示例3: generate
import org.apache.hadoop.hive.ql.parse.ASTNode; //导入方法依赖的package包/类
@Override
public boolean generate(ASTNode hiveRoot, CommonTree sqlRoot, ASTNode currentHiveNode,
CommonTree currentSqlNode, TranslateContext context) throws SqlXlateException {
if (currentHiveNode.getChildCount() == 2&¤tHiveNode.getType()==HiveParser.TOK_SELEXPR) {
ASTNode dot = super.newHiveASTNode(HiveParser.DOT, ".");
dot.addChild((ASTNode) currentHiveNode.getChild(0));
// if children count == 2 the second should only be text element
dot.addChild((ASTNode) currentHiveNode.getChild(1).getChild(0));
currentHiveNode.deleteChild(0);
currentHiveNode.deleteChild(0);
currentHiveNode.addChild(dot);
LOG.debug("Generated Cascated Element : " + dot.toStringTree());
return true;
}
return true;
}
示例4: copyAST
import org.apache.hadoop.hive.ql.parse.ASTNode; //导入方法依赖的package包/类
public static ASTNode copyAST(ASTNode original,
Function<ASTNode, Pair<ASTNode, Boolean>> overrideCopyFunction) {
Pair<ASTNode, Boolean> copy1 = overrideCopyFunction.apply(original);
ASTNode copy = copy1.getLeft();
if (copy1.getRight()) {
if (original.getChildren() != null) {
for (Node o : original.getChildren()) {
copy.addChild(copyAST((ASTNode) o, overrideCopyFunction));
}
}
}
return copy;
}
示例5: getSelectExpr
import org.apache.hadoop.hive.ql.parse.ASTNode; //导入方法依赖的package包/类
/**
* Get the select expression. In case of node is default retunrs "0" with alias
* otherwise the select phrase with alias.
*
* @param nodeWithoutAlias
* @param aliasNode
* @param isDefault
* @return
* @throws LensException
*/
private ASTNode getSelectExpr(ASTNode nodeWithoutAlias, ASTNode aliasNode, boolean isDefault)
throws LensException {
ASTNode node = getSelectExprAST();
if (nodeWithoutAlias == null && isDefault) {
node.addChild(HQLParser.parseExpr(DEFAULT_MEASURE));
node.addChild(aliasNode);
} else {
node.addChild(nodeWithoutAlias);
node.addChild(aliasNode);
}
return node;
}
示例6: processSelectExpression
import org.apache.hadoop.hive.ql.parse.ASTNode; //导入方法依赖的package包/类
/**
* Get the inner and outer AST with alias for each child of StorageCandidate
*
* @param sc
* @param outerSelectAst
* @param innerSelectAST
* @param aliasDecider
* @throws LensException
*/
private void processSelectExpression(StorageCandidateHQLContext sc, ASTNode outerSelectAst, ASTNode innerSelectAST,
AliasDecider aliasDecider) throws LensException {
//ASTNode selectAST = sc.getQueryAst().getSelectAST();
ASTNode selectAST = storageCandidateToSelectAstMap.get(sc);
if (selectAST == null) {
return;
}
// iterate over all children of the ast and get outer ast corresponding to it.
for (int i = 0; i < selectAST.getChildCount(); i++) {
ASTNode child = (ASTNode) selectAST.getChild(i);
ASTNode outerSelect = new ASTNode(child);
ASTNode selectExprAST = (ASTNode) child.getChild(0);
ASTNode outerAST = getOuterAST(selectExprAST, innerSelectAST, aliasDecider, sc, true,
cubeql.getBaseCube().getDimAttributeNames());
outerSelect.addChild(outerAST);
// has an alias? add it
if (child.getChildCount() > 1) {
outerSelect.addChild(child.getChild(1));
}
if (outerSelectAst.getChildCount() <= selectAST.getChildCount()) {
if (outerSelectAst.getChild(i) == null) {
outerSelectAst.addChild(outerSelect);
} else if (HQLParser.getString((ASTNode) outerSelectAst.getChild(i).getChild(0)).equals(DEFAULT_MEASURE)) {
outerSelectAst.replaceChildren(i, i, outerSelect);
}
}
}
sc.getQueryAst().setSelectAST(innerSelectAST);
}
示例7: processGroupByExpression
import org.apache.hadoop.hive.ql.parse.ASTNode; //导入方法依赖的package包/类
/**
* GroupbyAST is having dim only columns all the columns should have been
* projected. Get the alias for the projected columns and add to group by clause.
*
* @param astNode
* @return
* @throws LensException
*/
private ASTNode processGroupByExpression(ASTNode astNode) throws LensException {
ASTNode outerExpression = new ASTNode(astNode);
// iterate over all children of the ast and get outer ast corresponding to it.
for (Node child : astNode.getChildren()) {
// Columns in group by should have been projected as they are dimension columns
if (innerToOuterSelectASTs.containsKey(new HQLParser.HashableASTNode((ASTNode) child))) {
outerExpression.addChild(innerToOuterSelectASTs.get(new HQLParser.HashableASTNode((ASTNode) child)));
}
}
return outerExpression;
}
示例8: promoteSelect
import org.apache.hadoop.hive.ql.parse.ASTNode; //导入方法依赖的package包/类
private void promoteSelect(CubeQueryContext cubeql, List<SelectPhraseContext> selectExprs, List<String> groupByExprs)
throws LensException {
if (!selectPromotionEnabled) {
return;
}
if (!groupByExprs.isEmpty()) {
log.info("Not promoting select expression to groupby, since there are already group by expressions");
return;
}
// each selected column, if it is not a cube measure, and does not have
// aggregation on the column, then it is added to group by columns.
if (cubeql.hasAggregates()) {
for (SelectPhraseContext sel : selectExprs) {
String expr = sel.getExprWithoutAlias();
if (!groupByExprs.contains(expr)) {
if (!sel.isAggregate()) {
ASTNode exprAST = HQLParser.parseExpr(expr, cubeql.getConf());
ASTNode groupbyAST = cubeql.getGroupByAST();
if (!isConstantsUsed(exprAST)) {
if (groupbyAST != null) {
// groupby ast exists, add the expression to AST
groupbyAST.addChild(exprAST);
} else {
// no group by ast exist, create one
ASTNode newAST = new ASTNode(new CommonToken(TOK_GROUPBY, "TOK_GROUPBY"));
newAST.addChild(exprAST);
cubeql.setGroupByAST(newAST);
}
}
}
}
}
}
}
示例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: attachHiveNode
import org.apache.hadoop.hive.ql.parse.ASTNode; //导入方法依赖的package包/类
void attachHiveNode(ASTNode hiveRoot, ASTNode currentHiveNode,
ASTNode ret) {
currentHiveNode.addChild(ret);
if (hiveRoot != null && (hiveRoot.getChildren() == null || hiveRoot.getChildren().size() == 0)) {
hiveRoot.addChild(currentHiveNode);
}
}
示例11: buildTmpDestinationNode
import org.apache.hadoop.hive.ql.parse.ASTNode; //导入方法依赖的package包/类
ASTNode buildTmpDestinationNode() {
ASTNode desNode = SqlXlateUtil.newASTNode(HiveParser.TOK_DESTINATION, "TOK_DESTINATION");
ASTNode dirNode = SqlXlateUtil.newASTNode(HiveParser.TOK_DIR, "TOK_DIR");
desNode.addChild(dirNode);
ASTNode tmpNode = SqlXlateUtil.newASTNode(HiveParser.TOK_TMP_FILE, "TOK_TMP_FILE");
dirNode.addChild(tmpNode);
return desNode;
}
示例12: buildAllColRef
import org.apache.hadoop.hive.ql.parse.ASTNode; //导入方法依赖的package包/类
ASTNode buildAllColRef() {
ASTNode select = SqlXlateUtil.newASTNode(HiveParser.TOK_SELECT, "TOK_SELECT");
ASTNode selExpr = SqlXlateUtil.newASTNode(HiveParser.TOK_SELEXPR, "TOK_SELEXPR");
select.addChild(selExpr);
ASTNode allColRef = SqlXlateUtil.newASTNode(HiveParser.TOK_ALLCOLREF, "TOK_ALLCOLREF");
selExpr.addChild(allColRef);
return select;
}
示例13: generate
import org.apache.hadoop.hive.ql.parse.ASTNode; //导入方法依赖的package包/类
@Override
public boolean generate(ASTNode hiveRoot, CommonTree sqlRoot, ASTNode currentHiveNode,
CommonTree currentSqlNode, TranslateContext context) throws SqlXlateException {
ExplainSession.setExplain();
ASTNode explainNode = SqlXlateUtil.newASTNode(HiveParser.TOK_EXPLAIN, "TOK_EXPLAIN");
currentHiveNode.addChild(explainNode);
return generateChildren(hiveRoot, sqlRoot, explainNode, currentSqlNode, context);
}
示例14: mergeFilters
import org.apache.hadoop.hive.ql.parse.ASTNode; //导入方法依赖的package包/类
/**
* Merge Two Filters with op
*
* @param op
* @param left
* @param right
* @return
*/
public static ASTNode mergeFilters(ASTNode op, ASTNode left, ASTNode right) {
if (left == null && right == null) {
return null;
}
if (left == null) {
return right;
} else if (right == null) {
return left;
} else {
op.addChild(left);
op.addChild(right);
return op;
}
}
示例15: processOrderbyExpression
import org.apache.hadoop.hive.ql.parse.ASTNode; //导入方法依赖的package包/类
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;
}