本文整理汇总了Java中org.apache.hadoop.hive.ql.parse.HiveParser.DOT属性的典型用法代码示例。如果您正苦于以下问题:Java HiveParser.DOT属性的具体用法?Java HiveParser.DOT怎么用?Java HiveParser.DOT使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.apache.hadoop.hive.ql.parse.HiveParser
的用法示例。
在下文中一共展示了HiveParser.DOT属性的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: replaceColumnNames
void replaceColumnNames(ASTNode node) {
if (node == null) {
return;
}
int nodeType = node.getToken().getType();
if (nodeType == HiveParser.DOT) {
ASTNode tabident = HQLParser.findNodeByPath(node, TOK_TABLE_OR_COL, Identifier);
ASTNode colIdent = (ASTNode) node.getChild(1);
String column = colIdent.getText().toLowerCase();
String alias = tabident.getText().toLowerCase();
if (aliasToNativeTableInfo.get(alias) != null) {
colIdent.getToken().setText(aliasToNativeTableInfo.get(alias).getNativeColumn(column));
}
} else {
// recurse down
for (int i = 0; i < node.getChildCount(); i++) {
ASTNode child = (ASTNode) node.getChild(i);
replaceColumnNames(child);
}
}
}
示例2: updateOuterASTDuplicateAliases
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: 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);
}
}
}
示例4: 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;
}
示例5: generate
@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;
}
示例6: factFilterPushDown
/**
* Get fact filters for pushdown
*
* @param node
*/
public void factFilterPushDown(ASTNode node) {
if (node == null) {
log.debug("Join AST is null ");
return;
}
String filterCond = "";
if (node.getToken().getType() == HiveParser.KW_AND) {
ASTNode parentNode = (ASTNode) node.getChild(0).getParent();
// Skip the join conditions used as "and" for fact filter pushdown.
// eg. inner join fact.id1 = dim.id and fact.id2 = dim.id
if (parentNode.getChild(0).getChild(0).getType() == HiveParser.DOT
&& parentNode.getChild(0).getChild(1).getType() == HiveParser.DOT
&& parentNode.getChild(1).getChild(0).getType() == HiveParser.DOT
&& parentNode.getChild(1).getChild(1).getType() == HiveParser.DOT) {
return;
}
ASTNode right = (ASTNode) node.getChild(1);
filterCond = HQLParser.getString(right);
}
String factAlias = getFactAlias();
if (filterCond.matches("(.*)" + factAlias + "(.*)")) {
factFilterPush.append(filterCond).append(" and ");
}
for (int i = 0; i < node.getChildCount(); i++) {
ASTNode child = (ASTNode) node.getChild(i);
factFilterPushDown(child);
}
}
示例7: getFactKeysFromNode
/**
* Get fact keys used in the AST
*
* @param node
*/
public void getFactKeysFromNode(ASTNode node) {
if (node == null) {
log.debug("AST is null ");
return;
}
if (HQLParser.isAggregateAST(node)) {
return;
} else {
if (node.getToken().getType() == HiveParser.DOT
&& node.getParent().getChild(0).getType() != HiveParser.Identifier) {
String table = HQLParser.findNodeByPath(node, TOK_TABLE_OR_COL, Identifier).toString();
String column = node.getChild(1).toString().toLowerCase();
String factAlias = getFactAlias();
if (table.equals(factAlias)) {
factKeys.add(factAlias + "." + column);
}
}
}
for (int i = 0; i < node.getChildCount(); i++) {
ASTNode child = (ASTNode) node.getChild(i);
getFactKeysFromNode(child);
}
}
示例8: getAllDimColumns
/**
* Get all columns used for dimmension tables
* @param node
*/
public void getAllDimColumns(ASTNode node) {
if (node == null) {
log.debug("Input AST is null ");
return;
}
// Assuming column is specified with table.column format
if (node.getToken().getType() == HiveParser.DOT) {
String table = HQLParser.findNodeByPath(node, TOK_TABLE_OR_COL, Identifier).toString();
String column = node.getChild(1).toString();
Iterator iterator = tableToAliasMap.keySet().iterator();
while (iterator.hasNext()) {
String tab = (String) iterator.next();
String alias = tableToAliasMap.get(tab);
if ((table.equals(tab) || table.equals(alias)) && column != null) {
LinkedHashSet<String> cols;
if (!tableToAccessedColMap.containsKey(tab)) {
cols = new LinkedHashSet<String>();
cols.add(column);
tableToAccessedColMap.put(tab, cols);
} else {
cols = tableToAccessedColMap.get(tab);
if (!cols.contains(column)) {
cols.add(column);
}
}
}
}
}
for (int i = 0; i < node.getChildCount(); i++) {
ASTNode child = (ASTNode) node.getChild(i);
getAllDimColumns(child);
}
}
示例9: 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;
}
示例10: getTablesAndColumns
/**
* Gets the tables and columns.
*
* @param node the node
* @return the tables and columns
*/
public ArrayList<String> getTablesAndColumns(ASTNode node) {
if (node.getToken().getType() == HiveParser.DOT) {
String table = HQLParser.findNodeByPath(node, TOK_TABLE_OR_COL, Identifier).toString();
String column = node.getChild(1).toString().toLowerCase();
String keys = table.concat(".").concat(column);
allkeys.add(keys);
}
for (int i = 0; i < node.getChildCount(); i++) {
ASTNode child = (ASTNode) node.getChild(i);
getTablesAndColumns(child);
}
return (ArrayList<String>) allkeys;
}
示例11: getAllColumnsOfNode
/**
* Get columns used in ASTNode
*
* @param node
* @param msrs
* @return
*/
private Set<String> getAllColumnsOfNode(ASTNode node, Set<String> msrs, StorageCandidateHQLContext sc) {
if (node.getToken().getType() == HiveParser.DOT) {
String col = node.getChild(1).toString();
msrs.addAll(getSourceColumnOfRefColumn(col, sc));
}
for (int i = 0; i < node.getChildCount(); i++) {
ASTNode child = (ASTNode) node.getChild(i);
getAllColumnsOfNode(child, msrs, sc);
}
return msrs;
}
示例12: 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;
}
示例13: 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;
}