use of org.teiid.query.sql.LanguageObject in project teiid by teiid.
the class AuthorizationValidationVisitor method validateEntitlements.
/**
* Validate query entitlements
*/
protected void validateEntitlements(Query obj) {
// If query contains SELECT INTO, validate INTO portion
Into intoObj = obj.getInto();
if (intoObj != null) {
GroupSymbol intoGroup = intoObj.getGroup();
Collection<LanguageObject> intoElements = new LinkedList<LanguageObject>();
intoElements.add(intoGroup);
try {
intoElements.addAll(ResolverUtil.resolveElementsInGroup(intoGroup, getMetadata()));
} catch (QueryMetadataException err) {
handleException(err, intoGroup);
} catch (TeiidComponentException err) {
handleException(err, intoGroup);
}
validateEntitlements(intoElements, DataPolicy.PermissionType.CREATE, Context.INSERT);
}
// Validate this query's entitlements
Collection<LanguageObject> entitledObjects = new ArrayList<LanguageObject>(GroupCollectorVisitor.getGroupsIgnoreInlineViews(obj, true));
entitledObjects.addAll(ElementCollectorVisitor.getElements(obj, true));
if (entitledObjects.size() == 0) {
return;
}
validateEntitlements(entitledObjects, DataPolicy.PermissionType.READ, Context.QUERY);
}
use of org.teiid.query.sql.LanguageObject in project teiid by teiid.
the class AuthorizationValidationVisitor method addToNameMap.
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);
}
}
use of org.teiid.query.sql.LanguageObject in project teiid by teiid.
the class TestResolver method helpResolveWithBindings.
public static Command helpResolveWithBindings(String sql, QueryMetadataInterface metadata, List bindings) throws QueryResolverException, TeiidComponentException {
// parse
Command command = helpParse(sql);
QueryNode qn = new QueryNode(sql);
qn.setBindings(bindings);
// resolve
QueryResolver.resolveWithBindingMetadata(command, metadata, qn, true);
CheckSymbolsAreResolvedVisitor vis = new CheckSymbolsAreResolvedVisitor();
DeepPreOrderNavigator.doVisit(command, vis);
Collection<LanguageObject> unresolvedSymbols = vis.getUnresolvedSymbols();
// $NON-NLS-1$
assertTrue("Found unresolved symbols: " + unresolvedSymbols, unresolvedSymbols.isEmpty());
return command;
}
use of org.teiid.query.sql.LanguageObject in project teiid by teiid.
the class TestResolver method helpCheckElements.
private void helpCheckElements(LanguageObject langObj, String[] elementNames, String[] elementIDs) {
List<ElementSymbol> elements = new ArrayList<ElementSymbol>();
ElementCollectorVisitor.getElements(langObj, elements);
// $NON-NLS-1$
assertEquals("Wrong number of elements: ", elementNames.length, elements.size());
for (int i = 0; i < elements.size(); i++) {
ElementSymbol symbol = elements.get(i);
// $NON-NLS-1$
assertEquals("Element name does not match: ", elementNames[i].toUpperCase(), symbol.getName().toUpperCase());
Object elementID = symbol.getMetadataID();
try {
String name = metadata.getFullName(elementID);
// $NON-NLS-1$ //$NON-NLS-2$
assertNotNull("ElementSymbol " + symbol + " was not resolved and has no metadataID", elementID);
// $NON-NLS-1$
assertEquals("ElementID name does not match: ", elementIDs[i].toUpperCase(), name.toUpperCase());
} catch (TeiidComponentException e) {
throw new RuntimeException(e);
}
}
}
use of org.teiid.query.sql.LanguageObject in project teiid by teiid.
the class ResolverVisitor method resolveLanguageObject.
public static void resolveLanguageObject(LanguageObject obj, Collection<GroupSymbol> groups, GroupContext externalContext, QueryMetadataInterface metadata) throws TeiidComponentException, QueryResolverException {
if (obj == null) {
return;
}
// Resolve elements, deal with errors
final ResolverVisitor elementsVisitor = new ResolverVisitor(metadata, groups, externalContext);
// special handling for is distinct - we must resolve as both element and group
// until we generalize the notion of a scalar group reference as an "elementsymbol"
PostOrderNavigator nav = new PostOrderNavigator(elementsVisitor) {
@Override
public void visit(IsDistinctCriteria obj) {
obj.setLeftRowValue(resolveAsGroup(obj.getLeftRowValue()));
obj.setRightRowValue(resolveAsGroup(obj.getRightRowValue()));
super.visit(obj);
}
private LanguageObject resolveAsGroup(LanguageObject rowValue) {
if (rowValue instanceof ElementSymbol) {
ElementSymbol es = (ElementSymbol) rowValue;
if (es.getMetadataID() == null) {
try {
elementsVisitor.resolveElementSymbol(es);
} catch (QueryResolverException | TeiidComponentException e) {
GroupSymbol gs = new GroupSymbol(es.getName());
try {
ResolverUtil.resolveGroup(gs, metadata);
rowValue = gs;
} catch (QueryResolverException | TeiidComponentException e1) {
}
}
}
}
return rowValue;
}
};
obj.acceptVisitor(nav);
elementsVisitor.throwException(true);
}
Aggregations