private StringBuilder dump(StringBuilder sb) { Deque<ASTNode> stack = new ArrayDeque<ASTNode>(); stack.push(this); int tabLength = 0; while (!stack.isEmpty()) { ASTNode next = stack.peek(); if (!next.visited) { sb.append(StringUtils.repeat(" ", tabLength * 3)); sb.append(next.toString()); sb.append("\n"); if (next.children != null) { for (int i = next.children.size() - 1 ; i >= 0 ; i--) { stack.push((ASTNode)next.children.get(i)); } } tabLength++; next.visited = true; } else { tabLength--; next.visited = false; stack.pop(); } } return sb; }
private StringBuilder dump(StringBuilder sb) { Deque<ASTNode> stack = new ArrayDeque<ASTNode>(); stack.push(this); int tabLength = 0; while (!stack.isEmpty()) { ASTNode next = stack.peek(); if (!next.visited) { sb.append(StringUtils.repeat(" ", tabLength * 3)); sb.append(next.toString()); sb.append("\n"); if (next.children != null) { for (int i = next.children.size() - 1 ; i >= 0 ; i--) { stack.push((ASTNode)next.children.get(i)); } } tabLength++; next.visited = true; } else { tabLength--; next.visited = false; stack.pop(); } } return sb; }
private String replaceDefaultKeywordForMerge(String valueClause, Table table, ASTNode columnListNode) throws SemanticException { if (!valueClause.toLowerCase().contains("`default`")) { return valueClause; } Map<String, String> colNameToDefaultConstraint = getColNameToDefaultValueMap(table); String[] values = valueClause.trim().split(","); String[] replacedValues = new String[values.length]; // the list of the column names may be set in the query String[] columnNames = columnListNode == null ? table.getAllCols().stream().map(f -> f.getName()).toArray(size -> new String[size]) : columnListNode.getChildren().stream().map(n -> ((ASTNode)n).toString()).toArray(size -> new String[size]); for (int i = 0; i < values.length; i++) { if (values[i].trim().toLowerCase().equals("`default`")) { replacedValues[i] = MapUtils.getString(colNameToDefaultConstraint, columnNames[i], "null"); } else { replacedValues[i] = values[i]; } } return StringUtils.join(replacedValues, ','); }
private ResourceType getResourceType(ASTNode token) throws SemanticException { switch (token.getType()) { case HiveParser.TOK_JAR: return ResourceType.JAR; case HiveParser.TOK_FILE: return ResourceType.FILE; case HiveParser.TOK_ARCHIVE: return ResourceType.ARCHIVE; default: throw new SemanticException("Unexpected token " + token.toString()); } }
private ResourceType getResourceType(ASTNode token) throws SemanticException { switch (token.getType()) { case HiveParser.TOK_JAR: return ResourceType.JAR; case HiveParser.TOK_FILE: return ResourceType.FILE; case HiveParser.TOK_ARCHIVE: return ResourceType.ARCHIVE; default: throw new SemanticException("Unexpected token " + token.toString()); } }
String astKeyName = astExprNodePair.getKey().toString().toLowerCase(); if (astExprNodePair.getKey().getType() == HiveParser.Identifier) { astKeyName = stripIdentifierQuotes(astKeyName);
String str = next.toString(); rootNode.addtoMemoizedString(next.getType() != HiveParser.StringLiteral ? str.toLowerCase() : str); next.endIndx = rootNode.getMemoizedStringLen(); String str = next.toString(); rootNode.addtoMemoizedString((next.getType() == HiveParser.StringLiteral || null == str) ? str : str.toLowerCase()); rootNode.addtoMemoizedString(" ");
String astKeyName = astExprNodePair.getKey().toString().toLowerCase(); if (astExprNodePair.getKey().getType() == HiveParser.Identifier) { astKeyName = stripIdentifierQuotes(astKeyName);
String str = next.toString(); rootNode.addtoMemoizedString(next.getType() != HiveParser.StringLiteral ? str.toLowerCase() : str); next.endIndx = rootNode.getMemoizedStringLen(); String str = next.toString(); rootNode.addtoMemoizedString((next.getType() == HiveParser.StringLiteral || null == str) ? str : str.toLowerCase()); rootNode.addtoMemoizedString(" ");
throw new SemanticException("Invalid order by expression: " + obASTExpr.toString());
ExprNodeDesc obExprNDesc = astToExprNDescMap.get(ref); if (obExprNDesc == null) throw new SemanticException("Invalid order by expression: " + obASTExpr.toString());
public String dump() { StringBuilder sb = new StringBuilder(); sb.append('('); sb.append(toString()); ArrayList<Node> children = getChildren(); if (children != null) { for (Node node : getChildren()) { if (node instanceof ASTNode) { sb.append(((ASTNode) node).dump()); } else { sb.append("NON-ASTNODE!!"); } } } sb.append(')'); return sb.toString(); }
private ResourceType getResourceType(ASTNode token) throws SemanticException { switch (token.getType()) { case HiveParser.TOK_JAR: return ResourceType.JAR; case HiveParser.TOK_FILE: return ResourceType.FILE; case HiveParser.TOK_ARCHIVE: return ResourceType.ARCHIVE; default: throw new SemanticException("Unexpected token " + token.toString()); } }
private StringBuilder dump(StringBuilder sb, String ws) { sb.append(ws); sb.append(toString()); sb.append("\n"); ArrayList<Node> children = getChildren(); if (children != null) { for (Node node : getChildren()) { if (node instanceof ASTNode) { ((ASTNode) node).dump(sb, ws + " "); } else { sb.append(ws); sb.append(" NON-ASTNODE!!"); sb.append("\n"); } } } return sb; } }
/** * 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; }
/** * 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; }
/** * Gets the limit clause. * * @param node the node * @return the limit clause */ public String getLimitClause(ASTNode node) { if (node.getToken().getType() == HiveParser.TOK_LIMIT) { limit = HQLParser.findNodeByPath(node, HiveParser.Number).toString(); } for (int i = 0; i < node.getChildCount(); i++) { ASTNode child = (ASTNode) node.getChild(i); getLimitClause(child); } return limit; }
/** * Gets the limit clause. * * @param node the node * @return the limit clause */ public String getLimitClause(ASTNode node) { if (node.getToken().getType() == HiveParser.TOK_LIMIT) { limit = HQLParser.findNodeByPath(node, HiveParser.Number).toString(); } for (int i = 0; i < node.getChildCount(); i++) { ASTNode child = (ASTNode) node.getChild(i); getLimitClause(child); } return limit; }
static void updateOrderByWithFinalAlias(ASTNode orderby, ASTNode select) throws LensException{ if (orderby == null) { return; } for (Node orderbyNode : orderby.getChildren()) { ASTNode orderBychild = (ASTNode) orderbyNode; for (Node selectNode : select.getChildren()) { ASTNode selectChild = (ASTNode) selectNode; if (selectChild.getChildCount() == 2) { if (HQLParser.getString((ASTNode) selectChild.getChild(0)) .equals(HQLParser.getString((ASTNode) orderBychild.getChild(0)))) { ASTNode alias = new ASTNode((ASTNode) selectChild.getChild(1)); if (!alias.toString().matches("\\S+")) { throw new LensException(LensCubeErrorCode.ORDERBY_ALIAS_CONTAINING_WHITESPACE.getLensErrorInfo(), alias); } orderBychild.replaceChildren(0, 0, alias); break; } } } } } }
static void updateOrderByWithFinalAlias(ASTNode orderby, ASTNode select) throws LensException{ if (orderby == null) { return; } for (Node orderbyNode : orderby.getChildren()) { ASTNode orderBychild = (ASTNode) orderbyNode; for (Node selectNode : select.getChildren()) { ASTNode selectChild = (ASTNode) selectNode; if (selectChild.getChildCount() == 2) { if (HQLParser.getString((ASTNode) selectChild.getChild(0)) .equals(HQLParser.getString((ASTNode) orderBychild.getChild(0)))) { ASTNode alias = new ASTNode((ASTNode) selectChild.getChild(1)); if (!alias.toString().matches("\\S+")) { throw new LensException(LensCubeErrorCode.ORDERBY_ALIAS_CONTAINING_WHITESPACE.getLensErrorInfo(), alias); } orderBychild.replaceChildren(0, 0, alias); break; } } } } } }