use of org.teiid.api.exception.query.QueryMetadataException in project teiid by teiid.
the class PlanToProcessConverter method aliasCommand.
private Command aliasCommand(AccessNode aNode, Command command, Object modelID) throws TeiidComponentException, QueryPlannerException {
try {
command = (Command) command.clone();
boolean aliasGroups = modelID != null && (CapabilitiesUtil.supportsGroupAliases(modelID, metadata, capFinder) || CapabilitiesUtil.supports(Capability.QUERY_FROM_INLINE_VIEWS, modelID, metadata, capFinder));
boolean aliasColumns = modelID != null && (CapabilitiesUtil.supports(Capability.QUERY_SELECT_EXPRESSION, modelID, metadata, capFinder) || CapabilitiesUtil.supports(Capability.QUERY_FROM_INLINE_VIEWS, modelID, metadata, capFinder));
AliasGenerator visitor = new AliasGenerator(aliasGroups, !aliasColumns);
SourceHint sh = command.getSourceHint();
if (sh != null && aliasGroups) {
VDBMetaData vdb = context.getDQPWorkContext().getVDB();
ModelMetaData model = vdb.getModel(aNode.getModelName());
List<String> sourceNames = model.getSourceNames();
SpecificHint sp = null;
if (sourceNames.size() == 1) {
sp = sh.getSpecificHint(sourceNames.get(0));
}
if (sh.isUseAliases() || (sp != null && sp.isUseAliases())) {
visitor.setAliasMapping(context.getAliasMapping());
}
}
List<Reference> references = ReferenceCollectorVisitor.getReferences(command);
if (!references.isEmpty()) {
Set<String> correleatedGroups = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
for (Reference ref : references) {
if (ref.isCorrelated() && ref.getExpression().getGroupSymbol() != null) {
correleatedGroups.add(ref.getExpression().getGroupSymbol().getName());
}
}
visitor.setCorrelationGroups(correleatedGroups);
}
command.acceptVisitor(visitor);
} catch (QueryMetadataException err) {
throw new TeiidComponentException(QueryPlugin.Event.TEIID30249, err);
} catch (TeiidRuntimeException e) {
if (e.getCause() instanceof QueryPlannerException) {
throw (QueryPlannerException) e.getCause();
}
throw e;
}
return command;
}
use of org.teiid.api.exception.query.QueryMetadataException in project teiid by teiid.
the class PlanToProcessConverter method setRoutingName.
private void setRoutingName(AccessNode accessNode, PlanNode node, Command command) throws QueryPlannerException, TeiidComponentException {
// Look up connector binding name
try {
Object modelID = node.getProperty(NodeConstants.Info.MODEL_ID);
if (modelID == null || modelID instanceof TempMetadataID) {
if (command instanceof StoredProcedure) {
modelID = ((StoredProcedure) command).getModelID();
} else if (!(command instanceof Create || command instanceof Drop)) {
Collection<GroupSymbol> groups = GroupCollectorVisitor.getGroups(command, true);
GroupSymbol group = groups.iterator().next();
modelID = metadata.getModelID(group.getMetadataID());
}
}
String cbName = metadata.getFullName(modelID);
accessNode.setModelName(cbName);
accessNode.setModelId(modelID);
accessNode.setConformedTo((Set<Object>) node.getProperty(Info.CONFORMED_SOURCES));
} catch (QueryMetadataException e) {
throw new QueryPlannerException(QueryPlugin.Event.TEIID30251, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30251));
}
}
use of org.teiid.api.exception.query.QueryMetadataException in project teiid by teiid.
the class RowBasedSecurityHelper method resolveCondition.
static Criteria resolveCondition(QueryMetadataInterface metadata, final GroupSymbol group, String fullName, Map.Entry<String, DataPolicy> entry, PermissionMetaData pmd, String filterString) throws QueryMetadataException {
Criteria filter = (Criteria) pmd.getResolvedCondition();
if (filter == null) {
try {
filter = QueryParser.getQueryParser().parseCriteria(filterString);
GroupSymbol gs = group;
if (group.getDefinition() != null) {
gs = new GroupSymbol(fullName);
gs.setMetadataID(group.getMetadataID());
}
Collection<GroupSymbol> groups = Arrays.asList(gs);
for (SubqueryContainer container : ValueIteratorProviderCollectorVisitor.getValueIteratorProviders(filter)) {
container.getCommand().pushNewResolvingContext(groups);
QueryResolver.resolveCommand(container.getCommand(), metadata, false);
}
ResolverVisitor.resolveLanguageObject(filter, groups, metadata);
ValidatorReport report = Validator.validate(filter, metadata, new ValidationVisitor());
if (report.hasItems()) {
ValidatorFailure firstFailure = report.getItems().iterator().next();
// $NON-NLS-1$
throw new QueryMetadataException(QueryPlugin.Event.TEIID31129, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31129, entry.getKey(), fullName) + " " + firstFailure);
}
pmd.setResolvedCondition(filter.clone());
} catch (QueryMetadataException e) {
throw e;
} catch (TeiidException e) {
throw new QueryMetadataException(QueryPlugin.Event.TEIID31129, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31129, entry.getKey(), fullName));
}
} else {
filter = (Criteria) filter.clone();
}
return filter;
}
use of org.teiid.api.exception.query.QueryMetadataException in project teiid by teiid.
the class CriteriaCapabilityValidatorVisitor method visit.
@Override
public void visit(OrderBy obj) {
String collation = null;
try {
collation = (String) CapabilitiesUtil.getProperty(Capability.COLLATION_LOCALE, modelID, metadata, capFinder);
} catch (QueryMetadataException e) {
handleException(new TeiidComponentException(e));
} catch (TeiidComponentException e) {
handleException(e);
}
CommandContext commandContext = CommandContext.getThreadLocalContext();
if (collation != null && commandContext != null && commandContext.getOptions().isRequireTeiidCollation() && !collation.equals(DataTypeManager.COLLATION_LOCALE)) {
for (OrderByItem symbol : obj.getOrderByItems()) {
if (symbol.getSymbol().getType() == DataTypeManager.DefaultDataClasses.STRING || symbol.getSymbol().getType() == DataTypeManager.DefaultDataClasses.CLOB || symbol.getSymbol().getType() == DataTypeManager.DefaultDataClasses.CHAR) {
// we require the collation to match
// $NON-NLS-1$
markInvalid(obj, "source is not using the same collation as Teiid");
break;
}
}
}
}
use of org.teiid.api.exception.query.QueryMetadataException in project teiid by teiid.
the class CriteriaCapabilityValidatorVisitor method checkCompareCriteria.
public void checkCompareCriteria(AbstractCompareCriteria obj, Expression rightExpression) {
boolean negated = false;
// Check if operation is allowed
Capability operatorCap = null;
switch(obj.getOperator()) {
case CompareCriteria.NE:
negated = true;
case CompareCriteria.EQ:
operatorCap = Capability.CRITERIA_COMPARE_EQ;
break;
case CompareCriteria.LT:
case CompareCriteria.GT:
operatorCap = Capability.CRITERIA_COMPARE_ORDERED_EXCLUSIVE;
break;
case CompareCriteria.LE:
case CompareCriteria.GE:
operatorCap = Capability.CRITERIA_COMPARE_ORDERED;
break;
}
// Check if compares are allowed
if (!this.caps.supportsCapability(operatorCap)) {
boolean unsupported = true;
if (operatorCap == Capability.CRITERIA_COMPARE_ORDERED_EXCLUSIVE && this.caps.supportsCapability(Capability.CRITERIA_COMPARE_ORDERED) && this.caps.supportsCapability(Capability.CRITERIA_NOT)) {
unsupported = false;
}
if (unsupported) {
if (EvaluatableVisitor.willBecomeConstant(obj)) {
return;
}
// $NON-NLS-1$
markInvalid(obj, operatorCap + " CompareCriteria not supported by source");
return;
}
}
if (negated && !this.caps.supportsCapability(Capability.CRITERIA_NOT)) {
if (EvaluatableVisitor.willBecomeConstant(obj)) {
return;
}
// $NON-NLS-1$
markInvalid(obj, "Negation is not supported by source");
return;
}
// Check capabilities of the elements
try {
int support = SupportConstants.Element.SEARCHABLE_COMPARE;
if (!negated && obj.getOperator() == CompareCriteria.EQ) {
support = SupportConstants.Element.SEARCHABLE_EQUALITY;
}
checkElementsAreSearchable(obj.getLeftExpression(), support);
checkElementsAreSearchable(rightExpression, support);
} catch (QueryMetadataException e) {
handleException(new TeiidComponentException(e));
} catch (TeiidComponentException e) {
handleException(e);
}
}
Aggregations