@Test public void testIsolateReads() throws Exception { GlobalTableStoreImpl gtsi = new GlobalTableStoreImpl( BufferManagerFactory.getStandaloneBufferManager(), RealMetadataFactory.example1Cached().getVdbMetaData(), RealMetadataFactory.example1Cached()); tempStore = gtsi.getTempTableStore(); metadata = new TempMetadataAdapter(RealMetadataFactory.example1Cached(), tempStore.getMetadataStore()); execute( "create local temporary table x (e1 string, e2 integer)", new List[] {Arrays.asList(0)}); // $NON-NLS-1$ for (int i = 0; i < 300; i++) { execute( "insert into x (e2, e1) select e2, e1 from pm1.g1", new List[] {Arrays.asList(6)}); // $NON-NLS-1$ } setupTransaction(Connection.TRANSACTION_SERIALIZABLE); execute("select count(e1) from x", new List[] {Arrays.asList(1500)}); gtsi.updateMatViewRow("X", Arrays.asList(2), true); tc = null; // outside of the transaction we can see the row removed execute("select count(e1) from x", new List[] {Arrays.asList(1499)}); // back in the transaction we see the original state setupTransaction(Connection.TRANSACTION_SERIALIZABLE); execute("select count(e1) from x", new List[] {Arrays.asList(1500)}); synch.afterCompletion(Status.STATUS_COMMITTED); }
public void helpTestProcessor(FakeProcessorPlan plan, List[] expectedResults) throws TeiidException { BufferManager bufferMgr = BufferManagerFactory.getStandaloneBufferManager(); FakeDataManager dataManager = new FakeDataManager(); CommandContext context = new CommandContext("pid", "group", null, null, 1); // $NON-NLS-1$ //$NON-NLS-2$ QueryProcessor processor = new QueryProcessor(plan, context, bufferMgr, dataManager); BatchCollector collector = processor.createBatchCollector(); TupleBuffer tsID = null; while (true) { try { tsID = collector.collectTuples(); break; } catch (BlockedException e) { } } // Compare # of rows in actual and expected assertEquals( "Did not get expected # of rows", expectedResults.length, tsID.getRowCount()); // $NON-NLS-1$ // Compare actual with expected results TupleSource actual = tsID.createIndexedTupleSource(); if (expectedResults.length > 0) { for (int i = 0; i < expectedResults.length; i++) { List actRecord = actual.nextTuple(); List expRecord = expectedResults[i]; assertEquals("Did not match row at row index " + i, expRecord, actRecord); // $NON-NLS-1$ } } tsID.remove(); }
@Test public void testTypeConversion() throws Exception { BufferManager bm = BufferManagerFactory.getStandaloneBufferManager(); String str = "hello world"; Object source = new StreamSource(new StringReader(str)); XMLType xml = (XMLType) ConnectorWorkItem.convertToRuntimeType( bm, source, DataTypeManager.DefaultDataClasses.XML, null); assertEquals(str, xml.getString()); source = new StAXSource(XMLType.getXmlInputFactory().createXMLEventReader(new StringReader("<a/>"))); xml = (XMLType) ConnectorWorkItem.convertToRuntimeType( bm, source, DataTypeManager.DefaultDataClasses.XML, null); XMLInputFactory in = XMLType.getXmlInputFactory(); XMLStreamReader reader = in.createXMLStreamReader(new StringReader(xml.getString())); assertEquals(XMLEvent.START_DOCUMENT, reader.getEventType()); assertEquals(XMLEvent.START_ELEMENT, reader.next()); assertEquals("a", reader.getLocalName()); assertEquals(XMLEvent.END_ELEMENT, reader.next()); byte[] bytes = str.getBytes(Streamable.ENCODING); source = new InputStreamFactory.BlobInputStreamFactory(BlobType.createBlob(bytes)); BlobType blob = (BlobType) ConnectorWorkItem.convertToRuntimeType( bm, source, DataTypeManager.DefaultDataClasses.BLOB, null); assertArrayEquals(bytes, ObjectConverterUtil.convertToByteArray(blob.getBinaryStream())); }
@Test public void testCloseBeforeInitialization() throws TeiidComponentException { BufferManager bufferMgr = BufferManagerFactory.getStandaloneBufferManager(); FakeDataManager dataManager = new FakeDataManager(); CommandContext context = new CommandContext("pid", "group", null, null, 1); // $NON-NLS-1$ //$NON-NLS-2$ QueryProcessor processor = new QueryProcessor(null, context, bufferMgr, dataManager); processor.closeProcessing(); }
@Test public void testInherentUpdateUsingTemp() throws Exception { TransformationMetadata metadata = RealMetadataFactory.fromDDL( "create foreign table g1 (e1 string primary key, e2 integer, e3 boolean, e4 double, FOREIGN KEY (e1) REFERENCES G2 (e1)) options (updatable true);" + " create foreign table g2 (e1 string primary key, e2 integer, e3 boolean, e4 double) options (updatable true);" + " create view v options (updatable true) as select g1.e2 from g1 inner join g2 on g1.e1 = g2.e1;", "x", "pm1"); HardcodedDataManager hdm = new HardcodedDataManager(metadata); setUp(metadata, hdm); BufferManager bm = BufferManagerFactory.getStandaloneBufferManager(); SessionAwareCache<CachedResults> cache = new SessionAwareCache<CachedResults>( "resultset", DefaultCacheFactory.INSTANCE, SessionAwareCache.Type.RESULTSET, 0); cache.setTupleBufferCache(bm); dataManager = new TempTableDataManager(hdm, bm, cache); execute( "create temporary table x (e1 string, e2 integer, e3 string, primary key (e1))", new List[] {Arrays.asList(0)}); // $NON-NLS-1$ execute("insert into x values ('a', 1, 'b')", new List[] {Arrays.asList(1)}); TempMetadataID id = this.tempStore.getMetadataStore().getData().get("x"); // ensure that we're using the actual metadata assertNotNull(id); assertNotNull(this.metadata.getPrimaryKey(id)); hdm.addData( "SELECT g_0.e1 FROM g1 AS g_0, g2 AS g_1 WHERE g_0.e1 = g_1.e1 AND g_0.e2 = 1", new List[] {Arrays.asList("a")}); hdm.addData("DELETE FROM g1 WHERE g1.e1 = 'a'", new List[] {Arrays.asList(1)}); execute( "delete from v where e2 = (select max(e2) from x as z where e3 = z.e3)", new List[] {Arrays.asList(1)}, TestOptimizer.getGenericFinder()); // $NON-NLS-1$ }
@Test public void testForeignTemp() throws Exception { HardcodedDataManager hdm = new HardcodedDataManager(metadata); BufferManager bm = BufferManagerFactory.getStandaloneBufferManager(); SessionAwareCache<CachedResults> cache = new SessionAwareCache<CachedResults>( "resultset", DefaultCacheFactory.INSTANCE, SessionAwareCache.Type.RESULTSET, 0); cache.setTupleBufferCache(bm); dataManager = new TempTableDataManager(hdm, bm, cache); execute( "create foreign temporary table x (e1 string options (nameinsource 'a'), e2 integer, e3 string, primary key (e1)) options (cardinality 1000, updatable true) on pm1", new List[] {Arrays.asList(0)}); // $NON-NLS-1$ TempMetadataID id = this.tempStore.getMetadataStore().getData().get("x"); // ensure that we're using the actual metadata assertNotNull(id); assertNotNull(this.metadata.getPrimaryKey(id)); assertEquals(1000, this.metadata.getCardinality(id), 0); assertEquals("pm1", this.metadata.getName(this.metadata.getModelID(id))); hdm.addData("SELECT x.a, x.e2, x.e3 FROM x", new List[] {Arrays.asList(1, 2, "3")}); execute("select * from x", new List[] {Arrays.asList(1, 2, "3")}); // $NON-NLS-1$ hdm.addData( "SELECT g_0.e2 AS c_0, g_0.e3 AS c_1, g_0.a AS c_2 FROM x AS g_0 ORDER BY c_1, c_0", new List[] {Arrays.asList(2, "3", "1")}); hdm.addData("SELECT g_0.e3, g_0.e2 FROM x AS g_0", new List[] {Arrays.asList("3", 2)}); hdm.addData("DELETE FROM x WHERE x.a = '1'", new List[] {Arrays.asList(1)}); // ensure compensation behaves as if physical - not temp execute( "delete from x where e2 = (select max(e2) from x as z where e3 = x.e3)", new List[] {Arrays.asList(1)}, TestOptimizer.getGenericFinder()); // $NON-NLS-1$ hdm.addData( "SELECT g_0.e1 FROM g1 AS g_0, x AS g_1 WHERE g_1.a = g_0.e1", new List[] {Arrays.asList(1)}); // ensure pushdown support execute( "select g1.e1 from pm1.g1 g1, x where x.e1 = g1.e1", new List[] {Arrays.asList(1)}, TestOptimizer.getGenericFinder()); // $NON-NLS-1$ try { execute( "create local temporary table x (e1 string)", new List[] {Arrays.asList(0)}); // $NON-NLS-1$ fail(); } catch (QueryResolverException e) { } // ensure that drop works execute("drop table x", new List[] {Arrays.asList(0)}); try { execute("drop table x", new List[] {Arrays.asList(0)}); fail(); } catch (QueryResolverException e) { } }
@Test public void testUnmodifibleList() throws Exception { BufferManager bm = BufferManagerFactory.getStandaloneBufferManager(); final ExecutionFactory<Object, Object> ef = new ExecutionFactory<Object, Object>() { @Override public boolean isSourceRequired() { return false; } @Override public ResultSetExecution createResultSetExecution( QueryExpression command, ExecutionContext executionContext, RuntimeMetadata metadata, Object connection) throws TranslatorException { List<String> list1 = Collections.singletonList("1"); final Iterator<List<String>> iter = Arrays.asList(list1).iterator(); return new ResultSetExecution() { @Override public void execute() throws TranslatorException {} @Override public void close() {} @Override public void cancel() throws TranslatorException {} @Override public List<?> next() throws TranslatorException, DataNotAvailableException { if (iter.hasNext()) { return iter.next(); } return null; } }; } }; ConnectorManager cm = new ConnectorManager("FakeConnector", "FakeConnector") { // $NON-NLS-1$ //$NON-NLS-2$ public ExecutionFactory getExecutionFactory() { return ef; } public Object getConnectionFactory() { return null; } }; cm.start(); AtomicRequestMessage requestMsg = createNewAtomicRequestMessage(1, 1); requestMsg.setCommand( helpGetCommand("SELECT intkey FROM bqt1.smalla", EXAMPLE_BQT)); // $NON-NLS-1$ requestMsg.setBufferManager(bm); ConnectorWorkItem cwi = new ConnectorWorkItem(requestMsg, cm); cwi.execute(); AtomicResultsMessage message = cwi.more(); List[] results = message.getResults(); assertEquals(1, results.length); List<?> tuple = results[0]; assertEquals(1, tuple.get(0)); assertEquals(1, message.getFinalRow()); }
@Test public void testLobs() throws Exception { BufferManager bm = BufferManagerFactory.getStandaloneBufferManager(); final ExecutionFactory<Object, Object> ef = new ExecutionFactory<Object, Object>() { @Override public boolean isSourceRequired() { return false; } @Override public ResultSetExecution createResultSetExecution( QueryExpression command, ExecutionContext executionContext, RuntimeMetadata metadata, Object connection) throws TranslatorException { return new ResultSetExecution() { private boolean returned; @Override public void execute() throws TranslatorException {} @Override public void close() {} @Override public void cancel() throws TranslatorException {} @Override public List<?> next() throws TranslatorException, DataNotAvailableException { if (returned) { return null; } returned = true; return Arrays.asList(AutoGenDataService.CLOB_VAL); } }; } }; ConnectorManager cm = new ConnectorManager("FakeConnector", "FakeConnector") { // $NON-NLS-1$ //$NON-NLS-2$ public ExecutionFactory getExecutionFactory() { return ef; } public Object getConnectionFactory() { return null; } }; cm.start(); ef.setCopyLobs(true); AtomicRequestMessage requestMsg = createNewAtomicRequestMessage(1, 1); requestMsg.setCommand( helpGetCommand("SELECT CLOB_COLUMN FROM LOB_TESTING_ONE", EXAMPLE_BQT)); // $NON-NLS-1$ requestMsg.setBufferManager(bm); ConnectorWorkItem cwi = new ConnectorWorkItem(requestMsg, cm); cwi.execute(); AtomicResultsMessage message = cwi.more(); List[] resutls = message.getResults(); List<?> tuple = resutls[0]; ClobType clob = (ClobType) tuple.get(0); assertEquals(StorageMode.MEMORY, InputStreamFactory.getStorageMode(clob)); assertTrue(message.supportsImplicitClose()); ef.setCopyLobs(false); cwi = new ConnectorWorkItem(requestMsg, cm); cwi.execute(); message = cwi.more(); resutls = message.getResults(); tuple = resutls[0]; clob = (ClobType) tuple.get(0); assertEquals(StorageMode.OTHER, InputStreamFactory.getStorageMode(clob)); assertFalse(message.supportsImplicitClose()); }