use of org.teiid.query.sql.lang.Command in project teiid by teiid.
the class TestValidator method testCase4237.
/**
* Test case 4237. This test simulates the way the modeler transformation
* panel uses the query resolver and validator to validate a transformation for
* a virtual procedure. The modeler has to supply external metadata for the
* virtual procedure group and parameter names (simulated in this test).
*
* This virtual procedure calls a physical stored procedure directly.
*/
@Test
public void testCase4237() throws Exception {
QueryMetadataInterface metadata = helpCreateCase4237VirtualProcedureMetadata();
// $NON-NLS-1$
String sql = "CREATE VIRTUAL PROCEDURE BEGIN EXEC pm1.sp(vm1.sp.in1); END";
Command command = helpResolve(sql, new GroupSymbol("vm1.sp"), Command.TYPE_STORED_PROCEDURE, metadata);
helpRunValidator(command, new String[0], metadata);
}
use of org.teiid.query.sql.lang.Command in project teiid by teiid.
the class TestElementSymbolOptimizer method helpTestFullyQualify.
public void helpTestFullyQualify(String sql, QueryMetadataInterface metadata, String expected) throws QueryParserException, QueryResolverException, TeiidComponentException {
Command command = helpResolve(sql, metadata);
ResolverUtil.fullyQualifyElements(command);
String actual = command.toString();
// $NON-NLS-1$
assertEquals("Expected different fully qualified string", expected, actual);
}
use of org.teiid.query.sql.lang.Command in project teiid by teiid.
the class Request method parseCommand.
private Command parseCommand() throws QueryParserException {
if (requestMsg.getCommand() != null) {
return (Command) requestMsg.getCommand();
}
String[] commands = requestMsg.getCommands();
ParseInfo parseInfo = createParseInfo(this.requestMsg, this.workContext.getSession());
QueryParser queryParser = QueryParser.getQueryParser();
if (requestMsg.isPreparedStatement() || requestMsg.isCallableStatement() || !requestMsg.isBatchedUpdate()) {
String commandStr = commands[0];
if (preParser != null) {
commandStr = preParser.preParse(commandStr, this.context);
}
return queryParser.parseCommand(commandStr, parseInfo);
}
List<Command> parsedCommands = new ArrayList<Command>(commands.length);
for (int i = 0; i < commands.length; i++) {
String updateCommand = commands[i];
if (preParser != null) {
updateCommand = preParser.preParse(updateCommand, this.context);
}
parsedCommands.add(queryParser.parseCommand(updateCommand, parseInfo));
}
return new BatchedUpdateCommand(parsedCommands);
}
use of org.teiid.query.sql.lang.Command in project teiid by teiid.
the class ConnectorManager method logSRCCommand.
/**
* Add begin point to transaction monitoring table.
* @param qr Request that contains the MetaMatrix command information in the transaction.
*/
void logSRCCommand(AtomicRequestMessage qr, ExecutionContext context, Event cmdStatus, Long finalRowCnt, Long cpuTime, Object[] command) {
if (!LogManager.isMessageToBeRecorded(LogConstants.CTX_COMMANDLOGGING, MessageLevel.DETAIL)) {
return;
}
String sqlStr = null;
if (cmdStatus == Event.NEW) {
Command cmd = qr.getCommand();
sqlStr = cmd != null ? cmd.toString() : null;
}
String userName = qr.getWorkContext().getUserName();
String transactionID = null;
if (qr.isTransactional()) {
transactionID = qr.getTransactionContext().getTransactionId();
}
String modelName = qr.getModelName();
AtomicRequestID sid = qr.getAtomicRequestID();
// $NON-NLS-1$
String principal = userName == null ? "unknown" : userName;
CommandLogMessage message = null;
if (cmdStatus == Event.NEW) {
message = new CommandLogMessage(System.currentTimeMillis(), qr.getRequestID().toString(), sid.getNodeID(), transactionID, modelName, translatorName, qr.getWorkContext().getSessionId(), principal, sqlStr, context);
} else {
message = new CommandLogMessage(System.currentTimeMillis(), qr.getRequestID().toString(), sid.getNodeID(), transactionID, modelName, translatorName, qr.getWorkContext().getSessionId(), principal, finalRowCnt, cmdStatus, context, cpuTime);
if (cmdStatus == Event.SOURCE) {
message.setSourceCommand(command);
}
}
LogManager.log(MessageLevel.DETAIL, LogConstants.CTX_COMMANDLOGGING, message);
}
use of org.teiid.query.sql.lang.Command in project teiid by teiid.
the class TestProcessor method testCaseInGroupBy.
@Test
public void testCaseInGroupBy() {
String sql = // $NON-NLS-1$
"SELECT sum (IntKey), case when IntKey>=5000 then '5000 +' else '0-999' end " + // $NON-NLS-1$
"FROM BQT1.SmallA GROUP BY case when IntKey>=5000 then '5000 +' else '0-999' end";
// Plan query
FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
BasicSourceCapabilities caps = new BasicSourceCapabilities();
caps.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, true);
caps.setCapabilitySupport(Capability.QUERY_SEARCHED_CASE, true);
caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_SUM, true);
caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_ORDERED, true);
caps.setCapabilitySupport(Capability.QUERY_FROM_INLINE_VIEWS, true);
caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
// $NON-NLS-1$
capFinder.addCapabilities("BQT1", caps);
QueryMetadataInterface metadata = RealMetadataFactory.exampleBQTCached();
Command command = helpParse(sql);
ProcessorPlan plan = helpGetPlan(command, metadata, capFinder);
Set actualQueries = TestOptimizer.getAtomicQueries(plan);
// $NON-NLS-1$
String expectedSql = "SELECT SUM(v_0.c_1), v_0.c_0 FROM (SELECT CASE WHEN g_0.IntKey >= 5000 THEN '5000 +' ELSE '0-999' END AS c_0, g_0.IntKey AS c_1 FROM BQT1.SmallA AS g_0) AS v_0 GROUP BY v_0.c_0";
assertEquals(1, actualQueries.size());
assertEquals(expectedSql, actualQueries.iterator().next().toString());
List[] input1 = new List[] { Arrays.asList(new Object[] { new Integer(5), new Integer(10) }) };
HardcodedDataManager dataManager = new HardcodedDataManager();
dataManager.addData(expectedSql, input1);
List[] expected = new List[] { Arrays.asList(new Object[] { new Integer(5), new Integer(10) }) };
helpProcess(plan, dataManager, expected);
}
Aggregations