public static GroupSymbol helpExample(String groupName, String definition, Object metadataID) { GroupSymbol symbol = new GroupSymbol(groupName, definition); if (metadataID != null) { symbol.setMetadataID(metadataID); } return symbol; }
public void visit(GroupSymbol obj) { if (obj.equals(clone) && obj.getMetadataID() == group.getMetadataID()) { obj.setName(obj.getDefinition()); obj.setDefinition(null); } } });
@Override public Expression replaceExpression( Expression element) { if (element instanceof ElementSymbol) { ElementSymbol es = (ElementSymbol)element; if (es.getGroupSymbol().getDefinition() == null && es.getGroupSymbol().getName().equalsIgnoreCase(this.definition)) { es.getGroupSymbol().setDefinition(group.getDefinition()); es.getGroupSymbol().setName(group.getName()); } } return element; } }
public String getNonCorrelationName() { if (this.definition == null) { return this.getName(); } return this.getDefinition(); }
private boolean isSinglePart(GroupSymbol groupSymbol) { return (groupSymbol.getDefinition() != null || (!groupSymbol.isProcedure() && groupSymbol.getMetadataID() instanceof TempMetadataID && ((TempMetadataID) groupSymbol.getMetadataID()) .getMetadataType() != TempMetadataID.Type.SCALAR)); }
public static Query createMatViewQuery(Object matMetadataId, String matTableName, List<? extends Expression> select, boolean isGlobal) { Query query = new Query(); query.setSelect(new Select(select)); GroupSymbol gs = new GroupSymbol(matTableName); gs.setGlobalTable(isGlobal); gs.setMetadataID(matMetadataId); query.setFrom(new From(Arrays.asList(new UnaryFromClause(gs)))); return query; }
private String getPlan(QueryMetadataInterface metadata, ProcedureContainer procCommand) throws TeiidComponentException, QueryMetadataException, QueryResolverException { if(!procCommand.getGroup().isTempTable() && metadata.isVirtualGroup(procCommand.getGroup().getMetadataID())) { String plan = getPlan(metadata, procCommand.getGroup()); if (plan == null && !metadata.isProcedure(procCommand.getGroup().getMetadataID())) { int type = procCommand.getType(); //force validation getUpdateInfo(procCommand.getGroup(), metadata, type, true); } return plan; } return null; }
public static Collection<ElementSymbol> collectTempElements(GroupSymbol group, QueryMetadataInterface metadata) throws QueryMetadataException, TeiidComponentException { ArrayList<ElementSymbol> validElements = new ArrayList<ElementSymbol>(); // Create GroupSymbol for temp groups and add to groups Collection<?> tempGroups = metadata.getXMLTempGroups(group.getMetadataID()); for (Object tempGroupID : tempGroups) { String name = metadata.getFullName(tempGroupID); GroupSymbol tempGroup = new GroupSymbol(name); tempGroup.setMetadataID(tempGroupID); validElements.addAll(ResolverUtil.resolveElementsInGroup(tempGroup, metadata)); } return validElements; }
public static Object getTrackableGroup(GroupSymbol group, QueryMetadataInterface metadata) throws TeiidComponentException, QueryMetadataException { Object metadataID = group.getMetadataID(); if (group.isTempGroupSymbol()) { QueryMetadataInterface qmi = metadata.getSessionMetadata(); try { //exclude proc scoped temp tables if (group.isGlobalTable()) { return metadataID; } if (qmi != null) { Object mid = qmi.getGroupID(group.getNonCorrelationName()); if (mid == metadataID || metadata.isVirtualGroup(metadataID)) { //global temp should use the session metadata reference instead return mid; } } } catch (QueryMetadataException e) { //not a session table } if (metadata.isVirtualGroup(metadataID)) { //global temp table return metadataID; } } else { return metadataID; } return null; }
public void helpTestRecontextGroup(String oldGroupName, String oldGroupDefinition, String[] knownGroupNames, String expectedName) { GroupSymbol oldSymbol = null; if(oldGroupDefinition == null) { oldSymbol = new GroupSymbol(oldGroupName); } else { oldSymbol = new GroupSymbol(oldGroupName, oldGroupDefinition); } oldSymbol.setMetadataID(oldSymbol.getName()); // Dummy metadata ID TreeSet<String> known = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER); for (int i = 0; i < knownGroupNames.length; i++) { known.add(knownGroupNames[i].toUpperCase()); } GroupSymbol newSymbol = RulePlaceAccess.recontextSymbol(oldSymbol, known); assertEquals("New recontexted group name is not as expected: ", expectedName, newSymbol.getName()); //$NON-NLS-1$ }
/** * Construct a multiple element symbol * @param name Name of the symbol */ public MultipleElementSymbol(String name){ this.group = new GroupSymbol(name); }
public void registerTuples(QueryMetadataInterface metadata, String groupName, List<?>[] data) throws QueryResolverException, TeiidComponentException { GroupSymbol group = new GroupSymbol(groupName); ResolverUtil.resolveGroup(group, metadata); List<ElementSymbol> elementSymbols = ResolverUtil.resolveElementsInGroup(group, metadata); tuples.put(group.getName().toUpperCase(), new TupleInfo(elementSymbols, data)); }
public void testIsTempGroupSymbol() { GroupSymbol group = new GroupSymbol("g1"); //$NON-NLS-1$ assertFalse(group.isTempGroupSymbol()); group = new GroupSymbol("#temp"); //$NON-NLS-1$ assertTrue(group.isTempGroupSymbol()); }
public static boolean isView(GroupSymbol virtualGroup, QueryMetadataInterface qmi) throws TeiidComponentException, QueryMetadataException { return !(virtualGroup.getMetadataID() instanceof TempMetadataID) && qmi.isVirtualGroup(virtualGroup.getMetadataID());// && qmi.isVirtualModel(qmi.getModelID(virtualGroup.getMetadataID())); }
@Override public void visit(UnaryFromClause obj) { GroupSymbol symbol = obj.getGroup(); if (visitor.aliasGroups) { recontextGroup(symbol, false); } else { visitor.namingContext.groupNames.put(symbol.getName(), symbol.getNonCorrelationName()); } super.visit(obj); }
public static Integer regClass(org.teiid.CommandContext cc, String name) throws TeiidComponentException, QueryResolverException, org.teiid.query.parser.ParseException { VDBMetaData metadata = (VDBMetaData) cc.getVdb(); TransformationMetadata tm = metadata.getAttachment(TransformationMetadata.class); GroupSymbol symbol = new GroupSymbol(SQLParserUtil.normalizeId(name)); ResolverUtil.resolveGroup(symbol, tm); return tm.getMetadataStore().getOid(((Table)symbol.getMetadataID()).getUUID()); }
private static GroupSymbol getVarGroup(TargetedCommand cmd) { if (cmd.getGroup().getShortName().equalsIgnoreCase("X")) { //$NON-NLS-1$ return new GroupSymbol("X1"); //$NON-NLS-1$ } return new GroupSymbol("X"); //$NON-NLS-1$ }
@Test public void testTableAliasWithPeriod() throws Exception { String sql = "select \"pm1.g2\".*, e1, \"pm1.g2\".e2, pm1.g2.e2 from pm1.g1 as \"pm1.g2\""; Query query = (Query)helpResolve(sql); UnaryFromClause ufc = (UnaryFromClause)query.getFrom().getClauses().get(0); GroupSymbol gs = ufc.getGroup(); assertEquals("pm1.g2", gs.getName()); assertEquals("pm1.g1", gs.getDefinition()); assertFalse(gs.isTempTable()); assertEquals("SELECT \"pm1.g2\".*, e1, \"pm1.g2\".e2, \"pm1.g2\".e2 FROM pm1.g1 AS \"pm1.g2\"", query.toString()); assertEquals("[\"pm1.g2\".e1, \"pm1.g2\".e2, \"pm1.g2\".e3, \"pm1.g2\".e4, e1, \"pm1.g2\".e2, \"pm1.g2\".e2]", query.getProjectedSymbols().toString()); }
static private HashSet<GroupSymbol> findKeyPreserved(Set<GroupSymbol> keyPreservingGroups, Set<GroupSymbol> pk, HashMap<List<GroupSymbol>, List<HashSet<Object>>> crits, boolean left, QueryMetadataInterface metadata, Set<GroupSymbol> otherGroups) throws TeiidComponentException, QueryMetadataException { HashSet<GroupSymbol> result = new HashSet<GroupSymbol>(); for (GroupSymbol gs : pk) { for (Map.Entry<List<GroupSymbol>, List<HashSet<Object>>> entry : crits.entrySet()) { if (!entry.getKey().get(left?0:1).equals(gs) || !otherGroups.contains(entry.getKey().get(left?1:0))) { continue; } if (RuleRaiseAccess.matchesForeignKey(metadata, entry.getValue().get(left?0:1), entry.getValue().get(left?1:0), gs, false, true)) { keyPreservingGroups.add(gs); result.add(entry.getKey().get(left?1:0)); } } } return result; }
static void addToNameMap(Object metadataID, LanguageObject symbol, Map<String, LanguageObject> nameToSymbolMap, QueryMetadataInterface metadata) throws QueryMetadataException, TeiidComponentException { String fullName = metadata.getFullName(metadataID); Object modelId = metadata.getModelID(metadataID); String modelName = metadata.getFullName(modelId); if (!isSystemSchema(modelName)) { //foreign temp table full names are not schema qualified by default if (!metadata.isVirtualModel(modelId)) { GroupSymbol group = null; if (symbol instanceof ElementSymbol) { group = ((ElementSymbol)symbol).getGroupSymbol(); } else if (symbol instanceof GroupSymbol) { group = (GroupSymbol)symbol; } if (group != null && group.isTempGroupSymbol() && !group.isGlobalTable()) { fullName = modelName + AbstractMetadataRecord.NAME_DELIM_CHAR + modelId; } } nameToSymbolMap.put(fullName, symbol); } }