@Override public void loaded(String matTableName, TempTable table) { swapTempTable(matTableName, table); this.getMatTableInfo(matTableName).setState(MatState.LOADED, true); }
@Override public void setState(String stateId, InputStream istream) { try { ObjectInputStream ois = new ObjectInputStream(istream); loadTable(stateId, ois); ois.close(); } catch (Exception e) { MatTableInfo info = this.getMatTableInfo(stateId); if (!info.isUpToDate()) { info.setState(MatState.FAILED_LOAD, null); } throw new TeiidRuntimeException(QueryPlugin.Event.TEIID30222, e); } }
@Override public void failedLoad(String matTableName) { MatTableInfo info = getMatTableInfo(matTableName); synchronized (info) { if (info.state != MatState.LOADED) { info.setState(MatState.FAILED_LOAD, null); } } }
String viewName = stateId.substring(RelationalPlanner.MAT_PREFIX.length()); Object viewId = this.metadata.getGroupID(viewName); group.setMetadataID(getGlobalTempTableMetadataId(viewId)); } else { String viewName = stateId.substring(TempTableDataManager.CODE_PREFIX.length()); String keyElementName = viewName.substring(index + 1); viewName = viewName.substring(0, index); group.setMetadataID(getCodeTableMetadataId(viewName, returnElementName, keyElementName, stateId)); TempTable tempTable = this.createMatTable(stateId, group); tempTable.readFrom(ois); MatTableInfo info = this.getMatTableInfo(stateId); synchronized (info) { swapTempTable(stateId, tempTable); info.setState(state, true); info.updateTime = updateTime; info.loadingAddress = loadingAddress;
@Test public void testReadWrite() throws Exception { execute("SELECT * from vgroup3 where x = 'one'", Arrays.asList("one", "zne")); ByteArrayOutputStream baos = new ByteArrayOutputStream(); String matTableName = RelationalPlanner.MAT_PREFIX + "MATVIEW.VGROUP3"; this.globalStore.getState(matTableName, baos); MatTableInfo matTableInfo = this.globalStore.getMatTableInfo(matTableName); long time = matTableInfo.getUpdateTime(); this.globalStore.failedLoad(matTableName); this.globalStore.setState(matTableName, new ByteArrayInputStream(baos.toByteArray())); assertEquals(time, matTableInfo.getUpdateTime()); execute("SELECT * from vgroup3 where x = 'one'", Arrays.asList("one", "zne")); execute("select lookup('mattable.info', 'e1', 'e2', 5)", Arrays.asList((String)null)); baos = new ByteArrayOutputStream(); String codeTableName = "#CODE_MATTABLE.INFO.E2.E1"; this.globalStore.getState(codeTableName, baos); this.globalStore.setState(codeTableName, new ByteArrayInputStream(baos.toByteArray())); }
@Override public TempTable createMatTable(final String tableName, GroupSymbol group) throws TeiidComponentException, QueryMetadataException, TeiidProcessingException { Create create = getCreateCommand(group, true, metadata); TempTable table = tableStore.addTempTable(tableName, create, bufferManager, false, null); table.setUpdatable(false); CacheHint hint = table.getCacheHint(); if (hint != null) { table.setPreferMemory(hint.isPrefersMemory()); if (hint.getTtl() != null) { getMatTableInfo(tableName).setTtl(hint.getTtl()); } if (!create.getPrimaryKey().isEmpty()) { table.setUpdatable(hint.isUpdatable(false)); } } return table; }
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); }
@Override public boolean needsLoading(String matTableName, Serializable loadingAddress, boolean firstPass, boolean refresh, boolean invalidate) { MatTableInfo info = getMatTableInfo(matTableName); return info.shouldLoad(loadingAddress, firstPass, refresh, invalidate); }
@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); }
ArrayList<TempMetadataID> primaryKey = resolveIndex(metadata, id, pk); id.setPrimaryKey(primaryKey); id.addUniqueKey(resolveIndex(metadata, id, key)); id.addIndex(index, resolveIndex(metadata, id, index)); List<KeyRecord> fbis = table.getFunctionBasedIndexes(); for (KeyRecord keyRecord : fbis) { id.addIndex(keyRecord, resolveIndex(metadata, id, keyRecord)); updateCacheHint(viewId, group, id); return id;
@Override public void droppedMembers(Collection<Serializable> addresses) { for (MatTableInfo info : this.matTables.values()) { synchronized (info) { if (info.getState() == MatState.LOADING && addresses.contains(info.loadingAddress)) { info.setState(MatState.FAILED_LOAD, null); } } } }
public static Create getCreateCommand(GroupSymbol group, boolean matview, QueryMetadataInterface metadata) throws QueryMetadataException, TeiidComponentException { Create create = new Create(); create.setTable(group); List<ElementSymbol> allColumns = ResolverUtil.resolveElementsInGroup(group, metadata); create.setElementSymbolsAsColumns(allColumns); if (!matview) { for (int i = 0; i < allColumns.size(); i++) { ElementSymbol es = allColumns.get(i); if (!metadata.elementSupports(es.getMetadataID(), SupportConstants.Element.NULL)) { create.getColumns().get(i).setNullType(NullType.No_Nulls); if (es.getType() == DataTypeManager.DefaultDataClasses.INTEGER && metadata.elementSupports(es.getMetadataID(), SupportConstants.Element.AUTO_INCREMENT)) { create.getColumns().get(i).setAutoIncremented(true); //serial } } } } Object pk = metadata.getPrimaryKey(group.getMetadataID()); if (pk != null) { List<ElementSymbol> pkColumns = resolveIndex(metadata, allColumns, pk); create.getPrimaryKey().addAll(pkColumns); } return create; }
@Test public void testFunctionBasedIndexQuery() throws Exception { TempMetadataID id = this.globalStore.getGlobalTempTableMetadataId(metadata.getGroupID("MatView.vgroup2a")); assertEquals("SELECT MatView.VGroup2a.*, ucase(x) FROM MatView.VGroup2a option nocache MatView.VGroup2a", id.getQueryNode().getQuery()); }
@Override public void setState(InputStream istream) { try { ObjectInputStream ois = new ObjectInputStream(istream); while (true) { String tableName = (String)ois.readObject(); if (tableName == null) { break; } loadTable(tableName, ois); } ois.close(); } catch (Exception e) { throw new TeiidRuntimeException(QueryPlugin.Event.TEIID30219, e); } }
Create create = GlobalTableStoreImpl.getCreateCommand(group, false, metadata); tts.addTempTable(tempTableID, create, buffer, true, context);
if (store != null) { try { store.getTempTableStore().removeTempTables(); } catch (TeiidComponentException e) { LogManager.logDetail(LogConstants.CTX_DQP, e, "Error removing session scoped temp tables"); //$NON-NLS-1$
String viewName = stateId.substring(RelationalPlanner.MAT_PREFIX.length()); Object viewId = this.metadata.getGroupID(viewName); group.setMetadataID(getGlobalTempTableMetadataId(viewId)); } else { String viewName = stateId.substring(TempTableDataManager.CODE_PREFIX.length()); String keyElementName = viewName.substring(index + 1); viewName = viewName.substring(0, index); group.setMetadataID(getCodeTableMetadataId(viewName, returnElementName, keyElementName, stateId)); TempTable tempTable = this.createMatTable(stateId, group); tempTable.readFrom(ois); MatTableInfo info = this.getMatTableInfo(stateId); synchronized (info) { swapTempTable(stateId, tempTable); info.setState(state, true); info.updateTime = updateTime; info.loadingAddress = loadingAddress;
@Override public void failedLoad(String matTableName) { MatTableInfo info = getMatTableInfo(matTableName); synchronized (info) { if (info.state != MatState.LOADED) { info.setState(MatState.FAILED_LOAD, null); } } }
@Override public TempTable createMatTable(final String tableName, GroupSymbol group) throws TeiidComponentException, QueryMetadataException, TeiidProcessingException { Create create = getCreateCommand(group, true, metadata); TempTable table = tableStore.addTempTable(tableName, create, bufferManager, false, null); table.setUpdatable(false); CacheHint hint = table.getCacheHint(); if (hint != null) { table.setPreferMemory(hint.isPrefersMemory()); if (hint.getTtl() != null) { getMatTableInfo(tableName).setTtl(hint.getTtl()); } if (!create.getPrimaryKey().isEmpty()) { table.setUpdatable(hint.isUpdatable(false)); } } return table; }
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; }