@Test public void testRewriteExec() throws Exception { Command command = QueryParser.getQueryParser().parseCommand("exec pm1.sq2(session_id())"); QueryResolver.resolveCommand(command, RealMetadataFactory.example1Cached()); CommandContext context = new CommandContext(); context.setConnectionID("1"); Command rewriteCommand = QueryRewriter.rewrite(command, RealMetadataFactory.example1Cached(), context); assertEquals("EXEC pm1.sq2('1')", rewriteCommand.toString()); }
private Command rewriteExec(StoredProcedure storedProcedure) throws TeiidComponentException, TeiidProcessingException{ storedProcedure.setDisplayNamedParameters(false); for (SPParameter param : storedProcedure.getInputParameters()) { if (!processing || storedProcedure.isPushedInQuery() || storedProcedure.isSupportsExpressionParameters()) { param.setExpression(rewriteExpressionDirect(param.getExpression())); } else if (!(param.getExpression() instanceof Constant)) { boolean isBindEligible = !isConstantConvert(param.getExpression()); param.setExpression(evaluate(param.getExpression(), isBindEligible)); } } return storedProcedure; }
QueryRewriter { private Command rewriteExec(StoredProcedure storedProcedure) throws TeiidComponentException, TeiidProcessingException{ storedProcedure.setDisplayNamedParameters(false); for (SPParameter param : storedProcedure.getInputParameters()) { if (!processing || storedProcedure.isPushedInQuery() || storedProcedure.isSupportsExpressionParameters()) { param.setExpression(rewriteExpressionDirect(param.getExpression())); } else if (!(param.getExpression() instanceof Constant)) { boolean isBindEligible = !isConstantConvert(param.getExpression()); param.setExpression(evaluate(param.getExpression(), isBindEligible)); } } return storedProcedure; } }
QueryRewriter { private Command rewriteExec(StoredProcedure storedProcedure) throws TeiidComponentException, TeiidProcessingException{ storedProcedure.setDisplayNamedParameters(false); for (SPParameter param : storedProcedure.getInputParameters()) { if (!processing || storedProcedure.isPushedInQuery() || storedProcedure.isSupportsExpressionParameters()) { param.setExpression(rewriteExpressionDirect(param.getExpression())); } else if (!(param.getExpression() instanceof Constant)) { boolean isBindEligible = !isConstantConvert(param.getExpression()); param.setExpression(evaluate(param.getExpression(), isBindEligible)); } } return storedProcedure; } private  QueryRewriter(QueryMetadataInterface metadata,
            CommandContext context); }
QueryRewriter { private Command rewriteExec(StoredProcedure storedProcedure) throws TeiidComponentException, TeiidProcessingException{ storedProcedure.setDisplayNamedParameters(false); for (SPParameter param : storedProcedure.getInputParameters()) { if (!processing || storedProcedure.isPushedInQuery() || storedProcedure.isSupportsExpressionParameters()) { param.setExpression(rewriteExpressionDirect(param.getExpression())); } else if (!(param.getExpression() instanceof Constant)) { boolean isBindEligible = !isConstantConvert(param.getExpression()); param.setExpression(evaluate(param.getExpression(), isBindEligible)); } } return storedProcedure; } private  QueryRewriter(QueryMetadataInterface metadata,
            CommandContext context); static Command evaluateAndRewrite(Command command, Evaluator eval, CommandContext context, QueryMetadataInterface metadata); static Criteria evaluateAndRewrite(Criteria criteria, Evaluator eval, CommandContext context, QueryMetadataInterface metadata); static Command rewrite(Command command, QueryMetadataInterface metadata, CommandContext context, Map<ElementSymbol, Expression> variableValues); static Command rewrite(Command command, QueryMetadataInterface metadata, CommandContext context); static boolean isDistinctWithGroupBy(Query query); QueryCommand rewriteOrderBy(QueryCommand queryCommand); static void rewriteOrderBy(QueryCommand queryCommand,
            final OrderBy orderBy, final List projectedSymbols, CommandContext context, QueryMetadataInterface metadata); static Criteria rewriteCriteria(Criteria criteria, CommandContext context, QueryMetadataInterface metadata); static Criteria optimizeCriteria(CompoundCriteria criteria, QueryMetadataInterface metadata); static boolean isNull(Expression expr); static Expression rewriteExpression(Expression expression, CommandContext context, QueryMetadataInterface metadata); static Expression rewriteExpression(Expression expression, CommandContext context, QueryMetadataInterface metadata, boolean rewriteSubcommands); static Command rewriteAsUpsertProcedure(Insert insert, QueryMetadataInterface metadata, CommandContext context); static Query createInlineViewQuery(GroupSymbol inlineGroup,
                                               Command nested,
                                               QueryMetadataInterface metadata,
                                               List<? extends Expression> actualSymbols); static void makeSelectUnique(Select select, boolean expressionSymbolsOnly); static Command createDeleteProcedure(Delete delete, QueryMetadataInterface metadata, CommandContext context); static Command createUpdateProcedure(Update update, QueryMetadataInterface metadata, CommandContext context); }
QueryRewriter { private Command rewriteExec(StoredProcedure storedProcedure) throws TeiidComponentException, TeiidProcessingException{ storedProcedure.setDisplayNamedParameters(false); for (SPParameter param : storedProcedure.getInputParameters()) { if (!processing || storedProcedure.isPushedInQuery() || storedProcedure.isSupportsExpressionParameters()) { param.setExpression(rewriteExpressionDirect(param.getExpression())); } else if (!(param.getExpression() instanceof Constant)) { boolean isBindEligible = !isConstantConvert(param.getExpression()); param.setExpression(evaluate(param.getExpression(), isBindEligible)); } } return storedProcedure; } private  QueryRewriter(QueryMetadataInterface metadata,
            CommandContext context); static Command evaluateAndRewrite(Command command, Evaluator eval, CommandContext context, QueryMetadataInterface metadata); static Criteria evaluateAndRewrite(Criteria criteria, Evaluator eval, CommandContext context, QueryMetadataInterface metadata); static Command rewrite(Command command, QueryMetadataInterface metadata, CommandContext context, Map<ElementSymbol, Expression> variableValues); static Command rewrite(Command command, QueryMetadataInterface metadata, CommandContext context); static boolean isDistinctWithGroupBy(Query query); QueryCommand rewriteOrderBy(QueryCommand queryCommand); static void rewriteOrderBy(QueryCommand queryCommand,
            final OrderBy orderBy, final List projectedSymbols, CommandContext context, QueryMetadataInterface metadata); static Criteria rewriteCriteria(Criteria criteria, CommandContext context, QueryMetadataInterface metadata); static Criteria optimizeCriteria(CompoundCriteria criteria, QueryMetadataInterface metadata); static boolean isNull(Expression expr); static Expression rewriteExpression(Expression expression, CommandContext context, QueryMetadataInterface metadata); static Expression rewriteExpression(Expression expression, CommandContext context, QueryMetadataInterface metadata, boolean rewriteSubcommands); static Command rewriteAsUpsertProcedure(Insert insert, QueryMetadataInterface metadata, CommandContext context); static Query createInlineViewQuery(GroupSymbol inlineGroup,
                                               Command nested,
                                               QueryMetadataInterface metadata,
                                               List<? extends Expression> actualSymbols); static void makeSelectUnique(Select select, boolean expressionSymbolsOnly); static Command createDeleteProcedure(Delete delete, QueryMetadataInterface metadata, CommandContext context); static Command createUpdateProcedure(Update update, QueryMetadataInterface metadata, CommandContext context); static final CompareCriteria TRUE_CRITERIA; static final CompareCriteria FALSE_CRITERIA; static final CompareCriteria UNKNOWN_CRITERIA; }