use of org.teiid.query.sql.lang.StoredProcedure in project teiid by teiid.
the class PreparedStatementRequest method generatePlan.
/**
* @throws TeiidComponentException
* @throws TeiidProcessingException
* @see org.teiid.dqp.internal.process.Request#generatePlan()
*/
@Override
protected void generatePlan(boolean addLimit) throws TeiidComponentException, TeiidProcessingException {
createCommandContext();
String sqlQuery = requestMsg.getCommands()[0];
if (this.preParser != null) {
sqlQuery = this.preParser.preParse(sqlQuery, this.context);
}
CacheID id = new CacheID(this.workContext, Request.createParseInfo(this.requestMsg, this.workContext.getSession()), sqlQuery);
prepPlan = prepPlanCache.get(id);
if (prepPlan != null) {
// already in cache. obtain the values from cache
analysisRecord = prepPlan.getAnalysisRecord();
ProcessorPlan cachedPlan = prepPlan.getPlan();
this.userCommand = prepPlan.getCommand();
if (validateAccess(requestMsg.getCommands(), userCommand, CommandType.PREPARED)) {
// $NON-NLS-1$
LogManager.logDetail(LogConstants.CTX_DQP, requestId, "AuthorizationValidator indicates that the prepared plan for command will not be used");
prepPlan = null;
analysisRecord = null;
} else {
// $NON-NLS-1$
LogManager.logTrace(LogConstants.CTX_DQP, new Object[] { "Query exist in cache: ", sqlQuery });
processPlan = cachedPlan.clone();
}
}
if (prepPlan == null) {
// if prepared plan does not exist, create one
prepPlan = new PreparedPlan();
// $NON-NLS-1$
LogManager.logTrace(LogConstants.CTX_DQP, new Object[] { "Query does not exist in cache: ", sqlQuery });
super.generatePlan(true);
prepPlan.setCommand(this.userCommand);
// there's no need to cache the plan if it's a stored procedure, since we already do that in the optimizer
boolean cache = !(this.userCommand instanceof StoredProcedure);
// Defect 13751: Clone the plan in its current state (i.e. before processing) so that it can be used for later queries
prepPlan.setPlan(cache ? processPlan.clone() : processPlan, this.context);
prepPlan.setAnalysisRecord(analysisRecord);
if (cache) {
Determinism determinismLevel = this.context.getDeterminismLevel();
if (userCommand.getCacheHint() != null && userCommand.getCacheHint().getDeterminism() != null) {
// $NON-NLS-1$ //$NON-NLS-2$
LogManager.logTrace(LogConstants.CTX_DQP, new Object[] { "Cache hint modified the query determinism from ", this.context.getDeterminismLevel(), " to ", determinismLevel });
determinismLevel = userCommand.getCacheHint().getDeterminism();
}
this.prepPlanCache.put(id, determinismLevel, prepPlan, userCommand.getCacheHint() != null ? userCommand.getCacheHint().getTtl() : null);
}
}
if (requestMsg.isBatchedUpdate()) {
handlePreparedBatchUpdate();
} else {
List<Reference> params = prepPlan.getReferences();
List<?> values = requestMsg.getParameterValues();
PreparedStatementRequest.resolveParameterValues(params, values, this.context, this.metadata);
}
}
use of org.teiid.query.sql.lang.StoredProcedure in project teiid by teiid.
the class TestProcedureResolving method testDotInName.
@Test
public void testDotInName() throws Exception {
// $NON-NLS-1$
String ddl = "CREATE FOREIGN PROCEDURE \"my.proc\" (param STRING) RETURNS TABLE (a INTEGER, b STRING);";
TransformationMetadata tm = RealMetadataFactory.fromDDL(ddl, "x", "y");
StoredProcedure sp = (StoredProcedure) TestResolver.helpResolve("exec \"my.proc\"()", tm);
assertEquals(2, sp.getProjectedSymbols().size());
assertEquals("y.my.proc.b", sp.getProjectedSymbols().get(1).toString());
TestValidator.helpValidate("begin exec proc(); end", new String[] {}, tm);
}
use of org.teiid.query.sql.lang.StoredProcedure in project teiid by teiid.
the class TestProcedureResolving method testVarArgs.
@Test
public void testVarArgs() throws Exception {
String ddl = "create foreign procedure proc (x integer, VARIADIC z integer) returns (x string);\n";
TransformationMetadata tm = createMetadata(ddl);
// $NON-NLS-1$
String sql = "call proc (1, 2, 3)";
StoredProcedure sp = (StoredProcedure) TestResolver.helpResolve(sql, tm);
assertEquals("EXEC proc(1, 2, 3)", sp.toString());
assertEquals(new Constant(1), sp.getParameter(1).getExpression());
assertEquals(new Array(DataTypeManager.DefaultDataClasses.INTEGER, Arrays.asList((Expression) new Constant(2), new Constant(3))), sp.getParameter(2).getExpression());
assertEquals(SPParameter.RESULT_SET, sp.getParameter(3).getParameterType());
// $NON-NLS-1$
sql = "call proc (1)";
sp = (StoredProcedure) TestResolver.helpResolve(sql, tm);
assertEquals("EXEC proc(1)", sp.toString());
assertEquals(new Array(DataTypeManager.DefaultDataClasses.INTEGER, new ArrayList<Expression>(0)), sp.getParameter(2).getExpression());
sp = (StoredProcedure) QueryRewriter.evaluateAndRewrite(sp, new Evaluator(null, null, null), null, tm);
LanguageBridgeFactory lbf = new LanguageBridgeFactory(tm);
Call call = (Call) lbf.translate(sp);
assertEquals("EXEC proc(1)", call.toString());
// $NON-NLS-1$
sql = "call proc (1, (2, 3))";
sp = (StoredProcedure) TestResolver.helpResolve(sql, tm);
assertEquals("EXEC proc(1, (2, 3))", sp.toString());
assertEquals(new Constant(1), sp.getParameter(1).getExpression());
assertEquals(new Array(DataTypeManager.DefaultDataClasses.INTEGER, Arrays.asList((Expression) new Constant(2), new Constant(3))), sp.getParameter(2).getExpression());
assertEquals(SPParameter.RESULT_SET, sp.getParameter(3).getParameterType());
}
use of org.teiid.query.sql.lang.StoredProcedure in project teiid by teiid.
the class TestProcedureResolving method testOptionalParams.
@Test
public void testOptionalParams() throws Exception {
String ddl = "create foreign procedure proc (x integer, y string);\n";
TransformationMetadata tm = createMetadata(ddl);
// $NON-NLS-1$
String sql = "call proc (1)";
StoredProcedure sp = (StoredProcedure) TestResolver.helpResolve(sql, tm);
assertEquals(new Constant(null, DataTypeManager.DefaultDataClasses.STRING), sp.getParameter(2).getExpression());
// $NON-NLS-1$
sql = "call proc (1, 'a')";
sp = (StoredProcedure) TestResolver.helpResolve(sql, tm);
assertEquals(new Constant("a", DataTypeManager.DefaultDataClasses.STRING), sp.getParameter(2).getExpression());
}
use of org.teiid.query.sql.lang.StoredProcedure in project teiid by teiid.
the class TestProcedureResolving method testVarArgs2.
@Test
public void testVarArgs2() throws Exception {
String ddl = "create foreign procedure proc (VARIADIC z object) returns (x string);\n";
TransformationMetadata tm = createMetadata(ddl);
// $NON-NLS-1$
String sql = "call proc ()";
StoredProcedure sp = (StoredProcedure) TestResolver.helpResolve(sql, tm);
assertEquals("EXEC proc()", sp.toString());
assertEquals(new Array(DataTypeManager.DefaultDataClasses.OBJECT, new ArrayList<Expression>(0)), sp.getParameter(1).getExpression());
// $NON-NLS-1$
sql = "call proc (1, (2, 3))";
sp = (StoredProcedure) TestResolver.helpResolve(sql, tm);
assertEquals("EXEC proc(1, (2, 3))", sp.toString());
ArrayList<Expression> expressions = new ArrayList<Expression>();
expressions.add(new Constant(1));
expressions.add(new Array(DataTypeManager.DefaultDataClasses.INTEGER, Arrays.asList((Expression) new Constant(2), new Constant(3))));
assertEquals(new Array(DataTypeManager.DefaultDataClasses.OBJECT, expressions), sp.getParameter(1).getExpression());
}
Aggregations