use of org.teiid.api.exception.query.QueryMetadataException in project teiid by teiid.
the class CriteriaCapabilityValidatorVisitor method visit.
/**
* @see org.teiid.query.sql.LanguageVisitor#visit(org.teiid.query.sql.lang.SubqueryCompareCriteria)
*/
public void visit(SubqueryCompareCriteria crit) {
if (crit.getArrayExpression() != null) {
// $NON-NLS-1$
markInvalid(crit, "Quantified compare with an array cannot yet be pushed down.");
return;
}
// Check if quantification operator is allowed
Capability capability = Capability.QUERY_SUBQUERIES_SCALAR;
switch(crit.getPredicateQuantifier()) {
case SubqueryCompareCriteria.ALL:
capability = Capability.CRITERIA_QUANTIFIED_ALL;
break;
case SubqueryCompareCriteria.ANY:
capability = Capability.CRITERIA_QUANTIFIED_SOME;
break;
case SubqueryCompareCriteria.SOME:
capability = Capability.CRITERIA_QUANTIFIED_SOME;
break;
}
if (!this.caps.supportsCapability(capability)) {
// $NON-NLS-1$
markInvalid(crit, "SubqueryCompare not supported by source");
return;
}
checkCompareCriteria(crit, crit.getCommand().getProjectedSymbols().get(0));
// Check capabilities of the elements
try {
if (validateSubqueryPushdown(crit, modelID, metadata, capFinder, analysisRecord) == null) {
// $NON-NLS-1$
markInvalid(crit.getCommand(), "Subquery cannot be pushed down");
}
} catch (QueryMetadataException e) {
handleException(new TeiidComponentException(e));
} catch (TeiidComponentException e) {
handleException(e);
}
}
use of org.teiid.api.exception.query.QueryMetadataException in project teiid by teiid.
the class ColumnMaskingHelper method maskColumn.
private static Expression maskColumn(ElementSymbol col, GroupSymbol unaliased, QueryMetadataInterface metadata, ExpressionMappingVisitor emv, Map<String, DataPolicy> policies, CommandContext cc) throws TeiidComponentException, TeiidProcessingException {
Object metadataID = col.getMetadataID();
String fullName = metadata.getFullName(metadataID);
final GroupSymbol group = col.getGroupSymbol();
String elementType = metadata.getElementRuntimeTypeName(col.getMetadataID());
Class<?> expectedType = DataTypeManager.getDataTypeClass(elementType);
List<WhenThen> cases = null;
Collection<GroupSymbol> groups = Arrays.asList(unaliased);
for (Map.Entry<String, DataPolicy> entry : policies.entrySet()) {
DataPolicyMetadata dpm = (DataPolicyMetadata) entry.getValue();
PermissionMetaData pmd = dpm.getPermissionMap().get(fullName);
if (pmd == null) {
continue;
}
String maskString = pmd.getMask();
if (maskString == null) {
continue;
}
Criteria condition = null;
if (pmd.getCondition() != null) {
condition = RowBasedSecurityHelper.resolveCondition(metadata, group, metadata.getFullName(group.getMetadataID()), entry, pmd, pmd.getCondition());
} else {
condition = QueryRewriter.TRUE_CRITERIA;
}
Expression mask = (Expression) pmd.getResolvedMask();
if (mask == null) {
try {
mask = QueryParser.getQueryParser().parseExpression(pmd.getMask());
for (SubqueryContainer container : ValueIteratorProviderCollectorVisitor.getValueIteratorProviders(mask)) {
container.getCommand().pushNewResolvingContext(groups);
QueryResolver.resolveCommand(container.getCommand(), metadata, false);
}
ResolverVisitor.resolveLanguageObject(mask, groups, metadata);
ValidatorReport report = Validator.validate(mask, metadata, new ValidationVisitor());
if (report.hasItems()) {
ValidatorFailure firstFailure = report.getItems().iterator().next();
// $NON-NLS-1$
throw new QueryMetadataException(QueryPlugin.Event.TEIID31139, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31139, dpm.getName(), fullName) + " " + firstFailure);
}
if (mask.getType() != expectedType) {
mask = ResolverUtil.convertExpression(mask, elementType, metadata);
}
pmd.setResolvedMask(mask.clone());
if (!dpm.isAnyAuthenticated()) {
// we treat this as user deterministic since the data roles won't change. this may change if the logic becomes dynamic
// TODO: this condition may not even be used
cc.setDeterminismLevel(Determinism.USER_DETERMINISTIC);
}
} catch (QueryMetadataException e) {
throw e;
} catch (TeiidException e) {
throw new QueryMetadataException(QueryPlugin.Event.TEIID31129, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31129, dpm.getName(), fullName));
}
} else {
mask = (Expression) mask.clone();
}
if (group.getDefinition() != null) {
PreOrPostOrderNavigator.doVisit(mask, emv, PreOrPostOrderNavigator.PRE_ORDER, true);
}
if (cases == null) {
cases = new ArrayList<ColumnMaskingHelper.WhenThen>();
}
cases.add(new WhenThen(pmd.getOrder(), condition, mask));
}
if (cases == null) {
return col;
}
Collections.sort(cases);
List<Criteria> whens = new ArrayList<Criteria>();
List<Expression> thens = new ArrayList<Expression>();
for (WhenThen whenThen : cases) {
whens.add(whenThen.when);
thens.add(whenThen.then);
}
SearchedCaseExpression sce = new SearchedCaseExpression(whens, thens);
sce.setElseExpression(col);
sce.setType(expectedType);
Expression mask = QueryRewriter.rewriteExpression(sce, cc, metadata, true);
return mask;
}
use of org.teiid.api.exception.query.QueryMetadataException in project teiid by teiid.
the class TransformationMetadata method getElementID.
// ==================================================================================
// I N T E R F A C E M E T H O D S
// ==================================================================================
public Column getElementID(final String elementName) throws TeiidComponentException, QueryMetadataException {
int columnIndex = elementName.lastIndexOf(TransformationMetadata.DELIMITER_STRING);
if (columnIndex == -1) {
throw new QueryMetadataException(QueryPlugin.Event.TEIID30355, elementName + TransformationMetadata.NOT_EXISTS_MESSAGE);
}
Table table = this.store.findGroup(elementName.substring(0, columnIndex));
String shortElementName = elementName.substring(columnIndex + 1);
return getColumn(elementName, table, shortElementName);
}
use of org.teiid.api.exception.query.QueryMetadataException in project teiid by teiid.
the class TransformationMetadata method getVirtualPlan.
public QueryNode getVirtualPlan(final Object groupID) throws TeiidComponentException, QueryMetadataException {
Table tableRecord = (Table) groupID;
if (!tableRecord.isVirtual()) {
// $NON-NLS-1$
throw new QueryMetadataException(QueryPlugin.Event.TEIID30359, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30359, tableRecord.getFullName(), "Query"));
}
LiveTableQueryNode queryNode = new LiveTableQueryNode(tableRecord);
// get any bindings and add them onto the query node
List<String> bindings = tableRecord.getBindings();
if (bindings != null) {
for (Iterator<String> bindIter = bindings.iterator(); bindIter.hasNext(); ) {
queryNode.addBinding(bindIter.next());
}
}
return queryNode;
}
use of org.teiid.api.exception.query.QueryMetadataException in project teiid by teiid.
the class TransformationMetadata method getXMLSchemas.
public List<SQLXMLImpl> getXMLSchemas(final Object groupID) throws TeiidComponentException, QueryMetadataException {
Table tableRecord = (Table) groupID;
// lookup transformation record for the group
String groupName = tableRecord.getFullName();
// get the schema Paths
List<String> schemaPaths = tableRecord.getSchemaPaths();
List<SQLXMLImpl> schemas = new LinkedList<SQLXMLImpl>();
if (schemaPaths == null) {
return schemas;
}
String path = getParentPath(tableRecord.getResourcePath());
for (String string : schemaPaths) {
String parentPath = path;
boolean relative = false;
while (string.startsWith("../")) {
// $NON-NLS-1$
relative = true;
string = string.substring(3);
parentPath = getParentPath(parentPath);
}
SQLXMLImpl schema = null;
if (!relative) {
schema = getVDBResourceAsSQLXML(string);
}
if (schema == null) {
if (!parentPath.endsWith("/")) {
// $NON-NLS-1$
// $NON-NLS-1$
parentPath += "/";
}
schema = getVDBResourceAsSQLXML(parentPath + string);
}
if (schema == null) {
throw new QueryMetadataException(QueryPlugin.Event.TEIID30364, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30364, groupName));
}
schemas.add(schema);
}
return schemas;
}
Aggregations