public static GlobalTableStore createInstance(CompositeVDB vdb, BufferManager bufferManager, ObjectReplicator replicator) { VDBMetaData vdbMetadata = vdb.getVDB(); QueryMetadataInterface metadata = vdbMetadata.getAttachment(TransformationMetadata.class); GlobalTableStore gts = new GlobalTableStoreImpl(bufferManager, vdbMetadata, metadata); if (replicator != null) { try { gts = replicator.replicate(vdbMetadata.getFullName(), GlobalTableStore.class, gts, 300000); } catch (Exception e) { LogManager.logError(LogConstants.CTX_RUNTIME, e, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40088, gts)); } } if (vdb.getChildren() == null) { return gts; } TreeMap<String, GlobalTableStore> stores = new TreeMap<String, GlobalTableStore>(String.CASE_INSENSITIVE_ORDER); buildStoreMap(vdb, stores); return new CompositeGlobalTableStore(stores, gts, metadata); }
public GlobalTableStoreImpl getSessionScopedStore(boolean create) { GlobalTableStoreImpl impl = getSession().getAttachment(GlobalTableStoreImpl.class); if (!create) { return impl; } impl = getSession().getAttachment(GlobalTableStoreImpl.class); if (impl == null) { impl = new GlobalTableStoreImpl(getBufferManager(), null, getMetadata()); getSession().addAttchment(GlobalTableStoreImpl.class, impl); } return impl; }
@Before public void setUp() { tempStore = new TempTableStore("1", TransactionMode.ISOLATE_WRITES); //$NON-NLS-1$ BufferManager bm = BufferManagerFactory.getStandaloneBufferManager(); TransformationMetadata actualMetadata = RealMetadataFactory.exampleMaterializedView(); globalStore = new GlobalTableStoreImpl(bm, actualMetadata.getVdbMetaData(), actualMetadata); metadata = new TempMetadataAdapter(actualMetadata, tempStore.getMetadataStore()); hdm = new HardcodedDataManager(); hdm.addData("SELECT MatSrc.MatSrc.x FROM MatSrc.MatSrc", new List[] {Arrays.asList((String)null), Arrays.asList("one"), Arrays.asList("two"), Arrays.asList("three")}); hdm.addData("SELECT MatTable.info.e1, MatTable.info.e2 FROM MatTable.info", new List[] {Arrays.asList("a", 1), Arrays.asList("a", 2)}); hdm.addData("SELECT MatTable.info.e2, MatTable.info.e1 FROM MatTable.info", new List[] {Arrays.asList(1, "a"), Arrays.asList(2, "a")}); SessionAwareCache<CachedResults> cache = new SessionAwareCache<CachedResults>("resultset", DefaultCacheFactory.INSTANCE, SessionAwareCache.Type.RESULTSET, 0); cache.setTupleBufferCache(bm); dataManager = new TempTableDataManager(hdm, bm, cache); }
@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(2l), 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); }
@Test public void testDefaultMaterialization() throws Exception { String userSql = "SELECT * from vgroup2"; //$NON-NLS-1$ TransformationMetadata metadata = RealMetadataFactory.exampleMaterializedView(); AnalysisRecord analysis = new AnalysisRecord(true, DEBUG); Command command = helpGetCommand(userSql, metadata); CommandContext cc = new CommandContext(); GlobalTableStoreImpl gts = new GlobalTableStoreImpl(null, metadata.getVdbMetaData(), metadata); cc.setGlobalTableStore(gts); ProcessorPlan plan = TestOptimizer.getPlan(command, metadata, getGenericFinder(), analysis, true, cc); TestOptimizer.checkAtomicQueries(new String[] {"SELECT #MAT_MATVIEW.VGROUP2.x FROM #MAT_MATVIEW.VGROUP2"}, plan); Collection<Annotation> annotations = analysis.getAnnotations(); assertNotNull("Expected annotations but got none", annotations); //$NON-NLS-1$ assertEquals("Expected one annotation", 1, annotations.size()); //$NON-NLS-1$ assertEquals("Expected catagory mat view", annotations.iterator().next().getCategory(), Annotation.MATERIALIZED_VIEW); //$NON-NLS-1$ }
@Test public void testDefaultMaterializationWithCacheHint() throws Exception { String userSql = "SELECT * from vgroup4"; //$NON-NLS-1$ TransformationMetadata metadata = RealMetadataFactory.exampleMaterializedView(); AnalysisRecord analysis = new AnalysisRecord(true, DEBUG); Command command = helpGetCommand(userSql, metadata); CommandContext cc = new CommandContext(); GlobalTableStoreImpl gts = new GlobalTableStoreImpl(null, metadata.getVdbMetaData(), metadata); cc.setGlobalTableStore(gts); ProcessorPlan plan = TestOptimizer.getPlan(command, metadata, getGenericFinder(), analysis, true, cc); TestOptimizer.checkAtomicQueries(new String[] {"SELECT #MAT_MATVIEW.VGROUP4.x FROM #MAT_MATVIEW.VGROUP4"}, plan); Collection<Annotation> annotations = analysis.getAnnotations(); assertNotNull("Expected annotations but got none", annotations); //$NON-NLS-1$ assertEquals("Expected one annotation", 1, annotations.size()); //$NON-NLS-1$ assertEquals("Expected catagory mat view", annotations.iterator().next().getCategory(), Annotation.MATERIALIZED_VIEW); //$NON-NLS-1$ }
@Test public void testDefaultMaterializationWithPK() throws Exception { String userSql = "SELECT * from vgroup3 where x = 'foo'"; //$NON-NLS-1$ TransformationMetadata metadata = RealMetadataFactory.exampleMaterializedView(); AnalysisRecord analysis = new AnalysisRecord(true, DEBUG); Command command = helpGetCommand(userSql, metadata); CommandContext cc = new CommandContext(); GlobalTableStoreImpl gts = new GlobalTableStoreImpl(null, metadata.getVdbMetaData(), metadata); cc.setGlobalTableStore(gts); RelationalPlan plan = (RelationalPlan)TestOptimizer.getPlan(command, metadata, getGenericFinder(), analysis, true, cc); assertEquals(1f, plan.getRootNode().getEstimateNodeCardinality()); TestOptimizer.checkAtomicQueries(new String[] {"SELECT #MAT_MATVIEW.VGROUP3.x, #MAT_MATVIEW.VGROUP3.y FROM #MAT_MATVIEW.VGROUP3 WHERE #MAT_MATVIEW.VGROUP3.x = 'foo'"}, plan); Collection<Annotation> annotations = analysis.getAnnotations(); assertNotNull("Expected annotations but got none", annotations); //$NON-NLS-1$ assertEquals("Expected one annotation", 1, annotations.size()); //$NON-NLS-1$ assertEquals("Expected catagory mat view", annotations.iterator().next().getCategory(), Annotation.MATERIALIZED_VIEW); //$NON-NLS-1$ }
GlobalTableStoreImpl gts = new GlobalTableStoreImpl(bufferMgr, null, context.getMetadata()); context.setGlobalTableStore(gts);