Author: shawkins
Date: 2011-05-30 05:48:28 -0400 (Mon, 30 May 2011)
New Revision: 3204
Modified:
branches/7.4.x/api/src/main/java/org/teiid/metadata/Table.java
branches/7.4.x/engine/src/main/java/org/teiid/query/mapping/xml/MappingDocument.java
branches/7.4.x/engine/src/main/java/org/teiid/query/mapping/xml/MappingNode.java
branches/7.4.x/engine/src/main/java/org/teiid/query/metadata/TempMetadataAdapter.java
branches/7.4.x/engine/src/main/java/org/teiid/query/metadata/TempMetadataID.java
branches/7.4.x/engine/src/main/java/org/teiid/query/metadata/TransformationMetadata.java
branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/xml/ContextReplacerVisitor.java
branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/xml/CriteriaPlanner.java
branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/xml/SourceNodePlannerVisitor.java
branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/xml/XMLNodeMappingVisitor.java
branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/xml/XMLPlanner.java
branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/xml/XMLQueryPlanner.java
branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/xml/XMLStagaingQueryPlanner.java
branches/7.4.x/engine/src/main/java/org/teiid/query/resolver/command/SimpleQueryResolver.java
branches/7.4.x/engine/src/main/java/org/teiid/query/resolver/command/XMLQueryResolver.java
branches/7.4.x/engine/src/test/java/org/teiid/query/optimizer/xml/TestMarkExcludeVisitor.java
branches/7.4.x/engine/src/test/java/org/teiid/query/optimizer/xml/TestNameInSourceResolverVisitor.java
branches/7.4.x/engine/src/test/java/org/teiid/query/processor/xml/TestXMLProcessor.java
branches/7.4.x/engine/src/test/java/org/teiid/query/resolver/TestXMLResolver.java
branches/7.4.x/engine/src/test/java/org/teiid/query/unittest/RealMetadataFactory.java
branches/7.4.x/engine/src/test/java/org/teiid/query/validator/TestValidator.java
Log:
TEIID-1615 adding xml pseudo groups for document model subqueries and adding several
resolving and metadata improvements for xml
Modified: branches/7.4.x/api/src/main/java/org/teiid/metadata/Table.java
===================================================================
--- branches/7.4.x/api/src/main/java/org/teiid/metadata/Table.java 2011-05-29 18:10:40 UTC
(rev 3203)
+++ branches/7.4.x/api/src/main/java/org/teiid/metadata/Table.java 2011-05-30 09:48:28 UTC
(rev 3204)
@@ -23,8 +23,10 @@
package org.teiid.metadata;
import java.util.Collection;
+import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
+import java.util.Map;
import org.teiid.core.types.DataTypeManager;
import org.teiid.metadata.AbstractMetadataRecord.DataModifiable;
@@ -80,6 +82,8 @@
private transient long lastModified;
private transient long lastDataModification;
+ private transient Map<Class<?>, Object> attachments;
+
public List<String> getBindings() {
return bindings;
}
@@ -333,4 +337,46 @@
this.updatePlanEnabled = updatePlanEnabled;
}
+ /**
+ * Add attachment
+ *
+ * @param <T> the expected type
+ * @param attachment the attachment
+ * @param type the type
+ * @return any previous attachment
+ * @throws IllegalArgumentException for a null name, attachment or type
+ * @throws UnsupportedOperationException when not supported by the implementation
+ */
+ synchronized public <T> T addAttchment(Class<T> type, T attachment) {
+ if (type == null)
+ throw new IllegalArgumentException("Null type"); //$NON-NLS-1$
+ if (this.attachments == null) {
+ this.attachments = new HashMap<Class<?>, Object>();
+ }
+ Object result = this.attachments.put(type, attachment);
+ if (result == null)
+ return null;
+ return type.cast(result);
+ }
+
+ /**
+ * Get attachment
+ *
+ * @param <T> the expected type
+ * @param type the type
+ * @return the attachment or null if not present
+ * @throws IllegalArgumentException for a null name or type
+ */
+ synchronized public <T> T getAttachment(Class<T> type) {
+ if (type == null)
+ throw new IllegalArgumentException("Null type"); //$NON-NLS-1$
+ if (this.attachments == null) {
+ return null;
+ }
+ Object result = this.attachments.get(type.getName());
+ if (result == null)
+ return null;
+ return type.cast(result);
+ }
+
}
\ No newline at end of file
Modified:
branches/7.4.x/engine/src/main/java/org/teiid/query/mapping/xml/MappingDocument.java
===================================================================
---
branches/7.4.x/engine/src/main/java/org/teiid/query/mapping/xml/MappingDocument.java 2011-05-29
18:10:40 UTC (rev 3203)
+++
branches/7.4.x/engine/src/main/java/org/teiid/query/mapping/xml/MappingDocument.java 2011-05-30
09:48:28 UTC (rev 3204)
@@ -22,11 +22,6 @@
package org.teiid.query.mapping.xml;
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.io.StringWriter;
-
import org.teiid.core.TeiidRuntimeException;
import org.teiid.query.QueryPlugin;
@@ -160,26 +155,10 @@
/**
* @see org.teiid.query.mapping.xml.MappingNode#clone()
*/
- public Object clone() {
- // I found this as cheap way of cloneing for now fast, may be we will
- // do all the object cloneing later..
- try {
- MappingOutputter out = new MappingOutputter();
- StringWriter stream = new StringWriter();
- out.write(this, new PrintWriter(stream));
- MappingLoader loader = new MappingLoader();
- MappingDocument doc = loader.loadDocument(new
ByteArrayInputStream(stream.toString().getBytes()));
-
- // Copy the values of the instance variables.
- doc.formatted = this.formatted;
- doc.encoding = this.encoding;
- doc.name = this.name;
-
- return doc;
- } catch (IOException e) {
- throw new RuntimeException(e);
- } catch(MappingException e) {
- throw new RuntimeException(e);
- }
- }
+ public MappingDocument clone() {
+ MappingDocument clone = (MappingDocument) super.clone();
+ clone.root = (MappingBaseNode) clone.getChildren().iterator().next();
+ return clone;
+ }
+
}
Modified:
branches/7.4.x/engine/src/main/java/org/teiid/query/mapping/xml/MappingNode.java
===================================================================
---
branches/7.4.x/engine/src/main/java/org/teiid/query/mapping/xml/MappingNode.java 2011-05-29
18:10:40 UTC (rev 3203)
+++
branches/7.4.x/engine/src/main/java/org/teiid/query/mapping/xml/MappingNode.java 2011-05-30
09:48:28 UTC (rev 3204)
@@ -31,6 +31,7 @@
import java.util.List;
import java.util.Map;
+import org.teiid.core.TeiidRuntimeException;
import org.teiid.query.QueryPlugin;
import org.teiid.query.sql.symbol.ElementSymbol;
@@ -42,14 +43,16 @@
*/
public abstract class MappingNode implements Cloneable, Serializable {
- /** The parent of this node, null if root. */
+ private static final long serialVersionUID = 6761829541871178451L;
+
+ /** The parent of this node, null if root. */
private MappingNode parent;
/** Child nodes, usually just 1 or 2, but occasionally more */
- private LinkedList children = new LinkedList();
+ private List<MappingNode> children = new LinkedList<MappingNode>();
/** node properties, as defined in NodeConstants.Properties. */
- private Map nodeProperties;
+ private Map<Integer, Object> nodeProperties;
/** default constructor */
public MappingNode(){
@@ -89,8 +92,8 @@
}
}
- for (Iterator i = root.getChildren().iterator(); i.hasNext();) {
- MappingNode child = (MappingNode)i.next();
+ for (Iterator<MappingNode> i = root.getChildren().iterator(); i.hasNext();)
{
+ MappingNode child = i.next();
MappingNode found = findNode(child, partialName);
if (found != null) {
return found;
@@ -104,7 +107,7 @@
* Set the parent of this node. This method is restricted, as
* it should be called only when {@link #addChild adding a child node}
*/
- private void setParent( MappingNode parent ) {
+ void setParent( MappingNode parent ) {
this.parent = parent;
}
@@ -112,7 +115,7 @@
* Get the children contained by this node, or an empty List
* @return children; if no children, return empty List (never null)
*/
- public List getChildren(){
+ public List<MappingNode> getChildren(){
return this.children;
}
@@ -120,11 +123,11 @@
* Get all children of this node of a specified target node type. The value
* of node type should be one of {@link #ATTRIBUTE} or {@link #ELEMENT}.
*/
- public List getChildren( String type ) {
- List subset = new ArrayList();
- Iterator iter = children.iterator();
+ public List<MappingNode> getChildren( String type ) {
+ List<MappingNode> subset = new ArrayList<MappingNode>();
+ Iterator<MappingNode> iter = children.iterator();
while ( iter.hasNext() ) {
- MappingNode node = (MappingNode)iter.next();
+ MappingNode node = iter.next();
if ( node.getProperty(MappingNodeConstants.Properties.NODE_TYPE).equals(type)
) {
subset.add( node );
}
@@ -132,11 +135,11 @@
return subset;
}
- public List getNodeChildren() {
- List subset = new ArrayList();
- Iterator iter = children.iterator();
+ public List<MappingNode> getNodeChildren() {
+ List<MappingNode> subset = new ArrayList<MappingNode>();
+ Iterator<MappingNode> iter = children.iterator();
while ( iter.hasNext() ) {
- MappingNode node = (MappingNode)iter.next();
+ MappingNode node = iter.next();
if (
!node.getProperty(MappingNodeConstants.Properties.NODE_TYPE).equals(MappingNodeConstants.ATTRIBUTE)
) {
subset.add( node );
}
@@ -184,7 +187,7 @@
if (value != null){
// Get the default for the property ...
final Object defaultValue =
MappingNodeConstants.Defaults.DEFAULT_VALUES.get(propertyID);
- final Map props = getNodeProperties(); // props is never null
+ final Map<Integer, Object> props = getNodeProperties(); // props
is never null
if ( !value.equals(defaultValue) ) { // we know value is not null
// Set the value only if different than the default; note that the
'getProperty'
// method is returning the default if there isn't a value
@@ -209,9 +212,9 @@
* object.
* @see #getProperties
*/
- public Map getNodeProperties(){
+ public Map<Integer, Object> getNodeProperties(){
if(nodeProperties == null) {
- nodeProperties = new HashMap();
+ nodeProperties = new HashMap<Integer, Object>();
}
return nodeProperties;
}
@@ -318,9 +321,9 @@
str.append(node.getNodeProperties());
str.append("\n"); //$NON-NLS-1$
- Iterator i = node.getChildren().iterator();
+ Iterator<MappingNode> i = node.getChildren().iterator();
while (i.hasNext()){
- buildTreeString((MappingNode)i.next(), str, tabLevel);
+ buildTreeString(i.next(), str, tabLevel);
}
}
@@ -391,9 +394,9 @@
private static MappingNode traverseDownForFirstNodeWithPropertyString(Integer
propertyKey, Object value, boolean isStringValue, MappingNode node, boolean breadthFirst)
{
if (breadthFirst) {
- Iterator children = node.getChildren().iterator();
+ Iterator<MappingNode> children = node.getChildren().iterator();
while (children.hasNext()){
- MappingNode child = (MappingNode)children.next();
+ MappingNode child = children.next();
if (checkThisNodeForPropertyValue(propertyKey, value, isStringValue,
child)){
return child;
}
@@ -404,9 +407,9 @@
}
}
- Iterator children = node.getChildren().iterator();
+ Iterator<MappingNode> children = node.getChildren().iterator();
while (children.hasNext()){
- MappingNode child = (MappingNode)children.next();
+ MappingNode child = children.next();
//recursive call to this method
MappingNode result = traverseDownForFirstNodeWithPropertyString(propertyKey,
value, isStringValue, child, breadthFirst);
@@ -477,4 +480,18 @@
public String getNameInSource() {
return null;
}
+
+ public MappingNode clone() {
+ try {
+ MappingNode clone = (MappingNode) super.clone();
+ clone.children = new ArrayList<MappingNode>(children);
+ for (int i = 0; i < clone.children.size(); i++) {
+ clone.children.set(i, clone.children.get(i).clone());
+ clone.children.get(i).setParent(clone);
+ }
+ return clone;
+ } catch (CloneNotSupportedException e) {
+ throw new TeiidRuntimeException(e);
+ }
+ }
}
Modified:
branches/7.4.x/engine/src/main/java/org/teiid/query/metadata/TempMetadataAdapter.java
===================================================================
---
branches/7.4.x/engine/src/main/java/org/teiid/query/metadata/TempMetadataAdapter.java 2011-05-29
18:10:40 UTC (rev 3203)
+++
branches/7.4.x/engine/src/main/java/org/teiid/query/metadata/TempMetadataAdapter.java 2011-05-30
09:48:28 UTC (rev 3204)
@@ -33,6 +33,7 @@
import org.teiid.api.exception.query.QueryMetadataException;
import org.teiid.core.TeiidComponentException;
import org.teiid.core.types.DataTypeManager;
+import org.teiid.core.util.StringUtil;
import org.teiid.query.QueryPlugin;
import org.teiid.query.mapping.relational.QueryNode;
import org.teiid.query.mapping.xml.MappingNode;
@@ -154,6 +155,19 @@
throw new QueryMetadataException(msg);
}
+ @Override
+ public Collection getGroupsForPartialName(String partialGroupName)
+ throws TeiidComponentException, QueryMetadataException {
+ Collection groups = super.getGroupsForPartialName(partialGroupName);
+ ArrayList<String> allGroups = new ArrayList<String>(groups);
+ for (String name : tempStore.getData().keySet()) {
+ if (StringUtil.endsWithIgnoreCase(name, partialGroupName)
+ && (name.length() == partialGroupName.length() || (name.length() >
partialGroupName.length() && name.charAt(name.length() - partialGroupName.length()
- 1) == '.'))) {
+ allGroups.add(name);
+ }
+ }
+ return allGroups;
+ }
public Object getModelID(Object groupOrElementID)
throws TeiidComponentException, QueryMetadataException {
Modified:
branches/7.4.x/engine/src/main/java/org/teiid/query/metadata/TempMetadataID.java
===================================================================
---
branches/7.4.x/engine/src/main/java/org/teiid/query/metadata/TempMetadataID.java 2011-05-29
18:10:40 UTC (rev 3203)
+++
branches/7.4.x/engine/src/main/java/org/teiid/query/metadata/TempMetadataID.java 2011-05-30
09:48:28 UTC (rev 3204)
@@ -93,7 +93,8 @@
public enum Type {
VIRTUAL,
TEMP,
- SCALAR
+ SCALAR,
+ XML
}
private String ID; // never null, upper cased fully-qualified string
Modified:
branches/7.4.x/engine/src/main/java/org/teiid/query/metadata/TransformationMetadata.java
===================================================================
---
branches/7.4.x/engine/src/main/java/org/teiid/query/metadata/TransformationMetadata.java 2011-05-29
18:10:40 UTC (rev 3203)
+++
branches/7.4.x/engine/src/main/java/org/teiid/query/metadata/TransformationMetadata.java 2011-05-30
09:48:28 UTC (rev 3204)
@@ -188,7 +188,7 @@
}
Table table = this.store.findGroup(elementName.substring(0,
columnIndex).toUpperCase());
String shortElementName = elementName.substring(columnIndex + 1);
- for (Column column : (List<Column>)getElementIDsInGroupID(table)) {
+ for (Column column : getElementIDsInGroupID(table)) {
if (column.getName().equalsIgnoreCase(shortElementName)) {
return column;
}
@@ -256,7 +256,7 @@
return metadataRecord.getName();
}
- public List getElementIDsInGroupID(final Object groupID) throws
TeiidComponentException, QueryMetadataException {
+ public List<Column> getElementIDsInGroupID(final Object groupID) throws
TeiidComponentException, QueryMetadataException {
ArgCheck.isInstanceOf(Table.class, groupID);
return ((Table)groupID).getColumns();
}
@@ -710,13 +710,19 @@
ArgCheck.isInstanceOf(Table.class, groupID);
Table tableRecord = (Table) groupID;
+
+ MappingDocument mappingDoc = tableRecord.getAttachment(MappingDocument.class);
+
+ if (mappingDoc != null) {
+ return mappingDoc;
+ }
+
final String groupName = tableRecord.getFullName();
if(tableRecord.isVirtual()) {
- // get mappin transform
+ // get mapping transform
String document = tableRecord.getSelectTransformation();
InputStream inputStream = new ByteArrayInputStream(document.getBytes());
MappingLoader reader = new MappingLoader();
- MappingDocument mappingDoc = null;
try{
mappingDoc = reader.loadDocument(inputStream);
mappingDoc.setName(groupName);
@@ -727,6 +733,7 @@
inputStream.close();
} catch(Exception e) {}
}
+ tableRecord.addAttchment(MappingDocument.class, mappingDoc);
return mappingDoc;
}
@@ -757,14 +764,14 @@
/**
* @see
org.teiid.query.metadata.QueryMetadataInterface#getXMLTempGroups(java.lang.Object)
*/
- public Collection getXMLTempGroups(final Object groupID) throws
TeiidComponentException, QueryMetadataException {
+ public Collection<Table> getXMLTempGroups(final Object groupID) throws
TeiidComponentException, QueryMetadataException {
ArgCheck.isInstanceOf(Table.class, groupID);
Table tableRecord = (Table) groupID;
if(tableRecord.getTableType() == Table.Type.Document) {
return this.store.getXMLTempGroups(tableRecord);
}
- return Collections.EMPTY_SET;
+ return Collections.emptySet();
}
public int getCardinality(final Object groupID) throws TeiidComponentException,
QueryMetadataException {
Modified:
branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/xml/ContextReplacerVisitor.java
===================================================================
---
branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/xml/ContextReplacerVisitor.java 2011-05-29
18:10:40 UTC (rev 3203)
+++
branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/xml/ContextReplacerVisitor.java 2011-05-30
09:48:28 UTC (rev 3204)
@@ -41,7 +41,7 @@
*/
class ContextReplacerVisitor extends ExpressionMappingVisitor {
- private Collection contextFunctions = new LinkedList(); //contains Function objects
+ private Collection<Function> contextFunctions = new
LinkedList<Function>(); //contains Function objects
/**
* Construct a new visitor
@@ -55,7 +55,7 @@
* which were stripped out of the language object by this visitor
* @return Collection of Function
*/
- Collection getContextFunctions(){
+ Collection<Function> getContextFunctions(){
return this.contextFunctions;
}
@@ -78,9 +78,9 @@
* Helper to quickly replace 'context'
* @param obj Language object
*/
- static final Collection replaceContextFunctions(LanguageObject obj) {
+ static final Collection<Function> replaceContextFunctions(LanguageObject obj)
{
if (obj == null){
- return Collections.EMPTY_SET;
+ return Collections.emptySet();
}
ContextReplacerVisitor visitor = new ContextReplacerVisitor();
PreOrderNavigator.doVisit(obj, visitor);
Modified:
branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/xml/CriteriaPlanner.java
===================================================================
---
branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/xml/CriteriaPlanner.java 2011-05-29
18:10:40 UTC (rev 3203)
+++
branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/xml/CriteriaPlanner.java 2011-05-30
09:48:28 UTC (rev 3204)
@@ -64,9 +64,9 @@
static void placeUserCriteria(Criteria criteria, XMLPlannerEnvironment planEnv)
throws QueryPlannerException, QueryMetadataException, TeiidComponentException {
- for (Iterator conjunctIter = Criteria.separateCriteriaByAnd(criteria).iterator();
conjunctIter.hasNext();) {
+ for (Iterator<Criteria> conjunctIter =
Criteria.separateCriteriaByAnd(criteria).iterator(); conjunctIter.hasNext();) {
- Criteria conjunct = (Criteria) conjunctIter.next();
+ Criteria conjunct = conjunctIter.next();
if (planStagingTableCriteria(conjunct, planEnv)) {
continue;
@@ -79,11 +79,10 @@
MappingNode context = null;
- Collection contextFunctions =
ContextReplacerVisitor.replaceContextFunctions(conjunct);
+ Collection<Function> contextFunctions =
ContextReplacerVisitor.replaceContextFunctions(conjunct);
if (!contextFunctions.isEmpty()) {
//ensure that every part of the conjunct is to the same context
- for (Iterator i = contextFunctions.iterator(); i.hasNext();) {
- Function contextFunction = (Function)i.next();
+ for (Function contextFunction : contextFunctions) {
MappingNode otherContext = getContext(planEnv, contextFunction);
if (context == null) {
context = otherContext;
@@ -102,7 +101,7 @@
context = planEnv.mappingDoc;
}
- Set sourceNodes = collectSourceNodesInConjunct(conjunct, context,
planEnv.mappingDoc);
+ Set<MappingNode> sourceNodes = collectSourceNodesInConjunct(conjunct,
context, planEnv.mappingDoc);
//TODO: this can be replaced with method on the source node?
MappingSourceNode criteriaRs = findRootResultSetNode(context, sourceNodes,
criteria);
@@ -118,18 +117,16 @@
/**
* This method collects all the MappingSourceNode(s) at or below the context given.
*/
- private static Set collectSourceNodesInConjunct(Criteria conjunct, MappingNode
context, MappingDocument mappingDoc)
+ private static Set<MappingNode> collectSourceNodesInConjunct(Criteria conjunct,
MappingNode context, MappingDocument mappingDoc)
throws QueryPlannerException {
- Collection elements = ElementCollectorVisitor.getElements(conjunct, true);
- Set resultSets = new HashSet();
+ Collection<ElementSymbol> elements =
ElementCollectorVisitor.getElements(conjunct, true);
+ Set<MappingNode> resultSets = new HashSet<MappingNode>();
String contextFullName = context.getFullyQualifiedName().toUpperCase();
//validate that each element's group is under the current context or is in
the direct parentage
- for (Iterator i = elements.iterator(); i.hasNext();) {
- ElementSymbol elementSymbol = (ElementSymbol)i.next();
-
+ for (ElementSymbol elementSymbol : elements) {
String elementFullName = elementSymbol.getCanonicalName();
MappingNode node = MappingNode.findNode(mappingDoc, elementFullName);
@@ -158,20 +155,16 @@
return resultSets;
}
- private static MappingSourceNode findRootResultSetNode(MappingNode context, Set
resultSets, Criteria criteria)
+ private static MappingSourceNode findRootResultSetNode(MappingNode context,
Set<MappingNode> resultSets, Criteria criteria)
throws QueryPlannerException {
if (context instanceof MappingSourceNode) {
return (MappingSourceNode)context;
}
- Set criteriaResultSets = new HashSet();
+ Set<MappingNode> criteriaResultSets = new HashSet<MappingNode>();
// if the context node is not the root node then we need to find the root source
node from list.
- for (Iterator i = resultSets.iterator(); i.hasNext();) {
-
- // these are actually source nodes.
- MappingNode node = (MappingNode)i.next();
-
+ for (MappingNode node : resultSets) {
MappingNode root = node;
while (node != null) {
@@ -288,14 +281,13 @@
static String getStagingTableForConjunct(Criteria conjunct, QueryMetadataInterface
metadata)
throws QueryPlannerException, QueryMetadataException, TeiidComponentException {
- Collection elements = ElementCollectorVisitor.getElements(conjunct, true);
+ Collection<ElementSymbol> elements =
ElementCollectorVisitor.getElements(conjunct, true);
boolean first = true;
String resultSet = null;
// Check each remaining element to make sure it matches
- for(Iterator elemIter = elements.iterator(); elemIter.hasNext();) {
- ElementSymbol element = (ElementSymbol) elemIter.next();
+ for (ElementSymbol element : elements) {
GroupSymbol group = element.getGroupSymbol();
//assumes that all non-xml group elements are temp elements
boolean hasTempElement = !metadata.isXMLGroup(group.getMetadataID());
@@ -314,7 +306,7 @@
}
if (resultSet != null) {
- Collection functions =
ContextReplacerVisitor.replaceContextFunctions(conjunct);
+ Collection<Function> functions =
ContextReplacerVisitor.replaceContextFunctions(conjunct);
if (!functions.isEmpty()) {
throw new
QueryPlannerException(QueryPlugin.Util.getString("CriteriaPlanner.staging_context"));
//$NON-NLS-1$
}
Modified:
branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/xml/SourceNodePlannerVisitor.java
===================================================================
---
branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/xml/SourceNodePlannerVisitor.java 2011-05-29
18:10:40 UTC (rev 3203)
+++
branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/xml/SourceNodePlannerVisitor.java 2011-05-30
09:48:28 UTC (rev 3204)
@@ -229,7 +229,7 @@
throws QueryMetadataException, TeiidComponentException, QueryPlannerException {
// get elements in the old group
- List elements = ResolverUtil.resolveElementsInGroup(oldSymbol,
planEnv.getGlobalMetadata());
+ List<ElementSymbol> elements =
ResolverUtil.resolveElementsInGroup(oldSymbol, planEnv.getGlobalMetadata());
TempMetadataStore store = planEnv.getGlobalMetadata().getMetadataStore();
@@ -280,7 +280,7 @@
}
}
- private boolean canRaiseInputset(Command command, Collection<ElementSymbol>
bindings) throws TeiidComponentException {
+ private boolean canRaiseInputset(Command command, Collection<ElementSymbol>
bindings) {
// check to see if this is query.
if (!(command instanceof Query)) {
return false;
@@ -311,14 +311,13 @@
* @param criteria - criteria on which the elements need to modified
* @return true if converted; false otherwise
*/
- private boolean convertCriteria(GroupSymbol newGroupSymbol, Query
transformationQuery, Criteria criteria, TempMetadataAdapter metadata, Map symbolMap)
- throws QueryMetadataException, TeiidComponentException {
+ private boolean convertCriteria(GroupSymbol newGroupSymbol, Query
transformationQuery, Criteria criteria, TempMetadataAdapter metadata, Map symbolMap) {
String groupName = newGroupSymbol.getName();
Collection<ElementSymbol> elementsInCriteria =
ElementCollectorVisitor.getElements(criteria, true);
- Map mappedElements = new HashMap();
+ Map<ElementSymbol, ElementSymbol> mappedElements = new
HashMap<ElementSymbol, ElementSymbol>();
- List projectedSymbols = transformationQuery.getProjectedSymbols();
+ List<SingleElementSymbol> projectedSymbols =
transformationQuery.getProjectedSymbols();
boolean addedProjectedSymbol = false;
@@ -383,10 +382,8 @@
* If the element has alias wrapping, then return the matching alias element.
* @return matched alias symbol; null otherwise.
*/
- private AliasSymbol getMachingAlias(List elementsInGroup, ElementSymbol symbol) {
-
- for(Iterator i = elementsInGroup.iterator(); i.hasNext();) {
- final SingleElementSymbol element = (SingleElementSymbol)i.next();
+ private AliasSymbol getMachingAlias(List<SingleElementSymbol> elementsInGroup,
ElementSymbol symbol) {
+ for (SingleElementSymbol element : elementsInGroup) {
if (element instanceof AliasSymbol) {
AliasSymbol alias = (AliasSymbol)element;
if (alias.getSymbol().equals(symbol)) {
Modified:
branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/xml/XMLNodeMappingVisitor.java
===================================================================
---
branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/xml/XMLNodeMappingVisitor.java 2011-05-29
18:10:40 UTC (rev 3203)
+++
branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/xml/XMLNodeMappingVisitor.java 2011-05-30
09:48:28 UTC (rev 3204)
@@ -26,15 +26,20 @@
import org.teiid.api.exception.query.QueryPlannerException;
import org.teiid.core.TeiidComponentException;
+import org.teiid.core.TeiidException;
import org.teiid.core.TeiidRuntimeException;
import org.teiid.query.QueryPlugin;
import org.teiid.query.mapping.xml.MappingDocument;
import org.teiid.query.mapping.xml.MappingNode;
+import org.teiid.query.mapping.xml.MappingSourceNode;
import org.teiid.query.metadata.QueryMetadataInterface;
+import org.teiid.query.metadata.TempMetadataID;
+import org.teiid.query.resolver.util.ResolverVisitor;
import org.teiid.query.sql.LanguageObject;
import org.teiid.query.sql.lang.Criteria;
-import org.teiid.query.sql.navigator.PreOrderNavigator;
+import org.teiid.query.sql.navigator.PreOrPostOrderNavigator;
import org.teiid.query.sql.symbol.ElementSymbol;
+import org.teiid.query.sql.symbol.GroupSymbol;
import org.teiid.query.sql.symbol.Symbol;
import org.teiid.query.sql.visitor.AbstractSymbolMappingVisitor;
@@ -62,29 +67,56 @@
* @see AbstractSymbolMappingVisitor#getMappedSymbol(Symbol)
*/
protected Symbol getMappedSymbol(Symbol symbol) {
- if(!(symbol instanceof ElementSymbol)) {
- return null;
- }
-
- // Lookup full path to mapping node from symbol
- ElementSymbol element = (ElementSymbol) symbol;
-
try {
- String path = metadata.getFullName(element.getMetadataID()).toUpperCase();
-
+ Object metadataId = null;
+ Object groupId = null;
+ if (symbol instanceof GroupSymbol) {
+ GroupSymbol groupSymbol = (GroupSymbol)symbol;
+ metadataId = groupSymbol.getMetadataID();
+ groupId = metadataId;
+ } else {
+ ElementSymbol element = (ElementSymbol) symbol;
+ metadataId = element.getMetadataID();
+ groupId = element.getGroupSymbol().getMetadataID();
+ }
+ boolean xml = metadata.isXMLGroup(groupId);
+ if (!xml && !((groupId instanceof TempMetadataID) &&
((TempMetadataID)groupId).getMetadataType() == TempMetadataID.Type.XML)) {
+ return symbol;
+ }
+ String path = metadata.getFullName(metadataId).toUpperCase();
+
// Find mapping node for specified path
- MappingNode elementNode = MappingNode.findNode(rootNode, path);
- if(elementNode == null) {
+ MappingNode node = MappingNode.findNode(rootNode, path);
+ if(node == null) {
return null;
}
-
+ MappingSourceNode msn = node.getSourceNode();
+ if (msn == null) {
+ return null;
+ }
+ if (symbol instanceof GroupSymbol) {
+ GroupSymbol gs = msn.getMappedSymbol(new GroupSymbol(msn.getResultName()));
+ if (!xml && gs.getMetadataID() == null) {
+ ResolverVisitor.resolveLanguageObject(gs, metadata);
+ }
+ return gs;
+ }
// Construct a new element node based on mapping node reference
- String symbolName = elementNode.getNameInSource();
+ String symbolName = node.getNameInSource();
if (symbolName == null){
return null;
}
- return elementNode.getSourceNode().getMappedSymbol(new ElementSymbol(symbolName));
- } catch (TeiidComponentException err) {
+ ElementSymbol es = msn.getMappedSymbol(new ElementSymbol(symbolName));
+ if (!xml) {
+ if (((ElementSymbol)symbol).isExternalReference()) {
+ es.setIsExternalReference(true);
+ }
+ if (es.getMetadataID() == null) {
+ ResolverVisitor.resolveLanguageObject(es, metadata);
+ }
+ }
+ return es;
+ } catch (TeiidException err) {
throw new TeiidRuntimeException(err);
}
}
@@ -100,17 +132,15 @@
*/
public static Criteria convertCriteria(Criteria simpleCrit, MappingDocument rootNode,
QueryMetadataInterface metadata)
throws QueryPlannerException, TeiidComponentException{
- return (Criteria)convertObject(simpleCrit, rootNode, metadata);
+ return convertObject((Criteria)simpleCrit.clone(), rootNode, metadata, true);
}
- public static LanguageObject convertObject(LanguageObject object, MappingDocument
rootNode, QueryMetadataInterface metadata)
+ public static <T extends LanguageObject> T convertObject(T object,
MappingDocument rootNode, QueryMetadataInterface metadata, boolean deep)
throws QueryPlannerException, TeiidComponentException{
- LanguageObject copy = (LanguageObject)object.clone();
-
//Don't want to do deep visiting
XMLNodeMappingVisitor mappingVisitor = new XMLNodeMappingVisitor(rootNode,
metadata);
try {
- PreOrderNavigator.doVisit(copy, mappingVisitor);
+ PreOrPostOrderNavigator.doVisit(object, mappingVisitor,
PreOrPostOrderNavigator.PRE_ORDER, deep);
} catch (TeiidRuntimeException e) {
Throwable child = e.getChild();
@@ -126,7 +156,7 @@
throw new QueryPlannerException("ERR.015.004.0046",
QueryPlugin.Util.getString("ERR.015.004.0046", new Object[] {unmappedSymbols,
object})); //$NON-NLS-1$ //$NON-NLS-2$
}
- return copy;
+ return object;
}
}
Modified:
branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/xml/XMLPlanner.java
===================================================================
---
branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/xml/XMLPlanner.java 2011-05-29
18:10:40 UTC (rev 3203)
+++
branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/xml/XMLPlanner.java 2011-05-30
09:48:28 UTC (rev 3204)
@@ -57,6 +57,7 @@
import org.teiid.query.sql.symbol.ElementSymbol;
import org.teiid.query.sql.symbol.GroupSymbol;
import org.teiid.query.sql.symbol.SelectSymbol;
+import org.teiid.query.sql.symbol.SingleElementSymbol;
import org.teiid.query.sql.visitor.ElementCollectorVisitor;
import org.teiid.query.util.CommandContext;
@@ -110,7 +111,7 @@
GroupSymbol group = xmlQuery.getFrom().getGroups().iterator().next();
MappingDocument doc =
(MappingDocument)metadata.getMappingNode(group.getMetadataID());
- doc = (MappingDocument)doc.clone();
+ doc = doc.clone();
// make a copy of the document
planEnv.mappingDoc = doc;
@@ -247,10 +248,9 @@
}
// Get all the valid nodes to be marked as included.
- Collection validElements = ElementCollectorVisitor.getElements(select, true);
- HashSet elements = new HashSet(validElements.size());
- for (final Iterator i = validElements.iterator(); i.hasNext();) {
- final ElementSymbol element = (ElementSymbol)i.next();
+ Collection<ElementSymbol> validElements =
ElementCollectorVisitor.getElements(select, true);
+ HashSet<String> elements = new
HashSet<String>(validElements.size());
+ for (ElementSymbol element : validElements) {
elements.add(element.getCanonicalName());
}
@@ -277,8 +277,8 @@
return;
}
- List elements = orderBy.getSortKeys();
- List types = orderBy.getTypes();
+ List<SingleElementSymbol> elements = orderBy.getSortKeys();
+ List<Boolean> types = orderBy.getTypes();
for (int i = 0; i< elements.size(); i++) {
ElementSymbol elemSymbol = (ElementSymbol) elements.get(i);
@@ -301,7 +301,7 @@
by = new OrderBy();
}
ElementSymbol mappedSymbol = (ElementSymbol)sourceNode.getSymbolMap().get(new
ElementSymbol(elementNode.getNameInSource()));
- by.addVariable((ElementSymbol)mappedSymbol.clone(),
((Boolean)types.get(i)).booleanValue());
+ by.addVariable(mappedSymbol.clone(),
((Boolean)types.get(i)).booleanValue());
rs.setOrderBy(by);
}
}
Modified:
branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/xml/XMLQueryPlanner.java
===================================================================
---
branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/xml/XMLQueryPlanner.java 2011-05-29
18:10:40 UTC (rev 3203)
+++
branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/xml/XMLQueryPlanner.java 2011-05-30
09:48:28 UTC (rev 3204)
@@ -86,10 +86,8 @@
public void visit(MappingBaseNode baseNode) {
try {
// first if there are any explicit staging tables plan them first
- List stagingTables = baseNode.getStagingTables();
- for (final Iterator i = stagingTables.iterator(); i.hasNext();) {
-
- final String tableName = (String)i.next();
+ List<String> stagingTables = baseNode.getStagingTables();
+ for (String tableName : stagingTables) {
planStagingTable(tableName, planEnv);
}
@@ -206,15 +204,15 @@
static void prepareQuery(MappingSourceNode sourceNode, XMLPlannerEnvironment planEnv,
QueryCommand rsQuery)
throws TeiidComponentException, QueryResolverException {
- Collection externalGroups = getExternalGroups(sourceNode);
+ Collection<GroupSymbol> externalGroups = getExternalGroups(sourceNode);
rsQuery.setExternalGroupContexts(new GroupContext(null, externalGroups));
QueryResolver.resolveCommand(rsQuery, planEnv.getGlobalMetadata());
}
- private static Collection getExternalGroups(MappingSourceNode sourceNode) {
- Collection externalGroups = new HashSet();
+ private static Collection<GroupSymbol> getExternalGroups(MappingSourceNode
sourceNode) {
+ Collection<GroupSymbol> externalGroups = new HashSet<GroupSymbol>();
MappingSourceNode parentSource = sourceNode.getParentSourceNode();
while (parentSource != null) {
@@ -249,12 +247,12 @@
return singleParentage;
}
- private static LinkedList getResultSetStack(MappingSourceNode contextNode,
MappingBaseNode node) {
- LinkedList rsStack = new LinkedList();
+ private static LinkedList<MappingSourceNode>
getResultSetStack(MappingSourceNode contextNode, MappingBaseNode node) {
+ LinkedList<MappingSourceNode> rsStack = new
LinkedList<MappingSourceNode>();
while (node != null && node != contextNode) {
if (node instanceof MappingSourceNode) {
- rsStack.add(0, node);
+ rsStack.add(0, (MappingSourceNode)node);
}
node = node.getParentNode();
}
@@ -312,7 +310,7 @@
joinCriteria = (Criteria)joinCriteria.clone();
//update the from clause
- FromClause clause =
(FromClause)currentQuery.getFrom().getClauses().remove(0);
+ FromClause clause = currentQuery.getFrom().getClauses().remove(0);
JoinPredicate join = null;
Modified:
branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/xml/XMLStagaingQueryPlanner.java
===================================================================
---
branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/xml/XMLStagaingQueryPlanner.java 2011-05-29
18:10:40 UTC (rev 3203)
+++
branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/xml/XMLStagaingQueryPlanner.java 2011-05-30
09:48:28 UTC (rev 3204)
@@ -134,7 +134,7 @@
//check for already staged queries
if (groups.size() == 1) {
GroupSymbol group = groups.iterator().next();
- group = QueryUtil.createResolvedGroup((GroupSymbol)group.clone(),
planEnv.getGlobalMetadata());
+ group = QueryUtil.createResolvedGroup(group.clone(),
planEnv.getGlobalMetadata());
if (planEnv.isStagingTable(group.getMetadataID()) &&
stagableQuery.getCriteria() == null) {
return false;
}
Modified:
branches/7.4.x/engine/src/main/java/org/teiid/query/resolver/command/SimpleQueryResolver.java
===================================================================
---
branches/7.4.x/engine/src/main/java/org/teiid/query/resolver/command/SimpleQueryResolver.java 2011-05-29
18:10:40 UTC (rev 3203)
+++
branches/7.4.x/engine/src/main/java/org/teiid/query/resolver/command/SimpleQueryResolver.java 2011-05-30
09:48:28 UTC (rev 3204)
@@ -127,7 +127,7 @@
ResolverUtil.resolveOrderBy(query.getOrderBy(), query, metadata);
}
- List symbols = query.getSelect().getProjectedSymbols();
+ List<SingleElementSymbol> symbols =
query.getSelect().getProjectedSymbols();
if (query.getInto() != null) {
GroupSymbol symbol = query.getInto().getGroup();
@@ -281,7 +281,7 @@
// Look for elements that are not selectable and remove them
for (ElementSymbol element : elements) {
if(metadata.elementSupports(element.getMetadataID(),
SupportConstants.Element.SELECT)) {
- element = (ElementSymbol)element.clone();
+ element = element.clone();
element.setGroupSymbol(group);
result.add(element);
}
@@ -368,6 +368,9 @@
}
}
+ /**
+ * @param tfr
+ */
public LinkedHashSet<GroupSymbol>
preTableFunctionReference(TableFunctionReference tfr) {
LinkedHashSet<GroupSymbol> saved = new
LinkedHashSet<GroupSymbol>(this.currentGroups);
if (allowImplicit) {
@@ -571,7 +574,7 @@
public void visit(From obj) {
assert currentGroups.isEmpty();
- for (FromClause clause : (List<FromClause>)obj.getClauses()) {
+ for (FromClause clause : obj.getClauses()) {
checkImplicit(clause);
}
super.visit(obj);
Modified:
branches/7.4.x/engine/src/main/java/org/teiid/query/resolver/command/XMLQueryResolver.java
===================================================================
---
branches/7.4.x/engine/src/main/java/org/teiid/query/resolver/command/XMLQueryResolver.java 2011-05-29
18:10:40 UTC (rev 3203)
+++
branches/7.4.x/engine/src/main/java/org/teiid/query/resolver/command/XMLQueryResolver.java 2011-05-30
09:48:28 UTC (rev 3204)
@@ -25,26 +25,35 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
-import java.util.Iterator;
+import java.util.HashMap;
+import java.util.LinkedList;
import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
import org.teiid.api.exception.query.QueryMetadataException;
import org.teiid.api.exception.query.QueryResolverException;
import org.teiid.core.TeiidComponentException;
-import org.teiid.core.util.StringUtil;
import org.teiid.query.QueryPlugin;
+import org.teiid.query.mapping.xml.MappingDocument;
+import org.teiid.query.mapping.xml.MappingNode;
+import org.teiid.query.mapping.xml.MappingSourceNode;
import org.teiid.query.metadata.QueryMetadataInterface;
import org.teiid.query.metadata.TempMetadataAdapter;
+import org.teiid.query.metadata.TempMetadataID.Type;
+import org.teiid.query.optimizer.xml.SourceNodeGenaratorVisitor;
import org.teiid.query.resolver.CommandResolver;
import org.teiid.query.resolver.QueryResolver;
import org.teiid.query.resolver.util.ResolverUtil;
import org.teiid.query.resolver.util.ResolverVisitor;
+import org.teiid.query.sql.LanguageObject;
import org.teiid.query.sql.lang.Command;
import org.teiid.query.sql.lang.Criteria;
import org.teiid.query.sql.lang.GroupContext;
import org.teiid.query.sql.lang.OrderBy;
import org.teiid.query.sql.lang.Query;
import org.teiid.query.sql.lang.Select;
+import org.teiid.query.sql.lang.SubqueryContainer;
import org.teiid.query.sql.symbol.AliasSymbol;
import org.teiid.query.sql.symbol.AllInGroupSymbol;
import org.teiid.query.sql.symbol.AllSymbol;
@@ -52,16 +61,57 @@
import org.teiid.query.sql.symbol.ExpressionSymbol;
import org.teiid.query.sql.symbol.GroupSymbol;
import org.teiid.query.sql.symbol.SelectSymbol;
-import org.teiid.query.sql.visitor.CommandCollectorVisitor;
+import org.teiid.query.sql.symbol.SingleElementSymbol;
import org.teiid.query.sql.visitor.ElementCollectorVisitor;
import org.teiid.query.sql.visitor.GroupCollectorVisitor;
+import org.teiid.query.sql.visitor.ValueIteratorProviderCollectorVisitor;
/**
*/
public class XMLQueryResolver implements CommandResolver {
+
+ private static final class ResolvingNode {
+ ElementSymbol elementSymbol;
+ TreeMap<String, ResolvingNode> children = new TreeMap<String,
ResolvingNode>(String.CASE_INSENSITIVE_ORDER);
+
+ public void add(String name, ElementSymbol symbol) {
+ if (name == null) {
+ this.elementSymbol = symbol;
+ return;
+ }
+ int index = name.lastIndexOf('.');
+ String childName = name;
+ if (index >= 0) {
+ childName = name.substring(0, index);
+ name = name.substring(index + 1, name.length());
+ } else {
+ childName = null;
+ }
+ ResolvingNode child = children.get(name);
+ if (child == null) {
+ child = new ResolvingNode();
+ children.put(name, child);
+ }
+ child.add(childName, symbol);
+ }
+
+ public <T extends Collection<ElementSymbol>> T values(T values) {
+ if (elementSymbol != null) {
+ values.add(elementSymbol);
+ }
+ for (ResolvingNode node : children.values()) {
+ node.values(values);
+ }
+ return values;
+ }
+
+ public List<ElementSymbol> values() {
+ return values(new LinkedList<ElementSymbol>());
+ }
+ }
- /**
+ /**
* @see
org.teiid.query.resolver.CommandResolver#resolveCommand(org.teiid.query.sql.lang.Command,
TempMetadataAdapter, boolean)
*/
public void resolveCommand(Command command, TempMetadataAdapter metadata, boolean
resolveNullLiterals)
@@ -80,31 +130,41 @@
GroupContext externalGroups = query.getExternalGroupContexts();
// valid elements for select
- List<ElementSymbol> validSelectElems = getElementsInDocument(group, metadata);
- resolveXMLSelect(query, group, validSelectElems, metadata);
+ List<ElementSymbol> validSelectElems = ResolverUtil.resolveElementsInGroup(group,
metadata);
+ ResolvingNode root = new ResolvingNode();
+ for (ElementSymbol elementSymbol : validSelectElems) {
+ root.add(elementSymbol.getName(), elementSymbol);
+ }
+ resolveXMLSelect(query, group, root, metadata);
// valid elements for criteria and order by
- Collection<ElementSymbol> validCriteriaElements =
collectValidCriteriaElements(group, metadata);
+ Collection<ElementSymbol> validCriteriaElements = collectTempElements(group,
metadata);
+ for (ElementSymbol elementSymbol : validCriteriaElements) {
+ root.add(elementSymbol.getName(), elementSymbol);
+ }
Criteria crit = query.getCriteria();
OrderBy orderBy = query.getOrderBy();
-
- List<Command> commands = CommandCollectorVisitor.getCommands(query);
- for (Command subCommand : commands) {
- QueryResolver.setChildMetadata(subCommand, command);
-
- QueryResolver.resolveCommand(subCommand, metadata.getMetadata());
- }
-
+
if(crit != null) {
- resolveXMLCriteria(crit, externalGroups, validCriteriaElements, metadata);
+ List<SubqueryContainer> commands =
ValueIteratorProviderCollectorVisitor.getValueIteratorProviders(crit);
+ if (!commands.isEmpty()) {
+ addPseudoSubqueryGroups(metadata, group, validSelectElems);
+ for (SubqueryContainer subCommand : commands) {
+ QueryResolver.setChildMetadata(subCommand.getCommand(), command);
+
+ QueryResolver.resolveCommand(subCommand.getCommand(),
metadata.getMetadata());
+ }
+ }
+
+ resolveXMLCriteria(crit, externalGroups, root, metadata);
// Resolve functions in current query
ResolverVisitor.resolveLanguageObject(crit, metadata);
}
// resolve any orderby specified on the query
if(orderBy != null) {
- resolveXMLOrderBy(orderBy, externalGroups, validCriteriaElements, metadata);
+ resolveXMLOrderBy(orderBy, externalGroups, root, metadata);
}
//we throw exceptions in these cases, since the clauses will not be resolved
@@ -117,6 +177,62 @@
}
}
+ private void addPseudoSubqueryGroups(TempMetadataAdapter metadata,
+ GroupSymbol group, List<ElementSymbol> validSelectElems)
+ throws TeiidComponentException, QueryMetadataException,
+ QueryResolverException {
+ /*
+ * The next section of resolving logic adds in pseduo groups that can be used
+ * in subqueries
+ */
+ MappingDocument doc = (MappingDocument)
metadata.getMappingNode(group.getMetadataID());
+ doc = doc.clone();
+ doc = SourceNodeGenaratorVisitor.extractSourceNodes(doc);
+
+ HashMap<String, List<ElementSymbol>> psuedoGroups = new HashMap<String,
List<ElementSymbol>>();
+ for (ElementSymbol elementSymbol : validSelectElems) {
+ MappingNode node = MappingNode.findNode(doc, elementSymbol.getCanonicalName());
+ if (node == null) {
+ continue;
+ }
+ MappingSourceNode mappingSourceNode = node.getSourceNode();
+ if (mappingSourceNode == null) {
+ continue;
+ }
+ String mappingClass = mappingSourceNode.getSource();
+ String tableName = SingleElementSymbol.getShortName(mappingClass);
+
+ String name = elementSymbol.getName();
+ int index = name.lastIndexOf('.');
+ String xmlTableName = name.substring(0, index);
+ if (!xmlTableName.endsWith(tableName)) {
+ continue;
+ }
+ List<ElementSymbol> elements = psuedoGroups.get(xmlTableName);
+ if (elements == null) {
+ elements = new ArrayList<ElementSymbol>();
+ psuedoGroups.put(xmlTableName, elements);
+ }
+ ElementSymbol es = new ElementSymbol(name.substring(index+1, name.length()));
+ es.setType(elementSymbol.getType());
+ es.setMetadataID(elementSymbol.getMetadataID());
+ elements.add(es);
+ }
+
+ for (Map.Entry<String, List<ElementSymbol>> entry :
psuedoGroups.entrySet()) {
+ for (ElementSymbol elem : new ArrayList<ElementSymbol>(entry.getValue())) {
+ if (elem.getName().charAt(0) == '@') {
+ ElementSymbol alias = elem.clone();
+ alias.setShortName(elem.getName().substring(1));
+ if (!entry.getValue().contains(alias)) {
+ entry.getValue().add(alias);
+ }
+ }
+ }
+ ResolverUtil.addTempGroup(metadata, new GroupSymbol(entry.getKey()), entry.getValue(),
false).setMetadataType(Type.XML);
+ }
+ }
+
/**
* Method resolveXMLSelect.
* @param select Select clause in user command
@@ -128,7 +244,7 @@
* @throws QueryMetadataException if resolving fails
* @throws TeiidComponentException if resolving fails
*/
- void resolveXMLSelect(Query query, GroupSymbol group, List<ElementSymbol>
validElements, QueryMetadataInterface metadata)
+ void resolveXMLSelect(Query query, GroupSymbol group, ResolvingNode validElements,
QueryMetadataInterface metadata)
throws QueryMetadataException, TeiidComponentException, QueryResolverException {
GroupContext externalGroups = null;
@@ -159,7 +275,7 @@
}
select.clearSymbols();
AllSymbol all = new AllSymbol();
- all.setElementSymbols(validElements);
+ all.setElementSymbols(validElements.values());
select.addSymbol(all);
query.setSelect(select);
return;
@@ -177,7 +293,7 @@
if(elementPart.equalsIgnoreCase(group.getName())) {
select.clearSymbols();
AllSymbol all = new AllSymbol();
- all.setElementSymbols(validElements);
+ all.setElementSymbols(validElements.values());
select.addSymbol(all);
query.setSelect(select);
} else {
@@ -186,12 +302,12 @@
resolveElement(elementSymbol, validElements, externalGroups,
metadata);
// now find all the elements under this node and set as elements.
- List<ElementSymbol> elementsInNode =
getElementsUnderNode(elementSymbol, validElements, metadata);
+ List<ElementSymbol> elementsInNode =
getElementsUnderNode(elementSymbol, validElements.values(), metadata);
((AllInGroupSymbol)ss).setElementSymbols(elementsInNode);
}
} else if (ss instanceof AllSymbol) {
AllSymbol all = (AllSymbol)ss;
- all.setElementSymbols(validElements);
+ all.setElementSymbols(validElements.values());
return;
} else if (ss instanceof ExpressionSymbol) {
throw new
QueryResolverException(QueryPlugin.Util.getString("XMLQueryResolver.no_expressions_in_select"));
//$NON-NLS-1$
@@ -202,30 +318,12 @@
}
}
- /**
- * Collect all fully-qualified valid elements. These can then be used to
- * validate elements used in the query. It's easier to look up the valid
- * elements because the user is allow to used any partially-qualified name,
- * which makes the logic for doing lookups essentially impossible with the
- * existing metadata interface.
- * @param group Document group
- * @param metadata Metadata interface
- * @return Collection of ElementSymbol for each possible valid element
- * @throws QueryMetadataException
- * @throws TeiidComponentException
- * @throws QueryResolverException
- */
- public static Collection<ElementSymbol>
collectValidCriteriaElements(GroupSymbol group, QueryMetadataInterface metadata)
- throws QueryMetadataException, TeiidComponentException, QueryResolverException {
-
- // Get all groups and elements
- List<ElementSymbol> validElements = getElementsInDocument(group,
metadata);
-
+ 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());
- Iterator tempGroupIter = tempGroups.iterator();
- while(tempGroupIter.hasNext()) {
- Object tempGroupID = tempGroupIter.next();
+ Collection<?> tempGroups =
metadata.getXMLTempGroups(group.getMetadataID());
+ for (Object tempGroupID : tempGroups) {
String name = metadata.getFullName(tempGroupID);
GroupSymbol tempGroup = new GroupSymbol(name);
tempGroup.setMetadataID(tempGroupID);
@@ -235,7 +333,6 @@
return validElements;
}
-
/**
* <p> Resolve the criteria specified on the XML query. The elements specified
on the criteria should
* be present on one of the mapping node objects passed to this method, or else be an
element on a
@@ -255,7 +352,7 @@
* @param metadata QueryMetadataInterface the metadata(for resolving criteria on temp
groups)
* @throws QueryResolverException if any of the above fail conditions are met
*/
- public static void resolveXMLCriteria(Criteria criteria,GroupContext externalGroups,
Collection<ElementSymbol> validElements, QueryMetadataInterface metadata)
+ public static void resolveXMLCriteria(LanguageObject criteria,GroupContext
externalGroups, ResolvingNode validElements, QueryMetadataInterface metadata)
throws QueryMetadataException, TeiidComponentException, QueryResolverException {
// Walk through each element in criteria and check against valid elements
@@ -278,7 +375,7 @@
* @throws QueryMetadataException if resolving fails
* @throws TeiidComponentException if resolving fails
*/
- static void resolveXMLOrderBy(OrderBy orderBy, GroupContext externalGroups,
Collection<ElementSymbol> validElements, QueryMetadataInterface metadata)
+ static void resolveXMLOrderBy(OrderBy orderBy, GroupContext externalGroups,
ResolvingNode validElements, QueryMetadataInterface metadata)
throws QueryMetadataException, TeiidComponentException, QueryResolverException {
// Walk through each element in OrderBy clause and check against valid elements
@@ -298,100 +395,62 @@
* @throws QueryMetadataException
* @throws TeiidComponentException
*/
- static void resolveElement(ElementSymbol elem, Collection<ElementSymbol>
validElements, GroupContext externalGroups, QueryMetadataInterface metadata)
+ static void resolveElement(ElementSymbol elem, ResolvingNode validElements,
GroupContext externalGroups, QueryMetadataInterface metadata)
throws QueryResolverException, QueryMetadataException, TeiidComponentException {
// Get exact matching name
- String critElemName = elem.getName();
- String critElemNameSuffix = "." + elem.getCanonicalName();
//$NON-NLS-1$
+ String partialName = elem.getName();
+ String fullName = partialName;
- // Prepare results
- ElementSymbol exactMatch = null;
- List<ElementSymbol> partialMatches = new ArrayList<ElementSymbol>(2);
// anything over 1 is an error and should be rare
+ ResolvingNode current = validElements;
+ String part = partialName;
+ for (int i = 0; partialName != null; i++) {
+ int index = partialName.lastIndexOf('.');
+ if (index < 0) {
+ part = partialName;
+ partialName = null;
+ } else {
+ part = partialName.substring(index + 1, partialName.length());
+ partialName = partialName.substring(0, index);
+ }
+ current = current.children.get(part);
+ if (current == null) {
+ if (i == 0 && part.charAt(0) != '@') {
+ //handle attribute case
+ part = '@' + part;
+ current = validElements.children.get(part);
+ if (current != null) {
+ continue;
+ }
+ }
+ try {
+ ResolverVisitor.resolveLanguageObject(elem, Collections.EMPTY_LIST,
externalGroups, metadata);
+ return;
+ } catch (QueryResolverException e) {
+ throw new QueryResolverException(e, "ERR.015.008.0019",
QueryPlugin.Util.getString("ERR.015.008.0019", fullName)); //$NON-NLS-1$
//$NON-NLS-2$
+ }
+ }
+ }
- //List of XML attributes that might match the criteria element,
- //if the criteria is specified without the optional "@" sign
- List<ElementSymbol> attributeMatches = new
ArrayList<ElementSymbol>(2);
+ List<ElementSymbol> partialMatches = current.values();
- // look up name based on ID match - will work for uuid version
- try {
+ if (partialMatches.size() != 1) {
+ // Found multiple matches
+ throw new QueryResolverException("ERR.015.008.0020",
QueryPlugin.Util.getString("ERR.015.008.0020", fullName)); //$NON-NLS-1$
//$NON-NLS-2$
+ }
- Object elementID = metadata.getElementID(critElemName);
-
- if(elementID != null) {
- critElemName = metadata.getFullName(elementID);
- }
- } catch(QueryMetadataException e) {
- //e.printStackTrace();
- // ignore and go on
- }
-
- // Walk through each valid element looking for a match
- for (ElementSymbol currentElem : validElements) {
- // Look for exact match
- if(currentElem.getName().equalsIgnoreCase(critElemName)) {
- exactMatch = currentElem;
- break;
- }
-
- if(currentElem.getName().toUpperCase().endsWith(critElemNameSuffix)) {
- partialMatches.add(currentElem);
- } else {
- // The criteria element might be referring to an
- // XML attribute, but might not have the optional
- // "@" sign
- String currentElemName = currentElem.getName();
- int atSignIndex = currentElemName.indexOf("@"); //$NON-NLS-1$
- if (atSignIndex != -1){
- currentElemName = StringUtil.replace(currentElemName, "@",
""); //$NON-NLS-1$ //$NON-NLS-2$
- if(currentElemName.equalsIgnoreCase(critElemName)) {
- attributeMatches.add(currentElem);
- } else {
- currentElemName = currentElemName.toUpperCase();
- if(currentElemName.endsWith(critElemNameSuffix)) {
- attributeMatches.add(currentElem);
- }
- }
- }
- }
- }
-
- // Check for single partial match
- if(exactMatch == null){
- if (partialMatches.size() == 1) {
- exactMatch = partialMatches.get(0);
- } else if (partialMatches.size() == 0 && attributeMatches.size() ==
1){
- exactMatch = attributeMatches.get(0);
- }
- }
-
- if(exactMatch != null) {
- String name = elem.getOutputName();
- // Resolve based on exact match
- elem.setShortName(exactMatch.getShortName());
- elem.setShortCanonicalName(exactMatch.getShortCanonicalName());
- elem.setMetadataID(exactMatch.getMetadataID());
- elem.setType(exactMatch.getType());
- elem.setGroupSymbol(exactMatch.getGroupSymbol());
- elem.setOutputName(name);
- } else if(partialMatches.size() == 0 && attributeMatches.size() == 0){
- try {
- ResolverVisitor.resolveLanguageObject(elem, Collections.EMPTY_LIST,
externalGroups, metadata);
- } catch (QueryResolverException e) {
- throw new QueryResolverException(e, "ERR.015.008.0019",
QueryPlugin.Util.getString("ERR.015.008.0019", critElemName)); //$NON-NLS-1$
//$NON-NLS-2$
- }
- } else {
- // Found multiple matches
- throw new QueryResolverException("ERR.015.008.0020",
QueryPlugin.Util.getString("ERR.015.008.0020", critElemName)); //$NON-NLS-1$
//$NON-NLS-2$
- }
+ ElementSymbol exactMatch = partialMatches.get(0);
+ String name = elem.getOutputName();
+ // Resolve based on exact match
+ elem.setShortName(exactMatch.getShortName());
+ elem.setShortCanonicalName(exactMatch.getShortCanonicalName());
+ elem.setMetadataID(exactMatch.getMetadataID());
+ elem.setType(exactMatch.getType());
+ elem.setGroupSymbol(exactMatch.getGroupSymbol());
+ elem.setOutputName(name);
}
- static List<ElementSymbol> getElementsInDocument(GroupSymbol group,
QueryMetadataInterface metadata)
- throws QueryMetadataException, TeiidComponentException {
- return ResolverUtil.resolveElementsInGroup(group, metadata);
- }
-
- static List<ElementSymbol> getElementsUnderNode(ElementSymbol node,
List<ElementSymbol> validElements, QueryMetadataInterface metadata)
+ static List<ElementSymbol> getElementsUnderNode(ElementSymbol node,
Collection<ElementSymbol> validElements, QueryMetadataInterface metadata)
throws TeiidComponentException, QueryMetadataException {
List<ElementSymbol> elements = new ArrayList<ElementSymbol>();
Modified:
branches/7.4.x/engine/src/test/java/org/teiid/query/optimizer/xml/TestMarkExcludeVisitor.java
===================================================================
---
branches/7.4.x/engine/src/test/java/org/teiid/query/optimizer/xml/TestMarkExcludeVisitor.java 2011-05-29
18:10:40 UTC (rev 3203)
+++
branches/7.4.x/engine/src/test/java/org/teiid/query/optimizer/xml/TestMarkExcludeVisitor.java 2011-05-30
09:48:28 UTC (rev 3204)
@@ -47,11 +47,11 @@
QueryMetadataInterface metadata = TestXMLProcessor.exampleMetadataCached();
Query query = (Query)TestXMLProcessor.helpGetCommand(sql, metadata);
- Collection groups = GroupCollectorVisitor.getGroups(query, true);
- GroupSymbol group = (GroupSymbol) groups.iterator().next();
+ Collection<GroupSymbol> groups = GroupCollectorVisitor.getGroups(query,
true);
+ GroupSymbol group = groups.iterator().next();
MappingDocument docOrig =
(MappingDocument)metadata.getMappingNode(metadata.getGroupID(group.getName()));
- MappingDocument doc = (MappingDocument)docOrig.clone();
+ MappingDocument doc = docOrig.clone();
doc = XMLPlanner.preMarkExcluded(query, doc);
XMLPlanner.removeExcluded(doc);
Modified:
branches/7.4.x/engine/src/test/java/org/teiid/query/optimizer/xml/TestNameInSourceResolverVisitor.java
===================================================================
---
branches/7.4.x/engine/src/test/java/org/teiid/query/optimizer/xml/TestNameInSourceResolverVisitor.java 2011-05-29
18:10:40 UTC (rev 3203)
+++
branches/7.4.x/engine/src/test/java/org/teiid/query/optimizer/xml/TestNameInSourceResolverVisitor.java 2011-05-30
09:48:28 UTC (rev 3204)
@@ -63,7 +63,7 @@
GroupSymbol group = groups.iterator().next();
MappingDocument docOrig =
(MappingDocument)metadata.getMappingNode(metadata.getGroupID(group.getName()));
- MappingDocument doc = (MappingDocument)docOrig.clone();
+ MappingDocument doc = docOrig.clone();
XMLPlannerEnvironment env = new XMLPlannerEnvironment(metadata);
env.mappingDoc = doc;
Modified:
branches/7.4.x/engine/src/test/java/org/teiid/query/processor/xml/TestXMLProcessor.java
===================================================================
---
branches/7.4.x/engine/src/test/java/org/teiid/query/processor/xml/TestXMLProcessor.java 2011-05-29
18:10:40 UTC (rev 3203)
+++
branches/7.4.x/engine/src/test/java/org/teiid/query/processor/xml/TestXMLProcessor.java 2011-05-30
09:48:28 UTC (rev 3204)
@@ -90,7 +90,59 @@
*/
@SuppressWarnings("nls")
public class TestXMLProcessor {
- private static final boolean DEBUG = false;
+ private static final String CARDS_MANAGER = "<?xml version=\"1.0\"
encoding=\"UTF-8\"?>\r\n" + //$NON-NLS-1$
+ "<BaseballPlayers>\r\n" + //$NON-NLS-1$
+ " <Player PlayerID=\"1001\">\r\n" +
//$NON-NLS-1$
+ " <FirstName>Albert</FirstName>\r\n" +
//$NON-NLS-1$
+ " <LastName>Pujols</LastName>\r\n" +
//$NON-NLS-1$
+ " <Manager ManagerID=\"1004\">\r\n" +
//$NON-NLS-1$
+ " <FirstName>Tony</FirstName>\r\n" +
//$NON-NLS-1$
+ " <LastName>LaRussa</LastName>\r\n" +
//$NON-NLS-1$
+ " <Owner OwnerID=\"1009\">\r\n" +
//$NON-NLS-1$
+ " <FirstName>Bill</FirstName>\r\n" +
//$NON-NLS-1$
+ " <LastName>DeWitt</LastName>\r\n" +
//$NON-NLS-1$
+ " </Owner>\r\n" + //$NON-NLS-1$
+ " </Manager>\r\n" + //$NON-NLS-1$
+ " </Player>\r\n" + //$NON-NLS-1$
+ " <Player PlayerID=\"1002\">\r\n" +
//$NON-NLS-1$
+ " <FirstName>Jim</FirstName>\r\n" +
//$NON-NLS-1$
+ " <LastName>Edmunds</LastName>\r\n" +
//$NON-NLS-1$
+ " <Manager ManagerID=\"1004\">\r\n" +
//$NON-NLS-1$
+ " <FirstName>Tony</FirstName>\r\n" +
//$NON-NLS-1$
+ " <LastName>LaRussa</LastName>\r\n" +
//$NON-NLS-1$
+ " <Owner OwnerID=\"1009\">\r\n" +
//$NON-NLS-1$
+ " <FirstName>Bill</FirstName>\r\n" +
//$NON-NLS-1$
+ " <LastName>DeWitt</LastName>\r\n" +
//$NON-NLS-1$
+ " </Owner>\r\n" + //$NON-NLS-1$
+ " </Manager>\r\n" + //$NON-NLS-1$
+ " </Player>\r\n" + //$NON-NLS-1$
+ " <Player PlayerID=\"1003\">\r\n" +
//$NON-NLS-1$
+ " <FirstName>David</FirstName>\r\n" +
//$NON-NLS-1$
+ " <LastName>Eckstein</LastName>\r\n" +
//$NON-NLS-1$
+ " <Manager ManagerID=\"1004\">\r\n" +
//$NON-NLS-1$
+ " <FirstName>Tony</FirstName>\r\n" +
//$NON-NLS-1$
+ " <LastName>LaRussa</LastName>\r\n" +
//$NON-NLS-1$
+ " <Owner OwnerID=\"1009\">\r\n" +
//$NON-NLS-1$
+ " <FirstName>Bill</FirstName>\r\n" +
//$NON-NLS-1$
+ " <LastName>DeWitt</LastName>\r\n" +
//$NON-NLS-1$
+ " </Owner>\r\n" + //$NON-NLS-1$
+ " </Manager>\r\n" + //$NON-NLS-1$
+ " </Player>\r\n" + //$NON-NLS-1$
+ " <Player PlayerID=\"1005\">\r\n" +
//$NON-NLS-1$
+ " <FirstName>Derrek</FirstName>\r\n" +
//$NON-NLS-1$
+ " <LastName>Lee</LastName>\r\n" + //$NON-NLS-1$
+ " </Player>\r\n" + //$NON-NLS-1$
+ " <Player PlayerID=\"1006\">\r\n" +
//$NON-NLS-1$
+ " <FirstName>Corey</FirstName>\r\n" +
//$NON-NLS-1$
+ " <LastName>Patterson</LastName>\r\n" +
//$NON-NLS-1$
+ " </Player>\r\n" + //$NON-NLS-1$
+ " <Player PlayerID=\"1008\">\r\n" +
//$NON-NLS-1$
+ " <FirstName>Carlos</FirstName>\r\n" +
//$NON-NLS-1$
+ " <LastName>Zambrano</LastName>\r\n" +
//$NON-NLS-1$
+ " </Player>\r\n" + //$NON-NLS-1$
+ "</BaseballPlayers>\r\n\r\n";
+
+ private static final boolean DEBUG = false;
/**
* Construct some fake metadata. Basic conceptual tree is:
@@ -11153,63 +11205,18 @@
QueryMetadataInterface metadata = RealMetadataFactory.exampleCase3225();
FakeDataManager dataMgr = exampleDataManagerCase3225(metadata);
- String expectedDoc =
- "<?xml version=\"1.0\"
encoding=\"UTF-8\"?>\r\n" + //$NON-NLS-1$
- "<BaseballPlayers>\r\n" + //$NON-NLS-1$
- " <Player PlayerID=\"1001\">\r\n" +
//$NON-NLS-1$
- " <FirstName>Albert</FirstName>\r\n" +
//$NON-NLS-1$
- " <LastName>Pujols</LastName>\r\n" +
//$NON-NLS-1$
- " <Manager ManagerID=\"1004\">\r\n" +
//$NON-NLS-1$
- " <FirstName>Tony</FirstName>\r\n" +
//$NON-NLS-1$
- " <LastName>LaRussa</LastName>\r\n" +
//$NON-NLS-1$
- " <Owner OwnerID=\"1009\">\r\n" +
//$NON-NLS-1$
- " <FirstName>Bill</FirstName>\r\n" +
//$NON-NLS-1$
- " <LastName>DeWitt</LastName>\r\n" +
//$NON-NLS-1$
- " </Owner>\r\n" + //$NON-NLS-1$
- " </Manager>\r\n" + //$NON-NLS-1$
- " </Player>\r\n" + //$NON-NLS-1$
- " <Player PlayerID=\"1002\">\r\n" +
//$NON-NLS-1$
- " <FirstName>Jim</FirstName>\r\n" + //$NON-NLS-1$
- " <LastName>Edmunds</LastName>\r\n" +
//$NON-NLS-1$
- " <Manager ManagerID=\"1004\">\r\n" +
//$NON-NLS-1$
- " <FirstName>Tony</FirstName>\r\n" +
//$NON-NLS-1$
- " <LastName>LaRussa</LastName>\r\n" +
//$NON-NLS-1$
- " <Owner OwnerID=\"1009\">\r\n" +
//$NON-NLS-1$
- " <FirstName>Bill</FirstName>\r\n" +
//$NON-NLS-1$
- " <LastName>DeWitt</LastName>\r\n" +
//$NON-NLS-1$
- " </Owner>\r\n" + //$NON-NLS-1$
- " </Manager>\r\n" + //$NON-NLS-1$
- " </Player>\r\n" + //$NON-NLS-1$
- " <Player PlayerID=\"1003\">\r\n" +
//$NON-NLS-1$
- " <FirstName>David</FirstName>\r\n" +
//$NON-NLS-1$
- " <LastName>Eckstein</LastName>\r\n" +
//$NON-NLS-1$
- " <Manager ManagerID=\"1004\">\r\n" +
//$NON-NLS-1$
- " <FirstName>Tony</FirstName>\r\n" +
//$NON-NLS-1$
- " <LastName>LaRussa</LastName>\r\n" +
//$NON-NLS-1$
- " <Owner OwnerID=\"1009\">\r\n" +
//$NON-NLS-1$
- " <FirstName>Bill</FirstName>\r\n" +
//$NON-NLS-1$
- " <LastName>DeWitt</LastName>\r\n" +
//$NON-NLS-1$
- " </Owner>\r\n" + //$NON-NLS-1$
- " </Manager>\r\n" + //$NON-NLS-1$
- " </Player>\r\n" + //$NON-NLS-1$
- " <Player PlayerID=\"1005\">\r\n" +
//$NON-NLS-1$
- " <FirstName>Derrek</FirstName>\r\n" +
//$NON-NLS-1$
- " <LastName>Lee</LastName>\r\n" + //$NON-NLS-1$
- " </Player>\r\n" + //$NON-NLS-1$
- " <Player PlayerID=\"1006\">\r\n" +
//$NON-NLS-1$
- " <FirstName>Corey</FirstName>\r\n" +
//$NON-NLS-1$
- " <LastName>Patterson</LastName>\r\n" +
//$NON-NLS-1$
- " </Player>\r\n" + //$NON-NLS-1$
- " <Player PlayerID=\"1008\">\r\n" +
//$NON-NLS-1$
- " <FirstName>Carlos</FirstName>\r\n" +
//$NON-NLS-1$
- " <LastName>Zambrano</LastName>\r\n" +
//$NON-NLS-1$
- " </Player>\r\n" + //$NON-NLS-1$
- "</BaseballPlayers>\r\n\r\n"; //$NON-NLS-1$
- helpTestProcess("select * from xmltest.playersDoc where context(manager,
owner.@ownerid) = '1009'", expectedDoc, metadata, dataMgr);
//$NON-NLS-1$
+ helpTestProcess("select * from xmltest.playersDoc where context(manager,
owner.@ownerid) = '1009'", CARDS_MANAGER, metadata, dataMgr);
//$NON-NLS-1$
}
+ @Test public void testBaseballPlayersPseudoGroup() throws Exception {
+ QueryMetadataInterface metadata = RealMetadataFactory.exampleCase3225();
+ FakeDataManager dataMgr = exampleDataManagerCase3225(metadata);
+
+ helpTestProcess("select * from xmltest.playersDoc where context(manager,
manager.firstname) > ALL (select firstname from player)", CARDS_MANAGER, metadata,
dataMgr); //$NON-NLS-1$
+ }
+
/**
* Ensures that temp tables are still visible when processing criteria
*/
Modified:
branches/7.4.x/engine/src/test/java/org/teiid/query/resolver/TestXMLResolver.java
===================================================================
---
branches/7.4.x/engine/src/test/java/org/teiid/query/resolver/TestXMLResolver.java 2011-05-29
18:10:40 UTC (rev 3203)
+++
branches/7.4.x/engine/src/test/java/org/teiid/query/resolver/TestXMLResolver.java 2011-05-30
09:48:28 UTC (rev 3204)
@@ -22,8 +22,9 @@
package org.teiid.query.resolver;
-import junit.framework.TestCase;
+import static org.junit.Assert.*;
+import org.junit.Test;
import org.teiid.query.parser.QueryParser;
import org.teiid.query.resolver.util.ResolverUtil;
import org.teiid.query.sql.lang.Command;
@@ -38,7 +39,7 @@
import org.teiid.query.unittest.RealMetadataFactory;
-public class TestXMLResolver extends TestCase {
+public class TestXMLResolver {
public Command helpResolve(String sql) {
Command cmd = TestResolver.helpResolve(sql,
RealMetadataFactory.example1Cached());
@@ -54,7 +55,7 @@
TestResolver.helpResolveException(sql, RealMetadataFactory.example1Cached(),
expectedMessage);
}
- public void testXMLCriteriaShortElement() {
+ @Test public void testXMLCriteriaShortElement() {
CompareCriteria expected = new CompareCriteria();
GroupSymbol gs = new GroupSymbol("xmltest.doc1"); //$NON-NLS-1$
ElementSymbol es = new ElementSymbol("root.node1", null, gs);
//$NON-NLS-1$
@@ -67,7 +68,7 @@
assertEquals("Did not match expected criteria", expected, actual);
//$NON-NLS-1$
}
- public void testXMLCriteriaLongElement1() {
+ @Test public void testXMLCriteriaLongElement1() {
CompareCriteria expected = new CompareCriteria();
GroupSymbol gs = new GroupSymbol("xmltest.doc1"); //$NON-NLS-1$
ElementSymbol es = new ElementSymbol("root.node1", null, gs);
//$NON-NLS-1$
@@ -81,7 +82,7 @@
assertEquals("Did not match expected criteria", expected, actual);
//$NON-NLS-1$
}
- public void testXMLCriteriaLongElement2() {
+ @Test public void testXMLCriteriaLongElement2() {
CompareCriteria expected1 = new CompareCriteria();
GroupSymbol gs = new GroupSymbol("xmltest.doc4"); //$NON-NLS-1$
ElementSymbol es1 = new ElementSymbol("root.node1", null, gs);
//$NON-NLS-1$
@@ -94,7 +95,7 @@
assertEquals("Did not match expected criteria", expected1, actual);
//$NON-NLS-1$
}
- public void testXMLCriteriaLongElement3() {
+ @Test public void testXMLCriteriaLongElement3() {
GroupSymbol gs = new GroupSymbol("xmltest.doc4"); //$NON-NLS-1$
CompareCriteria expected2 = new CompareCriteria();
ElementSymbol es2 = new ElementSymbol("root.node1.@node2", null, gs);
//$NON-NLS-1$
@@ -108,7 +109,7 @@
assertEquals("Did not match expected criteria", expected2, actual);
//$NON-NLS-1$
}
- public void testXMLCriteriaLongElement4() {
+ @Test public void testXMLCriteriaLongElement4() {
GroupSymbol gs = new GroupSymbol("xmltest.doc4"); //$NON-NLS-1$
CompareCriteria expected3 = new CompareCriteria();
ElementSymbol es3 = new ElementSymbol("root.node3", null, gs);
//$NON-NLS-1$
@@ -121,76 +122,76 @@
assertEquals("Did not match expected criteria", expected3, actual);
//$NON-NLS-1$
}
- public void testXMLCriteriaLongElement5() {
+ @Test public void testXMLCriteriaLongElement5() {
helpResolve("select * from xmltest.doc4 where root.node1 =
'yyz'"); //$NON-NLS-1$
}
- public void testXMLCriteriaLongElement6() {
+ @Test public void testXMLCriteriaLongElement6() {
helpResolve("select * from xmltest.doc4 where root.node1.@node2 =
'yyz'"); //$NON-NLS-1$
}
- public void testXMLCriteriaLongElement7() {
+ @Test public void testXMLCriteriaLongElement7() {
helpResolve("select * from xmltest.doc4 where root.node3 =
'yyz'"); //$NON-NLS-1$
}
- public void testXMLCriteriaLongElement8() {
+ @Test public void testXMLCriteriaLongElement8() {
helpResolve("select * from xmltest.doc4 where node3 = 'yyz'");
//$NON-NLS-1$
}
- public void testXMLCriteriaLongElementFail1() {
+ @Test public void testXMLCriteriaLongElementFail1() {
helpResolveException("select * from xmltest.doc4 where node3.node1.node2 =
'xyz'"); //$NON-NLS-1$
}
- public void testXMLCriteriaLongElementFail2() {
+ @Test public void testXMLCriteriaLongElementFail2() {
helpResolveException("select * from xmltest.doc4 where
root.node1.node2.node3 = 'xyz'"); //$NON-NLS-1$
}
- public void testXMLCriteriaLongElementFail3() {
+ @Test public void testXMLCriteriaLongElementFail3() {
helpResolveException("select * from xmltest.doc4 where root.node1.node3 =
'xyz'"); //$NON-NLS-1$
}
- public void testXMLCriteriaLongElementFail4() {
+ @Test public void testXMLCriteriaLongElementFail4() {
helpResolveException("select * from xmltest.doc4 where node2.node1.node2 =
'xyz'"); //$NON-NLS-1$
}
- public void testXMLCriteriaTempElement1() {
+ @Test public void testXMLCriteriaTempElement1() {
helpResolve("select * from xmltest.doc4 where tm1.g1.e1 =
'x'"); //$NON-NLS-1$
}
- public void testXMLCriteriaTempElement2() {
+ @Test public void testXMLCriteriaTempElement2() {
helpResolve("select * from xmltest.doc4 where root.node1.@node2 =
'yyz' and tm1.g1.e2 = 'y'"); //$NON-NLS-1$
}
- public void testXMLCriteriaTempElement3() {
+ @Test public void testXMLCriteriaTempElement3() {
helpResolve("select * from xmltest.doc4 where tm1.g1.e1 = 'x' and
tm1.g1.e2 = 'y'"); //$NON-NLS-1$
}
- public void testXMLCriteriaTempElementFail1() {
+ @Test public void testXMLCriteriaTempElementFail1() {
helpResolveException("select * from xmltest.doc4 where tm1.g2.e1 =
'xyz'"); //$NON-NLS-1$
}
- public void testXMLCriteriaTempElementFail2() {
+ @Test public void testXMLCriteriaTempElementFail2() {
helpResolveException("select * from xmltest.doc4 where
root.node1.node2.node3 = 'xyz' and e1 = 'x'"); //$NON-NLS-1$
}
- public void testXMLCriteriaTempElementFail3() {
+ @Test public void testXMLCriteriaTempElementFail3() {
helpResolveException("select * from xmltest.doc4 where e3 = 'xyz'
and tm1.g2.e4='m'"); //$NON-NLS-1$
}
//tests ambiguously-named elements in both root temp group and document
- public void testXMLAmbiguousName1() {
+ @Test public void testXMLAmbiguousName1() {
helpResolve("select * from xmltest.doc4 where root.node1 is null");
//$NON-NLS-1$
}
- public void testXMLAmbiguousName2() {
+ @Test public void testXMLAmbiguousName2() {
helpResolve("select * from xmltest.doc4 where tm1.g1.node1 =
'yyz'"); //$NON-NLS-1$
}
- public void testXMLAmbiguousName3() {
+ @Test public void testXMLAmbiguousName3() {
helpResolveException("select * from xmltest.doc4 where node1 =
'yyz'"); //$NON-NLS-1$
}
- public void testXMLCriteriaLongElementInAnonymous() {
+ @Test public void testXMLCriteriaLongElementInAnonymous() {
CompareCriteria expected = new CompareCriteria();
GroupSymbol gs = new GroupSymbol("xmltest.doc2"); //$NON-NLS-1$
ElementSymbol es = new ElementSymbol("root.node1.node3", null, gs);
//$NON-NLS-1$
@@ -203,7 +204,7 @@
assertEquals("Did not match expected criteria", expected, actual);
//$NON-NLS-1$
}
- public void testXMLAmbiguousShortName() {
+ @Test public void testXMLAmbiguousShortName() {
CompareCriteria expected = new CompareCriteria();
ElementSymbol es = new ElementSymbol("node2"); //$NON-NLS-1$
GroupSymbol gs = new GroupSymbol("doc3"); //$NON-NLS-1$
@@ -218,95 +219,95 @@
/**
* defect 9745
*/
- public void testXMLAttributeInCriteria() {
+ @Test public void testXMLAttributeInCriteria() {
helpResolve("select * from xmltest.doc4 where root.node1.@node2 =
'x'"); //$NON-NLS-1$
}
/**
* defect 9745
*/
- public void testXMLAttributeInCriteria2() {
+ @Test public void testXMLAttributeInCriteria2() {
helpResolve("select * from xmltest.doc4 where root.node1.node2 =
'x'"); //$NON-NLS-1$
}
/**
* defect 9745
*/
- public void testXMLAttributeInCriteria3() {
+ @Test public void testXMLAttributeInCriteria3() {
helpResolve("select * from xmltest.doc4 where node2 = 'x'");
//$NON-NLS-1$
}
- public void testXMLAttributeElementAmbiguity1() {
+ @Test public void testXMLAttributeElementAmbiguity1() {
helpResolve("select * from xmltest.doc4 where root.node3.node4 =
'x'"); //$NON-NLS-1$
}
- public void testXMLAttributeElementAmbiguity2() {
+ @Test public void testXMLAttributeElementAmbiguity2() {
helpResolve("select * from xmltest.doc4 where root.node3.@node4 =
'x'"); //$NON-NLS-1$
}
- public void testXMLAttributeElementAmbiguity3() {
+ @Test public void testXMLAttributeElementAmbiguity3() {
helpResolve("select * from xmltest.doc4 where root.node3.node4 = 'x'
and root.node3.@node4='y'"); //$NON-NLS-1$
}
/*
* This should resolve to the XML element root.node3.root.node6
*/
- public void testXMLAttributeElementAmbiguity4() {
+ @Test public void testXMLAttributeElementAmbiguity4() {
helpResolve("select * from xmltest.doc4 where root.node6 =
'x'"); //$NON-NLS-1$
}
/*
* This should resolve to the XML attribute root.@node6
*/
- public void testXMLAttributeElementAmbiguity5() {
+ @Test public void testXMLAttributeElementAmbiguity5() {
helpResolve("select * from xmltest.doc4 where root.@node6 =
'x'"); //$NON-NLS-1$
}
- public void testXMLAttributeFullPath() {
+ @Test public void testXMLAttributeFullPath() {
helpResolve("select * from xmltest.doc4 where xmltest.doc4.root.@node6 =
'x'"); //$NON-NLS-1$
}
- public void testXMLCriteriaLongElementWithGroup1() {
+ @Test public void testXMLCriteriaLongElementWithGroup1() {
helpResolve("select * from xmltest.doc4 where xmltest.doc4.root.node1 =
'yyz'"); //$NON-NLS-1$
}
- public void testXMLCriteriaLongElementWithGroup2() {
+ @Test public void testXMLCriteriaLongElementWithGroup2() {
helpResolve("select * from xmltest.doc4 where xmltest.doc4.root.node1.@node2
= 'yyz'"); //$NON-NLS-1$
}
- public void testXMLCriteriaLongElementWithGroup3() {
+ @Test public void testXMLCriteriaLongElementWithGroup3() {
helpResolve("select * from xmltest.doc4 where xmltest.doc4.root.node3 =
'yyz'"); //$NON-NLS-1$
}
- /*public void testXMLElementPotentialAmbiguous() {
+ /*@Test public void testXMLElementPotentialAmbiguous() {
helpResolve("select * from xmltest.doc6 where node = 'yyz'");
}*/
- public void testXMLSelect() {
+ @Test public void testXMLSelect() {
helpResolve("select root.node3.@node4 from xmltest.doc4");
//$NON-NLS-1$
}
- public void testXMLSelect2() {
+ @Test public void testXMLSelect2() {
helpResolve("select root.node3.node4 from xmltest.doc4");
//$NON-NLS-1$
}
- public void testXMLSelect3() {
+ @Test public void testXMLSelect3() {
helpResolve("select root.@node6 from xmltest.doc4"); //$NON-NLS-1$
}
- public void testXMLSelect4() {
+ @Test public void testXMLSelect4() {
helpResolve("select root.node6 from xmltest.doc4"); //$NON-NLS-1$
}
- public void testXMLSelect5() {
+ @Test public void testXMLSelect5() {
helpResolve("select node2 from xmltest.doc4"); //$NON-NLS-1$
}
- public void testDEFECT_19771() {
+ @Test public void testDEFECT_19771() {
helpResolveException("select node2 AS NODE2 from xmltest.doc4");
//$NON-NLS-1$
}
- public void testContext() {
+ @Test public void testContext() {
GroupSymbol gs1 = new GroupSymbol("xmltest.doc1"); //$NON-NLS-1$
ElementSymbol es1 = new ElementSymbol("root.node1.node2.node3", null,
gs1); //$NON-NLS-1$
ElementSymbol es2 = new ElementSymbol("root.node1", null, gs1);
//$NON-NLS-1$
@@ -324,7 +325,7 @@
assertEquals("Did not match expected criteria", expected, actual);
//$NON-NLS-1$
}
- public void testRowLimit() {
+ @Test public void testRowLimit() {
GroupSymbol gs1 = new GroupSymbol("xmltest.doc1"); //$NON-NLS-1$
ElementSymbol es1 = new ElementSymbol("root.node1.node2.node3", null,
gs1); //$NON-NLS-1$
es1.setGroupSymbol(gs1);
@@ -342,7 +343,7 @@
assertEquals("Did not match expected criteria", expected, actual);
//$NON-NLS-1$
}
- public void testRowLimitException() {
+ @Test public void testRowLimitException() {
GroupSymbol gs1 = new GroupSymbol("xmltest.doc1"); //$NON-NLS-1$
ElementSymbol es1 = new ElementSymbol("root.node1.node2.node3", null,
gs1); //$NON-NLS-1$
Expression[] exprs = new Expression[]{es1};
@@ -359,23 +360,23 @@
assertEquals("Did not match expected criteria", expected, actual);
//$NON-NLS-1$
}
- public void testXMLQueryFail1() {
+ @Test public void testXMLQueryFail1() {
helpResolveException("SELECT DISTINCT * FROM vm1.doc1"); //$NON-NLS-1$
}
- public void testXMLQueryFail2() {
+ @Test public void testXMLQueryFail2() {
helpResolveException("SELECT a2 FROM vm1.doc1"); //$NON-NLS-1$
}
- public void testXMLQueryFail3() {
+ @Test public void testXMLQueryFail3() {
helpResolveException("SELECT * FROM vm1.doc1, vm1.doc2");
//$NON-NLS-1$
}
- public void testXMLWithOrderBy1() {
+ @Test public void testXMLWithOrderBy1() {
helpResolveException("select * from xmltest.doc4 order by node1");
//$NON-NLS-1$
}
- public void testConversionInXML() {
+ @Test public void testConversionInXML() {
// Expected left expression
GroupSymbol gs1 = new GroupSymbol("xmltest.doc1"); //$NON-NLS-1$
ElementSymbol es1 = new ElementSymbol("root.node1", null, gs1);
//$NON-NLS-1$
@@ -397,7 +398,7 @@
assertNotNull("Failed to resolve function",
actualRightExpr.getFunctionDescriptor()); //$NON-NLS-1$
}
- public void testXMLWithSelect1() throws Exception {
+ @Test public void testXMLWithSelect1() throws Exception {
CompareCriteria expected = new CompareCriteria();
GroupSymbol gs = new GroupSymbol("xmltest.doc1"); //$NON-NLS-1$
ElementSymbol es = new ElementSymbol("root.node1", null, gs);
//$NON-NLS-1$
@@ -410,11 +411,11 @@
assertEquals("Did not match expected criteria", expected, actual);
//$NON-NLS-1$
}
- public void testXMLWithSelect1a() {
+ @Test public void testXMLWithSelect1a() {
helpResolveException("select 'a' from xmltest.doc1 where node1 =
'yyz'", "Expressions cannot be selected by XML Queries");
//$NON-NLS-1$ //$NON-NLS-2$
}
- public void testXMLWithSelect2() {
+ @Test public void testXMLWithSelect2() {
CompareCriteria expected = new CompareCriteria();
GroupSymbol gs = new GroupSymbol("xmltest.doc1"); //$NON-NLS-1$
ElementSymbol es = new ElementSymbol("root.node1", null, gs);
//$NON-NLS-1$
Modified:
branches/7.4.x/engine/src/test/java/org/teiid/query/unittest/RealMetadataFactory.java
===================================================================
---
branches/7.4.x/engine/src/test/java/org/teiid/query/unittest/RealMetadataFactory.java 2011-05-29
18:10:40 UTC (rev 3203)
+++
branches/7.4.x/engine/src/test/java/org/teiid/query/unittest/RealMetadataFactory.java 2011-05-30
09:48:28 UTC (rev 3204)
@@ -2517,10 +2517,10 @@
// Create mapping classes - baseball players employees doc
QueryNode playersNode = new QueryNode("SELECT stock.employees.employeeNum,
firstName, lastName, supervisorNum FROM stock.employees WHERE specializesInItemNum is not
null"); //$NON-NLS-1$ //$NON-NLS-2$
- Table rsPlayers = createVirtualGroup("players", xmltest, playersNode);
//$NON-NLS-1$
+ Table rsPlayers = createVirtualGroup("player", xmltest, playersNode);
//$NON-NLS-1$
QueryNode managersNode = new QueryNode("SELECT stock.employees.employeeNum,
firstName, lastName, supervisorNum FROM stock.employees WHERE stock.employees.employeeNum
= ?"); //$NON-NLS-1$ //$NON-NLS-2$
- managersNode.addBinding("xmltest.players.supervisorNum"); //$NON-NLS-1$
+ managersNode.addBinding("xmltest.player.supervisorNum"); //$NON-NLS-1$
Table rsManagers = createVirtualGroup("managers", xmltest, managersNode);
//$NON-NLS-1$
// TODO what if elements in criteria weren't fully qualified? see defect
19541
@@ -2548,11 +2548,11 @@
MappingElement root2 = doc2.addChildElement(new
MappingElement("BaseballPlayers")); //$NON-NLS-1$
MappingElement player = root2.addChildElement(new
MappingElement("Player")); //$NON-NLS-1$
- player.setSource("xmltest.players"); //$NON-NLS-1$
+ player.setSource("xmltest.player"); //$NON-NLS-1$
player.setMaxOccurrs(-1);
- player.addAttribute(new MappingAttribute("PlayerID",
"xmltest.players.employeeNum")); //$NON-NLS-1$ //$NON-NLS-2$
- player.addChildElement(new MappingElement("FirstName",
"xmltest.players.firstName")); //$NON-NLS-1$ //$NON-NLS-2$
- player.addChildElement(new MappingElement("LastName",
"xmltest.players.lastName")); //$NON-NLS-1$ //$NON-NLS-2$
+ player.addAttribute(new MappingAttribute("PlayerID",
"xmltest.player.employeeNum")); //$NON-NLS-1$ //$NON-NLS-2$
+ player.addChildElement(new MappingElement("FirstName",
"xmltest.player.firstName")); //$NON-NLS-1$ //$NON-NLS-2$
+ player.addChildElement(new MappingElement("LastName",
"xmltest.player.lastName")); //$NON-NLS-1$ //$NON-NLS-2$
MappingElement manager = player.addChildElement(new
MappingElement("Manager")); //$NON-NLS-1$
manager.setSource("xmltest.managers");//$NON-NLS-1$
Modified:
branches/7.4.x/engine/src/test/java/org/teiid/query/validator/TestValidator.java
===================================================================
---
branches/7.4.x/engine/src/test/java/org/teiid/query/validator/TestValidator.java 2011-05-29
18:10:40 UTC (rev 3203)
+++
branches/7.4.x/engine/src/test/java/org/teiid/query/validator/TestValidator.java 2011-05-30
09:48:28 UTC (rev 3204)
@@ -120,9 +120,9 @@
MappingElement sourceNode = complexRoot.addChildElement(new
MappingElement("a1")); //$NON-NLS-1$
sourceNode.setSource("test.group"); //$NON-NLS-1$
- sourceNode.addChildElement(new MappingElement("a2", "e1"));
//$NON-NLS-1$ //$NON-NLS-2$
- sourceNode.addChildElement(new MappingElement("b2", "e2"));
//$NON-NLS-1$ //$NON-NLS-2$
- sourceNode.addChildElement(new MappingElement("c2", "e3"));
//$NON-NLS-1$ //$NON-NLS-2$
+ sourceNode.addChildElement(new MappingElement("a2",
"test.group.e1")); //$NON-NLS-1$ //$NON-NLS-2$
+ sourceNode.addChildElement(new MappingElement("b2",
"test.group.e2")); //$NON-NLS-1$ //$NON-NLS-2$
+ sourceNode.addChildElement(new MappingElement("c2",
"test.group.e3")); //$NON-NLS-1$ //$NON-NLS-2$
Schema docModel = RealMetadataFactory.createVirtualModel("vm1",
metadataStore); //$NON-NLS-1$
Table doc1 = RealMetadataFactory.createXmlDocument("doc1", docModel,
doc); //$NON-NLS-1$