Search in sources :

Example 6 with Command

use of org.teiid.query.sql.lang.Command in project teiid by teiid.

the class TestConnectorWorkItem method testSourcHints.

@Test
public void testSourcHints() throws Exception {
    // $NON-NLS-1$
    Command command = helpGetCommand("update bqt1.smalla set stringkey = 1 where stringkey = 2", EXAMPLE_BQT);
    command.setSourceHint(new SourceHint());
    AtomicRequestMessage arm = createNewAtomicRequestMessage(1, 1);
    arm.setCommand(command);
    ConnectorManager cm = TestConnectorManager.getConnectorManager();
    cm.registerRequest(arm);
}
Also used : Command(org.teiid.query.sql.lang.Command) BatchedUpdateCommand(org.teiid.query.sql.lang.BatchedUpdateCommand) AtomicRequestMessage(org.teiid.dqp.message.AtomicRequestMessage) SourceHint(org.teiid.query.sql.lang.SourceHint) Test(org.junit.Test)

Example 7 with Command

use of org.teiid.query.sql.lang.Command in project teiid by teiid.

the class TestConnectorWorkItem method testConvertIn.

@Test
public void testConvertIn() throws Exception {
    // $NON-NLS-1$
    Command command = helpGetCommand("select intkey from bqt1.smalla where stringkey in ('1', '2')", EXAMPLE_BQT);
    AtomicRequestMessage arm = createNewAtomicRequestMessage(1, 1);
    arm.setCommand(command);
    ConnectorManager cm = TestConnectorManager.getConnectorManager();
    cm.getExecutionFactory().setSourceRequired(false);
    ConnectorWork synchConnectorWorkItem = cm.registerRequest(arm);
    synchConnectorWorkItem.execute();
    synchConnectorWorkItem.close();
    FakeConnector fc = (FakeConnector) cm.getExecutionFactory();
    assertEquals("SELECT SmallA.IntKey FROM SmallA WHERE SmallA.StringKey = '2' OR SmallA.StringKey = '1'", fc.getCommands().get(0).toString());
    assertEquals(1, fc.getConnectionCount());
    assertEquals(1, fc.getCloseCount());
}
Also used : Command(org.teiid.query.sql.lang.Command) BatchedUpdateCommand(org.teiid.query.sql.lang.BatchedUpdateCommand) AtomicRequestMessage(org.teiid.dqp.message.AtomicRequestMessage) Test(org.junit.Test)

Example 8 with Command

use of org.teiid.query.sql.lang.Command in project teiid by teiid.

the class TestConnectorWorkItem method helpGetCommand.

private static Command helpGetCommand(String sql, QueryMetadataInterface metadata) throws Exception {
    Command command = QueryParser.getQueryParser().parseCommand(sql);
    QueryResolver.resolveCommand(command, metadata);
    return command;
}
Also used : Command(org.teiid.query.sql.lang.Command) BatchedUpdateCommand(org.teiid.query.sql.lang.BatchedUpdateCommand)

Example 9 with Command

use of org.teiid.query.sql.lang.Command in project teiid by teiid.

the class TestAuthorizationValidationVisitor method helpTest.

private void helpTest(String sql, QueryMetadataInterface metadata, String[] expectedInaccesible, VDBMetaData vdb, DataPolicyMetadata... roles) throws QueryParserException, QueryResolverException, TeiidComponentException {
    QueryParser parser = QueryParser.getQueryParser();
    Command command = parser.parseCommand(sql);
    QueryResolver.resolveCommand(command, metadata);
    DataRolePolicyDecider dataRolePolicyDecider = createPolicyDecider(metadata, vdb, roles);
    // $NON-NLS-1$
    AuthorizationValidationVisitor visitor = new AuthorizationValidationVisitor(dataRolePolicyDecider, context);
    ValidatorReport report = Validator.validate(command, metadata, visitor);
    if (report.hasItems()) {
        ValidatorFailure firstFailure = report.getItems().iterator().next();
        // strings
        Set<String> expected = new HashSet<String>(Arrays.asList(expectedInaccesible));
        // elements
        Set<String> actual = new HashSet<String>();
        for (LanguageObject obj : firstFailure.getInvalidObjects()) {
            if (obj instanceof ElementSymbol) {
                actual.add(((ElementSymbol) obj).getName());
            } else {
                actual.add(obj.toString());
            }
        }
        assertEquals(expected, actual);
    } else if (expectedInaccesible.length > 0) {
        // $NON-NLS-1$
        fail("Expected inaccessible objects, but got none.");
    }
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) QueryParser(org.teiid.query.parser.QueryParser) Command(org.teiid.query.sql.lang.Command) ValidatorFailure(org.teiid.query.validator.ValidatorFailure) ValidatorReport(org.teiid.query.validator.ValidatorReport) LanguageObject(org.teiid.query.sql.LanguageObject) HashSet(java.util.HashSet)

Example 10 with Command

use of org.teiid.query.sql.lang.Command in project teiid by teiid.

the class TestProcedureImpl method example.

public static Call example() throws Exception {
    // $NON-NLS-1$
    String sql = "EXEC pm1.sq3('x', 1)";
    Command command = new QueryParser().parseCommand(sql);
    QueryResolver.resolveCommand(command, TstLanguageBridgeFactory.metadata);
    return TstLanguageBridgeFactory.factory.translate((StoredProcedure) command);
}
Also used : QueryParser(org.teiid.query.parser.QueryParser) Command(org.teiid.query.sql.lang.Command)

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