private static void removeASTChild(ASTNode node) { Tree parent = node.getParent(); if (parent != null) { parent.deleteChild(node.getChildIndex()); node.setParent(null); } }
root = subQuery; } else { int nodeIdx = node.getChildIndex(); parent.setChild(nodeIdx, subQuery); if (subQuery.getChildIndex() == 0) { sibling = (ASTNode) parent.getChild(1); } else { } else { int pIdx = parent.getChildIndex(); gParent.setChild(pIdx, sibling);
root = subQuery; } else { int nodeIdx = node.getChildIndex(); parent.setChild(nodeIdx, subQuery); if (subQuery.getChildIndex() == 0) { sibling = (ASTNode) parent.getChild(1); } else { } else { int pIdx = parent.getChildIndex(); gParent.setChild(pIdx, sibling);
if (selectNode.getToken().getType() == HiveParser.Identifier && selectNode.getText().equals(DUPLICATE_EXPRESSION_PREFIX)) { sc.getQueryAst().getSelectAST().deleteChild(selectNode.getChildIndex());
private void trimHavingAndOrderby(ASTNode ast, Cube innerCube) { ASTNode havingAst = HQLParser.findNodeByPath(ast, TOK_INSERT, TOK_HAVING); if (havingAst != null) { ASTNode newHavingAst = HQLParser.trimHavingAst(havingAst, innerCube.getAllFieldNames()); if (newHavingAst != null) { havingAst.getParent().setChild(havingAst.getChildIndex(), newHavingAst); } else { havingAst.getParent().deleteChild(havingAst.getChildIndex()); } } ASTNode orderByAst = HQLParser.findNodeByPath(ast, TOK_INSERT, TOK_ORDERBY); if (orderByAst != null) { ASTNode newOrderByAst = HQLParser.trimOrderByAst(orderByAst, innerCube.getAllFieldNames()); if (newOrderByAst != null) { orderByAst.getParent().setChild(orderByAst.getChildIndex(), newOrderByAst); } else { orderByAst.getParent().deleteChild(orderByAst.getChildIndex()); } } }
private void trimHavingAndOrderby(ASTNode ast, Cube innerCube) { ASTNode havingAst = HQLParser.findNodeByPath(ast, TOK_INSERT, TOK_HAVING); if (havingAst != null) { ASTNode newHavingAst = HQLParser.trimHavingAst(havingAst, innerCube.getAllFieldNames()); if (newHavingAst != null) { havingAst.getParent().setChild(havingAst.getChildIndex(), newHavingAst); } else { havingAst.getParent().deleteChild(havingAst.getChildIndex()); } } ASTNode orderByAst = HQLParser.findNodeByPath(ast, TOK_INSERT, TOK_ORDERBY); if (orderByAst != null) { ASTNode newOrderByAst = HQLParser.trimOrderByAst(orderByAst, innerCube.getAllFieldNames()); if (newOrderByAst != null) { orderByAst.getParent().setChild(orderByAst.getChildIndex(), newOrderByAst); } else { orderByAst.getParent().deleteChild(orderByAst.getChildIndex()); } } }
if (selectNode.getToken().getType() == HiveParser.Identifier && selectNode.getText().equals(DUPLICATE_EXPRESSION_PREFIX)) { sc.getQueryAst().getSelectAST().deleteChild(selectNode.getChildIndex());
TimeRange timeRange = timeRangeTimeRangeEntry.getValue(); if (astNode.getParent() == queriedTimeRange.getAstNode()) { if (astNode.getChildIndex() == 2) { return Pair.of(getStringLiteralAST(formatAbsDate(timeRange.getFromDate())), false); } else if (astNode.getChildIndex() == 3) { return Pair.of(getStringLiteralAST(formatAbsDate(timeRange.getToDate())), false);
TimeRange timeRange = timeRangeTimeRangeEntry.getValue(); if (astNode.getParent() == queriedTimeRange.getAstNode()) { if (astNode.getChildIndex() == 2) { return Pair.of(getStringLiteralAST(formatAbsDate(timeRange.getFromDate())), false); } else if (astNode.getChildIndex() == 3) { return Pair.of(getStringLiteralAST(formatAbsDate(timeRange.getToDate())), false);
static ASTNode trimHavingAst(ASTNode astNode, Collection<String> columns) { if (astNode != null) { if (astNode.getParent() != null && astNode.getParent().getType() == DOT && astNode.getChildIndex() == 1) { return columns.contains(astNode.getText()) ? astNode : null; } for (int i = astNode.getChildCount() - 1; i >= 0; i--) { ASTNode replacement = trimHavingAst((ASTNode) astNode.getChild(i), columns); if (replacement == null) { astNode.deleteChild(i); } else { astNode.setChild(i, replacement); } } if (isAggregateAST(astNode) || BINARY_OPERATORS.contains(astNode.getType())) { if (astNode.getChildCount() == 1) { ASTNode child = (ASTNode) astNode.getChild(0); if (!BINARY_OPERATORS.contains(child.getType())) { return null; } else { return child; } } } } return astNode; } static ASTNode trimOrderByAst(ASTNode astNode, Collection<String> columns) {
static ASTNode trimHavingAst(ASTNode astNode, Collection<String> columns) { if (astNode != null) { if (astNode.getParent() != null && astNode.getParent().getType() == DOT && astNode.getChildIndex() == 1) { return columns.contains(astNode.getText()) ? astNode : null; } for (int i = astNode.getChildCount() - 1; i >= 0; i--) { ASTNode replacement = trimHavingAst((ASTNode) astNode.getChild(i), columns); if (replacement == null) { astNode.deleteChild(i); } else { astNode.setChild(i, replacement); } } if (isAggregateAST(astNode) || BINARY_OPERATORS.contains(astNode.getType())) { if (astNode.getChildCount() == 1) { ASTNode child = (ASTNode) astNode.getChild(0); if (!BINARY_OPERATORS.contains(child.getType())) { return null; } else { return child; } } } } return astNode; } static ASTNode trimOrderByAst(ASTNode astNode, Collection<String> columns) {
childNode.getParent().setChild(childNode.getChildIndex(), updatedTimeRange); return;
static ASTNode trimOrderByAst(ASTNode astNode, Collection<String> columns) { if (astNode != null) { if (astNode.getParent() != null && astNode.getParent().getType() == DOT && astNode.getChildIndex() == 1) { return columns.contains(astNode.getText()) ? astNode : null;
static ASTNode trimOrderByAst(ASTNode astNode, Collection<String> columns) { if (astNode != null) { if (astNode.getParent() != null && astNode.getParent().getType() == DOT && astNode.getChildIndex() == 1) { return columns.contains(astNode.getText()) ? astNode : null;
childNode.getParent().setChild(childNode.getChildIndex(), updatedTimeRange); return;
root = subQuery; } else { int nodeIdx = node.getChildIndex(); parent.setChild(nodeIdx, subQuery); if (subQuery.getChildIndex() == 0) { sibling = (ASTNode) parent.getChild(1); } else { } else { int pIdx = parent.getChildIndex(); gParent.setChild(pIdx, sibling);
"select"); int ci = ast.getChildIndex(); if (parent.getToken() == null || parent.getType() == HiveParser.TOK_EXPLAIN || parent.getType() == HiveParser.TOK_CREATETABLE) { } else { nextChild = (ASTNode) parent.getParent().getChild(parent.getChildIndex()+1);