@Override public String toString() { return expression.toStringTree(); }
@Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((expression == null) ? 0 : expression.toStringTree().hashCode()); return result; }
/** * Retrieves the source expression matching a given ASTNode's * string rendering exactly. */ public ASTNode getExpressionSource(ASTNode node) { return expressionMap.get(node.toStringTree()); }
public void addWindowingExprToClause(String clause, ASTNode windowingExprNode) { LinkedHashMap<String, ASTNode> windowingExprs = destToWindowingExprs.get(clause); if ( windowingExprs == null ) { windowingExprs = new LinkedHashMap<String, ASTNode>(); destToWindowingExprs.put(clause, windowingExprs); } windowingExprs.put(windowingExprNode.toStringTree(), windowingExprNode); }
/** * Puts a resolver entry corresponding to a source expression which is to be * used for identical expression recognition (e.g. for matching expressions * in the SELECT list with the GROUP BY clause). The convention for such * entries is an empty-string ("") as the table alias together with the * string rendering of the ASTNode as the column alias. */ public void putExpression(ASTNode node, ColumnInfo colInfo) { String treeAsString = node.toStringTree(); expressionMap.put(treeAsString, node); put("", treeAsString, colInfo); }
void checkValid() throws SemanticException { if (throwError) { throw new SemanticException(errMsg + errorNode.toStringTree()); } } }
/** * Retrieves the ColumnInfo corresponding to a source expression which * exactly matches the string rendering of the given ASTNode. */ public ColumnInfo getExpression(ASTNode node) throws SemanticException { return get("", node.toStringTree()); }
@Override public String toStringTree() { // The root might have changed because of tree modifications. // Compute the new root for this tree and set the astStr. getRootNodeWithValidASTStr(); // If rootNotModified is false, then startIndx and endIndx will be stale. if (startIndx >= 0 && endIndx <= rootNode.getMemoizedStringLen()) { return rootNode.getMemoizedSubString(startIndx, endIndx); } return toStringTree(rootNode); }
private PTFExpressionDef translate(ShapeDetails inpShape, PartitionExpression pExpr) throws SemanticException { PTFExpressionDef expDef = null; try { expDef = buildExpressionDef(inpShape, pExpr.getExpression()); } catch (HiveException he) { throw new SemanticException(he); } PTFTranslator.validateComparable(expDef.getOI(), String.format("Partition Expression %s is not a comparable expression", pExpr .getExpression().toStringTree())); return expDef; }
@Test public void testTxnCommitRollback() throws ParseException { ASTNode ast = parse("COMMIT"); Assert.assertEquals("AST doesn't match", "tok_commit", ast.toStringTree()); ast = parse("COMMIT WORK"); Assert.assertEquals("AST doesn't match", "tok_commit", ast.toStringTree()); ast = parse("ROLLBACK"); Assert.assertEquals("AST doesn't match", "tok_rollback", ast.toStringTree()); ast = parse("ROLLBACK WORK"); Assert.assertEquals("AST doesn't match", "tok_rollback", ast.toStringTree()); }
@Test public void testAutoCommit() throws ParseException { ASTNode ast = parse("SET AUTOCOMMIT TRUE"); Assert.assertEquals("AST doesn't match", "(tok_set_autocommit tok_true)", ast.toStringTree()); ast = parse("SET AUTOCOMMIT FALSE"); Assert.assertEquals("AST doesn't match", "(tok_set_autocommit tok_false)", ast.toStringTree()); } }
@Test public void testMultiInsert() throws ParseException { ASTNode ast = parse("from S insert into T1 select a, b insert into T2 select c, d"); Assert.assertEquals("AST doesn't match", "(tok_query (tok_from (tok_tabref (tok_tabname s))) " + "(tok_insert (tok_insert_into (tok_tab (tok_tabname t1))) (tok_select (tok_selexpr (tok_table_or_col a)) (tok_selexpr (tok_table_or_col b)))) " + "(tok_insert (tok_insert_into (tok_tab (tok_tabname t2))) (tok_select (tok_selexpr (tok_table_or_col c)) (tok_selexpr (tok_table_or_col d)))))", ast.toStringTree()); } }
@Test public void testDeleteNoWhere() throws ParseException { ASTNode ast = parse("DELETE FROM src"); Assert.assertEquals("AST doesn't match", "(tok_delete_from " + "(tok_tabname src))", ast.toStringTree()); } @Test
@Test public void test2() throws ParseException { ASTNode ast = parse("MERGE INTO target USING source ON target.pk = source.pk WHEN MATCHED THEN DELETE"); Assert.assertEquals( "(tok_merge " + "(tok_tabref (tok_tabname target)) (tok_tabref (tok_tabname source)) (= (. (tok_table_or_col target) pk) (. (tok_table_or_col source) pk)) " + "(tok_matched " + "tok_delete)" + ")", ast.toStringTree()); } @Test
@Test public void testUpdateNoWhereSingleSet() throws ParseException { ASTNode ast = parse("UPDATE src set key = 3"); Assert.assertEquals("AST doesn't match", "(tok_update_table " + "(tok_tabname src) " + "(tok_set_columns_clause " + "(= " + "(tok_table_or_col key) 3)))", ast.toStringTree()); } @Test
@Test public void test3() throws ParseException { ASTNode ast = parse("MERGE INTO target USING source ON target.pk = source.pk WHEN MATCHED AND target.a + source.b > 8 THEN DELETE"); Assert.assertEquals( "(tok_merge " + "(tok_tabref (tok_tabname target)) (tok_tabref (tok_tabname source)) (= (. (tok_table_or_col target) pk) (. (tok_table_or_col source) pk)) " + "(tok_matched " + "tok_delete " + "(> (+ (. (tok_table_or_col target) a) (. (tok_table_or_col source) b)) 8))" + ")", ast.toStringTree()); } @Test
@Test public void testExtractSubQueries() throws Exception { ASTNode ast = parse(IN_QUERY); ASTNode where = where(ast); List<ASTNode> sqs = SubQueryUtils.findSubQueries((ASTNode) where.getChild(0)); Assert.assertEquals(1,sqs.size()); ASTNode sq = sqs.get(0); Assert.assertEquals("(tok_subquery_expr (tok_subquery_op kw_in) (tok_query (tok_from (tok_tabref (tok_tabname src) s1)) (tok_insert (tok_destination (tok_dir tok_tmp_file)) (tok_select (tok_selexpr (tok_table_or_col key))) (tok_where (and (> (. (tok_table_or_col s1) key) '9') (> (. (tok_table_or_col s1) value) '9'))))) (. (tok_table_or_col src) key))" ,sq.toStringTree()); }
public PTFExpressionDef buildExpressionDef(ShapeDetails inpShape, ASTNode arg) throws HiveException { PTFExpressionDef argDef = new PTFExpressionDef(); ExprNodeDesc exprNode = semAly.genExprNodeDesc(arg, inpShape.getRr(), inpShape.getTypeCheckCtx()); ExprNodeEvaluator exprEval = WindowingExprNodeEvaluatorFactory.get(llInfo, exprNode); ObjectInspector oi = initExprNodeEvaluator(exprEval, exprNode, inpShape); argDef.setExpressionTreeString(arg.toStringTree()); argDef.setExprNode(exprNode); argDef.setExprEvaluator(exprEval); argDef.setOI(oi); return argDef; }
@Test public void testRewriteOuterQueryWhere() throws Exception { ASTNode ast = parse(IN_QUERY); ASTNode where = where(ast); List<ASTNode> sqs = SubQueryUtils.findSubQueries((ASTNode) where.getChild(0)); ASTNode sq = sqs.get(0); ASTNode newWhere = SubQueryUtils.rewriteParentQueryWhere((ASTNode) where.getChild(0), sq); Assert.assertEquals("(= 1 1)",newWhere.toStringTree()); }
@Test public void testRewriteOuterQueryWhere2() throws Exception { ASTNode ast = parse(IN_QUERY2); ASTNode where = where(ast); List<ASTNode> sqs = SubQueryUtils.findSubQueries((ASTNode) where.getChild(0)); ASTNode sq = sqs.get(0); ASTNode newWhere = SubQueryUtils.rewriteParentQueryWhere((ASTNode) where.getChild(0), sq); Assert.assertEquals("(> (tok_table_or_col value) '9')",newWhere.toStringTree()); }