Search in sources :

Example 66 with HardcodedDataManager

use of org.teiid.query.processor.HardcodedDataManager in project teiid by teiid.

the class TestProcErrors method testNestedBeginAtomicException.

@Test
public void testNestedBeginAtomicException() throws Exception {
    TransformationMetadata tm = RealMetadataFactory.example1Cached();
    String query = "BEGIN atomic\n" + " declare string VARIABLES.RESULT;\n" + " begin atomic select 1/0; exception e end end";
    ProcessorPlan plan = getProcedurePlan(query, tm);
    // Create expected results
    List<?>[] expected = new List[0];
    // $NON-NLS-1$
    CommandContext context = new CommandContext("pID", null, null, null, 1);
    QueryMetadataInterface metadata = new TempMetadataAdapter(tm, new TempMetadataStore());
    context.setMetadata(metadata);
    TransactionContext tc = new TransactionContext();
    Transaction txn = Mockito.mock(Transaction.class);
    tc.setTransaction(txn);
    tc.setTransactionType(Scope.REQUEST);
    TransactionService ts = Mockito.mock(TransactionService.class);
    context.setTransactionService(ts);
    context.setTransactionContext(tc);
    TestProcessor.helpProcess(plan, context, new HardcodedDataManager(), expected);
    Mockito.verify(txn, Mockito.times(3)).setRollbackOnly();
}
Also used : TempMetadataAdapter(org.teiid.query.metadata.TempMetadataAdapter) TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) CommandContext(org.teiid.query.util.CommandContext) TransactionService(org.teiid.dqp.service.TransactionService) HardcodedDataManager(org.teiid.query.processor.HardcodedDataManager) Transaction(javax.transaction.Transaction) TransactionContext(org.teiid.dqp.service.TransactionContext) List(java.util.List) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) ProcessorPlan(org.teiid.query.processor.ProcessorPlan) TempMetadataStore(org.teiid.query.metadata.TempMetadataStore) Test(org.junit.Test)

Example 67 with HardcodedDataManager

use of org.teiid.query.processor.HardcodedDataManager in project teiid by teiid.

the class TestProcErrors method testExceptionHandlingWithDynamic.

@Test
public void testExceptionHandlingWithDynamic() throws Exception {
    String ddl = "create virtual procedure vproc (x integer) returns integer as begin " + "raise sqlexception 'hello world' sqlstate 'abc', 5;" + "exception e " + "execute immediate 'select \"ERRORCODE\"' as x integer into #temp; " + "\"return\" = (select x from #temp);" + "end;";
    TransformationMetadata tm = TestProcedureResolving.createMetadata(ddl);
    // $NON-NLS-1$
    String sql = "call vproc(1)";
    ProcessorPlan plan = getProcedurePlan(sql, tm);
    HardcodedDataManager dataManager = new HardcodedDataManager(tm);
    helpTestProcess(plan, new List[] { Arrays.asList(5) }, dataManager, tm);
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) HardcodedDataManager(org.teiid.query.processor.HardcodedDataManager) ProcessorPlan(org.teiid.query.processor.ProcessorPlan) Test(org.junit.Test)

Example 68 with HardcodedDataManager

use of org.teiid.query.processor.HardcodedDataManager in project teiid by teiid.

the class TestJoinNode method testDupRemoveUnderJoin.

@Test
public void testDupRemoveUnderJoin() throws Exception {
    // $NON-NLS-1$
    String sql = "select a.e1, b.e2 from pm1.g1 as a, (select distinct e1, e2 from pm2.g2) as b";
    ProcessorPlan plan = TestProcessor.helpGetPlan(sql, RealMetadataFactory.example1Cached());
    HardcodedDataManager hdm = new HardcodedDataManager() {

        public TupleSource registerRequest(CommandContext context, Command command, String modelName, RegisterRequestParameter parameterObject) throws TeiidComponentException {
            final TupleSource source = super.registerRequest(context, command, modelName, parameterObject);
            return new TupleSource() {

                private int block;

                @Override
                public List<?> nextTuple() throws TeiidComponentException, TeiidProcessingException {
                    if (block++ % 2 == 0) {
                        throw BlockedException.INSTANCE;
                    }
                    return source.nextTuple();
                }

                @Override
                public void closeSource() {
                    source.closeSource();
                }
            };
        }
    };
    List<?>[] rows = new List<?>[1];
    for (int i = 0; i < rows.length; i++) {
        rows[i] = Arrays.asList(String.valueOf(i));
    }
    hdm.addData("SELECT pm1.g1.e1 FROM pm1.g1", rows);
    rows = new List<?>[1025];
    for (int i = 0; i < rows.length; i++) {
        rows[i] = Arrays.asList(String.valueOf(i), i);
    }
    hdm.addData("SELECT pm2.g2.e1, pm2.g2.e2 FROM pm2.g2", rows);
    BufferManagerImpl mgr = BufferManagerFactory.getTestBufferManager(1, 2);
    mgr.setTargetBytesPerRow(100);
    // $NON-NLS-1$ //$NON-NLS-2$
    CommandContext context = new CommandContext("pid", "test", null, null, 1);
    List<?>[] results = new List<?>[1025];
    for (int i = 0; i < results.length; i++) {
        results[i] = Arrays.asList("0", i);
    }
    TestProcessor.helpProcess(plan, context, hdm, results);
}
Also used : CommandContext(org.teiid.query.util.CommandContext) BufferManagerImpl(org.teiid.common.buffer.impl.BufferManagerImpl) HardcodedDataManager(org.teiid.query.processor.HardcodedDataManager) Command(org.teiid.query.sql.lang.Command) TupleSource(org.teiid.common.buffer.TupleSource) ArrayList(java.util.ArrayList) List(java.util.List) ProcessorPlan(org.teiid.query.processor.ProcessorPlan) RegisterRequestParameter(org.teiid.query.processor.RegisterRequestParameter) Test(org.junit.Test)

Example 69 with HardcodedDataManager

use of org.teiid.query.processor.HardcodedDataManager in project teiid by teiid.

the class TestJoinNode method testPrefetchDistinct.

@Test
public void testPrefetchDistinct() throws Exception {
    // $NON-NLS-1$
    String sql = "select a.e1, b.e2 from pm1.g1 as a, (select e1, e2 from pm2.g2 union select e1, e2 from pm2.g2) as b";
    ProcessorPlan plan = TestProcessor.helpGetPlan(sql, RealMetadataFactory.example1Cached());
    HardcodedDataManager hdm = new HardcodedDataManager() {

        public TupleSource registerRequest(CommandContext context, Command command, String modelName, RegisterRequestParameter parameterObject) throws TeiidComponentException {
            final TupleSource source = super.registerRequest(context, command, modelName, parameterObject);
            return new TupleSource() {

                private int block;

                @Override
                public List<?> nextTuple() throws TeiidComponentException, TeiidProcessingException {
                    if (block++ % 2 == 0) {
                        throw BlockedException.INSTANCE;
                    }
                    return source.nextTuple();
                }

                @Override
                public void closeSource() {
                    source.closeSource();
                }
            };
        }
    };
    List<?>[] rows = new List<?>[2];
    for (int i = 0; i < rows.length; i++) {
        rows[i] = Arrays.asList(String.valueOf(i));
    }
    hdm.addData("SELECT pm1.g1.e1 FROM pm1.g1", rows);
    rows = new List<?>[2];
    for (int i = 0; i < rows.length; i++) {
        rows[i] = Arrays.asList(String.valueOf(i), i);
    }
    hdm.addData("SELECT pm2.g2.e1, pm2.g2.e2 FROM pm2.g2", rows);
    BufferManagerImpl mgr = BufferManagerFactory.getTestBufferManager(1, 2);
    mgr.setTargetBytesPerRow(100);
    // $NON-NLS-1$ //$NON-NLS-2$
    CommandContext context = new CommandContext("pid", "test", null, null, 1);
    context.setBufferManager(mgr);
    TestProcessor.helpProcess(plan, context, hdm, new List<?>[] { Arrays.asList("0", 0), Arrays.asList("0", 1), Arrays.asList("1", 0), Arrays.asList("1", 1) });
}
Also used : CommandContext(org.teiid.query.util.CommandContext) BufferManagerImpl(org.teiid.common.buffer.impl.BufferManagerImpl) HardcodedDataManager(org.teiid.query.processor.HardcodedDataManager) Command(org.teiid.query.sql.lang.Command) TupleSource(org.teiid.common.buffer.TupleSource) ArrayList(java.util.ArrayList) List(java.util.List) ProcessorPlan(org.teiid.query.processor.ProcessorPlan) RegisterRequestParameter(org.teiid.query.processor.RegisterRequestParameter) Test(org.junit.Test)

Example 70 with HardcodedDataManager

use of org.teiid.query.processor.HardcodedDataManager in project teiid by teiid.

the class TestPreparedStatement method testInsertWithSimpleSelect.

@Test
public void testInsertWithSimpleSelect() throws Exception {
    // $NON-NLS-1$
    String preparedSql = "insert into pm1.g1 (e1, e2) select ?, ?";
    List<?>[] expected = new List<?>[] { Arrays.asList(1) };
    // $NON-NLS-1$
    List<?> values = Arrays.asList("a", "1");
    QueryMetadataInterface metadata = RealMetadataFactory.example1Cached();
    HardcodedDataManager dataManager = new HardcodedDataManager(metadata);
    dataManager.addData("INSERT INTO g1 (e1, e2) VALUES ('a', 1)", new List<?>[] { Arrays.asList(1) });
    BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
    helpTestProcessing(preparedSql, values, expected, dataManager, new DefaultCapabilitiesFinder(caps), metadata, null, false, false, false, RealMetadataFactory.example1VDB());
}
Also used : HardcodedDataManager(org.teiid.query.processor.HardcodedDataManager) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) ArrayList(java.util.ArrayList) List(java.util.List) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) DefaultCapabilitiesFinder(org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder) Test(org.junit.Test)

Aggregations

HardcodedDataManager (org.teiid.query.processor.HardcodedDataManager)140 Test (org.junit.Test)134 ProcessorPlan (org.teiid.query.processor.ProcessorPlan)97 List (java.util.List)75 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)63 BasicSourceCapabilities (org.teiid.query.optimizer.capabilities.BasicSourceCapabilities)53 ArrayList (java.util.ArrayList)44 DefaultCapabilitiesFinder (org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder)42 QueryMetadataInterface (org.teiid.query.metadata.QueryMetadataInterface)29 CommandContext (org.teiid.query.util.CommandContext)19 FakeCapabilitiesFinder (org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder)14 Options (org.teiid.query.util.Options)6 BufferManagerImpl (org.teiid.common.buffer.impl.BufferManagerImpl)5 RegisterRequestParameter (org.teiid.query.processor.RegisterRequestParameter)4 Command (org.teiid.query.sql.lang.Command)4 TupleSource (org.teiid.common.buffer.TupleSource)3 Insert (org.teiid.query.sql.lang.Insert)3 VDBMetaData (org.teiid.adminapi.impl.VDBMetaData)2 TeiidProcessingException (org.teiid.core.TeiidProcessingException)2 TeiidSQLException (org.teiid.jdbc.TeiidSQLException)2