Search in sources :

Example 96 with CommandContext

use of org.teiid.query.util.CommandContext in project teiid by teiid.

the class TestProcessor method testCase5413.

@Test
public void testCase5413() throws Exception {
    FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
    BasicSourceCapabilities caps = new BasicSourceCapabilities();
    caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
    // $NON-NLS-1$
    capFinder.addCapabilities("pm1", caps);
    // Plan query
    // $NON-NLS-1$
    String sql = "SELECT e1 FROM pm1.g2 WHERE LOOKUP('pm1.g1','e1', 'e2', 0) = e1";
    QueryMetadataInterface metadata = RealMetadataFactory.example1Cached();
    Command command = TestProcessor.helpParse(sql);
    CommandContext context = createCommandContext();
    ProcessorPlan plan = helpGetPlan(command, metadata, capFinder, context);
    // Run query
    List[] expected = new List[] { // $NON-NLS-1$
    Arrays.asList(new Object[] { "a" }) };
    FakeDataManager dataManager = new FakeDataManager();
    FakeDataStore.sampleData2(dataManager);
    helpProcess(plan, context, dataManager, expected);
}
Also used : FakeCapabilitiesFinder(org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder) CommandContext(org.teiid.query.util.CommandContext) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) Command(org.teiid.query.sql.lang.Command) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) Test(org.junit.Test)

Example 97 with CommandContext

use of org.teiid.query.util.CommandContext in project teiid by teiid.

the class TestProcessor method testDefect5004a.

/**
 * Test to ensure that multiple empty batches are handled by the grouping node as well
 */
@Test
public void testDefect5004a() throws Exception {
    // Create query
    // $NON-NLS-1$
    String sql = "SELECT COUNT(*) FROM pm1.g1 WHERE e1='xxxx'";
    // Create expected results
    List[] expected = new List[] { Arrays.asList(new Object[] { new Integer(0) }) };
    // Construct data manager with data
    FakeDataManager dataManager = new FakeDataManager();
    sampleData1(dataManager);
    CommandContext context = createCommandContext();
    context.setProcessorBatchSize(2);
    context.setMetadata(RealMetadataFactory.example1Cached());
    // Plan query
    ProcessorPlan plan = helpGetPlan(helpParse(sql), RealMetadataFactory.example1Cached(), new DefaultCapabilitiesFinder(), context);
    // Run query
    helpProcess(plan, context, dataManager, expected);
}
Also used : BigInteger(java.math.BigInteger) CommandContext(org.teiid.query.util.CommandContext) DefaultCapabilitiesFinder(org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder) Test(org.junit.Test)

Example 98 with CommandContext

use of org.teiid.query.util.CommandContext in project teiid by teiid.

the class TestQueryProcessor method testCloseBeforeInitialization.

@Test
public void testCloseBeforeInitialization() throws TeiidComponentException {
    BufferManager bufferMgr = BufferManagerFactory.getStandaloneBufferManager();
    FakeDataManager dataManager = new FakeDataManager();
    // $NON-NLS-1$ //$NON-NLS-2$
    CommandContext context = new CommandContext("pid", "group", null, null, 1);
    QueryProcessor processor = new QueryProcessor(null, context, bufferMgr, dataManager);
    processor.closeProcessing();
}
Also used : CommandContext(org.teiid.query.util.CommandContext) BufferManager(org.teiid.common.buffer.BufferManager) Test(org.junit.Test)

Example 99 with CommandContext

use of org.teiid.query.util.CommandContext in project teiid by teiid.

the class TestRowBasedSecurity method testSelectFilterOuterJoin1.

@Test
public void testSelectFilterOuterJoin1() throws Exception {
    TransformationMetadata tm = RealMetadataFactory.fromDDL("create foreign table t (x string, y integer); create foreign table t1 (x string, y integer); create view v as select t.x, t1.y from t left outer join t1 on t.y = t1.y", "x", "y");
    BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
    caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_OUTER, false);
    caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, false);
    caps.setCapabilitySupport(Capability.QUERY_FROM_INLINE_VIEWS, false);
    CommandContext context = createCommandContext();
    DQPWorkContext workContext = new DQPWorkContext();
    HashMap<String, DataPolicy> policies = new HashMap<String, DataPolicy>();
    DataPolicyMetadata policy = new DataPolicyMetadata();
    pmd = new PermissionMetaData();
    pmd.setResourceName("y.v");
    pmd.setCondition("x = user()");
    policy.addPermission(pmd);
    policy.setName("some-role");
    policies.put("some-role", policy);
    workContext.setPolicies(policies);
    context.setDQPWorkContext(workContext);
    HardcodedDataManager dataManager = new HardcodedDataManager();
    dataManager.addData("SELECT g_0.y AS c_0, g_0.x AS c_1 FROM y.t AS g_0 ORDER BY c_0", new List<?>[] { Arrays.asList(1, "a"), Arrays.asList(2, "b") });
    dataManager.addData("SELECT g_0.y AS c_0 FROM y.t1 AS g_0 ORDER BY c_0", new List<?>[] { Arrays.asList(1) });
    ProcessorPlan plan = helpGetPlan(helpParse("select count(1) from v"), tm, new DefaultCapabilitiesFinder(caps), context);
    List<?>[] expectedResults = new List<?>[] { Arrays.asList(0) };
    helpProcess(plan, context, dataManager, expectedResults);
    plan = helpGetPlan(helpParse("select count(1) from v where y is not null"), tm, new DefaultCapabilitiesFinder(caps), context);
    dataManager.addData("SELECT g_0.y FROM y.t AS g_0 WHERE g_0.x = 'user'", new List<?>[] { Arrays.asList(1), Arrays.asList(2) });
    dataManager.addData("SELECT g_0.y AS c_0 FROM y.t1 AS g_0 WHERE g_0.y IS NOT NULL ORDER BY c_0", Arrays.asList(1));
    expectedResults = new List<?>[] { Arrays.asList(1) };
    helpProcess(plan, context, dataManager, expectedResults);
}
Also used : DQPWorkContext(org.teiid.dqp.internal.process.DQPWorkContext) TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) CommandContext(org.teiid.query.util.CommandContext) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) HashMap(java.util.HashMap) DefaultCapabilitiesFinder(org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder) DataPolicyMetadata(org.teiid.adminapi.impl.DataPolicyMetadata) List(java.util.List) DataPolicy(org.teiid.adminapi.DataPolicy) PermissionMetaData(org.teiid.adminapi.impl.DataPolicyMetadata.PermissionMetaData) Test(org.junit.Test)

Example 100 with CommandContext

use of org.teiid.query.util.CommandContext in project teiid by teiid.

the class TestSQLXMLProcessing method executeStreaming.

private void executeStreaming(String sql, final List<?>[] expected, int batchSize) throws Throwable {
    final CommandContext cc = createCommandContext();
    if (batchSize != -1) {
        cc.setBufferManager(BufferManagerFactory.getTestBufferManager(0, 1));
    }
    final ResultsFuture<Runnable> r = new ResultsFuture<Runnable>();
    Executor ex = new Executor() {

        @Override
        public void execute(Runnable command) {
            r.getResultsReceiver().receiveResults(command);
        }
    };
    cc.setExecutor(ex);
    final ProcessorPlan plan = helpGetPlan(helpParse(sql), RealMetadataFactory.example1Cached(), new DefaultCapabilitiesFinder(), cc);
    final ResultsFuture<Void> result = new ResultsFuture<Void>();
    Thread t = new Thread() {

        @Override
        public void run() {
            try {
                doProcess(plan, dataManager, expected, cc);
                result.getResultsReceiver().receiveResults(null);
            } catch (Throwable e) {
                result.getResultsReceiver().exceptionOccurred(e);
            }
        }
    };
    t.start();
    Runnable runnable = r.get();
    runnable.run();
    try {
        result.get();
    } catch (ExecutionException e) {
        if (e.getCause() != null) {
            throw e.getCause();
        }
        throw e;
    }
}
Also used : ResultsFuture(org.teiid.client.util.ResultsFuture) Executor(java.util.concurrent.Executor) CommandContext(org.teiid.query.util.CommandContext) DefaultCapabilitiesFinder(org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

CommandContext (org.teiid.query.util.CommandContext)257 Test (org.junit.Test)179 BasicSourceCapabilities (org.teiid.query.optimizer.capabilities.BasicSourceCapabilities)104 DefaultCapabilitiesFinder (org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder)95 List (java.util.List)90 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)64 ArrayList (java.util.ArrayList)44 Command (org.teiid.query.sql.lang.Command)38 QueryMetadataInterface (org.teiid.query.metadata.QueryMetadataInterface)37 FakeCapabilitiesFinder (org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder)33 ProcessorPlan (org.teiid.query.processor.ProcessorPlan)26 Options (org.teiid.query.util.Options)20 BufferManager (org.teiid.common.buffer.BufferManager)19 HardcodedDataManager (org.teiid.query.processor.HardcodedDataManager)19 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)18 TeiidProcessingException (org.teiid.core.TeiidProcessingException)14 BufferManagerImpl (org.teiid.common.buffer.impl.BufferManagerImpl)13 BlockedException (org.teiid.common.buffer.BlockedException)11 TeiidComponentException (org.teiid.core.TeiidComponentException)11 Table (org.teiid.metadata.Table)11