static String getNewName(String groupName, TempMetadataStore store) { int index = 1; String newGroup = null; while (true) { newGroup = (groupName + "_" + index++).toUpperCase(); //$NON-NLS-1$ if (!store.getData().containsKey(newGroup)) { break; } } return newGroup; }
public void addToGlobalMetadata(Map<String, TempMetadataID> data) { this.globalTempMetadata.getData().putAll(data); }
@Override public void rollback() { LogManager.logDetail(LogConstants.CTX_DQP, "Rolling back txn", id, "restoring", clonedTables.keySet(), "using rollback tables", tables); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //remove any tables created in the scope of this txn tempTables.values().removeAll(clonedTables.values()); for (TempTable table : tempTables.values()) { table.remove(); } //restore the state tempMetadataStore.getData().clear(); tempMetadataStore.getData().putAll(clonedMetadata); tempTables.clear(); tempTables.putAll(clonedTables); //overlay the rollback tables tempTables.putAll(tables); }
@Override public void rollback() { LogManager.logDetail(LogConstants.CTX_DQP, "Rolling back txn", id, "restoring", clonedTables.keySet(), "using rollback tables", tables); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //remove any tables created in the scope of this txn tempTables.values().removeAll(clonedTables.values()); for (TempTable table : tempTables.values()) { table.remove(); } //restore the state tempMetadataStore.getData().clear(); tempMetadataStore.getData().putAll(clonedMetadata); tempTables.clear(); tempTables.putAll(clonedTables); //overlay the rollback tables tempTables.putAll(tables); }
@Override public Collection getGroupsForPartialName(String partialGroupName) throws TeiidComponentException, QueryMetadataException { Collection groups = super.getGroupsForPartialName(partialGroupName); ArrayList<String> allGroups = new ArrayList<String>(groups); for (Map.Entry<String, TempMetadataID> entry : tempStore.getData().entrySet()) { String name = entry.getKey(); if (StringUtil.endsWithIgnoreCase(name, partialGroupName) //don't want to match tables by anything less than the full name, //since this should be a temp or a global temp and in the latter case there's a real metadata entry //alternatively we could check to see if the name is already in the result list && (name.length() == partialGroupName.length() || (entry.getValue().getMetadataType() != Type.TEMP && name.length() > partialGroupName.length() && name.charAt(name.length() - partialGroupName.length() - 1) == '.'))) { allGroups.add(name); } } return allGroups; }
@Override public void rollback() { LogManager.logDetail(LogConstants.CTX_DQP, "Rolling back txn", id, "restoring", clonedTables.keySet(), "using rollback tables", tables); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //remove any tables created in the scope of this txn tempTables.values().removeAll(clonedTables.values()); for (TempTable table : tempTables.values()) { table.remove(); } //restore the state tempMetadataStore.getData().clear(); tempMetadataStore.getData().putAll(clonedMetadata); tempTables.clear(); tempTables.putAll(clonedTables); //overlay the rollback tables tempTables.putAll(tables); }
@Override public Collection getGroupsForPartialName(String partialGroupName) throws TeiidComponentException, QueryMetadataException { Collection groups = super.getGroupsForPartialName(partialGroupName); ArrayList<String> allGroups = new ArrayList<String>(groups); for (Map.Entry<String, TempMetadataID> entry : tempStore.getData().entrySet()) { String name = entry.getKey(); if (StringUtil.endsWithIgnoreCase(name, partialGroupName) //don't want to match tables by anything less than the full name, //since this should be a temp or a global temp and in the latter case there's a real metadata entry //alternatively we could check to see if the name is already in the result list && (name.length() == partialGroupName.length() || (entry.getValue().getMetadataType() != Type.TEMP && name.length() > partialGroupName.length() && name.charAt(name.length() - partialGroupName.length() - 1) == '.'))) { allGroups.add(name); } } return allGroups; }
@Override public Collection getGroupsForPartialName(String partialGroupName) throws TeiidComponentException, QueryMetadataException { Collection groups = super.getGroupsForPartialName(partialGroupName); ArrayList<String> allGroups = new ArrayList<String>(groups); for (Map.Entry<String, TempMetadataID> entry : tempStore.getData().entrySet()) { String name = entry.getKey(); if (StringUtil.endsWithIgnoreCase(name, partialGroupName) //don't want to match tables by anything less than the full name, //since this should be a temp or a global temp and in the latter case there's a real metadata entry //alternatively we could check to see if the name is already in the result list && (name.length() == partialGroupName.length() || (entry.getValue().getMetadataType() != Type.TEMP && name.length() > partialGroupName.length() && name.charAt(name.length() - partialGroupName.length() - 1) == '.'))) { allGroups.add(name); } } return allGroups; }
/** * Adds temp metadata (if any) of child command to temp metadata * (if any) of parent command. * @param childCommand * @param parentCommand */ static void mergeTempMetadata( Command childCommand, Command parentCommand) { TempMetadataStore childTempMetadata = childCommand.getTemporaryMetadata(); if (childTempMetadata != null && !childTempMetadata.getData().isEmpty()){ // Add to parent temp metadata TempMetadataStore parentTempMetadata = parentCommand.getTemporaryMetadata(); if (parentTempMetadata == null){ parentCommand.setTemporaryMetadata(childTempMetadata); } else { parentTempMetadata.getData().putAll(childTempMetadata.getData()); } } }
/** * Adds temp metadata (if any) of child command to temp metadata * (if any) of parent command. * @param childCommand * @param parentCommand */ static void mergeTempMetadata( Command childCommand, Command parentCommand) { TempMetadataStore childTempMetadata = childCommand.getTemporaryMetadata(); if (childTempMetadata != null && !childTempMetadata.getData().isEmpty()){ // Add to parent temp metadata TempMetadataStore parentTempMetadata = parentCommand.getTemporaryMetadata(); if (parentTempMetadata == null){ parentCommand.setTemporaryMetadata(childTempMetadata); } else { parentTempMetadata.getData().putAll(childTempMetadata.getData()); } } }
/** * Adds temp metadata (if any) of child command to temp metadata * (if any) of parent command. * @param childCommand * @param parentCommand */ static void mergeTempMetadata( Command childCommand, Command parentCommand) { TempMetadataStore childTempMetadata = childCommand.getTemporaryMetadata(); if (childTempMetadata != null && !childTempMetadata.getData().isEmpty()){ // Add to parent temp metadata TempMetadataStore parentTempMetadata = parentCommand.getTemporaryMetadata(); if (parentTempMetadata == null){ parentCommand.setTemporaryMetadata(childTempMetadata); } else { parentTempMetadata.getData().putAll(childTempMetadata.getData()); } } }
private static void setTempMetadata(final QueryMetadataInterface metadata, final AbstractValidationVisitor visitor, LanguageObject obj) { if (obj instanceof Command) { Command command = (Command)obj; visitor.currentCommand = command; TempMetadataStore tempMetadata = command.getTemporaryMetadata(); if(tempMetadata != null && !tempMetadata.getData().isEmpty()) { visitor.setMetadata(new TempMetadataAdapter(metadata, tempMetadata)); } } }
private static void setTempMetadata(final QueryMetadataInterface metadata, final AbstractValidationVisitor visitor, LanguageObject obj) { if (obj instanceof Command) { Command command = (Command)obj; visitor.currentCommand = command; TempMetadataStore tempMetadata = command.getTemporaryMetadata(); if(tempMetadata != null && !tempMetadata.getData().isEmpty()) { visitor.setMetadata(new TempMetadataAdapter(metadata, tempMetadata)); } } }
private Map<String, TempMetadataID> clonedMetadata = new ConcurrentHashMap<String, TempMetadataID>(tempMetadataStore.getData()); private Map<String, TempTable> clonedTables = new ConcurrentHashMap<String, TempTable>(tempTables);
public static void setChildMetadata(Command subCommand, TempMetadataStore parentTempMetadata, GroupContext parentContext) { TempMetadataStore tempMetadata = subCommand.getTemporaryMetadata(); if(tempMetadata == null) { subCommand.setTemporaryMetadata(parentTempMetadata.clone()); } else { tempMetadata.getData().putAll(parentTempMetadata.getData()); } subCommand.setExternalGroupContexts(parentContext); }
public static void setChildMetadata(Command subCommand, TempMetadataStore parentTempMetadata, GroupContext parentContext) { TempMetadataStore tempMetadata = subCommand.getTemporaryMetadata(); if(tempMetadata == null) { subCommand.setTemporaryMetadata(parentTempMetadata.clone()); } else { tempMetadata.getData().putAll(parentTempMetadata.getData()); } subCommand.setExternalGroupContexts(parentContext); }
private static void setTempMetadata(final QueryMetadataInterface metadata, final AbstractValidationVisitor visitor, LanguageObject obj) { if (obj instanceof Command) { Command command = (Command)obj; visitor.currentCommand = command; TempMetadataStore tempMetadata = command.getTemporaryMetadata(); if(tempMetadata != null && !tempMetadata.getData().isEmpty()) { visitor.setMetadata(new TempMetadataAdapter(metadata, tempMetadata)); } } }
public static void setChildMetadata(Command subCommand, TempMetadataStore parentTempMetadata, GroupContext parentContext) { TempMetadataStore tempMetadata = subCommand.getTemporaryMetadata(); if(tempMetadata == null) { subCommand.setTemporaryMetadata(parentTempMetadata.clone()); } else { tempMetadata.getData().putAll(parentTempMetadata.getData()); } subCommand.setExternalGroupContexts(parentContext); }
private Map<Integer, Object>[] createProjectedSymbolMetadata(Command originalCommand) throws TeiidComponentException { Map<Integer, Object>[] columnMetadata; // Allow command to use temporary metadata TempMetadataStore tempMetadata = originalCommand.getTemporaryMetadata(); if(tempMetadata != null && tempMetadata.getData().size() > 0) { TempMetadataAdapter tempFacade = new TempMetadataAdapter(this.metadata, tempMetadata); this.metadata = tempFacade; } List<Expression> projectedSymbols = originalCommand.getProjectedSymbols(); columnMetadata = new Map[projectedSymbols.size()]; Iterator<Expression> symbolIter = projectedSymbols.iterator(); for(int i=0; symbolIter.hasNext(); i++) { Expression symbol = symbolIter.next(); String shortColumnName = Symbol.getShortName(Symbol.getOutputName(symbol)); if(symbol instanceof AliasSymbol) { symbol = ((AliasSymbol)symbol).getSymbol(); } try { columnMetadata[i] = createColumnMetadata(shortColumnName, symbol); } catch(QueryMetadataException e) { throw new TeiidComponentException(QueryPlugin.Event.TEIID30559, e); } } return columnMetadata; }
@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$ }