/** Parses the Hive query. */ public static ASTNode parse( String command, Context ctx, String viewFullyQualifiedName) throws ParseException { ParseDriver pd = new ParseDriver(); ASTNode tree = pd.parse(command, ctx, viewFullyQualifiedName); tree = findRootNonNullToken(tree); handleSetColRefs(tree); return tree; }
/** * Constructs an AST for given DEFAULT string * @param newValue * @throws SemanticException */ private ASTNode getNodeReplacementforDefault(String newValue) throws SemanticException { ASTNode newNode = null; if(newValue== null) { newNode = ASTBuilder.construct(HiveParser.TOK_NULL, "TOK_NULL").node(); } else { try { newNode = new ParseDriver().parseExpression(newValue); } catch(Exception e) { throw new SemanticException("Error while parsing default value for DEFAULT keyword: " + newValue + ". Error message: " + e.getMessage()); } } return newNode; }
private int processQueryHint(ASTNode ast, QBParseInfo qbp, int posn) throws SemanticException{ ParseDriver pd = new ParseDriver(); String queryHintStr = ast.getText(); if (LOG.isDebugEnabled()) { LOG.debug("QUERY HINT: "+queryHintStr); } try { ASTNode hintNode = pd.parseHint(queryHintStr); qbp.setHints(hintNode); } catch (ParseException e) { throw new SemanticException("failed to parse query hint: "+e.getMessage(), e); } return posn + 1; }
public ASTNode parse(String command, Context ctx) throws ParseException { return parse(command, ctx, null); }
public TestParseDriverIntervals(String query) { parseDriver = new ParseDriver(); this.query = query; }
ParseDriver pd = new ParseDriver(); selNode = pd.parseSelect(selectExprStr, null); } catch (ParseException pe) { throw new SemanticException(pe);
String whereStr = "field5=1 and field6 in ('a', 'b')"; String havingStr = "sum(field7) > 11"; ASTNode tree = parseDriver.parse(selectStr + " from table1 where " + whereStr + " group by field1, field2 having " + havingStr); assertEquals(tree.getType(), 0); assertEquals(insertAST.getChildCount(), 5); assertEquals(insertAST.getChild(0).getType(), HiveParser.TOK_DESTINATION); assertTree((ASTNode) insertAST.getChild(1), parseDriver.parseSelect(selectStr, null)); assertEquals(insertAST.getChild(2).getType(), HiveParser.TOK_WHERE); assertTree((ASTNode) insertAST.getChild(2).getChild(0), parseDriver.parseExpression(whereStr)); assertEquals(insertAST.getChild(3).getType(), HiveParser.TOK_GROUPBY); assertEquals(insertAST.getChild(3).getChildCount(), 2); assertTree((ASTNode) insertAST.getChild(4).getChild(0), parseDriver.parseExpression(havingStr));
public static Action fromMetastoreExpression(String metastoreActionExpression) { ParseDriver driver = new ParseDriver(); ASTNode node = null; try { node = driver.parseTriggerActionExpression(metastoreActionExpression); } catch (ParseException e) { throw new IllegalArgumentException(
ParseDriver driver = new ParseDriver(); ASTNode node = null; try { node = driver.parseTriggerExpression(expression); } catch (ParseException e) { throw new IllegalArgumentException("Invalid expression: " + expression, e);
@Test public void testParseSelect() throws Exception { ASTNode tree = parseDriver.parseSelect("select field1, field2, sum(field3+field4)", null); assertEquals(tree.getType(), HiveParser.TOK_SELECT); assertEquals(tree.getChildCount(), 3); for (int i = 0; i < 3; i++) { assertEquals(((ASTNode) tree.getChild(i)).getType(), HiveParser.TOK_SELEXPR); } assertTree((ASTNode) tree.getChild(0).getChild(0), parseDriver.parseExpression("field1")); assertTree((ASTNode) tree.getChild(1).getChild(0), parseDriver.parseExpression("field2")); assertTree((ASTNode) tree.getChild(2).getChild(0), parseDriver.parseExpression("sum(field3+field4)")); }
@Test public void testParseExpression() throws Exception { ASTNode plusNode = parseDriver.parseExpression("field3 + field4"); assertEquals(plusNode.getType(), HiveParser.PLUS); assertEquals(plusNode.getChildCount(), 2); for (int i = 0; i < 2; i++) { assertEquals(plusNode.getChild(i).getType(), HiveParser.TOK_TABLE_OR_COL); assertEquals(plusNode.getChild(i).getChildCount(), 1); assertEquals(plusNode.getChild(i).getChild(0).getType(), HiveParser.Identifier); assertEquals(plusNode.getChild(i).getChild(0).getText(), "field" + (i + 3)); } ASTNode sumNode = parseDriver.parseExpression("sum(field3 + field4)"); assertEquals(sumNode.getType(), HiveParser.TOK_FUNCTION); assertEquals(sumNode.getChildCount(), 2); assertEquals(sumNode.getChild(0).getType(), HiveParser.Identifier); assertEquals(sumNode.getChild(0).getText(), "sum"); assertTree((ASTNode) sumNode.getChild(1), plusNode); ASTNode tree = parseDriver.parseExpression("case when field1 = 1 then sum(field3 + field4) when field1 != 2 then " + "sum(field3-field4) else sum(field3 * field4) end"); assertEquals(tree.getChildCount(), 6); assertEquals(tree.getChild(0).getType(), HiveParser.KW_WHEN); assertEquals(tree.getChild(1).getType(), HiveParser.EQUAL); assertTree((ASTNode) tree.getChild(2), sumNode); assertEquals(tree.getChild(3).getType(), HiveParser.NOTEQUAL); assertTree((ASTNode) tree.getChild(4), parseDriver.parseExpression("sum(field3-field4)")); assertTree((ASTNode) tree.getChild(5), parseDriver.parseExpression("sum(field3*field4)")); }
public ASTNode parse(String command) throws ParseException { return parse(command, null); }
@Before public void setup() throws SemanticException { pd = new ParseDriver(); }
ParseDriver pd = new ParseDriver(); selNode = pd.parseSelect(selectExprStr, null); } catch (ParseException pe) { throw new SemanticException(pe);
/** Parses the Hive query. */ public static ASTNode parse( String command, Context ctx, String viewFullyQualifiedName) throws ParseException { ParseDriver pd = new ParseDriver(); ASTNode tree = pd.parse(command, ctx, viewFullyQualifiedName); tree = findRootNonNullToken(tree); handleSetColRefs(tree); return tree; }
public ASTNode parse(String command, Context ctx) throws ParseException { return parse(command, ctx, null); }
@Before public void setup() throws SemanticException, IOException { pd = new ParseDriver(); }
ParseDriver parseDriver = new ParseDriver(); try { ASTNode defValAst = parseDriver.parseExpression(defaultValue);
ParseDriver pd = new ParseDriver(); selNode = pd.parseSelect(selectExprStr, null); } catch (ParseException pe) { throw new SemanticException(pe);
private void setQueryHints(QB qb) throws SemanticException { QBParseInfo qbp = getQBParseInfo(qb); String selClauseName = qbp.getClauseNames().iterator().next(); Tree selExpr0 = qbp.getSelForClause(selClauseName).getChild(0); if (selExpr0.getType() != HiveParser.QUERY_HINT) return; String hint = ctx.getTokenRewriteStream().toString( selExpr0.getTokenStartIndex(), selExpr0.getTokenStopIndex()); LOG.debug("Handling query hints: " + hint); ParseDriver pd = new ParseDriver(); try { ASTNode hintNode = pd.parseHint(hint); qbp.setHints(hintNode); } catch (ParseException e) { throw new SemanticException("failed to parse query hint: "+e.getMessage(), e); } }