Search in sources :

Example 26 with Command

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);
}
Also used : Command(org.teiid.query.sql.lang.Command) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) Test(org.junit.Test)

Example 27 with Command

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);
}
Also used : Command(org.teiid.query.sql.lang.Command)

Example 28 with Command

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);
}
Also used : QueryParser(org.teiid.query.parser.QueryParser) CreateProcedureCommand(org.teiid.query.sql.proc.CreateProcedureCommand) Command(org.teiid.query.sql.lang.Command) QueryCommand(org.teiid.query.sql.lang.QueryCommand) BatchedUpdateCommand(org.teiid.query.sql.lang.BatchedUpdateCommand) ArrayList(java.util.ArrayList) ParseInfo(org.teiid.query.parser.ParseInfo) BatchedUpdateCommand(org.teiid.query.sql.lang.BatchedUpdateCommand)

Example 29 with Command

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);
}
Also used : AtomicRequestID(org.teiid.dqp.message.AtomicRequestID) Command(org.teiid.query.sql.lang.Command) CommandLogMessage(org.teiid.logging.CommandLogMessage)

Example 30 with Command

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);
}
Also used : FakeCapabilitiesFinder(org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder) BigInteger(java.math.BigInteger) ColumnSet(org.teiid.metadata.ColumnSet) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) Command(org.teiid.query.sql.lang.Command) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) Test(org.junit.Test)

Aggregations

Command (org.teiid.query.sql.lang.Command)232 Test (org.junit.Test)142 QueryMetadataInterface (org.teiid.query.metadata.QueryMetadataInterface)90 BasicSourceCapabilities (org.teiid.query.optimizer.capabilities.BasicSourceCapabilities)73 FakeCapabilitiesFinder (org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder)66 List (java.util.List)64 CommandContext (org.teiid.query.util.CommandContext)38 ArrayList (java.util.ArrayList)37 BatchedUpdateCommand (org.teiid.query.sql.lang.BatchedUpdateCommand)36 BigInteger (java.math.BigInteger)29 DefaultCapabilitiesFinder (org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder)25 AnalysisRecord (org.teiid.query.analysis.AnalysisRecord)21 GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)20 ProcessorPlan (org.teiid.query.processor.ProcessorPlan)19 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)16 LinkedList (java.util.LinkedList)10 QueryParser (org.teiid.query.parser.QueryParser)10 RelationalPlan (org.teiid.query.processor.relational.RelationalPlan)10 QueryCommand (org.teiid.query.sql.lang.QueryCommand)10 StoredProcedure (org.teiid.query.sql.lang.StoredProcedure)10