use of org.teiid.api.exception.query.QueryMetadataException in project teiid by teiid.
the class QueryRewriter method rewriteSelectInto.
/**
* This method will alias each of the select into elements to the corresponding column name in the
* target table. This ensures that they will all be uniquely named.
*
* @param query
* @throws QueryValidatorException
*/
private Command rewriteSelectInto(Query query) throws TeiidProcessingException {
Into into = query.getInto();
try {
List<ElementSymbol> allIntoElements = Util.deepClone(ResolverUtil.resolveElementsInGroup(into.getGroup(), metadata), ElementSymbol.class);
Insert insert = new Insert(into.getGroup(), allIntoElements, Collections.emptyList());
insert.setSourceHint(query.getSourceHint());
query.setSourceHint(null);
query.setInto(null);
insert.setQueryExpression(query);
return rewriteInsert(correctDatatypes(insert));
} catch (QueryMetadataException e) {
throw new QueryValidatorException(e);
} catch (TeiidComponentException e) {
throw new QueryValidatorException(e);
}
}
use of org.teiid.api.exception.query.QueryMetadataException in project teiid by teiid.
the class TestCriteriaCapabilityValidatorVisitor method helpTestVisitorWithCommand.
// Assume there is a wrapped command - this will allow subqueries to be properly resolved
public void helpTestVisitorWithCommand(String sql, Object modelID, TransformationMetadata metadata, CapabilitiesFinder capFinder, boolean isValid, boolean expectException) {
try {
Command command = QueryParser.getQueryParser().parseCommand(sql);
QueryResolver.resolveCommand(command, metadata);
// $NON-NLS-1$
assertEquals("Got incorrect isValid flag", isValid, CriteriaCapabilityValidatorVisitor.canPushLanguageObject(command, modelID, metadata, capFinder, null));
} catch (QueryMetadataException e) {
if (!expectException) {
throw new RuntimeException(e);
}
} catch (TeiidException e) {
throw new RuntimeException(e);
}
}
use of org.teiid.api.exception.query.QueryMetadataException in project teiid by teiid.
the class ValidationVisitor method visit.
public void visit(Insert obj) {
validateGroupSupportsUpdate(obj.getGroup());
validateInsert(obj);
try {
if (obj.isUpsert()) {
Collection keys = getMetadata().getUniqueKeysInGroup(obj.getGroup().getMetadataID());
if (keys.isEmpty()) {
handleValidationError(QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31132, obj.getGroup()), obj);
} else {
Set<Object> keyCols = new LinkedHashSet<Object>(getMetadata().getElementIDsInKey(keys.iterator().next()));
for (ElementSymbol es : obj.getVariables()) {
keyCols.remove(es.getMetadataID());
}
if (!keyCols.isEmpty()) {
handleValidationError(QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31133, obj.getGroup(), obj.getVariables()), obj);
}
}
}
} catch (QueryMetadataException e1) {
handleException(e1);
} catch (TeiidComponentException e1) {
handleException(e1);
}
if (obj.getQueryExpression() != null) {
validateMultisourceInsert(obj.getGroup());
}
if (obj.getUpdateInfo() != null && obj.getUpdateInfo().isInherentInsert()) {
validateUpdate(obj, Command.TYPE_INSERT, obj.getUpdateInfo());
try {
if (obj.getUpdateInfo().findInsertUpdateMapping(obj, false) == null) {
handleValidationError(QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30376, obj.getVariables()), obj);
}
} catch (QueryValidatorException e) {
handleValidationError(e.getMessage(), obj);
}
}
}
use of org.teiid.api.exception.query.QueryMetadataException in project teiid by teiid.
the class AbstractValidationVisitor method validateElementsSupport.
// ######################### Helper methods for validation #########################
protected Collection<ElementSymbol> validateElementsSupport(Collection<ElementSymbol> elements, int supportsFlag) {
// Collect any identifiers not supporting flag
List<ElementSymbol> dontSupport = null;
ElementSymbol symbol = null;
try {
Iterator<ElementSymbol> elemIter = elements.iterator();
while (elemIter.hasNext()) {
symbol = elemIter.next();
if (!getMetadata().elementSupports(symbol.getMetadataID(), supportsFlag)) {
if (dontSupport == null) {
dontSupport = new ArrayList<ElementSymbol>();
}
dontSupport.add(symbol);
}
}
} catch (QueryMetadataException e) {
handleException(e, symbol);
} catch (TeiidComponentException e) {
handleException(e, symbol);
}
return dontSupport;
}
use of org.teiid.api.exception.query.QueryMetadataException in project teiid by teiid.
the class RulePlaceAccess method addAccessNode.
/**
* Adds a access node if the node is a source leaf node.
*
* @param metadata
* @param sourceNode
* @return true if the source node has an access pattern
* @throws QueryMetadataException
* @throws TeiidComponentException
*/
private void addAccessNode(QueryMetadataInterface metadata, PlanNode sourceNode, CapabilitiesFinder finder, boolean[] additionalRules) throws QueryMetadataException, TeiidComponentException {
boolean isInsert = false;
Object req = sourceNode.getProperty(NodeConstants.Info.ATOMIC_REQUEST);
if (req == null) {
req = sourceNode.getProperty(NodeConstants.Info.NESTED_COMMAND);
}
if (sourceNode.getProperty(NodeConstants.Info.TABLE_FUNCTION) != null) {
return;
}
if (req instanceof Insert) {
isInsert = true;
} else {
PlanNode parent = sourceNode.getParent();
if (parent.getType() == NodeConstants.Types.PROJECT && parent.getProperty(NodeConstants.Info.INTO_GROUP) != null) {
isInsert = true;
}
}
PlanNode apNode = sourceNode;
if (sourceNode.getChildCount() == 0) {
// Create the access node and insert
PlanNode accessNode = NodeFactory.getNewNode(NodeConstants.Types.ACCESS);
accessNode.addGroups(sourceNode.getGroups());
copyProperties(sourceNode, accessNode);
SourceHint sourceHint = (SourceHint) sourceNode.removeProperty(Info.SOURCE_HINT);
// TODO: trim the hint to only the sources possible under this model (typically 1, but could be more in
// multi-source
accessNode.setProperty(Info.SOURCE_HINT, sourceHint);
Object hint = sourceNode.removeProperty(NodeConstants.Info.IS_OPTIONAL);
if (hint != null) {
accessNode.setProperty(NodeConstants.Info.IS_OPTIONAL, hint);
}
Object modelId = null;
if (sourceNode.getGroups().size() == 1) {
GroupSymbol gs = sourceNode.getGroups().iterator().next();
modelId = gs.getModelMetadataId();
if (modelId != null) {
accessNode.setProperty(NodeConstants.Info.MODEL_ID, modelId);
}
}
if (req instanceof Create || req instanceof Drop) {
modelId = TempMetadataAdapter.TEMP_MODEL;
} else {
modelId = RuleRaiseAccess.getModelIDFromAccess(accessNode, metadata);
}
if (modelId != null) {
boolean multiSource = metadata.isMultiSource(modelId);
if (multiSource) {
accessNode.setProperty(Info.IS_MULTI_SOURCE, multiSource);
}
accessNode.setProperty(NodeConstants.Info.MODEL_ID, modelId);
}
if (req == null && modelId != null) {
// add "conformed" sources if they exist
GroupSymbol group = sourceNode.getGroups().iterator().next();
Object gid = group.getMetadataID();
String sources = metadata.getExtensionProperty(gid, CONFORMED_SOURCES, false);
if (sources != null) {
Set<Object> conformed = new LinkedHashSet<Object>();
conformed.add(modelId);
for (String source : StringUtil.split(sources, ",")) {
// $NON-NLS-1$
Object mid = metadata.getModelID(source.trim());
if (metadata.isVirtualModel(mid)) {
// TODO: could validate this up-front
throw new QueryMetadataException(QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31148, metadata.getName(mid), group));
}
conformed.add(mid);
}
accessNode.setProperty(Info.CONFORMED_SOURCES, conformed);
}
}
// Insert
sourceNode.addAsParent(accessNode);
apNode = accessNode;
// set additional information
for (GroupSymbol group : accessNode.getGroups()) {
if (group.getCheckMatViewStatus() != null) {
LinkedHashSet<Object> viewsToCheck = new LinkedHashSet<Object>();
viewsToCheck.add(group.getCheckMatViewStatus());
accessNode.setProperty(Info.CHECK_MAT_VIEW, viewsToCheck);
}
Object modelID = metadata.getModelID(group.getMetadataID());
if (CapabilitiesUtil.requiresCriteria(modelID, metadata, finder)) {
additionalRules[1] = true;
}
}
}
// Add access pattern(s), if any, as property of access node
if (!isInsert && addAccessPatternsProperty(apNode, metadata)) {
additionalRules[0] = true;
}
}
Aggregations