void addGByClauseRewrite(ASTNode selectExpr) { if ( gByClauseAdditions == null ) { gByClauseAdditions = ""; } if ( !addGroupByClause || !gByClauseAdditions.equals("") ) { gByClauseAdditions += ", "; } gByClauseAdditions += stream.toString( selectExpr.getTokenStartIndex(), selectExpr.getTokenStopIndex()); }
void addGByClauseRewrite(ASTNode selectExpr) { if ( gByClauseAdditions == null ) { gByClauseAdditions = ""; } if ( !addGroupByClause || !gByClauseAdditions.equals("") ) { gByClauseAdditions += ", "; } gByClauseAdditions += stream.toString( selectExpr.getTokenStartIndex(), selectExpr.getTokenStopIndex()); }
void addSelectClauseRewrite(ASTNode selectExpr, String alias) { if ( selectClauseAdditions == null ) { selectClauseAdditions = ""; } selectClauseAdditions += ", " + stream.toString(selectExpr.getTokenStartIndex(), selectExpr.getTokenStopIndex()) + " as " + alias; }
void addSelectClauseRewrite(ASTNode selectExpr, String alias) { if ( selectClauseAdditions == null ) { selectClauseAdditions = ""; } selectClauseAdditions += ", " + stream.toString(selectExpr.getTokenStartIndex(), selectExpr.getTokenStopIndex()) + " as " + alias; }
/** * This allows us to take an arbitrary ASTNode and turn it back into SQL that produced it without * needing to understand what it is (except for QuotedIdentifiers). */ private String getMatchedText(ASTNode n) { quotedIdenfierHelper.visit(n); return ctx.getTokenRewriteStream().toString(n.getTokenStartIndex(), n.getTokenStopIndex() + 1).trim(); }
private void addCondition(StringBuilder b, ASTNode cond, boolean rewritten) { if ( !rewritten ) { b.append(stream.toString(cond.getTokenStartIndex(), cond.getTokenStopIndex())); } else { addReference(b, cond); } }
private String getMatchedText(ASTNode n) { return getTokenRewriteStream().toString(n.getTokenStartIndex(), n.getTokenStopIndex() + 1).trim(); } /**
private void addCondition(StringBuilder b, ASTNode cond, boolean rewritten) { if ( !rewritten ) { b.append(stream.toString(cond.getTokenStartIndex(), cond.getTokenStopIndex())); } else { addReference(b, cond); } }
/** * This allows us to take an arbitrary ASTNode and turn it back into SQL that produced it without * needing to understand what it is (except for QuotedIdentifiers) * */ private String getMatchedText(ASTNode n) { quotedIdenfierHelper.visit(n); return ctx.getTokenRewriteStream().toString(n.getTokenStartIndex(), n.getTokenStopIndex() + 1).trim(); } /**
private String getMatchedText(ASTNode n) { return getTokenRewriteStream().toString(n.getTokenStartIndex(), n.getTokenStopIndex() + 1).trim(); } /**
void addWhereClauseRewrite(ASTNode predicate) { String cond = stream.toString(predicate.getTokenStartIndex(), predicate.getTokenStopIndex()); addWhereClauseRewrite(cond); }
public static String enhanceXPath(final String prefix, final int index, final String xpath) { if (log.isDebugEnabled()) { log.debug("prefix: " + prefix); log.debug("index: " + index); log.debug("xpath: " + xpath); } final ANTLRStringStream stringStream = new ANTLRStringStream(xpath); final XPathEnhancerLexer xl = new XPathEnhancerLexer(stringStream); final TokenRewriteStream trs = new TokenRewriteStream(xl); final XPathEnhancerParser xp = new XPathEnhancerParser(trs, index, prefix); try { xp.main(); } catch (RecognitionException e) { throw new IllegalArgumentException(xpath + " is no valid XPath expression", e); } final String enhanced = trs.toString(); return enhanced; }
void addWhereClauseRewrite(ASTNode predicate) { String cond = stream.toString(predicate.getTokenStartIndex(), predicate.getTokenStopIndex()); addWhereClauseRewrite(cond); }
out.println("\nRewritten Query:\n" + stream.toString(program, ast.getTokenStartIndex(), ast.getTokenStopIndex())); } finally {
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); } }
public QBSubQuery(String outerQueryId, int sqIdx, ASTNode subQueryAST, ASTNode parentQueryExpression, SubQueryTypeDef operator, ASTNode originalSQAST, Context ctx) { super(); this.subQueryAST = subQueryAST; this.parentQueryExpression = parentQueryExpression; this.operator = operator; this.outerQueryId = outerQueryId; this.sqIdx = sqIdx; this.alias = "sq_" + this.sqIdx; this.numCorrExprsinSQ = 0; this.numOuterCorrExprsForHaving = 0; String s = ctx.getTokenRewriteStream().toString( originalSQAST.getTokenStartIndex(), originalSQAST.getTokenStopIndex()); originalSQASTOrigin = new ASTNodeOrigin("SubQuery", alias, s, alias, originalSQAST); numOfCorrelationExprsAddedToSQSelect = 0; groupbyAddedToSQ = false; if ( operator.getType() == SubQueryType.NOT_IN ) { notInCheck = new NotInCheck(); } subQueryDiagnostic = SubQueryDiagnostic.getRewrite(this, ctx.getTokenRewriteStream(), ctx); }
public QBSubQuery(String outerQueryId, int sqIdx, ASTNode subQueryAST, ASTNode parentQueryExpression, SubQueryTypeDef operator, ASTNode originalSQAST, Context ctx) { super(); this.subQueryAST = subQueryAST; this.parentQueryExpression = parentQueryExpression; this.operator = operator; this.outerQueryId = outerQueryId; this.sqIdx = sqIdx; this.alias = "sq_" + this.sqIdx; this.numCorrExprsinSQ = 0; this.numOuterCorrExprsForHaving = 0; String s = ctx.getTokenRewriteStream().toString( originalSQAST.getTokenStartIndex(), originalSQAST.getTokenStopIndex()); originalSQASTOrigin = new ASTNodeOrigin("SubQuery", alias, s, alias, originalSQAST); numOfCorrelationExprsAddedToSQSelect = 0; groupbyAddedToSQ = false; if ( operator.getType() == SubQueryType.NOT_IN ) { notInCheck = new NotInCheck(); } subQueryDiagnostic = SubQueryDiagnostic.getRewrite(this, ctx.getTokenRewriteStream(), ctx); }
String rewrittenQuery = tokenRewriteStream.toString( ast.getTokenStartIndex(), ast.getTokenStopIndex()); return rewrittenQuery;
stream.toString(subQuery.getAlias(), sqAST.getTokenStartIndex(), sqAST.getTokenStopIndex())