本文整理汇总了Java中org.apache.hadoop.hive.ql.parse.HiveParser.TOK_TABLE_OR_COL属性的典型用法代码示例。如果您正苦于以下问题:Java HiveParser.TOK_TABLE_OR_COL属性的具体用法?Java HiveParser.TOK_TABLE_OR_COL怎么用?Java HiveParser.TOK_TABLE_OR_COL使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.apache.hadoop.hive.ql.parse.HiveParser
的用法示例。
在下文中一共展示了HiveParser.TOK_TABLE_OR_COL属性的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getNumFactTableInExpressions
/**
* Get number of fact columns used in the an expression
*
* @param node
* @param count
* @return Number of fact columns used in expression
*/
protected int getNumFactTableInExpressions(ASTNode node, MutableInt count) {
if (node == null) {
log.debug("ASTNode is null ");
return 0;
}
if (node.getToken().getType() == HiveParser.TOK_TABLE_OR_COL) {
String factAlias = getFactAlias();
String table = node.getChild(0).getText();
if (table.equals(factAlias)) {
count.add(1);
}
}
for (int i = 0; i < node.getChildCount(); i++) {
ASTNode child = (ASTNode) node.getChild(i);
getNumFactTableInExpressions(child, count);
}
return count.intValue();
}
示例2: getColsForHavingAST
private void getColsForHavingAST(CubeQueryContext cubeql, ASTNode clause) throws LensException {
if (clause == null) {
return;
}
// split having clause phrases to be column level sothat having clause can be pushed to multiple facts if required.
if (HQLParser.isAggregateAST(clause) || clause.getType() == HiveParser.TOK_TABLE_OR_COL
|| clause.getType() == HiveParser.DOT || clause.getChildCount() == 0) {
QueriedPhraseContext qur = new QueriedPhraseContext(clause);
qur.setAggregate(true);
getColsForTree(cubeql, clause, qur, true);
cubeql.addColumnsQueried(qur.getTblAliasToColumns());
cubeql.addQueriedPhrase(qur);
} else {
for (Node child : clause.getChildren()) {
getColsForHavingAST(cubeql, (ASTNode)child);
}
}
}
示例3: transform
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: hasTableOrColumn
private boolean hasTableOrColumn(ASTNode node) {
if (node.getToken() != null) {
if (node.getToken().getType() == HiveParser.TOK_TABLE_OR_COL) {
return true;
}
}
for (int i = 0; i < node.getChildCount(); i++) {
if (hasTableOrColumn((ASTNode) node.getChild(i))) {
return true;
}
}
return false;
}
示例5: replaceAliases
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;
}
示例6: 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;
}
}
示例7: hasMeasuresNotInDefaultAggregates
private boolean hasMeasuresNotInDefaultAggregates(CubeQueryContext cubeql, ASTNode node, String function,
boolean aggregateResolverDisabled) {
if (node == null) {
return false;
}
if (HQLParser.isAggregateAST(node)) {
if (node.getChild(0).getType() == HiveParser.Identifier) {
function = BaseSemanticAnalyzer.unescapeIdentifier(node.getChild(0).getText());
}
} else if (cubeql.isCubeMeasure(node)) {
// Exit for the recursion
String colname;
if (node.getToken().getType() == HiveParser.TOK_TABLE_OR_COL) {
colname = node.getChild(0).getText();
} else {
// node in 'alias.column' format
ASTNode colIdent = (ASTNode) node.getChild(1);
colname = colIdent.getText();
}
colname = colname.toLowerCase();
if (cubeql.getQueriedExprs().contains(colname)) {
String cubeAlias = cubeql.getAliasForTableName(cubeql.getCube().getName());
for (ASTNode exprNode : cubeql.getExprCtx().getExpressionContext(colname, cubeAlias).getAllASTNodes()) {
if (hasMeasuresNotInDefaultAggregates(cubeql, exprNode, function, aggregateResolverDisabled)) {
return true;
}
}
return false;
} else {
CubeMeasure measure = cubeql.getCube().getMeasureByName(colname);
if (function != null && !function.isEmpty()) {
// Get the cube measure object and check if the passed function is the
// default one set for this measure
return !function.equalsIgnoreCase(measure.getAggregate());
} else if (!aggregateResolverDisabled && measure.getAggregate() != null) {
// not inside any aggregate, but default aggregate exists
return false;
}
return true;
}
}
for (int i = 0; i < node.getChildCount(); i++) {
if (hasMeasuresNotInDefaultAggregates(cubeql, (ASTNode) node.getChild(i), function, aggregateResolverDisabled)) {
// Return on the first measure not inside its default aggregate
return true;
}
}
return false;
}