@Override public TempMetadataID getGlobalTempTableMetadataId(String matTableName) { return this.tableStore.getMetadataStore().getTempGroupID(matTableName); }
@Override public TempMetadataID getGlobalTempTableMetadataId(String matTableName) { return this.tableStore.getMetadataStore().getTempGroupID(matTableName); }
@Override public TempMetadataID getGlobalTempTableMetadataId(String matTableName) { return this.tableStore.getMetadataStore().getTempGroupID(matTableName); }
@Override public List<?> updateMatViewRow(String matTableName, List<?> tuple, boolean delete) throws TeiidComponentException { TempTable tempTable = tableStore.getTempTable(matTableName); if (tempTable != null) { TempMetadataID id = tableStore.getMetadataStore().getTempGroupID(matTableName); synchronized (id) { boolean clone = tempTable.getActive().get() != 0; if (clone) { tempTable = tempTable.clone(); } List<?> result = tempTable.updateTuple(tuple, delete); if (clone) { swapTempTable(matTableName, tempTable); } return result; } } return null; }
@Override public List<?> updateMatViewRow(String matTableName, List<?> tuple, boolean delete) throws TeiidComponentException { TempTable tempTable = tableStore.getTempTable(matTableName); if (tempTable != null) { TempMetadataID id = tableStore.getMetadataStore().getTempGroupID(matTableName); synchronized (id) { boolean clone = tempTable.getActive().get() != 0; if (clone) { tempTable = tempTable.clone(); } List<?> result = tempTable.updateTuple(tuple, delete); if (clone) { swapTempTable(matTableName, tempTable); } return result; } } return null; }
@Override public List<?> updateMatViewRow(String matTableName, List<?> tuple, boolean delete) throws TeiidComponentException { TempTable tempTable = tableStore.getTempTable(matTableName); if (tempTable != null) { TempMetadataID id = tableStore.getMetadataStore().getTempGroupID(matTableName); synchronized (id) { boolean clone = tempTable.getActive().get() != 0; if (clone) { tempTable = tempTable.clone(); } List<?> result = tempTable.updateTuple(tuple, delete); if (clone) { swapTempTable(matTableName, tempTable); } return result; } } return null; }
@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); }
@Override public TempMetadataID getCodeTableMetadataId( String codeTableName, String returnElementName, String keyElementName, String matTableName) throws TeiidComponentException, QueryMetadataException { ElementSymbol keyElement = new ElementSymbol(matTableName + ElementSymbol.SEPARATOR + keyElementName); ElementSymbol returnElement = new ElementSymbol(matTableName + ElementSymbol.SEPARATOR + returnElementName); keyElement.setType(DataTypeManager.getDataTypeClass(metadata.getElementRuntimeTypeName(metadata.getElementID(codeTableName + ElementSymbol.SEPARATOR + keyElementName)))); returnElement.setType(DataTypeManager.getDataTypeClass(metadata.getElementRuntimeTypeName(metadata.getElementID(codeTableName + ElementSymbol.SEPARATOR + returnElementName)))); TempMetadataID id = this.tableStore.getMetadataStore().getTempGroupID(matTableName); if (id == null) { synchronized (this) { id = this.tableStore.getMetadataStore().addTempGroup(matTableName, Arrays.asList(keyElement, returnElement), false, true); String queryString = Reserved.SELECT + ' ' + new ElementSymbol(keyElementName) + " ," + new ElementSymbol(returnElementName) + ' ' + Reserved.FROM + ' ' + new GroupSymbol(codeTableName); //$NON-NLS-1$ id.setQueryNode(new QueryNode(queryString)); id.setPrimaryKey(id.getElements().subList(0, 1)); CacheHint hint = new CacheHint(true, null); id.setCacheHint(hint); } } return id; }
@Override public TempMetadataID getCodeTableMetadataId( String codeTableName, String returnElementName, String keyElementName, String matTableName) throws TeiidComponentException, QueryMetadataException { ElementSymbol keyElement = new ElementSymbol(matTableName + ElementSymbol.SEPARATOR + keyElementName); ElementSymbol returnElement = new ElementSymbol(matTableName + ElementSymbol.SEPARATOR + returnElementName); keyElement.setType(DataTypeManager.getDataTypeClass(metadata.getElementRuntimeTypeName(metadata.getElementID(codeTableName + ElementSymbol.SEPARATOR + keyElementName)))); returnElement.setType(DataTypeManager.getDataTypeClass(metadata.getElementRuntimeTypeName(metadata.getElementID(codeTableName + ElementSymbol.SEPARATOR + returnElementName)))); TempMetadataID id = this.tableStore.getMetadataStore().getTempGroupID(matTableName); if (id == null) { synchronized (this) { id = this.tableStore.getMetadataStore().addTempGroup(matTableName, Arrays.asList(keyElement, returnElement), false, true); String queryString = Reserved.SELECT + ' ' + new ElementSymbol(keyElementName) + " ," + new ElementSymbol(returnElementName) + ' ' + Reserved.FROM + ' ' + new GroupSymbol(codeTableName); //$NON-NLS-1$ id.setQueryNode(new QueryNode(queryString)); id.setPrimaryKey(id.getElements().subList(0, 1)); CacheHint hint = new CacheHint(true, null); id.setCacheHint(hint); } } return id; }
@Override public TempMetadataID getCodeTableMetadataId( String codeTableName, String returnElementName, String keyElementName, String matTableName) throws TeiidComponentException, QueryMetadataException { ElementSymbol keyElement = new ElementSymbol(matTableName + ElementSymbol.SEPARATOR + keyElementName); ElementSymbol returnElement = new ElementSymbol(matTableName + ElementSymbol.SEPARATOR + returnElementName); keyElement.setType(DataTypeManager.getDataTypeClass(metadata.getElementRuntimeTypeName(metadata.getElementID(codeTableName + ElementSymbol.SEPARATOR + keyElementName)))); returnElement.setType(DataTypeManager.getDataTypeClass(metadata.getElementRuntimeTypeName(metadata.getElementID(codeTableName + ElementSymbol.SEPARATOR + returnElementName)))); TempMetadataID id = this.tableStore.getMetadataStore().getTempGroupID(matTableName); if (id == null) { synchronized (this) { id = this.tableStore.getMetadataStore().addTempGroup(matTableName, Arrays.asList(keyElement, returnElement), false, true); String queryString = Reserved.SELECT + ' ' + new ElementSymbol(keyElementName) + " ," + new ElementSymbol(returnElementName) + ' ' + Reserved.FROM + ' ' + new GroupSymbol(codeTableName); //$NON-NLS-1$ id.setQueryNode(new QueryNode(queryString)); id.setPrimaryKey(id.getElements().subList(0, 1)); CacheHint hint = new CacheHint(true, null); id.setCacheHint(hint); } } return id; }
public void setNewVDBState(DQPWorkContext newWorkContext) { this.vdbState = new VDBState(); VDBMetaData vdb = newWorkContext.getVDB(); GlobalTableStore actualGlobalStore = vdb.getAttachment(GlobalTableStore.class); this.vdbState.globalTables = actualGlobalStore; this.vdbState.session = newWorkContext.getSession(); this.vdbState.classLoader = vdb.getAttachment(ClassLoader.class); this.vdbState.vdbName = vdb.getName(); this.vdbState.vdbVersion = vdb.getVersion(); this.vdbState.dqpWorkContext = newWorkContext; TempMetadataAdapter metadata = new TempMetadataAdapter(vdb.getAttachment(QueryMetadataInterface.class), globalState.sessionTempTableStore.getMetadataStore()); metadata.setSession(true); this.vdbState.metadata = metadata; }
public void setNewVDBState(DQPWorkContext newWorkContext) { this.vdbState = new VDBState(); VDBMetaData vdb = newWorkContext.getVDB(); GlobalTableStore actualGlobalStore = vdb.getAttachment(GlobalTableStore.class); this.vdbState.globalTables = actualGlobalStore; this.vdbState.session = newWorkContext.getSession(); this.vdbState.classLoader = vdb.getAttachment(ClassLoader.class); this.vdbState.vdbName = vdb.getName(); this.vdbState.vdbVersion = vdb.getVersion(); this.vdbState.dqpWorkContext = newWorkContext; TempMetadataAdapter metadata = new TempMetadataAdapter(vdb.getAttachment(QueryMetadataInterface.class), globalState.sessionTempTableStore.getMetadataStore()); metadata.setSession(true); this.vdbState.metadata = metadata; }
public void setNewVDBState(DQPWorkContext newWorkContext) { this.vdbState = new VDBState(); VDBMetaData vdb = newWorkContext.getVDB(); GlobalTableStore actualGlobalStore = vdb.getAttachment(GlobalTableStore.class); this.vdbState.globalTables = actualGlobalStore; this.vdbState.session = newWorkContext.getSession(); this.vdbState.classLoader = vdb.getAttachment(ClassLoader.class); this.vdbState.vdbName = vdb.getName(); this.vdbState.vdbVersion = vdb.getVersion(); this.vdbState.dqpWorkContext = newWorkContext; TempMetadataAdapter metadata = new TempMetadataAdapter(vdb.getAttachment(QueryMetadataInterface.class), globalState.sessionTempTableStore.getMetadataStore()); metadata.setSession(true); this.vdbState.metadata = metadata; }
public void setUp(QueryMetadataInterface qmi, ProcessorDataManager dm, BufferManager bm) { tempStore = new TempTableStore("1", TransactionMode.ISOLATE_WRITES); //$NON-NLS-1$ metadata = new TempMetadataAdapter(qmi, tempStore.getMetadataStore()); metadata.setSession(true); SessionAwareCache<CachedResults> cache = new SessionAwareCache<CachedResults>("resultset", DefaultCacheFactory.INSTANCE, SessionAwareCache.Type.RESULTSET, 0); cache.setTupleBufferCache(bm); dataManager = new TempTableDataManager(dm, bm, cache); }
metadata = new TempMetadataAdapter(this.metadata, tempTableStore.getMetadataStore());
@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 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 g2.e1, 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 WHERE 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$ }
/** * if the metadata has not been supplied via setMetadata, this method will create the appropriate state * * @throws TeiidComponentException */ protected void initMetadata() throws TeiidComponentException { if (this.metadata != null) { return; } // Prepare dependencies for running the optimizer this.capabilitiesFinder = new CachedFinder(this.connectorManagerRepo, workContext.getVDB()); if (this.bufferManager.getOptions() != null) { this.capabilitiesFinder = new TempCapabilitiesFinder(this.capabilitiesFinder, this.bufferManager.getOptions().getDefaultNullOrder()); } else { this.capabilitiesFinder = new TempCapabilitiesFinder(this.capabilitiesFinder); } VDBMetaData vdbMetadata = workContext.getVDB(); metadata = vdbMetadata.getAttachment(QueryMetadataInterface.class); globalTables = vdbMetadata.getAttachment(GlobalTableStore.class); if (metadata == null) { throw new TeiidComponentException(QueryPlugin.Event.TEIID30489, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30489, this.vdbName, this.vdbVersion)); } TempMetadataAdapter tma = new TempMetadataAdapter(metadata, this.tempTableStore.getMetadataStore()); tma.setSession(true); this.metadata = tma; }
/** * if the metadata has not been supplied via setMetadata, this method will create the appropriate state * * @throws TeiidComponentException */ protected void initMetadata() throws TeiidComponentException { if (this.metadata != null) { return; } // Prepare dependencies for running the optimizer this.capabilitiesFinder = new CachedFinder(this.connectorManagerRepo, workContext.getVDB()); if (this.bufferManager.getOptions() != null) { this.capabilitiesFinder = new TempCapabilitiesFinder(this.capabilitiesFinder, this.bufferManager.getOptions().getDefaultNullOrder()); } else { this.capabilitiesFinder = new TempCapabilitiesFinder(this.capabilitiesFinder); } VDBMetaData vdbMetadata = workContext.getVDB(); metadata = vdbMetadata.getAttachment(QueryMetadataInterface.class); globalTables = vdbMetadata.getAttachment(GlobalTableStore.class); if (metadata == null) { throw new TeiidComponentException(QueryPlugin.Event.TEIID30489, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30489, this.vdbName, this.vdbVersion)); } TempMetadataAdapter tma = new TempMetadataAdapter(metadata, this.tempTableStore.getMetadataStore()); tma.setSession(true); this.metadata = tma; }
/** * if the metadata has not been supplied via setMetadata, this method will create the appropriate state * * @throws TeiidComponentException */ protected void initMetadata() throws TeiidComponentException { if (this.metadata != null) { return; } // Prepare dependencies for running the optimizer this.capabilitiesFinder = new CachedFinder(this.connectorManagerRepo, workContext.getVDB()); if (this.bufferManager.getOptions() != null) { this.capabilitiesFinder = new TempCapabilitiesFinder(this.capabilitiesFinder, this.bufferManager.getOptions().getDefaultNullOrder()); } else { this.capabilitiesFinder = new TempCapabilitiesFinder(this.capabilitiesFinder); } VDBMetaData vdbMetadata = workContext.getVDB(); metadata = vdbMetadata.getAttachment(QueryMetadataInterface.class); globalTables = vdbMetadata.getAttachment(GlobalTableStore.class); if (metadata == null) { throw new TeiidComponentException(QueryPlugin.Event.TEIID30489, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30489, this.vdbName, this.vdbVersion)); } TempMetadataAdapter tma = new TempMetadataAdapter(metadata, this.tempTableStore.getMetadataStore()); tma.setSession(true); this.metadata = tma; }