teiid SVN: r853 - in trunk/common-internal/src/main/java/com/metamatrix/common: config/model and 1 other directory.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2009-04-30 17:31:54 -0400 (Thu, 30 Apr 2009)
New Revision: 853
Removed:
trunk/common-internal/src/main/java/com/metamatrix/common/actions/ExchangeDouble.java
trunk/common-internal/src/main/java/com/metamatrix/common/actions/ExchangeFloat.java
trunk/common-internal/src/main/java/com/metamatrix/common/actions/ExchangeInt.java
trunk/common-internal/src/main/java/com/metamatrix/common/actions/ExchangeLong.java
trunk/common-internal/src/main/java/com/metamatrix/common/actions/ExchangeShort.java
Modified:
trunk/common-internal/src/main/java/com/metamatrix/common/actions/AbstractObjectEditor.java
trunk/common-internal/src/main/java/com/metamatrix/common/config/model/BasicConfigurationObjectEditor.java
Log:
removing unused exchange primitive classes
Modified: trunk/common-internal/src/main/java/com/metamatrix/common/actions/AbstractObjectEditor.java
===================================================================
--- trunk/common-internal/src/main/java/com/metamatrix/common/actions/AbstractObjectEditor.java 2009-04-29 20:16:12 UTC (rev 852)
+++ trunk/common-internal/src/main/java/com/metamatrix/common/actions/AbstractObjectEditor.java 2009-04-30 21:31:54 UTC (rev 853)
@@ -161,41 +161,6 @@
}
}
- protected void createExchangeInt(Object targetId, AttributeDefinition attrDefn, int oldValue, int newValue) {
- if ( this.createActions ) {
- ActionDefinition action = new ExchangeInt(targetId,attrDefn,oldValue,newValue );
- this.getDestination().addAction(action);
- }
- }
-
- protected void createExchangeLong(Object targetId, AttributeDefinition attrDefn, long oldValue, long newValue) {
- if ( this.createActions ) {
- ActionDefinition action = new ExchangeLong(targetId, attrDefn,oldValue,newValue );
- this.getDestination().addAction(action);
- }
- }
-
- protected void createExchangeDouble(Object targetId, AttributeDefinition attrDefn, double oldValue, double newValue) {
- if ( this.createActions ) {
- ActionDefinition action = new ExchangeDouble(targetId, attrDefn,oldValue,newValue );
- this.getDestination().addAction(action);
- }
- }
-
- protected void createExchangeFloat(Object targetId, AttributeDefinition attrDefn, float oldValue, float newValue) {
- if ( this.createActions ) {
- ActionDefinition action = new ExchangeFloat(targetId, attrDefn,oldValue,newValue );
- this.getDestination().addAction(action);
- }
- }
-
- protected void createExchangeShort(Object targetId, AttributeDefinition attrDefn, short oldValue, short newValue) {
- if ( this.createActions ) {
- ActionDefinition action = new ExchangeShort(targetId, attrDefn,oldValue,newValue );
- this.getDestination().addAction(action);
- }
- }
-
protected void createDestroyAction(Object targetId, Object targetObject) {
if ( this.createActions ) {
ActionDefinition action = new DestroyObject(targetId,targetObject);
Deleted: trunk/common-internal/src/main/java/com/metamatrix/common/actions/ExchangeDouble.java
===================================================================
--- trunk/common-internal/src/main/java/com/metamatrix/common/actions/ExchangeDouble.java 2009-04-29 20:16:12 UTC (rev 852)
+++ trunk/common-internal/src/main/java/com/metamatrix/common/actions/ExchangeDouble.java 2009-04-30 21:31:54 UTC (rev 853)
@@ -1,98 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package com.metamatrix.common.actions;
-
-public class ExchangeDouble extends ExchangePrimitive {
- private double previousValue;
- private double newValue;
- public ExchangeDouble(Object target, AttributeDefinition attribute, double previousValue, double newValue) {
- super(target,attribute);
- this.previousValue = previousValue;
- this.newValue = newValue;
- }
- private ExchangeDouble(Object target, Integer attributeCode, double previousValue, double newValue) {
- super(target,attributeCode);
- this.previousValue = previousValue;
- this.newValue = newValue;
- }
- private ExchangeDouble(ExchangeDouble rhs) {
- super(rhs);
- this.previousValue = rhs.previousValue;
- this.newValue = rhs.newValue;
- }
-
- public synchronized double getPreviousValue(){
- return previousValue;
- }
- public synchronized double getNewValue(){
- return newValue;
- }
- /**
- * Returns a string representing the current state of the object.
- * @return the string representation of this instance.
- */
- public String toString() {
- return getActionDescription() + "; new value = " + newValue + ", previous value = " + previousValue; //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- /**
- * Return a deep cloned instance of this object. Subclasses must override
- * this method.
- * @return the object that is the clone of this instance.
- */
- public synchronized Object clone() {
- return new ExchangeDouble(this);
- }
- /**
- * Returns true if the specified object is semantically equal to this instance.
- * Note: this method is consistent with <code>compareTo()</code>.
- * <p>
- * @param obj the object that this instance is to be compared to.
- * @return whether the object is equal to this object.
- */
- public synchronized boolean equals(Object obj) {
- // Check if instances are identical ...
- if ( this == obj ) return true;
-
- // Check if object can be compared to this one
- // (this includes checking for null ) ...
- if ( obj instanceof ExchangeDouble ) {
- ExchangeDouble that = (ExchangeDouble) obj;
- return ( this.getNewValue() == that.getNewValue() && this.getPreviousValue() == that.getPreviousValue() );
- }
-
- // Otherwise not comparable ...
- return false;
- }
- /**
- * Obtain the definition of the action that undoes this action definition. If a modification action with the
- * returned action definition is applied to the same target (when the state is such as that left by
- * the original modification action), the resulting target will be left in a state that is identical to the target
- * before either action were applied.
- * @return the action definition that undoes this action definition.
- */
- public synchronized ActionDefinition getUndoActionDefinition() {
- return new ExchangeDouble(this.getTarget(),this.getAttributeCode(),this.newValue, this.previousValue);
- }
-}
-
Deleted: trunk/common-internal/src/main/java/com/metamatrix/common/actions/ExchangeFloat.java
===================================================================
--- trunk/common-internal/src/main/java/com/metamatrix/common/actions/ExchangeFloat.java 2009-04-29 20:16:12 UTC (rev 852)
+++ trunk/common-internal/src/main/java/com/metamatrix/common/actions/ExchangeFloat.java 2009-04-30 21:31:54 UTC (rev 853)
@@ -1,98 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package com.metamatrix.common.actions;
-
-public class ExchangeFloat extends ExchangePrimitive {
- private float previousValue;
- private float newValue;
- public ExchangeFloat(Object target, AttributeDefinition attribute, float previousValue, float newValue) {
- super(target,attribute);
- this.previousValue = previousValue;
- this.newValue = newValue;
- }
- private ExchangeFloat(Object target, Integer attributeCode, float previousValue, float newValue) {
- super(target,attributeCode);
- this.previousValue = previousValue;
- this.newValue = newValue;
- }
- private ExchangeFloat(ExchangeFloat rhs) {
- super(rhs);
- this.previousValue = rhs.previousValue;
- this.newValue = rhs.newValue;
- }
-
- public synchronized float getPreviousValue(){
- return previousValue;
- }
- public synchronized float getNewValue(){
- return newValue;
- }
- /**
- * Returns a string representing the current state of the object.
- * @return the string representation of this instance.
- */
- public String toString() {
- return getActionDescription() + "; new value = " + newValue + ", previous value = " + previousValue; //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- /**
- * Return a deep cloned instance of this object. Subclasses must override
- * this method.
- * @return the object that is the clone of this instance.
- */
- public synchronized Object clone() {
- return new ExchangeFloat(this);
- }
- /**
- * Returns true if the specified object is semantically equal to this instance.
- * Note: this method is consistent with <code>compareTo()</code>.
- * <p>
- * @param obj the object that this instance is to be compared to.
- * @return whether the object is equal to this object.
- */
- public synchronized boolean equals(Object obj) {
- // Check if instances are identical ...
- if ( this == obj ) return true;
-
- // Check if object can be compared to this one
- // (this includes checking for null ) ...
- if ( obj instanceof ExchangeFloat ) {
- ExchangeFloat that = (ExchangeFloat) obj;
- return ( this.getNewValue() == that.getNewValue() && this.getPreviousValue() == that.getPreviousValue() );
- }
-
- // Otherwise not comparable ...
- return false;
- }
- /**
- * Obtain the definition of the action that undoes this action definition. If a modification action with the
- * returned action definition is applied to the same target (when the state is such as that left by
- * the original modification action), the resulting target will be left in a state that is identical to the target
- * before either action were applied.
- * @return the action definition that undoes this action definition.
- */
- public synchronized ActionDefinition getUndoActionDefinition() {
- return new ExchangeFloat(this.getTarget(),this.getAttributeCode(),this.newValue, this.previousValue);
- }
-}
-
Deleted: trunk/common-internal/src/main/java/com/metamatrix/common/actions/ExchangeInt.java
===================================================================
--- trunk/common-internal/src/main/java/com/metamatrix/common/actions/ExchangeInt.java 2009-04-29 20:16:12 UTC (rev 852)
+++ trunk/common-internal/src/main/java/com/metamatrix/common/actions/ExchangeInt.java 2009-04-30 21:31:54 UTC (rev 853)
@@ -1,107 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package com.metamatrix.common.actions;
-
-public class ExchangeInt extends ExchangePrimitive {
- private int previousValue;
-
- private int newValue;
-
- public ExchangeInt(Object target, AttributeDefinition attribute, int previousValue, int newValue) {
- super(target,attribute);
- this.previousValue = previousValue;
- this.newValue = newValue;
- }
- private ExchangeInt(Object target, Integer attributeCode, int previousValue, int newValue) {
- super(target,attributeCode);
- this.previousValue = previousValue;
- this.newValue = newValue;
- }
-
- private ExchangeInt(ExchangeInt rhs) {
- super(rhs);
- this.previousValue = rhs.previousValue;
- this.newValue = rhs.newValue;
- }
-
- public synchronized int getPreviousValue() {
- return previousValue;
- }
-
- public synchronized int getNewValue() {
- return newValue;
- }
-
- /**
- * Returns a string representing the current state of the object.
- * @return the string representation of this instance.
- */
- public String toString() {
- return getActionDescription() + "; new value = " + newValue + ", previous value = " + previousValue; //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- /**
- * Return a deep cloned instance of this object. Subclasses must override
- * this method.
- * @return the object that is the clone of this instance.
- */
- public synchronized Object clone() {
- return new ExchangeInt(this);
- }
-
- /**
- * Returns true if the specified object is semantically equal to this instance.
- * Note: this method is consistent with <code>compareTo()</code>.
- * <p>
- * @param obj the object that this instance is to be compared to.
- * @return whether the object is equal to this object.
- */
- public synchronized boolean equals(Object obj) {
- // Check if instances are identical ...
- if (this == obj) {
- return true;
- }
-
- // Check if object can be compared to this one
- // (this includes checking for null ) ...
- if (obj instanceof ExchangeInt) {
- ExchangeInt that = (ExchangeInt)obj;
- return (this.getNewValue() == that.getNewValue() && this.getPreviousValue() == that.getPreviousValue());
- }
-
- // Otherwise not comparable ...
- return false;
- }
- /**
- * Obtain the definition of the action that undoes this action definition. If a modification action with the
- * returned action definition is applied to the same target (when the state is such as that left by
- * the original modification action), the resulting target will be left in a state that is identical to the target
- * before either action were applied.
- * @return the action definition that undoes this action definition.
- */
- public synchronized ActionDefinition getUndoActionDefinition() {
- return new ExchangeInt(this.getTarget(), this.getAttributeCode(), this.newValue, this.previousValue);
- }
-}
-
-
Deleted: trunk/common-internal/src/main/java/com/metamatrix/common/actions/ExchangeLong.java
===================================================================
--- trunk/common-internal/src/main/java/com/metamatrix/common/actions/ExchangeLong.java 2009-04-29 20:16:12 UTC (rev 852)
+++ trunk/common-internal/src/main/java/com/metamatrix/common/actions/ExchangeLong.java 2009-04-30 21:31:54 UTC (rev 853)
@@ -1,109 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package com.metamatrix.common.actions;
-
-public class ExchangeLong extends ExchangePrimitive {
- private long previousValue;
-
- private long newValue;
-
- public ExchangeLong(Object target, AttributeDefinition attribute, long previousValue, long newValue) {
- super(target,attribute);
- this.previousValue = previousValue;
- this.newValue = newValue;
- }
- private ExchangeLong(Object target, Integer attributeCode, long previousValue, long newValue) {
- super(target,attributeCode);
- this.previousValue = previousValue;
- this.newValue = newValue;
- }
-
- private ExchangeLong(ExchangeLong rhs) {
- super(rhs);
- this.previousValue = rhs.previousValue;
- this.newValue = rhs.newValue;
- }
-
- public synchronized long getPreviousValue() {
- return previousValue;
- }
-
- public synchronized long getNewValue() {
- return newValue;
- }
-
- /**
- * Returns a string representing the current state of the object.
- * @return the string representation of this instance.
- */
- public String toString() {
- return getActionDescription() + "; new value = " + newValue + ", previous value = " + previousValue; //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- /**
- * Return a deep cloned instance of this object. Subclasses must override
- * this method.
- * @return the object that is the clone of this instance.
- */
- public synchronized Object clone() {
- return new ExchangeLong(this);
- }
-
- /**
- * Returns true if the specified object is semantically equal to this instance.
- * Note: this method is consistent with <code>compareTo()</code>.
- * <p>
- * @param obj the object that this instance is to be compared to.
- * @return whether the object is equal to this object.
- */
- public synchronized boolean equals(Object obj) {
- // Check if instances are identical ...
- if (this == obj) {
- return true;
- }
-
- // Check if object can be compared to this one
- // (this includes checking for null ) ...
- if (obj instanceof ExchangeLong) {
- ExchangeLong that = (ExchangeLong)obj;
- return (this.getNewValue() == that.getNewValue() && this.getPreviousValue() == that.getPreviousValue());
- }
-
- // Otherwise not comparable ...
- return false;
- }
-
- /**
- * Obtain the definition of the action that undoes this action definition. If a modification action with the
- * returned action definition is applied to the same target (when the state is such as that left by
- * the original modification action), the resulting target will be left in a state that is identical to the target
- * before either action were applied.
- * @return the action definition that undoes this action definition.
- */
- public synchronized ActionDefinition getUndoActionDefinition() {
- return new ExchangeLong(this.getTarget(),this.getAttributeCode(),this.newValue, this.previousValue);
- }
-}
-
-
-
Deleted: trunk/common-internal/src/main/java/com/metamatrix/common/actions/ExchangeShort.java
===================================================================
--- trunk/common-internal/src/main/java/com/metamatrix/common/actions/ExchangeShort.java 2009-04-29 20:16:12 UTC (rev 852)
+++ trunk/common-internal/src/main/java/com/metamatrix/common/actions/ExchangeShort.java 2009-04-30 21:31:54 UTC (rev 853)
@@ -1,109 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package com.metamatrix.common.actions;
-
-public class ExchangeShort extends ExchangePrimitive {
- private short previousValue;
-
- private short newValue;
-
- public ExchangeShort(Object target, AttributeDefinition attribute, short previousValue, short newValue) {
- super(target,attribute);
- this.previousValue = previousValue;
- this.newValue = newValue;
- }
- private ExchangeShort(Object target, Integer attributeCode, short previousValue, short newValue) {
- super(target,attributeCode);
- this.previousValue = previousValue;
- this.newValue = newValue;
- }
-
- private ExchangeShort(ExchangeShort rhs) {
- super(rhs);
- this.previousValue = rhs.previousValue;
- this.newValue = rhs.newValue;
- }
-
- public synchronized short getPreviousValue() {
- return previousValue;
- }
-
- public synchronized short getNewValue() {
- return newValue;
- }
-
- /**
- * Returns a string representing the current state of the object.
- * @return the string representation of this instance.
- */
- public String toString() {
- return getActionDescription() + "; new value = " + newValue + ", previous value = " + previousValue; //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- /**
- * Return a deep cloned instance of this object. Subclasses must override
- * this method.
- * @return the object that is the clone of this instance.
- */
- public synchronized Object clone() {
- return new ExchangeShort(this);
- }
-
- /**
- * Returns true if the specified object is semantically equal to this instance.
- * Note: this method is consistent with <code>compareTo()</code>.
- * <p>
- * @param obj the object that this instance is to be compared to.
- * @return whether the object is equal to this object.
- */
- public synchronized boolean equals(Object obj) {
- // Check if instances are identical ...
- if (this == obj) {
- return true;
- }
-
- // Check if object can be compared to this one
- // (this includes checking for null ) ...
- if (obj instanceof ExchangeShort) {
- ExchangeShort that = (ExchangeShort)obj;
- return (this.getNewValue() == that.getNewValue() && this.getPreviousValue() == that.getPreviousValue());
- }
-
- // Otherwise not comparable ...
- return false;
- }
-
- /**
- * Obtain the definition of the action that undoes this action definition. If a modification action with the
- * returned action definition is applied to the same target (when the state is such as that left by
- * the original modification action), the resulting target will be left in a state that is identical to the target
- * before either action were applied.
- * @return the action definition that undoes this action definition.
- */
- public synchronized ActionDefinition getUndoActionDefinition() {
- return new ExchangeShort(this.getTarget(),this.getAttributeCode(),this.newValue, this.previousValue);
- }
-}
-
-
-
Modified: trunk/common-internal/src/main/java/com/metamatrix/common/config/model/BasicConfigurationObjectEditor.java
===================================================================
--- trunk/common-internal/src/main/java/com/metamatrix/common/config/model/BasicConfigurationObjectEditor.java 2009-04-29 20:16:12 UTC (rev 852)
+++ trunk/common-internal/src/main/java/com/metamatrix/common/config/model/BasicConfigurationObjectEditor.java 2009-04-30 21:31:54 UTC (rev 853)
@@ -22,11 +22,47 @@
package com.metamatrix.common.config.model;
-import java.util.*;
+import java.util.Collection;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Properties;
import com.metamatrix.common.CommonPlugin;
-import com.metamatrix.common.actions.*;
-import com.metamatrix.common.config.api.*;
+import com.metamatrix.common.actions.AbstractObjectEditor;
+import com.metamatrix.common.actions.ActionDefinition;
+import com.metamatrix.common.actions.AddObject;
+import com.metamatrix.common.actions.CreateObject;
+import com.metamatrix.common.actions.DestroyObject;
+import com.metamatrix.common.actions.ExchangeBoolean;
+import com.metamatrix.common.actions.ExchangeObject;
+import com.metamatrix.common.actions.RemoveObject;
+import com.metamatrix.common.config.api.AuthenticationProvider;
+import com.metamatrix.common.config.api.ComponentDefn;
+import com.metamatrix.common.config.api.ComponentObject;
+import com.metamatrix.common.config.api.ComponentObjectID;
+import com.metamatrix.common.config.api.ComponentType;
+import com.metamatrix.common.config.api.ComponentTypeDefn;
+import com.metamatrix.common.config.api.ComponentTypeDefnID;
+import com.metamatrix.common.config.api.ComponentTypeID;
+import com.metamatrix.common.config.api.Configuration;
+import com.metamatrix.common.config.api.ConfigurationID;
+import com.metamatrix.common.config.api.ConfigurationObjectEditor;
+import com.metamatrix.common.config.api.ConnectorBinding;
+import com.metamatrix.common.config.api.DeployedComponent;
+import com.metamatrix.common.config.api.DeployedComponentID;
+import com.metamatrix.common.config.api.Host;
+import com.metamatrix.common.config.api.HostID;
+import com.metamatrix.common.config.api.PropDefnAllowedValue;
+import com.metamatrix.common.config.api.PropDefnAllowedValueID;
+import com.metamatrix.common.config.api.ResourceDescriptor;
+import com.metamatrix.common.config.api.RuntimeMetadataServiceComponentType;
+import com.metamatrix.common.config.api.ServiceComponentDefn;
+import com.metamatrix.common.config.api.ServiceComponentDefnID;
+import com.metamatrix.common.config.api.SharedResource;
+import com.metamatrix.common.config.api.VMComponentDefn;
+import com.metamatrix.common.config.api.VMComponentDefnID;
import com.metamatrix.common.config.api.exceptions.ConfigurationException;
import com.metamatrix.common.config.api.exceptions.InvalidComponentException;
import com.metamatrix.common.log.LogConfiguration;
@@ -39,7 +75,6 @@
import com.metamatrix.common.util.LogCommonConstants;
import com.metamatrix.core.id.ObjectIDFactory;
import com.metamatrix.core.id.UUIDFactory;
-import com.metamatrix.core.util.Assertion;
/**
* BasicConfigurationObjectEditor provides the update capabiltiy to the implemented versions
@@ -339,38 +374,6 @@
}
}
*/
- } else if ( action instanceof ExchangeInt ) {
-// ExchangeInt anAction = (ExchangeInt) action;
-/*
- if ( target instanceof BasicDatabase ) {
- BasicDatabase db = (BasicDatabase) target;
- if (anAction.getAttributeCode().intValue() == ConfigurationModel.Attribute.MAXIMUM_RESULTS_SIZE.getCode()) {
- db.setMaximumResultsSize(anAction.getPreviousValue());
- } else if (anAction.getAttributeCode().intValue() == ConfigurationModel.Attribute.MAXIMUM_SET_CRITERIA_SIZE.getCode()) {
- db.setMaximumSetCriteriaSize(anAction.getPreviousValue());
- }
- } else if ( target instanceof BasicDataElement ) {
- BasicDataElement de = (BasicDataElement) target;
- if (anAction.getAttributeCode().intValue() == ConfigurationModel.Attribute.MAXIMUM_SCALE.getCode()) {
- BasicElementType et = (BasicElementType) de.getElementType();
- et.setMaximumScale(anAction.getPreviousValue());
- } else if (anAction.getAttributeCode().intValue() == ConfigurationModel.Attribute.MINIMUM_SCALE.getCode()) {
- BasicElementType et = (BasicElementType) de.getElementType();
- et.setMinimumScale(anAction.getPreviousValue());
- }
- }
-*/
- } else if ( action instanceof ExchangeLong ) {
-// ExchangeLong anAction = (ExchangeLong) action;
-/*
- if ( target instanceof BasicDataElement ) {
- BasicDataElement de = (BasicDataElement) target;
- if (anAction.getAttributeCode().intValue() == ConfigurationModel.Attribute.COLUMN_SIZE.getCode()) {
- BasicElementType et = (BasicElementType) de.getElementType();
- et.setColumnSize(anAction.getPreviousValue());
- }
- }
-*/
} else if ( action instanceof ExchangeBoolean ) {
ExchangeBoolean anAction = (ExchangeBoolean) action;
if ( target instanceof BasicConfiguration ) {
15 years, 7 months
teiid SVN: r852 - in trunk/engine/src/test/java/com/metamatrix/query: processor and 2 other directories.
by teiid-commits@lists.jboss.org
Author: loleary
Date: 2009-04-29 16:16:12 -0400 (Wed, 29 Apr 2009)
New Revision: 852
Modified:
trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestOptimizer.java
trunk/engine/src/test/java/com/metamatrix/query/processor/TestProcessor.java
trunk/engine/src/test/java/com/metamatrix/query/resolver/TestResolver.java
trunk/engine/src/test/java/com/metamatrix/query/rewriter/TestQueryRewriter.java
Log:
TEIID-539: Added test cases for use of BETWEEN expression
Reviewed by: jhelbling
Modified: trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestOptimizer.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestOptimizer.java 2009-04-29 18:47:52 UTC (rev 851)
+++ trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestOptimizer.java 2009-04-29 20:16:12 UTC (rev 852)
@@ -7187,6 +7187,91 @@
helpPlan(sql, FakeMetadataFactory.exampleBQT(), new String[] {});
}
+ /**
+ * Test <code>QueryOptimizer</code>'s ability to plan a fully-pushed-down
+ * query containing a <code>BETWEEN</code> comparison in the queries
+ * <code>WHERE</code> statement.
+ * <p>
+ * For example:
+ * <p>
+ * SELECT * FROM pm1.g1 WHERE e2 BETWEEN 1 AND 2
+ */
+ public void testBetween() {
+ helpPlan("select * from pm1.g1 where e2 between 1 and 2", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
+ new String[] { "SELECT pm1.g1.e1, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4 FROM pm1.g1 WHERE (e2 >= 1) AND (e2 <= 2)"} ); //$NON-NLS-1$
+ }
+
+ /**
+ * Test <code>QueryOptimizer</code>'s ability to plan a fully-pushed-down
+ * query containing a <code>CASE</code> expression in which a
+ * <code>BETWEEN</code> comparison is used in the queries
+ * <code>SELECT</code> statement.
+ * <p>
+ * For example:
+ * <p>
+ * SELECT CASE WHEN e2 BETWEEN 3 AND 5 THEN e2 ELSE -1 END FROM pm1.g1
+ */
+ public void testBetweenInCase() {
+ FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+ BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
+ caps.setCapabilitySupport(Capability.QUERY_SEARCHED_CASE, true);
+ capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+ helpPlan("select case when e2 between 3 and 5 then e2 else -1 end from pm1.g1", //$NON-NLS-1$
+ FakeMetadataFactory.example1Cached(), null, capFinder,
+ new String[] { "SELECT CASE WHEN (e2 >= 3) AND (e2 <= 5) THEN e2 ELSE -1 END FROM pm1.g1"}, //$NON-NLS-1$
+ TestOptimizer.SHOULD_SUCCEED);
+ }
+
+ /**
+ * Test <code>QueryOptimizer</code>'s ability to plan a fully-pushed-down
+ * query containing an aggregate SUM with a <code>CASE</code> expression
+ * in which a <code>BETWEEN</code> comparison is used in the queries
+ * <code>SELECT</code> statement.
+ * <p>
+ * For example:
+ * <p>
+ * SELECT SUM(CASE WHEN e2 BETWEEN 3 AND 5 THEN e2 ELSE -1 END) FROM pm1.g1
+ */
+ public void testBetweenInCaseInSum() {
+ FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+ BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
+ caps.setCapabilitySupport(Capability.QUERY_SEARCHED_CASE, true);
+ caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
+ caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_SUM, true);
+ capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+ helpPlan("select sum(case when e2 between 3 and 5 then e2 else -1 end) from pm1.g1", //$NON-NLS-1$
+ FakeMetadataFactory.example1Cached(), null, capFinder,
+ new String[] { "SELECT SUM(CASE WHEN (e2 >= 3) AND (e2 <= 5) THEN e2 ELSE -1 END) FROM pm1.g1"}, //$NON-NLS-1$
+ TestOptimizer.SHOULD_SUCCEED);
+ }
+
+ /**
+ * Test <code>QueryOptimizer</code>'s ability to plan a fully-pushed-down
+ * query containing an aggregate SUM with a <code>CASE</code> expression
+ * in which a <code>BETWEEN</code> comparison is used in the queries
+ * <code>SELECT</code> statement and a GROUP BY is specified.
+ * <p>
+ * For example:
+ * <p>
+ * SELECT e1, SUM(CASE WHEN e2 BETWEEN 3 AND 5 THEN e2 ELSE -1 END)
+ * FROM pm1.g1 GROUP BY e1
+ */
+ public void testBetweenInCaseInSumWithGroupBy() {
+ FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+ BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
+ caps.setCapabilitySupport(Capability.QUERY_SEARCHED_CASE, true);
+ caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
+ caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_SUM, true);
+ capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+ helpPlan("select sum(case when e2 between 3 and 5 then e2 else -1 end) from pm1.g1 group by e1", //$NON-NLS-1$
+ FakeMetadataFactory.example1Cached(), null, capFinder,
+ new String[] { "SELECT SUM(CASE WHEN (e2 >= 3) AND (e2 <= 5) THEN e2 ELSE -1 END) FROM pm1.g1 GROUP BY e1"}, //$NON-NLS-1$
+ TestOptimizer.SHOULD_SUCCEED);
+ }
+
private static final boolean DEBUG = false;
}
Modified: trunk/engine/src/test/java/com/metamatrix/query/processor/TestProcessor.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/processor/TestProcessor.java 2009-04-29 18:47:52 UTC (rev 851)
+++ trunk/engine/src/test/java/com/metamatrix/query/processor/TestProcessor.java 2009-04-29 20:16:12 UTC (rev 852)
@@ -256,7 +256,7 @@
id = processor.getResultsID();
processor.process();
assertEquals(0, bufferMgr.getPinnedCount());
- examineResults(expectedResults, bufferMgr, processor.getResultsID());
+ if ( expectedResults != null ) examineResults(expectedResults, bufferMgr, processor.getResultsID());
} finally {
bufferMgr.removeTupleSource(id);
}
@@ -4439,6 +4439,134 @@
helpProcess(plan, dataManager, expected);
}
+ /**
+ * Test <code>QueryProcessor</code>'s ability to process a query containing
+ * a <code>CASE</code> expression in which a <code>BETWEEN</code>
+ * comparison is used in the queries <code>SELECT</code> statement.
+ * <p>
+ * For example:
+ * <p>
+ * SELECT CASE WHEN e2 BETWEEN 3 AND 5 THEN e2 ELSE -1 END FROM pm1.g1
+ */
+ public void testBetweenInCase() {
+ // Create query
+ final String sql = "SELECT CASE WHEN e2 BETWEEN 3 AND 5 THEN e2 ELSE -1 END FROM pm1.g1"; //$NON-NLS-1$
+
+ // Create expected results
+ List[] expected = new List[] {
+ Arrays.asList(new Object[] { new Integer(-1) }),
+ Arrays.asList(new Object[] { new Integer(-1) }),
+ Arrays.asList(new Object[] { new Integer(3) }),
+ Arrays.asList(new Object[] { new Integer(-1) }),
+ Arrays.asList(new Object[] { new Integer(-1) }),
+ Arrays.asList(new Object[] { new Integer(-1) })
+ };
+
+ // Construct data manager with data
+ FakeDataManager dataManager = new FakeDataManager();
+ sampleData1(dataManager);
+
+ // Plan query
+ ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+ // Run query
+ helpProcess(plan, dataManager, expected);
+ }
+
+ /**
+ * Test <code>QueryProcessor</code>'s ability to process a query containing
+ * an aggregate SUM with a <code>CASE</code> expression in which a
+ * <code>BETWEEN</code> comparison is used in the queries <code>SELECT</code>
+ * statement.
+ * <p>
+ * For example:
+ * <p>
+ * SELECT SUM(CASE WHEN e2 BETWEEN 3 AND 5 THEN e2 ELSE -1 END) FROM pm1.g1
+ */
+ public void testBetweenInCaseInSum() {
+ // Create query
+ final String sql = "SELECT SUM(CASE WHEN e2 BETWEEN 3 AND 5 THEN e2 ELSE -1 END) FROM pm1.g1"; //$NON-NLS-1$
+
+ // Create expected results
+ List[] expected = new List[] {
+ Arrays.asList(new Object[] { new Long(-2) })
+ };
+
+ // Construct data manager with data
+ FakeDataManager dataManager = new FakeDataManager();
+ sampleData1(dataManager);
+
+ // Plan query
+ ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+ // Run query
+ helpProcess(plan, dataManager, expected);
+ }
+
+ /**
+ * Test <code>QueryProcessor</code>'s ability to process a query containing
+ * an aggregate SUM with a <code>CASE</code> expression in which a
+ * <code>BETWEEN</code> comparison is used in the queries <code>SELECT</code>
+ * statement and a GROUP BY is specified.
+ * <p>
+ * For example:
+ * <p>
+ * SELECT e1, SUM(CASE WHEN e2 BETWEEN 3 AND 5 THEN e2 ELSE -1 END)
+ * FROM pm1.g1 GROUP BY e1 ORDER BY e1
+ */
+ public void testBetweenInCaseInSumWithGroupBy() {
+ // Create query
+ final String sql = "SELECT e1, SUM(CASE WHEN e2 BETWEEN 3 AND 5 THEN e2 ELSE -1 END) FROM pm1.g1 GROUP BY e1 ORDER BY e1"; //$NON-NLS-1$
+
+ // Create expected results
+ List[] expected = new List[] {
+ Arrays.asList(new Object[] { null, new Long(-1) }),
+ Arrays.asList(new Object[] { "a", new Long(1) }), //$NON-NLS-1$
+ Arrays.asList(new Object[] { "b", new Long(-1) }), //$NON-NLS-1$
+ Arrays.asList(new Object[] { "c", new Long(-1) }) //$NON-NLS-1$
+ };
+
+ // Construct data manager with data
+ FakeDataManager dataManager = new FakeDataManager();
+ sampleData1(dataManager);
+
+ // Plan query
+ ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+ // Run query
+ helpProcess(plan, dataManager, expected);
+ }
+
+ /**
+ * Test <code>QueryProcessor</code>'s ability to process a query containing
+ * an aggregate COUNT with a <code>CASE</code> expression in which a
+ * <code>BETWEEN</code> comparison is used in the queries <code>SELECT</code>
+ * statement.
+ * <p>
+ * For example:
+ * <p>
+ * SELECT COUNT(CASE WHEN e2 BETWEEN 3 AND 5 THEN e2 END) FROM pm1.g1
+ */
+ public void testBetweenInCaseInCount() {
+ // Create query
+ final String sql = "SELECT COUNT(CASE WHEN e2 BETWEEN 3 AND 5 THEN e2 END) FROM pm1.g1"; //$NON-NLS-1$
+
+ // Create expected results
+ List[] expected = new List[] {
+ Arrays.asList(new Object[] { new Integer(1) })
+ };
+
+ // Construct data manager with data
+ FakeDataManager dataManager = new FakeDataManager();
+ sampleData1(dataManager);
+
+ // Plan query
+ ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+ // Run query
+ helpProcess(plan, dataManager, expected);
+ }
+
public void testCase() {
// Create query
String sql = "SELECT e2, CASE e2 WHEN 1 THEN 2 ELSE 3 END FROM pm1.g1 WHERE e2 BETWEEN 1 AND 2"; //$NON-NLS-1$
Modified: trunk/engine/src/test/java/com/metamatrix/query/resolver/TestResolver.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/resolver/TestResolver.java 2009-04-29 18:47:52 UTC (rev 851)
+++ trunk/engine/src/test/java/com/metamatrix/query/resolver/TestResolver.java 2009-04-29 20:16:12 UTC (rev 852)
@@ -4656,5 +4656,47 @@
public void testSecondPassFunctionResolving() {
helpResolve("SELECT pm1.g1.e1 FROM pm1.g1 where lower(?) = e1 "); //$NON-NLS-1$
}
+
+ /**
+ * Test <code>QueryResolver</code>'s ability to resolve a query that
+ * contains an aggregate <code>SUM</code> which uses a <code>CASE</code>
+ * expression which contains <code>BETWEEN</code> criteria as its value.
+ * <p>
+ * For example:
+ * <p>
+ * SELECT SUM(CASE WHEN e2 BETWEEN 3 AND 5 THEN e2 ELSE -1 END) FROM pm1.g1
+ */
+ public void testAggregateWithBetweenInCaseInSelect() {
+ String sql = "SELECT SUM(CASE WHEN e2 BETWEEN 3 AND 5 THEN e2 ELSE -1 END) FROM pm1.g1"; //$NON-NLS-1$
+ helpResolve(sql);
+ }
+ /**
+ * Test <code>QueryResolver</code>'s ability to resolve a query that
+ * contains a <code>CASE</code> expression which contains
+ * <code>BETWEEN</code> criteria in the queries <code>SELECT</code> clause.
+ * <p>
+ * For example:
+ * <p>
+ * SELECT CASE WHEN e2 BETWEEN 3 AND 5 THEN e2 ELSE -1 END FROM pm1.g1
+ */
+ public void testBetweenInCaseInSelect() {
+ String sql = "SELECT CASE WHEN e2 BETWEEN 3 AND 5 THEN e2 ELSE -1 END FROM pm1.g1"; //$NON-NLS-1$
+ helpResolve(sql);
+ }
+
+ /**
+ * Test <code>QueryResolver</code>'s ability to resolve a query that
+ * contains a <code>CASE</code> expression which contains
+ * <code>BETWEEN</code> criteria in the queries <code>WHERE</code> clause.
+ * <p>
+ * For example:
+ * <p>
+ * SELECT * FROM pm1.g1 WHERE e3 = CASE WHEN e2 BETWEEN 3 AND 5 THEN e2 ELSE -1 END
+ */
+ public void testBetweenInCase() {
+ String sql = "SELECT * FROM pm1.g1 WHERE e3 = CASE WHEN e2 BETWEEN 3 AND 5 THEN e2 ELSE -1 END"; //$NON-NLS-1$
+ helpResolve(sql);
+ }
+
}
\ No newline at end of file
Modified: trunk/engine/src/test/java/com/metamatrix/query/rewriter/TestQueryRewriter.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/rewriter/TestQueryRewriter.java 2009-04-29 18:47:52 UTC (rev 851)
+++ trunk/engine/src/test/java/com/metamatrix/query/rewriter/TestQueryRewriter.java 2009-04-29 20:16:12 UTC (rev 852)
@@ -62,6 +62,7 @@
import com.metamatrix.query.sql.symbol.ExpressionSymbol;
import com.metamatrix.query.sql.symbol.GroupSymbol;
import com.metamatrix.query.sql.symbol.Reference;
+import com.metamatrix.query.sql.symbol.SearchedCaseExpression;
import com.metamatrix.query.sql.symbol.SingleElementSymbol;
import com.metamatrix.query.sql.visitor.CorrelatedReferenceCollectorVisitor;
import com.metamatrix.query.unittest.FakeMetadataFacade;
@@ -2103,5 +2104,120 @@
}
}
-
+
+ /**
+ * Test <code>QueryRewriter</code>'s ability to rewrite a query that
+ * contains an aggregate function which uses a <code>CASE</code>
+ * expression which contains <code>BETWEEN</code> criteria as its value.
+ * <p>
+ * An aggregate function list is defined and queries are created that
+ * use each function from the list. The list includes:
+ * <p>
+ * "SUM", "MAX", "MIN", "AVG", "COUNT"
+ * <p>
+ * It is expected that the BETWEEN expression will be rewritten as
+ * <code>CompoundCriteria</code>.
+ * <p>
+ * <table>
+ * <tr><th align="left" colspan=2>For example:
+ * <tr><td width="10*"><td>SELECT SUM(CASE WHEN e2 BETWEEN 3 AND 5
+ * THEN e2 ELSE -1 END) FROM pm1.g1
+ * <tr><th align="left" colspan=2>Is rewritten as:
+ * <tr><td width="10*"><td>SELECT SUM(CASE WHEN (e2 >= 3) AND (e2 <= 5)
+ * THEN e2 ELSE -1 END) FROM pm1.g1
+ * </table>
+ *
+ * @see com.metamatrix.query.rewriter.QueryRewriter
+ * @see com.metamatrix.query.sql.lang.BetweenCriteria
+ * @see com.metamatrix.query.sql.lang.CompoundCriteria
+ * @see com.metamatrix.query.sql.symbol.AggregateSymbol
+ * @see com.metamatrix.query.sql.symbol.SearchedCaseExpression
+ */
+ public void testAggregateWithBetweenInCaseInSelect() {
+ // Define a list of aggregates to test against
+ List<String> aggregateCommands = Arrays.asList( new String[] { "SUM", "MAX", "MIN", "AVG", "COUNT" } ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
+
+ // Define a query and the expected rewritten query
+ // ?AGGREGATE? represents the string substitution for an aggregate from aggregateCommands
+ String sqlBefore = "SELECT ?AGGREGATE?(CASE WHEN e2 BETWEEN 3 AND 5 THEN e2 ELSE -1 END) FROM pm1.g1"; //$NON-NLS-1$
+ String sqlAfter = "SELECT ?AGGREGATE?(CASE WHEN (e2 >= 3) AND (e2 <= 5) THEN e2 ELSE -1 END) FROM pm1.g1"; //$NON-NLS-1$
+
+ // Iterate through the aggregateCommands
+ for ( String aCmd : aggregateCommands ) {
+ // Replace ?AGGREGATE? with the command from aggregateCommands
+ String sql = sqlBefore.replace("?AGGREGATE?", aCmd); //$NON-NLS-1$
+ String exSql = sqlAfter.replace("?AGGREGATE?", aCmd); //$NON-NLS-1$
+ // Test QueryRewriter
+ Command cmd = helpTestRewriteCommand( sql, exSql );
+ // Check the rewritten command to verify that CompundCriteria replaced BetweenCriteria
+ CompoundCriteria ccrit = (CompoundCriteria) ((SearchedCaseExpression) ((ExpressionSymbol) cmd.getProjectedSymbols().get(0)).getExpression()).getWhen().get(0);
+ assertEquals( "e2 >= 3", ccrit.getCriteria(0).toString() ); //$NON-NLS-1$
+ assertEquals( "e2 <= 5", ccrit.getCriteria(1).toString() ); //$NON-NLS-1$
+ }
+ }
+
+ /**
+ * Test <code>QueryRewriter</code>'s ability to rewrite a query that
+ * contains a <code>CASE</code> expression which contains
+ * <code>BETWEEN</code> criteria in the queries <code>SELECT</code> clause.
+ * <p>
+ * It is expected that the BETWEEN expression will be rewritten as
+ * <code>CompoundCriteria</code>.
+ * <p>
+ * <table>
+ * <tr><th align="left" colspan=2>For example:
+ * <tr><td width="10*"><td>SELECT CASE WHEN e2 BETWEEN 3 AND 5 THEN e2
+ * ELSE -1 END FROM pm1.g1
+ * <tr><th align="left" colspan=2>Is rewritten as:
+ * <tr><td width="10*"><td>SELECT CASE WHEN (e2 >= 3) AND (e2 <= 5) THEN e2
+ * ELSE -1 END FROM pm1.g1
+ * </table>
+ *
+ * @see com.metamatrix.query.rewriter.QueryRewriter
+ * @see com.metamatrix.query.sql.lang.BetweenCriteria
+ * @see com.metamatrix.query.sql.lang.CompoundCriteria
+ * @see com.metamatrix.query.sql.symbol.SearchedCaseExpression
+ */
+ public void testBetweenInCaseInSelect() {
+ String sqlBefore = "SELECT CASE WHEN e2 BETWEEN 3 AND 5 THEN e2 ELSE -1 END FROM pm1.g1"; //$NON-NLS-1$
+ String sqlAfter = "SELECT CASE WHEN (e2 >= 3) AND (e2 <= 5) THEN e2 ELSE -1 END FROM pm1.g1"; //$NON-NLS-1$
+
+ Command cmd = helpTestRewriteCommand( sqlBefore, sqlAfter );
+ CompoundCriteria ccrit = (CompoundCriteria) ((SearchedCaseExpression) ((ExpressionSymbol) cmd.getProjectedSymbols().get(0)).getExpression()).getWhen().get(0);
+ assertEquals( "e2 >= 3", ccrit.getCriteria(0).toString() ); //$NON-NLS-1$
+ assertEquals( "e2 <= 5", ccrit.getCriteria(1).toString() ); //$NON-NLS-1$
+ }
+
+ /**
+ * Test <code>QueryRewriter</code>'s ability to rewrite a query that
+ * contains a <code>CASE</code> expression which contains
+ * <code>BETWEEN</code> criteria in the queries <code>WHERE</code> clause.
+ * <p>
+ * It is expected that the BETWEEN expression will be rewritten as
+ * <code>CompoundCriteria</code>.
+ * <p>
+ * <table>
+ * <tr><th align="left" colspan=2>For example:
+ * <tr><td width="10*"><td>SELECT * FROM pm1.g1 WHERE e3 = CASE WHEN e2
+ * BETWEEN 3 AND 5 THEN e2 ELSE -1 END
+ * <tr><th align="left" colspan=2>Is rewritten as:
+ * <tr><td width="10*"><td>SELECT * FROM pm1.g1 WHERE e3 = CASE WHEN
+ * (e2 >= 3) AND (e2 <= 5) THEN e2 ELSE -1 END
+ * </table>
+ *
+ * @see com.metamatrix.query.rewriter.QueryRewriter
+ * @see com.metamatrix.query.sql.lang.BetweenCriteria
+ * @see com.metamatrix.query.sql.lang.CompoundCriteria
+ * @see com.metamatrix.query.sql.symbol.SearchedCaseExpression
+ */
+ public void testBetweenInCase() {
+ String sqlBefore = "SELECT * FROM pm1.g1 WHERE e3 = CASE WHEN e2 BETWEEN 3 AND 5 THEN e2 ELSE -1 END"; //$NON-NLS-1$
+ String sqlAfter = "SELECT * FROM pm1.g1 WHERE e3 = CASE WHEN (e2 >= 3) AND (e2 <= 5) THEN e2 ELSE -1 END"; //$NON-NLS-1$
+
+ Command cmd = helpTestRewriteCommand( sqlBefore, sqlAfter );
+ CompoundCriteria ccrit = (CompoundCriteria) ((SearchedCaseExpression) ((CompareCriteria) ((Query) cmd).getCriteria()).getRightExpression()).getWhen().get(0);
+ assertEquals( "e2 >= 3", ccrit.getCriteria(0).toString() ); //$NON-NLS-1$
+ assertEquals( "e2 <= 5", ccrit.getCriteria(1).toString() ); //$NON-NLS-1$
+ }
+
}
15 years, 7 months
teiid SVN: r851 - trunk/server/src/main/java/com/metamatrix/metadata/runtime/model.
by teiid-commits@lists.jboss.org
Author: vhalbert(a)redhat.com
Date: 2009-04-29 14:47:52 -0400 (Wed, 29 Apr 2009)
New Revision: 851
Modified:
trunk/server/src/main/java/com/metamatrix/metadata/runtime/model/UpdateController.java
Log:
Teiid 538 - This fixes the problem with not exposing the exception, it was falling thru.
Modified: trunk/server/src/main/java/com/metamatrix/metadata/runtime/model/UpdateController.java
===================================================================
--- trunk/server/src/main/java/com/metamatrix/metadata/runtime/model/UpdateController.java 2009-04-29 18:41:39 UTC (rev 850)
+++ trunk/server/src/main/java/com/metamatrix/metadata/runtime/model/UpdateController.java 2009-04-29 18:47:52 UTC (rev 851)
@@ -346,17 +346,17 @@
BasicVirtualDatabaseID vdbID = null;
try {
- vdbID = (BasicVirtualDatabaseID) this.getReadTransaction().getVirtualDatabaseID(vdbInfo.getName(), null);
- if (vdbID != null) {
- vdbVersion = Integer.toString(Integer.parseInt(vdbID.getVersion()) + 1);
- VirtualDatabase latestVdb = RuntimeMetadataCatalog.getInstance().getVirtualDatabase(vdbID);
- createdBy = latestVdb.getCreatedBy();
- creationDate = latestVdb.getCreationDate();
- }
+ vdbID = (BasicVirtualDatabaseID) this.getReadTransaction().getVirtualDatabaseID(vdbInfo.getName(), null);
+ } catch (ManagedConnectionException e) {
+ throw new VirtualDatabaseException(e);
+ }
+ if (vdbID != null) {
+ vdbVersion = Integer.toString(Integer.parseInt(vdbID.getVersion()) + 1);
+ VirtualDatabase latestVdb = RuntimeMetadataCatalog.getInstance().getVirtualDatabase(vdbID);
+ createdBy = latestVdb.getCreatedBy();
+ creationDate = latestVdb.getCreationDate();
+ }
- } catch (Throwable e4) {
-
- }
vdbID = new BasicVirtualDatabaseID(vdbInfo.getName(), vdbVersion);
15 years, 7 months
teiid SVN: r850 - trunk/server/src/main/java/com/metamatrix/metadata/runtime/spi/jdbc.
by teiid-commits@lists.jboss.org
Author: vhalbert(a)redhat.com
Date: 2009-04-29 14:41:39 -0400 (Wed, 29 Apr 2009)
New Revision: 850
Modified:
trunk/server/src/main/java/com/metamatrix/metadata/runtime/spi/jdbc/JDBCTranslator.java
Log:
Teiid 538 - This fixes the invalid sql statement
Modified: trunk/server/src/main/java/com/metamatrix/metadata/runtime/spi/jdbc/JDBCTranslator.java
===================================================================
--- trunk/server/src/main/java/com/metamatrix/metadata/runtime/spi/jdbc/JDBCTranslator.java 2009-04-28 22:25:48 UTC (rev 849)
+++ trunk/server/src/main/java/com/metamatrix/metadata/runtime/spi/jdbc/JDBCTranslator.java 2009-04-29 18:41:39 UTC (rev 850)
@@ -119,23 +119,18 @@
+ JDBCNames.VirtualDatabases.TABLE_NAME
+ WHERE
+ "{fn ucase(" +JDBCNames.VirtualDatabases.ColumnName.VDB_NM + ")}=?" //$NON-NLS-1$ //$NON-NLS-2$
- + AND + JDBCNames.VirtualDatabases.ColumnName.VERSION_DATE + "=(" //$NON-NLS-1$
+
+ + AND + JDBCNames.VirtualDatabases.ColumnName.VDB_VERSION + "=(" //$NON-NLS-1$
+ SELECT + MAX + "(" //$NON-NLS-1$
- + JDBCNames.VirtualDatabases.ColumnName.VERSION_DATE +")" //$NON-NLS-1$
+ + JDBCNames.VirtualDatabases.ColumnName.VDB_VERSION +")" //$NON-NLS-1$
+ FROM
+ JDBCNames.VirtualDatabases.TABLE_NAME
+ WHERE
- + "{fn ucase(" +JDBCNames.VirtualDatabases.ColumnName.VDB_NM + ")}=?" //$NON-NLS-1$ //$NON-NLS-2$
- + AND
- + JDBCNames.VirtualDatabases.ColumnName.VDB_STATUS + "=" //$NON-NLS-1$
- + "(" + SELECT + MAX + "(" + JDBCNames.VirtualDatabases.ColumnName.VDB_STATUS + ")" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- + FROM
- + JDBCNames.VirtualDatabases.TABLE_NAME
- + WHERE
- + "{fn ucase(" +JDBCNames.VirtualDatabases.ColumnName.VDB_NM + ")}=?" //$NON-NLS-1$ //$NON-NLS-2$
+ + "{fn ucase(" +JDBCNames.VirtualDatabases.ColumnName.VDB_NM + ")}=? " //$NON-NLS-1$ //$NON-NLS-2$
+ AND + "(" + JDBCNames.VirtualDatabases.ColumnName.VDB_STATUS + "=" + VDBStatus.ACTIVE //$NON-NLS-1$ //$NON-NLS-2$
+ OR + JDBCNames.VirtualDatabases.ColumnName.VDB_STATUS + "=" + VDBStatus.ACTIVE_DEFAULT //$NON-NLS-1$
- +")))"; //$NON-NLS-1$
+ +") )"; //$NON-NLS-1$
+
public static final String SELECT_VIRTUAL_DATABASE_ID_LV
= SELECT + JDBCNames.VirtualDatabases.ColumnName.VDB_UID + "," //$NON-NLS-1$
@@ -145,13 +140,13 @@
+ JDBCNames.VirtualDatabases.TABLE_NAME
+ WHERE
+ "{fn ucase(" +JDBCNames.VirtualDatabases.ColumnName.VDB_NM + ")}=?" //$NON-NLS-1$ //$NON-NLS-2$
- + AND + JDBCNames.VirtualDatabases.ColumnName.VERSION_DATE + "=(" //$NON-NLS-1$
+ + AND + JDBCNames.VirtualDatabases.ColumnName.VDB_VERSION + "=(" //$NON-NLS-1$
+ SELECT + MAX + "(" //$NON-NLS-1$
- + JDBCNames.VirtualDatabases.ColumnName.VERSION_DATE +")" //$NON-NLS-1$
+ + JDBCNames.VirtualDatabases.ColumnName.VDB_VERSION +")" //$NON-NLS-1$
+ FROM
+ JDBCNames.VirtualDatabases.TABLE_NAME
+ WHERE
- + "{fn ucase(" +JDBCNames.VirtualDatabases.ColumnName.VDB_NM + ")}=?"; //$NON-NLS-1$ //$NON-NLS-2$
+ + "{fn ucase(" +JDBCNames.VirtualDatabases.ColumnName.VDB_NM + ")}=? )"; //$NON-NLS-1$ //$NON-NLS-2$
//select objects
public static final String SELECT_VIRTUAL_DATABASES
15 years, 7 months
teiid SVN: r849 - in trunk/engine/src: main/java/com/metamatrix/query/optimizer/relational/rules and 2 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2009-04-28 18:25:48 -0400 (Tue, 28 Apr 2009)
New Revision: 849
Modified:
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/PlanToProcessConverter.java
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleImplementJoinStrategy.java
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RulePlanSorts.java
trunk/engine/src/main/java/com/metamatrix/query/processor/relational/GroupingNode.java
trunk/engine/src/main/java/com/metamatrix/query/processor/relational/SortNode.java
trunk/engine/src/main/java/com/metamatrix/query/processor/relational/SortUtility.java
trunk/engine/src/main/java/com/metamatrix/query/processor/relational/TupleCollector.java
trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestLimit.java
trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestOptimizer.java
trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestOptionalJoins.java
trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestSortOptimization.java
Log:
TEIID-178, TEIID-175 adding support for a non blocking sort and general planning time sort optimization.
Modified: trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/PlanToProcessConverter.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/PlanToProcessConverter.java 2009-04-28 21:30:50 UTC (rev 848)
+++ trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/PlanToProcessConverter.java 2009-04-28 22:25:48 UTC (rev 849)
@@ -66,7 +66,6 @@
import com.metamatrix.query.processor.relational.MergeJoinStrategy.SortOption;
import com.metamatrix.query.processor.relational.SortUtility.Mode;
import com.metamatrix.query.resolver.util.ResolverUtil;
-import com.metamatrix.query.sql.LanguageObject;
import com.metamatrix.query.sql.lang.Command;
import com.metamatrix.query.sql.lang.Criteria;
import com.metamatrix.query.sql.lang.JoinType;
@@ -150,7 +149,6 @@
throws QueryPlannerException, MetaMatrixComponentException {
RelationalNode processNode = null;
- LanguageObject possiblyDependentObject = null;
switch(node.getType()) {
case NodeConstants.Types.PROJECT:
@@ -213,7 +211,6 @@
}
Criteria joinCrit = Criteria.combineCriteria(joinCrits);
jnode.setJoinCriteria(joinCrit);
- possiblyDependentObject = joinCrit;
processNode = jnode;
@@ -230,8 +227,6 @@
Criteria crit = (Criteria)node.getProperty(NodeConstants.Info.PROCEDURE_CRITERIA);
- possiblyDependentObject = crit;
-
if (crit != null) {
List references = (List)node.getProperty(NodeConstants.Info.PROCEDURE_INPUTS);
List defaults = (List)node.getProperty(NodeConstants.Info.PROCEDURE_DEFAULTS);
@@ -247,7 +242,6 @@
} else {
AccessNode aNode = null;
Command command = (Command) node.getProperty(NodeConstants.Info.ATOMIC_REQUEST);
- possiblyDependentObject = command;
Object modelID = node.getProperty(NodeConstants.Info.MODEL_ID);
if(node.hasBooleanProperty(NodeConstants.Info.IS_DEPENDENT_SET)) {
@@ -287,8 +281,7 @@
try {
if (command instanceof Query) {
processNode = correctProjectionForTempTable(node,
- aNode,
- possiblyDependentObject);
+ aNode);
}
} catch (QueryMetadataException err) {
throw new MetaMatrixComponentException(err);
@@ -314,7 +307,6 @@
SelectNode selnode = new SelectNode(getID());
selnode.setCriteria(crit);
processNode = selnode;
- possiblyDependentObject = crit;
break;
@@ -337,7 +329,7 @@
case NodeConstants.Types.GROUP:
GroupingNode gnode = new GroupingNode(getID());
gnode.setGroupingElements( (List) node.getProperty(NodeConstants.Info.GROUP_COLS) );
-
+ gnode.setRemoveDuplicates(node.hasBooleanProperty(NodeConstants.Info.IS_DUP_REMOVAL));
processNode = gnode;
break;
@@ -397,15 +389,14 @@
}
if(processNode != null) {
- processNode = prepareToAdd(node, processNode, possiblyDependentObject);
+ processNode = prepareToAdd(node, processNode);
}
return processNode;
}
private RelationalNode correctProjectionForTempTable(PlanNode node,
- AccessNode aNode,
- LanguageObject possiblyDependentObject) throws QueryMetadataException,
+ AccessNode aNode) throws QueryMetadataException,
MetaMatrixComponentException {
if (node.getGroups().size() != 1) {
return aNode;
@@ -425,15 +416,14 @@
pnode.setSelectSymbols(projectSymbols);
//if the following cast fails it means that we have a dependent temp table - that is not yet possible
- aNode = (AccessNode)prepareToAdd(node, aNode, possiblyDependentObject);
+ aNode = (AccessNode)prepareToAdd(node, aNode);
node.setProperty(NodeConstants.Info.OUTPUT_COLS, projectSymbols);
pnode.addChild(aNode);
return pnode;
}
private RelationalNode prepareToAdd(PlanNode node,
- RelationalNode processNode,
- LanguageObject possiblyDependentObject) {
+ RelationalNode processNode) {
// Set the output elements from the plan node
List cols = (List) node.getProperty(NodeConstants.Info.OUTPUT_COLS);
Modified: trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleImplementJoinStrategy.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleImplementJoinStrategy.java 2009-04-28 21:30:50 UTC (rev 848)
+++ trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleImplementJoinStrategy.java 2009-04-28 22:25:48 UTC (rev 849)
@@ -43,6 +43,7 @@
import com.metamatrix.query.optimizer.relational.plantree.NodeFactory;
import com.metamatrix.query.optimizer.relational.plantree.PlanNode;
import com.metamatrix.query.processor.relational.MergeJoinStrategy.SortOption;
+import com.metamatrix.query.sql.lang.JoinType;
import com.metamatrix.query.sql.lang.OrderBy;
import com.metamatrix.query.sql.symbol.SingleElementSymbol;
import com.metamatrix.query.util.CommandContext;
@@ -66,10 +67,23 @@
for (PlanNode joinNode : NodeEditor.findAllNodes(plan, NodeConstants.Types.JOIN, NodeConstants.Types.ACCESS)) {
JoinStrategyType stype = (JoinStrategyType) joinNode.getProperty(NodeConstants.Info.JOIN_STRATEGY);
- if (JoinStrategyType.MERGE.equals(stype)) {
- insertSort(joinNode.getFirstChild(), (List<SingleElementSymbol>) joinNode.getProperty(NodeConstants.Info.LEFT_EXPRESSIONS), joinNode, metadata, capabilitiesFinder);
- insertSort(joinNode.getLastChild(), (List<SingleElementSymbol>) joinNode.getProperty(NodeConstants.Info.RIGHT_EXPRESSIONS), joinNode, metadata, capabilitiesFinder);
+ if (!JoinStrategyType.MERGE.equals(stype)) {
+ continue;
}
+/* if (joinNode.getProperty(NodeConstants.Info.JOIN_TYPE) == JoinType.JOIN_INNER) {
+ //there is a possible optimization at runtime here based upon the cardinality
+ float leftCost = NewCalculateCostUtil.computeCostForTree(joinNode.getFirstChild(), metadata);
+ float rightCost = NewCalculateCostUtil.computeCostForTree(joinNode.getLastChild(), metadata);
+ if (leftCost != NewCalculateCostUtil.UNKNOWN_VALUE && leftCost < context.getProcessorBatchSize() * context.getProcessorBatchSize()
+ && rightCost != NewCalculateCostUtil.UNKNOWN_VALUE && rightCost > context.getProcessorBatchSize()) {
+ joinNode.setProperty(NodeConstants.Info.SORT_LEFT, SortOption.SORT);
+ joinNode.setProperty(NodeConstants.Info.SORT_RIGHT, SortOption.SORT);
+ continue;
+ }
+ }
+*/
+ insertSort(joinNode.getFirstChild(), (List<SingleElementSymbol>) joinNode.getProperty(NodeConstants.Info.LEFT_EXPRESSIONS), joinNode, metadata, capabilitiesFinder);
+ insertSort(joinNode.getLastChild(), (List<SingleElementSymbol>) joinNode.getProperty(NodeConstants.Info.RIGHT_EXPRESSIONS), joinNode, metadata, capabilitiesFinder);
}
return plan;
Modified: trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RulePlanSorts.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RulePlanSorts.java 2009-04-28 21:30:50 UTC (rev 848)
+++ trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RulePlanSorts.java 2009-04-28 22:25:48 UTC (rev 849)
@@ -22,6 +22,8 @@
package com.metamatrix.query.optimizer.relational.rules;
+import java.util.List;
+
import com.metamatrix.api.exception.MetaMatrixComponentException;
import com.metamatrix.api.exception.query.QueryMetadataException;
import com.metamatrix.api.exception.query.QueryPlannerException;
@@ -34,7 +36,9 @@
import com.metamatrix.query.optimizer.relational.plantree.NodeConstants;
import com.metamatrix.query.optimizer.relational.plantree.NodeEditor;
import com.metamatrix.query.optimizer.relational.plantree.PlanNode;
+import com.metamatrix.query.optimizer.relational.plantree.NodeConstants.Info;
import com.metamatrix.query.processor.relational.MergeJoinStrategy.SortOption;
+import com.metamatrix.query.sql.lang.JoinType;
import com.metamatrix.query.sql.lang.SetQuery;
import com.metamatrix.query.util.CommandContext;
@@ -49,11 +53,10 @@
AnalysisRecord analysisRecord, CommandContext context)
throws QueryPlannerException, QueryMetadataException,
MetaMatrixComponentException {
- optimizeSorts(false, plan);
- return plan;
+ return optimizeSorts(false, plan, plan);
}
- private void optimizeSorts(boolean parentBlocking, PlanNode node) {
+ private PlanNode optimizeSorts(boolean parentBlocking, PlanNode node, PlanNode root) {
node = NodeEditor.findNodePreOrder(node,
NodeConstants.Types.SORT
| NodeConstants.Types.DUP_REMOVE
@@ -61,7 +64,7 @@
| NodeConstants.Types.JOIN
| NodeConstants.Types.SET_OP, NodeConstants.Types.ACCESS);
if (node == null) {
- return;
+ return root;
}
switch (node.getType()) {
case NodeConstants.Types.SORT:
@@ -72,6 +75,33 @@
if (mergeSortWithDupRemoval(node)) {
node.setProperty(NodeConstants.Info.IS_DUP_REMOVAL, true);
}
+ List orderColumns = (List)node.getProperty(NodeConstants.Info.SORT_ORDER);
+ PlanNode possibleSort = NodeEditor.findNodePreOrder(node, NodeConstants.Types.GROUP | NodeConstants.Types.JOIN, NodeConstants.Types.SOURCE | NodeConstants.Types.ACCESS);
+ if (possibleSort != null) {
+ NodeConstants.Info expr = Info.GROUP_COLS;
+ if (possibleSort.getType() == NodeConstants.Types.JOIN) {
+ if (possibleSort.getProperty(NodeConstants.Info.JOIN_STRATEGY) != JoinStrategyType.MERGE
+ || possibleSort.getProperty(NodeConstants.Info.JOIN_TYPE) != JoinType.JOIN_INNER) {
+ break;
+ }
+ expr = Info.LEFT_EXPRESSIONS;
+ }
+ List exprs = (List)possibleSort.getProperty(expr);
+ if (exprs != null && exprs.containsAll(orderColumns)) {
+ exprs.removeAll(orderColumns);
+ orderColumns.addAll(exprs);
+ possibleSort.setProperty(expr, orderColumns);
+ if (node.getParent() == null) {
+ root = node.getFirstChild();
+ root.removeFromParent();
+ node = root;
+ } else {
+ PlanNode nextNode = node.getFirstChild();
+ NodeEditor.removeChildNode(node.getParent(), node);
+ node = nextNode;
+ }
+ }
+ }
break;
case NodeConstants.Types.DUP_REMOVE:
if (parentBlocking) {
@@ -80,6 +110,12 @@
}
break;
case NodeConstants.Types.GROUP:
+ if (!node.hasCollectionProperty(NodeConstants.Info.GROUP_COLS)) {
+ break;
+ }
+ if (mergeSortWithDupRemovalAcrossSource(node)) {
+ node.setProperty(NodeConstants.Info.IS_DUP_REMOVAL, true);
+ }
//TODO: check the join interesting order
parentBlocking = true;
break;
@@ -87,13 +123,20 @@
if (node.getProperty(NodeConstants.Info.JOIN_STRATEGY) != JoinStrategyType.MERGE) {
break;
}
+ /*
+ * Look under the left and the right sources for a dup removal operation
+ * join
+ * [project]
+ * source
+ * dup remove | union not all
+ */
parentBlocking = true;
PlanNode toTest = node.getFirstChild();
- if (mergeSortWithDupRemovalForJoin(toTest)) {
+ if (mergeSortWithDupRemovalAcrossSource(toTest)) {
node.setProperty(NodeConstants.Info.SORT_LEFT, SortOption.SORT_DISTINCT);
}
toTest = node.getLastChild();
- if (mergeSortWithDupRemovalForJoin(toTest)) {
+ if (mergeSortWithDupRemovalAcrossSource(toTest)) {
node.setProperty(NodeConstants.Info.SORT_RIGHT, SortOption.SORT_DISTINCT);
}
break;
@@ -107,18 +150,12 @@
break;
}
for (PlanNode child : node.getChildren()) {
- optimizeSorts(parentBlocking, child);
+ root = optimizeSorts(parentBlocking, child, root);
}
+ return root;
}
- /**
- * Look under the left and the right sources for a dup removal operation
- * join
- * [project]
- * source
- * dup remove | union not all
- */
- private boolean mergeSortWithDupRemovalForJoin(PlanNode toTest) {
+ private boolean mergeSortWithDupRemovalAcrossSource(PlanNode toTest) {
PlanNode source = NodeEditor.findNodePreOrder(toTest, NodeConstants.Types.SOURCE, NodeConstants.Types.ACCESS | NodeConstants.Types.JOIN);
return source != null && mergeSortWithDupRemoval(source);
}
Modified: trunk/engine/src/main/java/com/metamatrix/query/processor/relational/GroupingNode.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/processor/relational/GroupingNode.java 2009-04-28 21:30:50 UTC (rev 848)
+++ trunk/engine/src/main/java/com/metamatrix/query/processor/relational/GroupingNode.java 2009-04-28 22:25:48 UTC (rev 849)
@@ -59,6 +59,7 @@
// Grouping columns set by the planner
private List sortElements;
private List sortTypes;
+ private boolean removeDuplicates;
// Collection phase
private int phase = COLLECTION;
@@ -112,6 +113,10 @@
lastRow = null;
currentGroupTuple = null;
}
+
+ public void setRemoveDuplicates(boolean removeDuplicates) {
+ this.removeDuplicates = removeDuplicates;
+ }
/**
* Called by the planner to initialize the grouping node. Set the list of grouping
@@ -306,7 +311,7 @@
this.phase = GROUP;
} else {
this.sortUtility = new SortUtility(collectionID, sortElements,
- sortTypes, false, getBufferManager(),
+ sortTypes, removeDuplicates, getBufferManager(),
getConnectionID());
this.phase = SORT;
}
@@ -446,6 +451,7 @@
super.copy(this, clonedNode);
clonedNode.sortElements = sortElements;
clonedNode.sortTypes = sortTypes;
+ clonedNode.removeDuplicates = removeDuplicates;
return clonedNode;
}
@@ -465,6 +471,8 @@
}
props.put(PROP_GROUP_COLS, groupCols);
}
+
+ props.put(PROP_REMOVE_DUPS, this.removeDuplicates);
return props;
}
Modified: trunk/engine/src/main/java/com/metamatrix/query/processor/relational/SortNode.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/processor/relational/SortNode.java 2009-04-28 21:30:50 UTC (rev 848)
+++ trunk/engine/src/main/java/com/metamatrix/query/processor/relational/SortNode.java 2009-04-28 22:25:48 UTC (rev 849)
@@ -115,6 +115,8 @@
private void collectionPhase() throws BlockedException, TupleSourceNotFoundException, MetaMatrixComponentException, MetaMatrixProcessingException {
try {
collector.collectTuples();
+ } catch (BlockedOnMemoryException e) {
+ throw e;
} catch (BlockedException e) {
if (mode != Mode.DUP_REMOVE || !collector.collectedAny()) {
throw e;
Modified: trunk/engine/src/main/java/com/metamatrix/query/processor/relational/SortUtility.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/processor/relational/SortUtility.java 2009-04-28 21:30:50 UTC (rev 848)
+++ trunk/engine/src/main/java/com/metamatrix/query/processor/relational/SortUtility.java 2009-04-28 22:25:48 UTC (rev 849)
@@ -72,6 +72,7 @@
private Comparator comparator;
private TupleSourceID outputID;
+ private IndexedTupleSource outTs;
private boolean doneReading;
private int sortPhaseRow = 1;
private int phase = INITIAL_SORT;
@@ -237,7 +238,8 @@
}
protected void mergePhase() throws BlockedOnMemoryException, MetaMatrixComponentException, TupleSourceNotFoundException {
- TupleCollector outCollector = null;
+ appendOutput();
+ TupleCollector tempCollector = null;
while(this.activeTupleIDs.size() > 1) {
// Load and pin batch from sorted sublists while memory available
this.workingBatches = new ArrayList<TupleBatch>(activeTupleIDs.size());
@@ -297,11 +299,11 @@
// Output the row and update pointers
collector.addTuple(currentRow);
if (this.outputID != null && chosenBatchIndex != masterSortIndex && sortedIndex > masterSortIndex) {
- if (outCollector == null) {
+ if (tempCollector == null) {
tempOutId = createTupleSource();
- outCollector = new TupleCollector(tempOutId, this.bufferManager);
+ tempCollector = new TupleCollector(tempOutId, this.bufferManager);
}
- outCollector.addTuple(currentRow);
+ tempCollector.addTuple(currentRow);
}
incrementWorkingBatch(chosenBatchIndex, chosenBatch);
}
@@ -325,19 +327,11 @@
}
}
- if (outCollector != null) {
- outCollector.close();
- //transfer the new dup removed tuples to the output id
- TupleCollector tc = new TupleCollector(outputID, this.bufferManager);
- IndexedTupleSource ts = this.bufferManager.getTupleSource(outCollector.getTupleSourceID());
- try {
- while (ts.hasNext()) {
- tc.addTuple(ts.nextTuple());
- }
- } catch (MetaMatrixProcessingException e) {
- throw new MetaMatrixComponentException(e);
- }
- }
+ if (tempCollector != null) {
+ tempCollector.close();
+ this.outTs = this.bufferManager.getTupleSource(tempOutId);
+ appendOutput();
+ }
// Close sorted source (all others have been removed)
if (doneReading) {
@@ -355,6 +349,27 @@
this.phase = INITIAL_SORT;
}
+ private void appendOutput() throws TupleSourceNotFoundException,
+ MetaMatrixComponentException {
+ if (this.outTs != null) {
+ //transfer the new dup removed tuples to the output id
+ TupleCollector tc = new TupleCollector(outputID, this.bufferManager);
+ try {
+ try {
+ while (outTs.hasNext()) {
+ tc.addTuple(outTs.nextTuple());
+ }
+ } catch (MetaMatrixProcessingException e) {
+ throw new MetaMatrixComponentException(e);
+ }
+ } catch (BlockedOnMemoryException e) {
+ tc.saveBatch(false);
+ throw e;
+ }
+ outTs = null;
+ }
+ }
+
/**
* Increment the working batch at batchIndex. The currentBatch is the currentBatch
* for that batchIndex, which we already happen to have. Return whether the batch
Modified: trunk/engine/src/main/java/com/metamatrix/query/processor/relational/TupleCollector.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/processor/relational/TupleCollector.java 2009-04-28 21:30:50 UTC (rev 848)
+++ trunk/engine/src/main/java/com/metamatrix/query/processor/relational/TupleCollector.java 2009-04-28 22:25:48 UTC (rev 849)
@@ -35,11 +35,13 @@
public class TupleCollector {
private TupleSourceID tsid;
+ private BufferManager bm;
+ private boolean captureBounds;
private int batchSize;
private ArrayList<List<?>> batch;
private int index;
- private BufferManager bm;
+ private ArrayList<List<?>> bounds;
public TupleCollector(TupleSourceID tsid, BufferManager bm) throws TupleSourceNotFoundException, MetaMatrixComponentException {
this.tsid = tsid;
@@ -48,6 +50,10 @@
this.index = bm.getRowCount(tsid) + 1;
}
+ public void setCaptureBounds(boolean captureBounds) {
+ this.captureBounds = captureBounds;
+ }
+
public TupleSourceID getTupleSourceID() {
return tsid;
}
@@ -70,7 +76,13 @@
return;
}
toSave = new ArrayList<List<?>>(0);
- }
+ } /*else if (captureBounds) {
+ if (bounds.isEmpty()) {
+ bounds.add(toSave.get(0));
+ }
+ if (bounds )
+ bounds.add(toSave.get(toSave.size() -1));
+ }*/
TupleBatch tb = new TupleBatch(index, toSave);
tb.setTerminationFlag(isLast);
this.bm.addTupleBatch(tsid, tb);
Modified: trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestLimit.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestLimit.java 2009-04-28 21:30:50 UTC (rev 848)
+++ trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestLimit.java 2009-04-28 22:25:48 UTC (rev 849)
@@ -742,7 +742,7 @@
0, // PlanExecution
1, // Project
0, // Select
- 1, // Sort
+ 0, // Sort
0 // UnionAll
}, NODE_TYPES);
Modified: trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestOptimizer.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestOptimizer.java 2009-04-28 21:30:50 UTC (rev 848)
+++ trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestOptimizer.java 2009-04-28 22:25:48 UTC (rev 849)
@@ -304,7 +304,7 @@
if (shouldSucceed) {
try {
//do planning
- plan = QueryOptimizer.optimizePlan(command, md, null, capFinder, analysisRecord, null);
+ plan = QueryOptimizer.optimizePlan(command, md, null, capFinder, analysisRecord, new CommandContext());
} catch (Throwable e) {
throw new MetaMatrixRuntimeException(e);
Modified: trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestOptionalJoins.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestOptionalJoins.java 2009-04-28 21:30:50 UTC (rev 848)
+++ trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestOptionalJoins.java 2009-04-28 22:25:48 UTC (rev 849)
@@ -78,7 +78,7 @@
public void testOptionalJoinNode3_1() {
ProcessorPlan plan = TestOptimizer.helpPlan("SELECT pm1.g1.e1, pm2.g2.e1 FROM pm1.g1 LEFT OUTER JOIN /* optional */ pm2.g2 on pm1.g1.e1 = pm2.g2.e1", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
- new String[] {"SELECT g_0.e1 AS c_0 FROM pm2.g2 AS g_0 ORDER BY c_0", "SELECT g_0.e1 AS c_0 FROM pm1.g1 AS g_0 ORDER BY c_0"} ); //$NON-NLS-1$
+ new String[] {"SELECT g_0.e1 AS c_0 FROM pm2.g2 AS g_0 ORDER BY c_0", "SELECT g_0.e1 AS c_0 FROM pm1.g1 AS g_0 ORDER BY c_0"} ); //$NON-NLS-1$ //$NON-NLS-2$
TestOptimizer.checkNodeTypes(plan, new int[] {
2, // Access
Modified: trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestSortOptimization.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestSortOptimization.java 2009-04-28 21:30:50 UTC (rev 848)
+++ trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestSortOptimization.java 2009-04-28 22:25:48 UTC (rev 849)
@@ -107,5 +107,65 @@
});
checkNodeTypes(plan, new int[] {0}, new Class[] {DupRemoveSortNode.class});
}
+
+ @Test public void testGroupDupCombination() {
+ FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+ BasicSourceCapabilities caps = new BasicSourceCapabilities();
+ capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+ // Create query
+ String sql = "select max(e1), e2 from (select distinct e1, e2 from pm1.g1) x group by e2"; //$NON-NLS-1$
+
+ ProcessorPlan plan = helpPlan(sql, FakeMetadataFactory.example1Cached(), null, capFinder,
+ new String[] {"SELECT pm1.g1.e1, pm1.g1.e2 FROM pm1.g1"}, TestOptimizer.SHOULD_SUCCEED); //$NON-NLS-1$
+
+ checkNodeTypes(plan, new int[] {
+ 1, // Access
+ 0, // DependentAccess
+ 0, // DependentSelect
+ 0, // DependentProject
+ 0, // DupRemove
+ 1, // Grouping
+ 0, // NestedLoopJoinStrategy
+ 0, // MergeJoinStrategy
+ 0, // Null
+ 0, // PlanExecution
+ 1, // Project
+ 0, // Select
+ 0, // Sort
+ 0 // UnionAll
+ });
+ checkNodeTypes(plan, new int[] {0}, new Class[] {DupRemoveSortNode.class});
+ }
+
+ @Test public void testSortGroupCombination() {
+ FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+ BasicSourceCapabilities caps = new BasicSourceCapabilities();
+ capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+ // Create query
+ String sql = "select max(e1), e2 from pm1.g1 x group by e2 order by e2"; //$NON-NLS-1$
+
+ ProcessorPlan plan = helpPlan(sql, FakeMetadataFactory.example1Cached(), null, capFinder,
+ new String[] {"SELECT pm1.g1.e2, pm1.g1.e1 FROM pm1.g1"}, TestOptimizer.SHOULD_SUCCEED); //$NON-NLS-1$
+
+ checkNodeTypes(plan, new int[] {
+ 1, // Access
+ 0, // DependentAccess
+ 0, // DependentSelect
+ 0, // DependentProject
+ 0, // DupRemove
+ 1, // Grouping
+ 0, // NestedLoopJoinStrategy
+ 0, // MergeJoinStrategy
+ 0, // Null
+ 0, // PlanExecution
+ 1, // Project
+ 0, // Select
+ 0, // Sort
+ 0 // UnionAll
+ });
+ checkNodeTypes(plan, new int[] {0}, new Class[] {DupRemoveSortNode.class});
+ }
+
}
15 years, 8 months
teiid SVN: r848 - trunk/server/src/main/sqlrepository/schema/postgres.
by teiid-commits@lists.jboss.org
Author: vhalbert(a)redhat.com
Date: 2009-04-28 17:30:50 -0400 (Tue, 28 Apr 2009)
New Revision: 848
Modified:
trunk/server/src/main/sqlrepository/schema/postgres/mm_create.sql
Log:
TEIID 537: updated the mm_create.sql for LOGENTRIES table to add quotes to the Exception column
Modified: trunk/server/src/main/sqlrepository/schema/postgres/mm_create.sql
===================================================================
--- trunk/server/src/main/sqlrepository/schema/postgres/mm_create.sql 2009-04-28 17:36:46 UTC (rev 847)
+++ trunk/server/src/main/sqlrepository/schema/postgres/mm_create.sql 2009-04-28 21:30:50 UTC (rev 848)
@@ -139,7 +139,7 @@
TIMESTAMP VARCHAR(50) NOT NULL,
CONTEXT VARCHAR(64) NOT NULL,
MSGLEVEL NUMERIC(10) NOT NULL CONSTRAINT FK_LOGENTRIES_MSGTYPES REFERENCES LOGMESSAGETYPES (MESSAGELEVEL) ,
- EXCEPTION VARCHAR(4000),
+ "EXCEPTION" VARCHAR(4000),
MESSAGE VARCHAR(2000) NOT NULL,
HOSTNAME VARCHAR(64) NOT NULL,
VMID VARCHAR(64) NOT NULL,
15 years, 8 months
teiid SVN: r847 - in trunk/engine/src: main/java/com/metamatrix/common/buffer/impl and 8 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2009-04-28 13:36:46 -0400 (Tue, 28 Apr 2009)
New Revision: 847
Added:
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RulePlanSorts.java
trunk/engine/src/main/java/com/metamatrix/query/processor/relational/TupleCollector.java
trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestSortOptimization.java
Removed:
trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DupRemoveNode.java
Modified:
trunk/engine/src/main/java/com/metamatrix/common/buffer/MemoryNotAvailableException.java
trunk/engine/src/main/java/com/metamatrix/common/buffer/impl/BufferManagerImpl.java
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/PlanToProcessConverter.java
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/RelationalPlanner.java
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/plantree/NodeConstants.java
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/plantree/NodeEditor.java
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleConstants.java
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleImplementJoinStrategy.java
trunk/engine/src/main/java/com/metamatrix/query/processor/relational/BatchCollector.java
trunk/engine/src/main/java/com/metamatrix/query/processor/relational/BatchIterator.java
trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DependentCriteriaProcessor.java
trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DuplicateFilter.java
trunk/engine/src/main/java/com/metamatrix/query/processor/relational/GroupingNode.java
trunk/engine/src/main/java/com/metamatrix/query/processor/relational/ListNestedSortComparator.java
trunk/engine/src/main/java/com/metamatrix/query/processor/relational/MergeJoinStrategy.java
trunk/engine/src/main/java/com/metamatrix/query/processor/relational/NestedLoopJoinStrategy.java
trunk/engine/src/main/java/com/metamatrix/query/processor/relational/SortNode.java
trunk/engine/src/main/java/com/metamatrix/query/processor/relational/SortUtility.java
trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestLimit.java
trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestOptimizer.java
trunk/engine/src/test/java/com/metamatrix/query/optimizer/xml/TestXMLPlanner.java
trunk/engine/src/test/java/com/metamatrix/query/processor/TestProcessor.java
trunk/engine/src/test/java/com/metamatrix/query/processor/TestVirtualDepJoin.java
trunk/engine/src/test/java/com/metamatrix/query/processor/relational/TestSortNode.java
Log:
TEIID-178, TEIID-175 adding support for a non blocking sort and general planning time sort optimization.
Modified: trunk/engine/src/main/java/com/metamatrix/common/buffer/MemoryNotAvailableException.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/common/buffer/MemoryNotAvailableException.java 2009-04-27 19:02:50 UTC (rev 846)
+++ trunk/engine/src/main/java/com/metamatrix/common/buffer/MemoryNotAvailableException.java 2009-04-28 17:36:46 UTC (rev 847)
@@ -22,12 +22,12 @@
package com.metamatrix.common.buffer;
-import com.metamatrix.api.exception.MetaMatrixProcessingException;
+import com.metamatrix.api.exception.MetaMatrixException;
/**
* Indicates memory was not available for the requested operation.
*/
-public class MemoryNotAvailableException extends MetaMatrixProcessingException {
+public class MemoryNotAvailableException extends MetaMatrixException {
/**
* No-arg costructor required by Externalizable semantics
Modified: trunk/engine/src/main/java/com/metamatrix/common/buffer/impl/BufferManagerImpl.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/common/buffer/impl/BufferManagerImpl.java 2009-04-27 19:02:50 UTC (rev 846)
+++ trunk/engine/src/main/java/com/metamatrix/common/buffer/impl/BufferManagerImpl.java 2009-04-28 17:36:46 UTC (rev 847)
@@ -470,7 +470,11 @@
if (LogManager.isMessageToBeRecorded(LogCommonConstants.CTX_BUFFER_MGR, MessageLevel.TRACE)) {
LogManager.logTrace(LogCommonConstants.CTX_BUFFER_MGR, new Object[]{"AddTupleBatch for", tupleSourceID, "with " + tupleBatch.getRowCount() + " rows"}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
-
+
+ if (tupleBatch.getRowCount() == 0 && !tupleBatch.getTerminationFlag()) {
+ return;
+ }
+
// Look up info
TupleSourceInfo info = getTupleSourceInfo(tupleSourceID, true);
Modified: trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/PlanToProcessConverter.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/PlanToProcessConverter.java 2009-04-27 19:02:50 UTC (rev 846)
+++ trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/PlanToProcessConverter.java 2009-04-28 17:36:46 UTC (rev 847)
@@ -49,7 +49,6 @@
import com.metamatrix.query.processor.relational.DependentAccessNode;
import com.metamatrix.query.processor.relational.DependentProcedureAccessNode;
import com.metamatrix.query.processor.relational.DependentProcedureExecutionNode;
-import com.metamatrix.query.processor.relational.DupRemoveNode;
import com.metamatrix.query.processor.relational.GroupingNode;
import com.metamatrix.query.processor.relational.JoinNode;
import com.metamatrix.query.processor.relational.LimitNode;
@@ -65,6 +64,7 @@
import com.metamatrix.query.processor.relational.SortNode;
import com.metamatrix.query.processor.relational.UnionAllNode;
import com.metamatrix.query.processor.relational.MergeJoinStrategy.SortOption;
+import com.metamatrix.query.processor.relational.SortUtility.Mode;
import com.metamatrix.query.resolver.util.ResolverUtil;
import com.metamatrix.query.sql.LanguageObject;
import com.metamatrix.query.sql.lang.Command;
@@ -201,7 +201,7 @@
List joinCrits = (List) node.getProperty(NodeConstants.Info.JOIN_CRITERIA);
if(stype.equals(JoinStrategyType.MERGE)) {
- MergeJoinStrategy mjStrategy = new MergeJoinStrategy(node.hasBooleanProperty(NodeConstants.Info.SORT_LEFT), node.hasBooleanProperty(NodeConstants.Info.SORT_RIGHT));
+ MergeJoinStrategy mjStrategy = new MergeJoinStrategy((SortOption)node.getProperty(NodeConstants.Info.SORT_LEFT), (SortOption)node.getProperty(NodeConstants.Info.SORT_RIGHT), false);
jnode.setJoinStrategy(mjStrategy);
List leftExpressions = (List) node.getProperty(NodeConstants.Info.LEFT_EXPRESSIONS);
List rightExpressions = (List) node.getProperty(NodeConstants.Info.RIGHT_EXPRESSIONS);
@@ -319,21 +319,21 @@
break;
case NodeConstants.Types.SORT:
+ case NodeConstants.Types.DUP_REMOVE:
SortNode sortNode = new SortNode(getID());
List elements = (List) node.getProperty(NodeConstants.Info.SORT_ORDER);
List sortTypes = (List) node.getProperty(NodeConstants.Info.ORDER_TYPES);
sortNode.setSortElements(elements, sortTypes);
+ if (node.getType() == NodeConstants.Types.DUP_REMOVE) {
+ sortNode.setMode(Mode.DUP_REMOVE);
+ } else if (node.hasBooleanProperty(NodeConstants.Info.IS_DUP_REMOVAL)) {
+ sortNode.setMode(Mode.DUP_REMOVE_SORT);
+ }
processNode = sortNode;
break;
-
- case NodeConstants.Types.DUP_REMOVE:
- processNode = new DupRemoveNode(getID());
-
- break;
-
case NodeConstants.Types.GROUP:
GroupingNode gnode = new GroupingNode(getID());
gnode.setGroupingElements( (List) node.getProperty(NodeConstants.Info.GROUP_COLS) );
@@ -362,7 +362,11 @@
if(useAll) {
processNode = unionAllNode;
} else {
- processNode = new DupRemoveNode(getID());
+ SortNode sNode = new SortNode(getID());
+ boolean onlyDupRemoval = node.hasBooleanProperty(NodeConstants.Info.IS_DUP_REMOVAL);
+ sNode.setMode(onlyDupRemoval?Mode.DUP_REMOVE:Mode.DUP_REMOVE_SORT);
+ processNode = sNode;
+
unionAllNode.setElements( (List) node.getProperty(NodeConstants.Info.OUTPUT_COLS) );
processNode.addChild(unionAllNode);
}
Modified: trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/RelationalPlanner.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/RelationalPlanner.java 2009-04-27 19:02:50 UTC (rev 846)
+++ trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/RelationalPlanner.java 2009-04-28 17:36:46 UTC (rev 847)
@@ -293,6 +293,8 @@
RuleStack rules = new RuleStack();
rules.push(RuleConstants.COLLAPSE_SOURCE);
+
+ rules.push(RuleConstants.PLAN_SORTS);
if(hints.hasJoin) {
rules.push(RuleConstants.IMPLEMENT_JOIN_STRATEGY);
Modified: trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/plantree/NodeConstants.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/plantree/NodeConstants.java 2009-04-27 19:02:50 UTC (rev 846)
+++ trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/plantree/NodeConstants.java 2009-04-28 17:36:46 UTC (rev 847)
@@ -87,8 +87,8 @@
RIGHT_EXPRESSIONS, // List <SingleElementSymbol>
DEPENDENT_VALUE_SOURCE, // String
NON_EQUI_JOIN_CRITERIA, // List <CompareCriteria>
- SORT_LEFT, // Boolean
- SORT_RIGHT, // Boolean
+ SORT_LEFT, // SortOption
+ SORT_RIGHT, // SortOption
REMOVED_JOIN_GROUPS, //Set<GroupSymbol>
IS_OPTIONAL, // Boolean
@@ -110,7 +110,7 @@
// Sort node properties
ORDER_TYPES, // List <Boolean>
SORT_ORDER, // List <SingleElementSymbol>
- SORT_CONTROLLER, // Boolean
+ IS_DUP_REMOVAL, // Boolean
// Source node properties
SYMBOL_MAP, // SymbolMap
Modified: trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/plantree/NodeEditor.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/plantree/NodeEditor.java 2009-04-27 19:02:50 UTC (rev 846)
+++ trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/plantree/NodeEditor.java 2009-04-28 17:36:46 UTC (rev 847)
@@ -49,18 +49,18 @@
}
}
- public static final PlanNode findNodePreOrder(PlanNode root, int type) {
- return findNodePreOrder(root, type, NodeConstants.Types.NO_TYPE);
+ public static final PlanNode findNodePreOrder(PlanNode root, int types) {
+ return findNodePreOrder(root, types, NodeConstants.Types.NO_TYPE);
}
- public static final PlanNode findNodePreOrder(PlanNode root, int type, int stopTypes) {
- if(root.getType() == type) {
+ public static final PlanNode findNodePreOrder(PlanNode root, int types, int stopTypes) {
+ if((types & root.getType()) == root.getType()) {
return root;
} else if((stopTypes & root.getType()) == root.getType()) {
return null;
} else if(root.getChildCount() > 0) {
for (PlanNode child : root.getChildren()) {
- PlanNode found = findNodePreOrder(child, type, stopTypes);
+ PlanNode found = findNodePreOrder(child, types, stopTypes);
if(found != null) {
return found;
}
Modified: trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleConstants.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleConstants.java 2009-04-27 19:02:50 UTC (rev 846)
+++ trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleConstants.java 2009-04-28 17:36:46 UTC (rev 847)
@@ -52,4 +52,5 @@
public static final OptimizerRule PLAN_UNIONS = new RulePlanUnions();
public static final OptimizerRule PLAN_PROCEDURES = new RulePlanProcedures();
public static final OptimizerRule CALCULATE_COST = new RuleCalculateCost();
+ public static final OptimizerRule PLAN_SORTS = new RulePlanSorts();
}
Modified: trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleImplementJoinStrategy.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleImplementJoinStrategy.java 2009-04-27 19:02:50 UTC (rev 846)
+++ trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleImplementJoinStrategy.java 2009-04-28 17:36:46 UTC (rev 847)
@@ -42,6 +42,7 @@
import com.metamatrix.query.optimizer.relational.plantree.NodeEditor;
import com.metamatrix.query.optimizer.relational.plantree.NodeFactory;
import com.metamatrix.query.optimizer.relational.plantree.PlanNode;
+import com.metamatrix.query.processor.relational.MergeJoinStrategy.SortOption;
import com.metamatrix.query.sql.lang.OrderBy;
import com.metamatrix.query.sql.symbol.SingleElementSymbol;
import com.metamatrix.query.util.CommandContext;
@@ -111,7 +112,7 @@
return;
}
- joinNode.setProperty(joinNode.getFirstChild() == childNode ? NodeConstants.Info.SORT_LEFT : NodeConstants.Info.SORT_RIGHT, Boolean.TRUE);
+ joinNode.setProperty(joinNode.getFirstChild() == childNode ? NodeConstants.Info.SORT_LEFT : NodeConstants.Info.SORT_RIGHT, SortOption.SORT);
if (needsCorrection) {
PlanNode projectNode = NodeFactory.getNewNode(NodeConstants.Types.PROJECT);
Added: trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RulePlanSorts.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RulePlanSorts.java (rev 0)
+++ trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RulePlanSorts.java 2009-04-28 17:36:46 UTC (rev 847)
@@ -0,0 +1,146 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package com.metamatrix.query.optimizer.relational.rules;
+
+import com.metamatrix.api.exception.MetaMatrixComponentException;
+import com.metamatrix.api.exception.query.QueryMetadataException;
+import com.metamatrix.api.exception.query.QueryPlannerException;
+import com.metamatrix.query.analysis.AnalysisRecord;
+import com.metamatrix.query.metadata.QueryMetadataInterface;
+import com.metamatrix.query.optimizer.capabilities.CapabilitiesFinder;
+import com.metamatrix.query.optimizer.relational.OptimizerRule;
+import com.metamatrix.query.optimizer.relational.RuleStack;
+import com.metamatrix.query.optimizer.relational.plantree.JoinStrategyType;
+import com.metamatrix.query.optimizer.relational.plantree.NodeConstants;
+import com.metamatrix.query.optimizer.relational.plantree.NodeEditor;
+import com.metamatrix.query.optimizer.relational.plantree.PlanNode;
+import com.metamatrix.query.processor.relational.MergeJoinStrategy.SortOption;
+import com.metamatrix.query.sql.lang.SetQuery;
+import com.metamatrix.query.util.CommandContext;
+
+/**
+ * Attempts to minimize the cost of sorting operations across the plan.
+ */
+public class RulePlanSorts implements OptimizerRule {
+
+ @Override
+ public PlanNode execute(PlanNode plan, QueryMetadataInterface metadata,
+ CapabilitiesFinder capabilitiesFinder, RuleStack rules,
+ AnalysisRecord analysisRecord, CommandContext context)
+ throws QueryPlannerException, QueryMetadataException,
+ MetaMatrixComponentException {
+ optimizeSorts(false, plan);
+ return plan;
+ }
+
+ private void optimizeSorts(boolean parentBlocking, PlanNode node) {
+ node = NodeEditor.findNodePreOrder(node,
+ NodeConstants.Types.SORT
+ | NodeConstants.Types.DUP_REMOVE
+ | NodeConstants.Types.GROUP
+ | NodeConstants.Types.JOIN
+ | NodeConstants.Types.SET_OP, NodeConstants.Types.ACCESS);
+ if (node == null) {
+ return;
+ }
+ switch (node.getType()) {
+ case NodeConstants.Types.SORT:
+ parentBlocking = true;
+ if (node.hasBooleanProperty(NodeConstants.Info.IS_DUP_REMOVAL)) {
+ break;
+ }
+ if (mergeSortWithDupRemoval(node)) {
+ node.setProperty(NodeConstants.Info.IS_DUP_REMOVAL, true);
+ }
+ break;
+ case NodeConstants.Types.DUP_REMOVE:
+ if (parentBlocking) {
+ node.setType(NodeConstants.Types.SORT);
+ node.setProperty(NodeConstants.Info.IS_DUP_REMOVAL, true);
+ }
+ break;
+ case NodeConstants.Types.GROUP:
+ //TODO: check the join interesting order
+ parentBlocking = true;
+ break;
+ case NodeConstants.Types.JOIN:
+ if (node.getProperty(NodeConstants.Info.JOIN_STRATEGY) != JoinStrategyType.MERGE) {
+ break;
+ }
+ parentBlocking = true;
+ PlanNode toTest = node.getFirstChild();
+ if (mergeSortWithDupRemovalForJoin(toTest)) {
+ node.setProperty(NodeConstants.Info.SORT_LEFT, SortOption.SORT_DISTINCT);
+ }
+ toTest = node.getLastChild();
+ if (mergeSortWithDupRemovalForJoin(toTest)) {
+ node.setProperty(NodeConstants.Info.SORT_RIGHT, SortOption.SORT_DISTINCT);
+ }
+ break;
+ case NodeConstants.Types.SET_OP:
+ // assumes the use of the merge algorithm
+ if (node.getProperty(NodeConstants.Info.SET_OPERATION) != SetQuery.Operation.UNION) {
+ parentBlocking = true;
+ } else if (!node.hasBooleanProperty(NodeConstants.Info.USE_ALL) && !parentBlocking) {
+ node.setProperty(NodeConstants.Info.IS_DUP_REMOVAL, true);
+ }
+ break;
+ }
+ for (PlanNode child : node.getChildren()) {
+ optimizeSorts(parentBlocking, child);
+ }
+ }
+
+ /**
+ * Look under the left and the right sources for a dup removal operation
+ * join
+ * [project]
+ * source
+ * dup remove | union not all
+ */
+ private boolean mergeSortWithDupRemovalForJoin(PlanNode toTest) {
+ PlanNode source = NodeEditor.findNodePreOrder(toTest, NodeConstants.Types.SOURCE, NodeConstants.Types.ACCESS | NodeConstants.Types.JOIN);
+ return source != null && mergeSortWithDupRemoval(source);
+ }
+
+ private boolean mergeSortWithDupRemoval(PlanNode node) {
+ switch (node.getFirstChild().getType()) {
+ case NodeConstants.Types.SET_OP:
+ if (node.getFirstChild().getProperty(NodeConstants.Info.SET_OPERATION) == SetQuery.Operation.UNION && !node.getFirstChild().hasBooleanProperty(NodeConstants.Info.USE_ALL)) {
+ node.getFirstChild().setProperty(NodeConstants.Info.USE_ALL, true);
+ return true;
+ }
+ break;
+ case NodeConstants.Types.DUP_REMOVE:
+ NodeEditor.removeChildNode(node, node.getFirstChild());
+ return true;
+ }
+ return false;
+ }
+
+ @Override
+ public String toString() {
+ return "PlanSorts"; //$NON-NLS-1$
+ }
+
+}
Property changes on: trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RulePlanSorts.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/engine/src/main/java/com/metamatrix/query/processor/relational/BatchCollector.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/processor/relational/BatchCollector.java 2009-04-27 19:02:50 UTC (rev 846)
+++ trunk/engine/src/main/java/com/metamatrix/query/processor/relational/BatchCollector.java 2009-04-28 17:36:46 UTC (rev 847)
@@ -40,6 +40,7 @@
private boolean done = false;
private TupleSourceID tsID;
private int rowCount = 0;
+ private boolean collectedAny;
public BatchCollector(RelationalNode sourceNode) throws MetaMatrixComponentException {
this.sourceNode = sourceNode;
@@ -61,6 +62,7 @@
if(batch.getRowCount() > 0) {
this.rowCount = batch.getEndRow();
sourceNode.getBufferManager().addTupleBatch(tsID, batch);
+ collectedAny = true;
}
// Check for termination condition - batch ending with null row
@@ -77,6 +79,12 @@
return tsID;
}
+ public boolean collectedAny() {
+ boolean result = collectedAny;
+ collectedAny = false;
+ return result;
+ }
+
public int getRowCount() {
return rowCount;
}
@@ -92,5 +100,9 @@
public TupleSourceID getTupleSourceID() {
return this.tsID;
}
+
+ public boolean isDone() {
+ return done;
+ }
}
Modified: trunk/engine/src/main/java/com/metamatrix/query/processor/relational/BatchIterator.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/processor/relational/BatchIterator.java 2009-04-27 19:02:50 UTC (rev 846)
+++ trunk/engine/src/main/java/com/metamatrix/query/processor/relational/BatchIterator.java 2009-04-28 17:36:46 UTC (rev 847)
@@ -23,7 +23,6 @@
package com.metamatrix.query.processor.relational;
import java.util.List;
-import java.util.NoSuchElementException;
import com.metamatrix.api.exception.MetaMatrixComponentException;
import com.metamatrix.api.exception.MetaMatrixProcessingException;
@@ -82,7 +81,7 @@
public List<?> nextTuple() throws MetaMatrixComponentException,
MetaMatrixProcessingException {
if (currentTuple == null && !hasNext()) {
- throw new NoSuchElementException();
+ return null;
}
List result = currentTuple;
currentTuple = null;
@@ -103,13 +102,17 @@
}
public void setPosition(int position) {
+ if (position == this.currentRow) {
+ return;
+ }
+ if (position < this.currentRow && (this.currentBatch == null || position < this.currentBatch.getBeginRow())) {
+ throw new UnsupportedOperationException("Backwards positioning is not allowed"); //$NON-NLS-1$
+ }
this.currentRow = position;
+ this.currentTuple = null;
+ if (currentBatch.getEndRow() < currentRow) {
+ this.currentBatch = null;
+ }
}
- public int available() {
- if (currentBatch == null) {
- return 0;
- }
- return currentBatch.getEndRow() - currentRow;
- }
}
Modified: trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DependentCriteriaProcessor.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DependentCriteriaProcessor.java 2009-04-27 19:02:50 UTC (rev 846)
+++ trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DependentCriteriaProcessor.java 2009-04-28 17:36:46 UTC (rev 847)
@@ -94,8 +94,7 @@
} catch (TupleSourceNotFoundException e) {
throw new MetaMatrixComponentException(e);
}
- this.sortUtility = new SortUtility(originalVs.getTupleSourceID(), ts.getSchema(), sortSymbols, sortDirection, true, dependentNode.getBufferManager(),
- dependentNode.getConnectionID());
+ this.sortUtility = new SortUtility(originalVs.getTupleSourceID(), sortSymbols, sortDirection, true, dependentNode.getBufferManager(), dependentNode.getConnectionID());
}
dvs = new DependentValueSource(sortUtility.sort(), dependentNode.getBufferManager());
for (SetState setState : dependentSetStates) {
Deleted: trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DupRemoveNode.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DupRemoveNode.java 2009-04-27 19:02:50 UTC (rev 846)
+++ trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DupRemoveNode.java 2009-04-28 17:36:46 UTC (rev 847)
@@ -1,77 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package com.metamatrix.query.processor.relational;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.api.exception.MetaMatrixProcessingException;
-import com.metamatrix.query.sql.lang.OrderBy;
-
-public class DupRemoveNode extends SortNode {
-
- public DupRemoveNode(int nodeID) {
- super(nodeID);
- }
-
- public void reset() {
- super.reset();
- }
-
- public void open()
- throws MetaMatrixComponentException, MetaMatrixProcessingException {
-
- // Set up duplicate removal
- super.setRemoveDuplicates(true);
-
- // Set up all elements for sorting
- List sourceElements = getChildren()[0].getElements();
- List sortTypes = new ArrayList(sourceElements.size());
- for(int i=0; i<sourceElements.size(); i++) {
- sortTypes.add(Boolean.valueOf(OrderBy.ASC));
- }
- super.setSortElements(sourceElements, sortTypes);
-
- super.open();
- }
-
- public Object clone(){
- DupRemoveNode clonedNode = new DupRemoveNode(super.getID());
- super.copy(this, clonedNode);
-
- return clonedNode;
- }
-
- /*
- * @see com.metamatrix.query.processor.Describable#getDescriptionProperties()
- */
- public Map getDescriptionProperties() {
- // Default implementation - should be overridden
- Map props = super.getDescriptionProperties();
- props.put(PROP_TYPE, "Duplicate Removal"); //$NON-NLS-1$
- return props;
- }
-
-}
Modified: trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DuplicateFilter.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DuplicateFilter.java 2009-04-27 19:02:50 UTC (rev 846)
+++ trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DuplicateFilter.java 2009-04-28 17:36:46 UTC (rev 847)
@@ -29,8 +29,10 @@
import com.metamatrix.api.exception.MetaMatrixProcessingException;
import com.metamatrix.api.exception.query.ExpressionEvaluationException;
import com.metamatrix.api.exception.query.FunctionExecutionException;
-import com.metamatrix.common.buffer.*;
-import com.metamatrix.common.buffer.BufferManager.TupleSourceStatus;
+import com.metamatrix.common.buffer.BufferManager;
+import com.metamatrix.common.buffer.TupleSource;
+import com.metamatrix.common.buffer.TupleSourceID;
+import com.metamatrix.common.buffer.TupleSourceNotFoundException;
import com.metamatrix.common.buffer.BufferManager.TupleSourceType;
import com.metamatrix.query.function.aggregate.AggregateFunction;
import com.metamatrix.query.sql.lang.OrderBy;
@@ -45,7 +47,6 @@
private AggregateFunction proxy;
private BufferManager mgr;
private String groupName;
- private int batchSize;
// Derived and static - can be reused
private List elements;
@@ -54,12 +55,10 @@
// Temporary state - should be reset
private TupleSourceID collectionID = null;
- private List collectionRows;
- private int collectionRow = 1;
private SortUtility sortUtility = null;
private TupleSourceID sortedID = null;
+ private TupleCollector tupleCollector;
-
/**
* Constructor for DuplicateFilter.
*/
@@ -69,7 +68,6 @@
this.proxy = proxy;
this.mgr = mgr;
this.groupName = groupName;
- this.batchSize = batchSize;
}
/**
@@ -93,8 +91,7 @@
this.proxy.reset();
this.collectionID = null;
- this.collectionRows = null;
- this.collectionRow = 1;
+ this.tupleCollector = null;
this.sortUtility = null;
this.sortedID = null;
}
@@ -108,24 +105,12 @@
try {
if(collectionID == null) {
collectionID = mgr.createTupleSource(elements, elementTypes, groupName, TupleSourceType.PROCESSOR);
+ this.tupleCollector = new TupleCollector(collectionID, mgr);
}
- if(collectionRows == null) {
- collectionRows = new ArrayList(batchSize);
- }
-
List row = new ArrayList(1);
row.add(input);
- collectionRows.add(row);
- if(collectionRows.size() == batchSize) {
- TupleBatch batch = new TupleBatch(collectionRow, collectionRows);
- mgr.addTupleBatch(collectionID, batch);
-
- // Reset state for next batch
- collectionRow = collectionRow + batch.getRowCount();
- collectionRows = new ArrayList(batchSize);
- }
-
+ this.tupleCollector.addTuple(row);
} catch(TupleSourceNotFoundException e) {
throw new MetaMatrixComponentException(e, e.getMessage());
}
@@ -140,15 +125,10 @@
try {
if(collectionID != null) {
- // First save any hanging collection rows
- if(collectionRows.size() > 0) {
- TupleBatch batch = new TupleBatch(collectionRow, collectionRows);
- mgr.addTupleBatch(collectionID, batch);
- }
- mgr.setStatus(collectionID, TupleSourceStatus.FULL);
+ this.tupleCollector.close();
// Sort
- sortUtility = new SortUtility(collectionID, elements, elements, sortTypes, true, mgr, groupName);
+ sortUtility = new SortUtility(collectionID, elements, sortTypes, true, mgr, groupName);
this.sortedID = sortUtility.sort();
// Add all input to proxy
Modified: trunk/engine/src/main/java/com/metamatrix/query/processor/relational/GroupingNode.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/processor/relational/GroupingNode.java 2009-04-27 19:02:50 UTC (rev 846)
+++ trunk/engine/src/main/java/com/metamatrix/query/processor/relational/GroupingNode.java 2009-04-28 17:36:46 UTC (rev 847)
@@ -297,21 +297,22 @@
this.sourceBatch = null;
}
+ this.getBufferManager().setStatus(this.collectionID, TupleSourceStatus.FULL);
+
if(this.sortElements == null || this.rowCount == 0) {
// No need to sort
- this.getBufferManager().setStatus(this.collectionID, TupleSourceStatus.FULL);
this.sortedID = this.collectionID;
this.collectionID = null;
this.phase = GROUP;
} else {
- this.sortUtility = new SortUtility(collectionID, collectedExpressions,
- sortElements, sortTypes, false,
- getBufferManager(), getConnectionID());
+ this.sortUtility = new SortUtility(collectionID, sortElements,
+ sortTypes, false, getBufferManager(),
+ getConnectionID());
this.phase = SORT;
}
}
- private void sortPhase() throws BlockedException, MetaMatrixComponentException {
+ private void sortPhase() throws BlockedException, MetaMatrixComponentException, MetaMatrixProcessingException {
this.sortedID = this.sortUtility.sort();
this.phase = GROUP;
}
Modified: trunk/engine/src/main/java/com/metamatrix/query/processor/relational/ListNestedSortComparator.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/processor/relational/ListNestedSortComparator.java 2009-04-27 19:02:50 UTC (rev 846)
+++ trunk/engine/src/main/java/com/metamatrix/query/processor/relational/ListNestedSortComparator.java 2009-04-28 17:36:46 UTC (rev 847)
@@ -24,6 +24,8 @@
import java.util.*;
+import com.metamatrix.core.util.Assertion;
+
/**
* This class can be used for comparing lists of elements, when the fields to
* be sorted on and the comparison mechanism are dynamically specified. <p>
@@ -61,7 +63,7 @@
int[] sortParameters;
/**
- * Indicates whether comparision should be based on ascending or descending
+ * Indicates whether comparison should be based on ascending or descending
* order.
*/
boolean ascendingOrder = false;
@@ -146,7 +148,7 @@
} else if ( param1 instanceof Comparable ) {
compare = ((Comparable)param1).compareTo(param2);
} else {
- compare = param1.toString().compareTo(param2.toString());
+ Assertion.failed("Expected comparable types"); //$NON-NLS-1$
}
k++;
}
Modified: trunk/engine/src/main/java/com/metamatrix/query/processor/relational/MergeJoinStrategy.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/processor/relational/MergeJoinStrategy.java 2009-04-27 19:02:50 UTC (rev 846)
+++ trunk/engine/src/main/java/com/metamatrix/query/processor/relational/MergeJoinStrategy.java 2009-04-28 17:36:46 UTC (rev 847)
@@ -29,6 +29,7 @@
import com.metamatrix.api.exception.MetaMatrixProcessingException;
import com.metamatrix.api.exception.query.CriteriaEvaluationException;
import com.metamatrix.common.buffer.TupleSourceNotFoundException;
+import com.metamatrix.query.processor.relational.SortUtility.Mode;
import com.metamatrix.query.sql.lang.JoinType;
import com.metamatrix.query.sql.lang.OrderBy;
@@ -89,11 +90,13 @@
private SortUtility rightSort;
private SortOption processingSortRight;
- public MergeJoinStrategy(boolean sortLeft, boolean sortRight) {
- this(sortLeft?SortOption.SORT:SortOption.SKIP_SORT, sortRight?SortOption.SORT:SortOption.SKIP_SORT, false);
- }
-
public MergeJoinStrategy(SortOption sortLeft, SortOption sortRight, boolean grouping) {
+ if (sortLeft == null) {
+ sortLeft = SortOption.SKIP_SORT;
+ }
+ if (sortRight == null) {
+ sortRight = SortOption.SKIP_SORT;
+ }
this.sortLeft = sortLeft;
this.sortRight = sortRight;
this.grouping = grouping;
@@ -260,13 +263,12 @@
}
if (!outerMatched) {
- if (matchState == MatchState.MATCH_LEFT) {
- if (this.joinNode.getJoinType().isOuter()) {
- return outputTuple(this.leftSource.getCurrentTuple(), this.rightSource.getOuterVals());
- }
- } else if (joinNode.getJoinType() == JoinType.JOIN_FULL_OUTER) {
- return outputTuple(this.leftSource.getOuterVals(), this.rightSource.getCurrentTuple());
+ if (matchState == MatchState.MATCH_RIGHT) {
+ return outputTuple(this.leftSource.getOuterVals(), this.rightSource.getCurrentTuple());
}
+ if (this.joinNode.getJoinType().isOuter()) {
+ return outputTuple(this.leftSource.getCurrentTuple(), this.rightSource.getOuterVals());
+ }
}
}
}
@@ -334,12 +336,11 @@
MetaMatrixProcessingException {
if (sortLeft != SortOption.SKIP_SORT) {
if (this.leftSort == null) {
- List sourceElements = joinNode.getChildren()[0].getElements();
List expressions = this.joinNode.getLeftExpressions();
- this.leftSort = new SortUtility(this.leftSource.collectTuples(), sourceElements,
- expressions, Collections.nCopies(expressions.size(), OrderBy.ASC), sortLeft == SortOption.SORT_DISTINCT,
- this.joinNode.getBufferManager(), this.joinNode.getConnectionID());
- this.leftSource.setDistinct(sortLeft == SortOption.SORT_DISTINCT);
+ this.leftSort = new SortUtility(this.leftSource.collectTuples(),
+ expressions, Collections.nCopies(expressions.size(), OrderBy.ASC), sortLeft == SortOption.SORT_DISTINCT?Mode.DUP_REMOVE_SORT:Mode.SORT,
+ this.joinNode.getBufferManager(), this.joinNode.getConnectionID(), true);
+ this.leftSource.setDistinct(sortLeft == SortOption.SORT_DISTINCT && expressions.size() == this.leftSource.getOuterVals().size());
}
this.leftSource.setTupleSource(leftSort.sort());
} else if (this.joinNode.isDependent() || JoinType.JOIN_FULL_OUTER.equals(joinNode.getJoinType())) {
@@ -356,19 +357,20 @@
super.loadRight();
if (processingSortRight != SortOption.SKIP_SORT) {
if (this.rightSort == null) {
- List sourceElements = joinNode.getChildren()[1].getElements();
List expressions = this.joinNode.getRightExpressions();
- this.rightSort = new SortUtility(this.rightSource.getTupleSourceID(), sourceElements,
- expressions, Collections.nCopies(expressions.size(), OrderBy.ASC), processingSortRight == SortOption.SORT_DISTINCT,
- this.joinNode.getBufferManager(), this.joinNode.getConnectionID());
- this.rightSource.setDistinct(processingSortRight == SortOption.SORT_DISTINCT);
+ this.rightSort = new SortUtility(this.rightSource.getTupleSourceID(),
+ expressions, Collections.nCopies(expressions.size(), OrderBy.ASC), processingSortRight == SortOption.SORT_DISTINCT?Mode.DUP_REMOVE_SORT:Mode.SORT,
+ this.joinNode.getBufferManager(), this.joinNode.getConnectionID(), true);
+ this.rightSource.setDistinct(processingSortRight == SortOption.SORT_DISTINCT && expressions.size() == this.rightSource.getOuterVals().size());
}
this.rightSource.setTupleSource(rightSort.sort());
}
}
public void setProcessingSortRight(boolean processingSortRight) {
- this.processingSortRight = processingSortRight?SortOption.SORT:SortOption.SKIP_SORT;
+ if (processingSortRight && this.processingSortRight == SortOption.SKIP_SORT) {
+ this.processingSortRight = SortOption.SORT;
+ }
}
/**
Modified: trunk/engine/src/main/java/com/metamatrix/query/processor/relational/NestedLoopJoinStrategy.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/processor/relational/NestedLoopJoinStrategy.java 2009-04-27 19:02:50 UTC (rev 846)
+++ trunk/engine/src/main/java/com/metamatrix/query/processor/relational/NestedLoopJoinStrategy.java 2009-04-28 17:36:46 UTC (rev 847)
@@ -33,7 +33,7 @@
public class NestedLoopJoinStrategy extends MergeJoinStrategy {
public NestedLoopJoinStrategy() {
- super(false, false);
+ super(SortOption.SKIP_SORT, SortOption.SKIP_SORT, false);
}
/**
Modified: trunk/engine/src/main/java/com/metamatrix/query/processor/relational/SortNode.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/processor/relational/SortNode.java 2009-04-27 19:02:50 UTC (rev 846)
+++ trunk/engine/src/main/java/com/metamatrix/query/processor/relational/SortNode.java 2009-04-28 17:36:46 UTC (rev 847)
@@ -35,18 +35,19 @@
import com.metamatrix.common.buffer.TupleBatch;
import com.metamatrix.common.buffer.TupleSourceID;
import com.metamatrix.common.buffer.TupleSourceNotFoundException;
+import com.metamatrix.query.processor.relational.SortUtility.Mode;
import com.metamatrix.query.sql.lang.OrderBy;
public class SortNode extends RelationalNode {
private List sortElements;
- private List sortTypes;
- private boolean removeDuplicates;
+ private List<Boolean> sortTypes;
+ private Mode mode = Mode.SORT;
private SortUtility sortUtility;
private int phase = COLLECTION;
private TupleSourceID outputID;
- private int rowCount;
+ private int rowCount = -1;
private int outputBeginRow = 1;
private BatchCollector collector;
@@ -63,12 +64,12 @@
sortUtility = null;
phase = COLLECTION;
outputID = null;
- rowCount = 0;
+ rowCount = -1;
outputBeginRow = 1;
this.collector = null;
}
- public void setSortElements(List sortElements, List sortTypes) {
+ public void setSortElements(List sortElements, List<Boolean> sortTypes) {
this.sortElements = sortElements;
this.sortTypes = sortTypes;
}
@@ -76,10 +77,14 @@
public List getSortElements() {
return this.sortElements;
}
+
+ public Mode getMode() {
+ return mode;
+ }
- protected void setRemoveDuplicates(boolean removeDuplicates) {
- this.removeDuplicates = removeDuplicates;
- }
+ public void setMode(Mode mode) {
+ this.mode = mode;
+ }
public void open()
throws MetaMatrixComponentException, MetaMatrixProcessingException {
@@ -88,81 +93,54 @@
this.collector = new BatchCollector(this.getChildren()[0]);
}
- /**
- * 1ST PHASE - COLLECTION
- * Collect all batches from child node, save in collected tuple source
- *
- * 2ND PHASE - SORT INITIAL SUBLISTS
- * Repeat until all batches from collection TS have been read
- * Get and pin batches from collection TS until MemoryNotAvailableException
- * Sort batches
- * Write batches into new sorted TS
- * Unpin all batches
- * Remove collection TS
- *
- * 3RD PHASE - MERGE SORTED SUBLISTS
- * Repeat until there is one sublist
- * Repeat until all sorted sublists have been merged
- * For each sorted sublist S
- * Load and pin a batch until memory not available
- * Merge from pinned batches
- * As batch is done, unpin and load next
- * Output merge into new sublist T
- * Remove merged sublists
- * Let sublists = set of T's
- *
- * 4TH PHASE - OUTPUT
- * Return batches from single sublist from T
- */
public TupleBatch nextBatchDirect()
throws BlockedException, MetaMatrixComponentException, MetaMatrixProcessingException {
try {
if(this.phase == COLLECTION) {
- collectionPhase(null);
+ collectionPhase();
}
if(this.phase == SORT) {
sortPhase();
}
- if(this.phase == OUTPUT) {
- return outputPhase();
- }
+ return outputPhase();
} catch(TupleSourceNotFoundException e) {
throw new MetaMatrixComponentException(e, e.getMessage());
}
-
- TupleBatch terminationBatch = new TupleBatch(1, Collections.EMPTY_LIST);
- terminationBatch.setTerminationFlag(true);
- return terminationBatch;
}
- protected void collectionPhase(TupleBatch batch) throws BlockedException, TupleSourceNotFoundException, MetaMatrixComponentException, MetaMatrixProcessingException {
- RelationalNode sourceNode = this.getChildren()[0];
- TupleSourceID collectionID = collector.collectTuples(batch);
- this.rowCount = collector.getRowCount();
- if(this.rowCount == 0) {
- this.phase = OUTPUT;
- } else {
- List sourceElements = sourceNode.getElements();
- this.sortUtility = new SortUtility(collectionID, sourceElements,
- sortElements, sortTypes, this.removeDuplicates,
- getBufferManager(), getConnectionID());
- this.phase = SORT;
- }
+ private void collectionPhase() throws BlockedException, TupleSourceNotFoundException, MetaMatrixComponentException, MetaMatrixProcessingException {
+ try {
+ collector.collectTuples();
+ } catch (BlockedException e) {
+ if (mode != Mode.DUP_REMOVE || !collector.collectedAny()) {
+ throw e;
+ }
+ }
+ if (this.sortUtility == null) {
+ this.sortUtility = new SortUtility(collector.getTupleSourceID(), sortElements,
+ sortTypes, this.mode, getBufferManager(),
+ getConnectionID(), true);
+ }
+ this.phase = SORT;
}
- private void sortPhase() throws BlockedException, TupleSourceNotFoundException, MetaMatrixComponentException {
- this.outputID = this.sortUtility.sort();
- this.rowCount = getBufferManager().getRowCount(outputID);
+ private void sortPhase() throws BlockedException, MetaMatrixComponentException, MetaMatrixProcessingException {
+ this.outputID = this.sortUtility.sort();
this.phase = OUTPUT;
-
}
private TupleBatch outputPhase() throws BlockedException, TupleSourceNotFoundException, MetaMatrixComponentException {
- if(this.rowCount == 0 || this.outputBeginRow > this.rowCount) {
+ if (this.rowCount == -1) {
+ this.rowCount = getBufferManager().getFinalRowCount(outputID);
+ if (this.rowCount == -1) {
+ this.phase = this.collector.isDone()?SORT:COLLECTION;
+ }
+ }
+ if(this.rowCount == 0 || (this.rowCount != -1 && this.outputBeginRow > this.rowCount)) {
TupleBatch terminationBatch = new TupleBatch(1, Collections.EMPTY_LIST);
terminationBatch.setTerminationFlag(true);
return terminationBatch;
@@ -171,13 +149,13 @@
int endPinned = this.outputBeginRow+getBatchSize()-1;
try {
TupleBatch outputBatch = getBufferManager().pinTupleBatch(outputID, beginPinned, endPinned);
-
+
this.outputBeginRow += outputBatch.getRowCount();
- if(outputBeginRow > rowCount) {
+ if(rowCount != -1 && outputBeginRow > rowCount) {
outputBatch.setTerminationFlag(true);
}
-
+
return outputBatch;
} catch(MemoryNotAvailableException e) {
throw BlockedOnMemoryException.INSTANCE;
@@ -206,18 +184,17 @@
protected void getNodeString(StringBuffer str) {
super.getNodeString(str);
- str.append(sortElements);
+ str.append("[").append(mode).append("] "); //$NON-NLS-1$ //$NON-NLS-2$
+ if (this.mode != Mode.DUP_REMOVE) {
+ str.append(sortElements);
+ }
}
protected void copy(SortNode source, SortNode target){
super.copy(source, target);
- if(source.sortElements != null){
- target.sortElements = new ArrayList(source.sortElements);
- }
- if(sortTypes != null){
- target.sortTypes = new ArrayList(source.sortTypes);
- }
- target.removeDuplicates = source.removeDuplicates;
+ target.sortElements = source.sortElements;
+ target.sortTypes = source.sortTypes;
+ target.mode = source.mode;
}
public Object clone(){
@@ -230,9 +207,19 @@
public Map getDescriptionProperties() {
// Default implementation - should be overridden
Map props = super.getDescriptionProperties();
- props.put(PROP_TYPE, "Sort"); //$NON-NLS-1$
+ switch (mode) {
+ case SORT:
+ props.put(PROP_TYPE, "Sort"); //$NON-NLS-1$
+ break;
+ case DUP_REMOVE:
+ props.put(PROP_TYPE, "Duplicate Removal"); //$NON-NLS-1$
+ break;
+ case DUP_REMOVE_SORT:
+ props.put(PROP_TYPE, "Duplicate Removal And Sort"); //$NON-NLS-1$
+ break;
+ }
- if(this.sortElements != null) {
+ if(this.mode != Mode.DUP_REMOVE && this.sortElements != null) {
Boolean ASC_B = Boolean.valueOf(OrderBy.ASC);
List cols = new ArrayList(this.sortElements.size());
for(int i=0; i<this.sortElements.size(); i++) {
@@ -246,7 +233,7 @@
props.put(PROP_SORT_COLS, cols);
}
- props.put(PROP_REMOVE_DUPS, "" + this.removeDuplicates); //$NON-NLS-1$
+ props.put(PROP_REMOVE_DUPS, this.mode);
return props;
}
Modified: trunk/engine/src/main/java/com/metamatrix/query/processor/relational/SortUtility.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/processor/relational/SortUtility.java 2009-04-27 19:02:50 UTC (rev 846)
+++ trunk/engine/src/main/java/com/metamatrix/query/processor/relational/SortUtility.java 2009-04-28 17:36:46 UTC (rev 847)
@@ -30,9 +30,10 @@
import java.util.List;
import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.common.buffer.BlockedException;
+import com.metamatrix.api.exception.MetaMatrixProcessingException;
import com.metamatrix.common.buffer.BlockedOnMemoryException;
import com.metamatrix.common.buffer.BufferManager;
+import com.metamatrix.common.buffer.IndexedTupleSource;
import com.metamatrix.common.buffer.MemoryNotAvailableException;
import com.metamatrix.common.buffer.TupleBatch;
import com.metamatrix.common.buffer.TupleSourceID;
@@ -40,58 +41,74 @@
import com.metamatrix.common.buffer.BufferManager.TupleSourceStatus;
import com.metamatrix.common.buffer.BufferManager.TupleSourceType;
import com.metamatrix.core.util.Assertion;
+import com.metamatrix.query.sql.lang.OrderBy;
import com.metamatrix.query.sql.symbol.SingleElementSymbol;
import com.metamatrix.query.util.TypeRetrievalUtil;
/**
*/
public class SortUtility {
+
+ public enum Mode {
+ SORT,
+ DUP_REMOVE,
+ DUP_REMOVE_SORT
+ }
+ //constructor state
private TupleSourceID sourceID;
- private List sourceElements;
- private List sortElements;
- private List sortTypes;
- private boolean removeDuplicates;
-
- private BufferManager bufferManager;
+ protected List sortElements;
+ protected List<Boolean> sortTypes;
+ private Mode mode;
+ protected BufferManager bufferManager;
private String groupName;
+ private boolean useAllColumns;
+
+ //init state
private int batchSize;
- private List schema;
+ protected List schema;
private String[] schemaTypes;
+ protected int[] sortCols;
+ private Comparator comparator;
- // For collecting tuples to be sorted
+ private TupleSourceID outputID;
+ private boolean doneReading;
private int sortPhaseRow = 1;
- private int phase = SORT;
- private int rowCount;
- private int[] sortCols;
- private List activeTupleIDs = new ArrayList();
- private List workingBatches;
+ private int phase = INITIAL_SORT;
+ protected List<TupleSourceID> activeTupleIDs = new ArrayList<TupleSourceID>();
+ private List<TupleBatch> workingBatches;
private int[] workingPointers;
+ private int masterSortIndex;
+ private TupleSourceID mergedID;
+ private TupleSourceID tempOutId;
// Phase constants for readability
- private static final int SORT = 1;
+ private static final int INITIAL_SORT = 1;
private static final int MERGE = 2;
private static final int DONE = 3;
-
- /**
- * Constructor for SortUtility.
- */
- public SortUtility(TupleSourceID sourceID, List sourceElements, List sortElements, List sortTypes, boolean removeDuplicates,
- BufferManager bufferMgr, String groupName) {
-
+
+ public SortUtility(TupleSourceID sourceID, List sortElements, List<Boolean> sortTypes, boolean removeDups, BufferManager bufferMgr,
+ String groupName) {
+ this(sourceID, sortElements, sortTypes, removeDups?Mode.DUP_REMOVE_SORT:Mode.SORT, bufferMgr, groupName, false);
+ }
+
+ public SortUtility(TupleSourceID sourceID, List sortElements, List<Boolean> sortTypes, Mode mode, BufferManager bufferMgr,
+ String groupName, boolean useAllColumns) {
this.sourceID = sourceID;
- this.sourceElements = sourceElements;
this.sortElements = sortElements;
this.sortTypes = sortTypes;
- this.removeDuplicates = removeDuplicates;
+ this.mode = mode;
this.bufferManager = bufferMgr;
this.groupName = groupName;
+ this.useAllColumns = useAllColumns;
}
-
- /**
- */
+
+ public boolean isDone() {
+ return this.doneReading && this.phase == DONE;
+ }
+
public TupleSourceID sort()
- throws BlockedException, MetaMatrixComponentException {
+ throws BlockedOnMemoryException, MetaMatrixComponentException {
try {
// One time setup
@@ -99,23 +116,25 @@
initialize();
}
- if (rowCount == 0) {
- TupleSourceID mergedID = bufferManager.createTupleSource(this.schema, this.schemaTypes, this.groupName, TupleSourceType.PROCESSOR);
- activeTupleIDs.add(mergedID);
- phase = DONE;
+ if(this.phase == INITIAL_SORT) {
+ initialSort();
}
- if(this.phase == SORT) {
- sortPhase();
- }
-
if(this.phase == MERGE) {
try {
mergePhase();
} finally {
+ if (this.mergedID != null) {
+ this.bufferManager.removeTupleSource(mergedID);
+ this.mergedID = null;
+ }
+ if (this.tempOutId != null) {
+ this.bufferManager.removeTupleSource(tempOutId);
+ this.tempOutId = null;
+ }
if (workingBatches != null) {
for (int i = 0; i < workingBatches.size(); i++) {
- TupleBatch tupleBatch = (TupleBatch)workingBatches.get(i);
+ TupleBatch tupleBatch = workingBatches.get(i);
if (tupleBatch != null) {
unpinWorkingBatch(i, tupleBatch);
}
@@ -124,191 +143,216 @@
workingBatches = null;
}
}
-
- TupleSourceID result = (TupleSourceID) this.activeTupleIDs.get(0);
- this.bufferManager.setStatus(result, TupleSourceStatus.FULL);
- return result;
+ if (this.outputID != null) {
+ return this.outputID;
+ }
+ return this.activeTupleIDs.get(0);
} catch(TupleSourceNotFoundException e) {
throw new MetaMatrixComponentException(e, e.getMessage());
}
}
- protected void sortPhase() throws BlockedException, TupleSourceNotFoundException, MetaMatrixComponentException {
- ArrayList pinned = new ArrayList(); // of int[2] representing begin, end
+ private TupleSourceID createTupleSource() throws MetaMatrixComponentException {
+ return bufferManager.createTupleSource(this.schema, this.schemaTypes, this.groupName, TupleSourceType.PROCESSOR);
+ }
- // Loop until all data has been read and sorted
- while(sortPhaseRow <= this.rowCount) {
- List workingTuples = new ArrayList();
+ protected void initialSort() throws BlockedOnMemoryException, TupleSourceNotFoundException, MetaMatrixComponentException {
+ while(!doneReading) {
+ ArrayList<int[]> pinned = new ArrayList<int[]>(); // of int[2] representing begin, end
+ List<List<Object>> workingTuples = new ArrayList<List<Object>>();
+ // Load data until out of memory
+ while(!doneReading) {
+ try {
+ // Load and pin batch
+ TupleBatch batch = bufferManager.pinTupleBatch(sourceID, sortPhaseRow, sortPhaseRow + batchSize - 1);
+
+ if (batch.getRowCount() == 0) {
+ if (bufferManager.getStatus(sourceID) == TupleSourceStatus.FULL) {
+ doneReading = true;
+ }
+ break;
+ }
+ // Remember pinned rows
+ pinned.add(new int[] { sortPhaseRow, batch.getEndRow() });
- // Load data until out of memory
- while(sortPhaseRow <= this.rowCount) {
- try {
- // Load and pin batch
- TupleBatch batch = bufferManager.pinTupleBatch(sourceID, sortPhaseRow, sortPhaseRow + batchSize - 1);
+ addTuples(workingTuples, batch);
+
+ sortPhaseRow += batch.getRowCount();
+ } catch(MemoryNotAvailableException e) {
+ break;
+ }
+ }
+
+ if(workingTuples.isEmpty()) {
+ break;
+ }
+
+ TupleSourceID activeID = createTupleSource();
+ activeTupleIDs.add(activeID);
+ int sortedThisPass = workingTuples.size();
+ if (this.mode == Mode.SORT) {
+ //perform a stable sort
+ Collections.sort(workingTuples, comparator);
+ }
+ int writeBegin = 1;
+ while(writeBegin <= sortedThisPass) {
+ int writeEnd = Math.min(sortedThisPass, writeBegin + batchSize - 1);
+
+ TupleBatch writeBatch = new TupleBatch(writeBegin, workingTuples.subList(writeBegin-1, writeEnd));
+ bufferManager.addTupleBatch(activeID, writeBatch);
+ writeBegin += writeBatch.getRowCount();
+ }
+
+ // Clean up - unpin rows
+ for (int[] bounds : pinned) {
+ bufferManager.unpinTupleBatch(sourceID, bounds[0], bounds[1]);
+ }
+ }
- if(batch.getRowCount() > 0) {
- // Remember pinned rows
- pinned.add(new int[] { sortPhaseRow, batch.getEndRow() });
+ if (!doneReading && (mode != Mode.DUP_REMOVE || this.activeTupleIDs.isEmpty())) {
+ throw BlockedOnMemoryException.INSTANCE;
+ }
+
+ if (this.activeTupleIDs.isEmpty()) {
+ activeTupleIDs.add(createTupleSource());
+ }
- // Add to previous batches for sorting
- workingTuples.addAll(Arrays.asList(batch.getAllTuples()));
+ // Clean up
+ this.phase = MERGE;
+ }
- // Adjust beginning of next batch
- sortPhaseRow = batch.getEndRow() + 1;
- }
-
+ protected void addTuples(List workingTuples, TupleBatch batch) {
+ if (this.mode == Mode.SORT) {
+ workingTuples.addAll(Arrays.asList(batch.getAllTuples()));
+ return;
+ }
+ for (List<Object> list : batch.getAllTuples()) {
+ int index = Collections.binarySearch(workingTuples, list, comparator);
+ if (index >= 0) {
+ continue;
+ }
+ workingTuples.add(-index - 1, list);
+ }
+ }
+
+ protected void mergePhase() throws BlockedOnMemoryException, MetaMatrixComponentException, TupleSourceNotFoundException {
+ TupleCollector outCollector = null;
+ while(this.activeTupleIDs.size() > 1) {
+ // Load and pin batch from sorted sublists while memory available
+ this.workingBatches = new ArrayList<TupleBatch>(activeTupleIDs.size());
+ int sortedIndex = 0;
+ for(; sortedIndex<activeTupleIDs.size(); sortedIndex++) {
+ TupleSourceID activeID = activeTupleIDs.get(sortedIndex);
+ try {
+ TupleBatch sortedBatch = bufferManager.pinTupleBatch(activeID, 1, this.batchSize);
+ workingBatches.add(sortedBatch);
} catch(MemoryNotAvailableException e) {
break;
}
}
-
- // Check for no memory available and block
- if(workingTuples.isEmpty()) {
- /* Defect 19087: We couldn't load any batches in memory, and we need to re-enqueue the work,
- * so this should be a BlockedOnMemoryException instead of a BlockedException
- */
+
+ //if we cannot make progress, just block for now
+ if (workingBatches.size() < 2) {
throw BlockedOnMemoryException.INSTANCE;
}
+
+ // Initialize pointers into working batches
+ this.workingPointers = new int[workingBatches.size()];
+ Arrays.fill(this.workingPointers, 1);
- // Sort whatever is in memory
- Comparator comp = new ListNestedSortComparator(sortCols, sortTypes);
- Collections.sort( workingTuples, comp );
+ mergedID = createTupleSource();
- // Write to temporary tuple source
- TupleSourceID sortedID = bufferManager.createTupleSource(this.schema, this.schemaTypes, this.groupName, TupleSourceType.PROCESSOR);
- activeTupleIDs.add(sortedID);
- int sortedThisPass = workingTuples.size();
- int writeBegin = 1;
- while(writeBegin <= sortedThisPass) {
- int writeEnd = Math.min(sortedThisPass, writeBegin + batchSize - 1);
-
- TupleBatch writeBatch = new TupleBatch(writeBegin, workingTuples.subList(writeBegin-1, writeEnd));
- bufferManager.addTupleBatch(sortedID, writeBatch);
- writeBegin += writeBatch.getRowCount();
- }
-
- // Clean up - unpin rows
- Iterator iter = pinned.iterator();
- while(iter.hasNext()) {
- int[] bounds = (int[]) iter.next();
- bufferManager.unpinTupleBatch(sourceID, bounds[0], bounds[1]);
- }
- pinned.clear();
- }
-
- // Clean up
- this.phase = MERGE;
- }
-
- protected void mergePhase() throws BlockedException, TupleSourceNotFoundException, MetaMatrixComponentException {
- // In the case where there is a single activeTupleID but removeDuplicates == true,
- // we need to execute this loop exactly once. We also need to execute any time
- // the number of active tuple IDs is > 1
-
- if(this.activeTupleIDs.size() > 1 || this.removeDuplicates) {
- do {
- // Load and pin batch from sorted sublists while memory available
- this.workingBatches = new ArrayList(activeTupleIDs.size());
- int sortedIndex = 0;
- for(; sortedIndex<activeTupleIDs.size(); sortedIndex++) {
- TupleSourceID activeID = (TupleSourceID) activeTupleIDs.get(sortedIndex);
- try {
- TupleBatch sortedBatch = bufferManager.pinTupleBatch(activeID, 1, this.batchSize);
- workingBatches.add(sortedBatch);
- } catch(MemoryNotAvailableException e) {
- break;
- }
- }
-
- //if we cannot make progress, just block for now
- if (workingBatches.size() < 2 && !(workingBatches.size() == 1 && this.removeDuplicates && activeTupleIDs.size() == 1)) {
- throw BlockedOnMemoryException.INSTANCE;
- }
-
- // Initialize pointers into working batches
- this.workingPointers = new int[workingBatches.size()];
+ // Merge from working sorted batches
+ TupleCollector collector = new TupleCollector(mergedID, this.bufferManager);
+ while(true) {
+ // Find least valued row among working batches
+ List<?> currentRow = null;
+ int chosenBatchIndex = -1;
+ TupleBatch chosenBatch = null;
for(int i=0; i<workingBatches.size(); i++) {
- this.workingPointers[i] = 1;
- }
-
- // Initialize merge output
- TupleSourceID mergedID = bufferManager.createTupleSource(this.schema, this.schemaTypes, this.groupName, TupleSourceType.PROCESSOR);
- int mergedRowBegin = 1;
-
- // Merge from working sorted batches
- List currentRows = new ArrayList(this.batchSize);
- ListNestedSortComparator comparator = new ListNestedSortComparator(sortCols, sortTypes);
- while(true) {
- // Find least valued row among working batches
- List currentRow = null;
- int chosenBatchIndex = -1;
- TupleBatch chosenBatch = null;
- for(int i=0; i<workingBatches.size(); i++) {
- TupleBatch batch = (TupleBatch) workingBatches.get(i);
- if(batch != null) {
- List testRow = batch.getTuple(workingPointers[i]);
- if(currentRow == null || comparator.compare(testRow, currentRow) < 0) {
- // Found lower row
- currentRow = testRow;
- chosenBatchIndex = i;
- chosenBatch = batch;
- }
- }
+ TupleBatch batch = workingBatches.get(i);
+ if(batch == null) {
+ continue;
}
-
- // Check for termination condition - all batches must have been null
- if(currentRow == null) {
- break;
+ List<?> testRow = batch.getTuple(workingPointers[i]);
+ int compare = -1;
+ if (currentRow != null) {
+ compare = comparator.compare(testRow, currentRow);
}
- // Output the row and update pointers
- currentRows.add(currentRow);
- incrementWorkingBatch(chosenBatchIndex, chosenBatch);
-
- // Move past this same row on all batches if dup removal is on
- if(this.removeDuplicates) {
- for(int i=0; i<workingBatches.size(); i++) {
- TupleBatch batch = (TupleBatch) workingBatches.get(i);
- while(batch != null) {
- List testRow = batch.getTuple(workingPointers[i]);
- if(comparator.compare(testRow, currentRow) == 0) {
- if(incrementWorkingBatch(i, batch)) {
- batch = (TupleBatch) workingBatches.get(i);
- }
- } else {
- break;
- }
- }
- }
+ if(compare < 0) {
+ // Found lower row
+ currentRow = testRow;
+ chosenBatchIndex = i;
+ chosenBatch = batch;
+ } else if (compare == 0 && this.mode != Mode.SORT) {
+ incrementWorkingBatch(i, batch);
}
-
-
- // Check for full batch and store
- if(currentRows.size() == this.batchSize) {
- bufferManager.addTupleBatch(mergedID, new TupleBatch(mergedRowBegin, currentRows));
- mergedRowBegin = mergedRowBegin + this.batchSize;
- currentRows = new ArrayList(this.batchSize);
- }
}
- // Save any remaining partial batch
- if(currentRows.size() > 0) {
- bufferManager.addTupleBatch(mergedID, new TupleBatch(mergedRowBegin, currentRows));
+ // Check for termination condition - all batches must have been null
+ if(currentRow == null) {
+ break;
}
-
- // Remove merged sublists
- for(int i=0; i<sortedIndex; i++) {
- bufferManager.removeTupleSource((TupleSourceID)activeTupleIDs.remove(0));
+ // Output the row and update pointers
+ collector.addTuple(currentRow);
+ if (this.outputID != null && chosenBatchIndex != masterSortIndex && sortedIndex > masterSortIndex) {
+ if (outCollector == null) {
+ tempOutId = createTupleSource();
+ outCollector = new TupleCollector(tempOutId, this.bufferManager);
+ }
+ outCollector.addTuple(currentRow);
}
+ incrementWorkingBatch(chosenBatchIndex, chosenBatch);
+ }
- this.activeTupleIDs.add(mergedID);
-
- } while(this.activeTupleIDs.size() > 1);
+ // Save without closing
+ collector.saveBatch(false);
+
+ // Remove merged sublists
+ for(int i=0; i<sortedIndex; i++) {
+ TupleSourceID id = activeTupleIDs.remove(0);
+ if (!id.equals(this.outputID)) {
+ bufferManager.removeTupleSource(id);
+ }
+ }
+
+ this.activeTupleIDs.add(mergedID);
+ this.mergedID = null;
+ masterSortIndex = masterSortIndex - sortedIndex + 1;
+ if (masterSortIndex < 0) {
+ masterSortIndex = this.activeTupleIDs.size() - 1;
+ }
+ }
+
+ if (outCollector != null) {
+ outCollector.close();
+ //transfer the new dup removed tuples to the output id
+ TupleCollector tc = new TupleCollector(outputID, this.bufferManager);
+ IndexedTupleSource ts = this.bufferManager.getTupleSource(outCollector.getTupleSourceID());
+ try {
+ while (ts.hasNext()) {
+ tc.addTuple(ts.nextTuple());
+ }
+ } catch (MetaMatrixProcessingException e) {
+ throw new MetaMatrixComponentException(e);
+ }
}
-
+
// Close sorted source (all others have been removed)
- bufferManager.setStatus((TupleSourceID) activeTupleIDs.get(0), TupleSourceStatus.FULL);
- this.phase = DONE;
+ if (doneReading) {
+ bufferManager.setStatus(activeTupleIDs.get(0), TupleSourceStatus.FULL);
+ if (this.outputID != null) {
+ bufferManager.setStatus(outputID, TupleSourceStatus.FULL);
+ }
+ this.phase = DONE;
+ return;
+ }
+ Assertion.assertTrue(mode == Mode.DUP_REMOVE);
+ if (this.outputID == null) {
+ this.outputID = activeTupleIDs.get(0);
+ }
+ this.phase = INITIAL_SORT;
}
/**
@@ -316,7 +360,7 @@
* for that batchIndex, which we already happen to have. Return whether the batch
* was changed or not. True = changed.
*/
- private boolean incrementWorkingBatch(int batchIndex, TupleBatch currentBatch) throws BlockedOnMemoryException, TupleSourceNotFoundException, MetaMatrixComponentException {
+ private void incrementWorkingBatch(int batchIndex, TupleBatch currentBatch) throws BlockedOnMemoryException, TupleSourceNotFoundException, MetaMatrixComponentException {
workingPointers[batchIndex] += 1;
if(workingPointers[batchIndex] > currentBatch.getEndRow()) {
TupleSourceID tsID = unpinWorkingBatch(batchIndex, currentBatch);
@@ -332,22 +376,16 @@
} else {
workingBatches.set(batchIndex, newBatch);
}
-
- // Return true
- return true;
-
} catch(MemoryNotAvailableException e) {
throw BlockedOnMemoryException.INSTANCE;
}
-
}
- return false;
}
private TupleSourceID unpinWorkingBatch(int batchIndex,
TupleBatch currentBatch) throws TupleSourceNotFoundException,
MetaMatrixComponentException {
- TupleSourceID tsID = (TupleSourceID)activeTupleIDs.get(batchIndex);
+ TupleSourceID tsID = activeTupleIDs.get(batchIndex);
int lastBeginRow = currentBatch.getBeginRow();
int lastEndRow = currentBatch.getEndRow();
bufferManager.unpinTupleBatch(tsID, lastBeginRow, lastEndRow);
@@ -358,19 +396,33 @@
this.schema = this.bufferManager.getTupleSchema(this.sourceID);
this.schemaTypes = TypeRetrievalUtil.getTypeNames(schema);
this.batchSize = bufferManager.getProcessorBatchSize();
- this.rowCount = bufferManager.getRowCount(this.sourceID);
+ if (useAllColumns && mode != Mode.SORT) {
+ if (this.sortElements != null) {
+ this.sortElements = new ArrayList(this.sortElements);
+ List toAdd = new ArrayList(schema);
+ toAdd.removeAll(this.sortElements);
+ this.sortElements.addAll(toAdd);
+ this.sortTypes = new ArrayList<Boolean>(this.sortTypes);
+ this.sortTypes.addAll(Collections.nCopies(this.sortElements.size() - this.sortTypes.size(), OrderBy.ASC));
+ } else {
+ this.sortElements = this.schema;
+ this.sortTypes = Collections.nCopies(this.sortElements.size(), OrderBy.ASC);
+ }
+ }
+
int[] cols = new int[sortElements.size()];
Iterator iter = sortElements.iterator();
for (int i = 0; i < cols.length; i++) {
- SingleElementSymbol elem = (SingleElementSymbol) iter.next();
+ SingleElementSymbol elem = (SingleElementSymbol)iter.next();
- cols[i] = sourceElements.indexOf(elem);
+ cols[i] = schema.indexOf(elem);
Assertion.assertTrue(cols[i] != -1);
}
-
this.sortCols = cols;
+ this.comparator = new ListNestedSortComparator(sortCols, sortTypes);
}
+
}
Added: trunk/engine/src/main/java/com/metamatrix/query/processor/relational/TupleCollector.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/processor/relational/TupleCollector.java (rev 0)
+++ trunk/engine/src/main/java/com/metamatrix/query/processor/relational/TupleCollector.java 2009-04-28 17:36:46 UTC (rev 847)
@@ -0,0 +1,86 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package com.metamatrix.query.processor.relational;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import com.metamatrix.api.exception.MetaMatrixComponentException;
+import com.metamatrix.common.buffer.BufferManager;
+import com.metamatrix.common.buffer.TupleBatch;
+import com.metamatrix.common.buffer.TupleSourceID;
+import com.metamatrix.common.buffer.TupleSourceNotFoundException;
+import com.metamatrix.common.buffer.BufferManager.TupleSourceStatus;
+
+public class TupleCollector {
+
+ private TupleSourceID tsid;
+
+ private int batchSize;
+ private ArrayList<List<?>> batch;
+ private int index;
+ private BufferManager bm;
+
+ public TupleCollector(TupleSourceID tsid, BufferManager bm) throws TupleSourceNotFoundException, MetaMatrixComponentException {
+ this.tsid = tsid;
+ this.batchSize = bm.getProcessorBatchSize();
+ this.bm = bm;
+ this.index = bm.getRowCount(tsid) + 1;
+ }
+
+ public TupleSourceID getTupleSourceID() {
+ return tsid;
+ }
+
+ public void addTuple(List<?> tuple) throws TupleSourceNotFoundException, MetaMatrixComponentException {
+ if (batch == null) {
+ batch = new ArrayList<List<?>>(batchSize/4);
+ }
+ batch.add(tuple);
+ if (batch.size() == batchSize) {
+ saveBatch(false);
+ }
+ }
+
+ public void saveBatch(boolean isLast) throws TupleSourceNotFoundException,
+ MetaMatrixComponentException {
+ ArrayList<List<?>> toSave = batch;
+ if (toSave == null || toSave.isEmpty()) {
+ if (!isLast) {
+ return;
+ }
+ toSave = new ArrayList<List<?>>(0);
+ }
+ TupleBatch tb = new TupleBatch(index, toSave);
+ tb.setTerminationFlag(isLast);
+ this.bm.addTupleBatch(tsid, tb);
+ this.index += toSave.size();
+ batch = null;
+ }
+
+ public void close() throws TupleSourceNotFoundException, MetaMatrixComponentException {
+ saveBatch(true);
+ this.bm.setStatus(this.tsid, TupleSourceStatus.FULL);
+ }
+
+}
Property changes on: trunk/engine/src/main/java/com/metamatrix/query/processor/relational/TupleCollector.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestLimit.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestLimit.java 2009-04-27 19:02:50 UTC (rev 846)
+++ trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestLimit.java 2009-04-28 17:36:46 UTC (rev 847)
@@ -31,6 +31,8 @@
import com.metamatrix.query.mapping.relational.QueryNode;
import com.metamatrix.query.optimizer.TestOptimizer.DependentProjectNode;
import com.metamatrix.query.optimizer.TestOptimizer.DependentSelectNode;
+import com.metamatrix.query.optimizer.TestOptimizer.DupRemoveNode;
+import com.metamatrix.query.optimizer.TestOptimizer.DupRemoveSortNode;
import com.metamatrix.query.optimizer.capabilities.BasicSourceCapabilities;
import com.metamatrix.query.optimizer.capabilities.FakeCapabilitiesFinder;
import com.metamatrix.query.optimizer.capabilities.SourceCapabilities.Capability;
@@ -39,7 +41,6 @@
import com.metamatrix.query.processor.TestProcessor;
import com.metamatrix.query.processor.relational.AccessNode;
import com.metamatrix.query.processor.relational.DependentAccessNode;
-import com.metamatrix.query.processor.relational.DupRemoveNode;
import com.metamatrix.query.processor.relational.GroupingNode;
import com.metamatrix.query.processor.relational.LimitNode;
import com.metamatrix.query.processor.relational.MergeJoinStrategy;
@@ -575,7 +576,7 @@
0, // DependentAccess
0, // DependentSelect
0, // DependentProject
- 1, // DupRemove
+ 0, // DupRemove
0, // Grouping
1, // Limit
0, // NestedLoopJoinStrategy
@@ -584,9 +585,10 @@
0, // PlanExecution
0, // Project
0, // Select
- 1, // Sort
+ 0, // Sort
1 // UnionAll
}, NODE_TYPES);
+ TestOptimizer.checkNodeTypes(plan, new int[] {1}, new Class[]{DupRemoveSortNode.class});
}
public void testCombinedLimits() throws Exception {
Modified: trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestOptimizer.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestOptimizer.java 2009-04-27 19:02:50 UTC (rev 846)
+++ trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestOptimizer.java 2009-04-28 17:36:46 UTC (rev 847)
@@ -58,7 +58,6 @@
import com.metamatrix.query.processor.ProcessorPlan;
import com.metamatrix.query.processor.relational.AccessNode;
import com.metamatrix.query.processor.relational.DependentAccessNode;
-import com.metamatrix.query.processor.relational.DupRemoveNode;
import com.metamatrix.query.processor.relational.GroupingNode;
import com.metamatrix.query.processor.relational.JoinNode;
import com.metamatrix.query.processor.relational.MergeJoinStrategy;
@@ -72,6 +71,7 @@
import com.metamatrix.query.processor.relational.SelectNode;
import com.metamatrix.query.processor.relational.SortNode;
import com.metamatrix.query.processor.relational.UnionAllNode;
+import com.metamatrix.query.processor.relational.SortUtility.Mode;
import com.metamatrix.query.resolver.QueryResolver;
import com.metamatrix.query.resolver.util.BindVariableVisitor;
import com.metamatrix.query.rewriter.QueryRewriter;
@@ -92,6 +92,8 @@
public interface DependentJoin {}
public interface DependentSelectNode {}
public interface DependentProjectNode {}
+ public interface DupRemoveNode {}
+ public interface DupRemoveSortNode {}
public static final int[] FULL_PUSHDOWN = new int[] {
1, // Access
@@ -441,6 +443,19 @@
} else {
updateCounts(DependentSelectNode.class, counts, types);
}
+ } else if (nodeType.equals(SortNode.class)) {
+ Mode mode = ((SortNode)relationalNode).getMode();
+ switch(mode) {
+ case DUP_REMOVE:
+ updateCounts(DupRemoveNode.class, counts, types);
+ break;
+ case DUP_REMOVE_SORT:
+ updateCounts(DupRemoveSortNode.class, counts, types);
+ break;
+ case SORT:
+ updateCounts(SortNode.class, counts, types);
+ break;
+ }
} else {
updateCounts(nodeType, counts, types);
}
@@ -7145,7 +7160,7 @@
// Create query
String sql = "select IntKey from bqt1.smalla where stringkey not like '2%'"; //$NON-NLS-1$
- ProcessorPlan plan = helpPlan(sql, FakeMetadataFactory.exampleBQT(), null, capFinder,
+ ProcessorPlan plan = helpPlan(sql, FakeMetadataFactory.exampleBQTCached(), null, capFinder,
new String[] {"SELECT stringkey, IntKey FROM bqt1.smalla"}, TestOptimizer.SHOULD_SUCCEED); //$NON-NLS-1$
checkNodeTypes(plan, new int[] {
Added: trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestSortOptimization.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestSortOptimization.java (rev 0)
+++ trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestSortOptimization.java 2009-04-28 17:36:46 UTC (rev 847)
@@ -0,0 +1,111 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package com.metamatrix.query.optimizer;
+
+import static com.metamatrix.query.optimizer.TestOptimizer.*;
+
+import org.junit.Test;
+
+import com.metamatrix.query.optimizer.capabilities.BasicSourceCapabilities;
+import com.metamatrix.query.optimizer.capabilities.FakeCapabilitiesFinder;
+import com.metamatrix.query.processor.ProcessorPlan;
+import com.metamatrix.query.unittest.FakeMetadataFactory;
+
+public class TestSortOptimization {
+
+ @Test public void testSortDupCombination() {
+ FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+ BasicSourceCapabilities caps = new BasicSourceCapabilities();
+ capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+ // Create query
+ String sql = "select distinct e1, e2 from pm1.g1 order by e2"; //$NON-NLS-1$
+
+ ProcessorPlan plan = helpPlan(sql, FakeMetadataFactory.example1Cached(), null, capFinder,
+ new String[] {"SELECT e1, e2 FROM pm1.g1"}, TestOptimizer.SHOULD_SUCCEED); //$NON-NLS-1$
+
+ checkNodeTypes(plan, FULL_PUSHDOWN);
+ checkNodeTypes(plan, new int[] {1}, new Class[] {DupRemoveSortNode.class});
+ }
+
+ @Test public void testSortDupCombination1() {
+ FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+ BasicSourceCapabilities caps = new BasicSourceCapabilities();
+ capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+ // Create query
+ String sql = "select e1, e2 from pm1.g1 union select e1, e2 from pm1.g2 order by e2"; //$NON-NLS-1$
+
+ ProcessorPlan plan = helpPlan(sql, FakeMetadataFactory.example1Cached(), null, capFinder,
+ new String[] {"SELECT e1, e2 FROM pm1.g1", "SELECT e1, e2 FROM pm1.g2"}, TestOptimizer.SHOULD_SUCCEED); //$NON-NLS-1$ //$NON-NLS-2$
+
+ checkNodeTypes(plan, new int[] {
+ 2, // Access
+ 0, // DependentAccess
+ 0, // DependentSelect
+ 0, // DependentProject
+ 0, // DupRemove
+ 0, // Grouping
+ 0, // NestedLoopJoinStrategy
+ 0, // MergeJoinStrategy
+ 0, // Null
+ 0, // PlanExecution
+ 0, // Project
+ 0, // Select
+ 0, // Sort
+ 1 // UnionAll
+ });
+ checkNodeTypes(plan, new int[] {1}, new Class[] {DupRemoveSortNode.class});
+ }
+
+ @Test public void testSortDupCombination2() {
+ FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+ BasicSourceCapabilities caps = new BasicSourceCapabilities();
+ capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+ // Create query
+ String sql = "select x.*, y.* from (select distinct e1, e2 from pm1.g1) x, (select distinct e1, e2 from pm1.g2) y where x.e1 = y.e1"; //$NON-NLS-1$
+
+ ProcessorPlan plan = helpPlan(sql, FakeMetadataFactory.example1Cached(), null, capFinder,
+ new String[] {"SELECT e1, e2 FROM pm1.g1", "SELECT e1, e2 FROM pm1.g2"}, TestOptimizer.SHOULD_SUCCEED); //$NON-NLS-1$ //$NON-NLS-2$
+
+ checkNodeTypes(plan, new int[] {
+ 2, // Access
+ 0, // DependentAccess
+ 0, // DependentSelect
+ 0, // DependentProject
+ 0, // DupRemove
+ 0, // Grouping
+ 0, // NestedLoopJoinStrategy
+ 1, // MergeJoinStrategy
+ 0, // Null
+ 0, // PlanExecution
+ 1, // Project
+ 0, // Select
+ 0, // Sort
+ 0 // UnionAll
+ });
+ checkNodeTypes(plan, new int[] {0}, new Class[] {DupRemoveSortNode.class});
+ }
+
+}
Property changes on: trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestSortOptimization.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/engine/src/test/java/com/metamatrix/query/optimizer/xml/TestXMLPlanner.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/optimizer/xml/TestXMLPlanner.java 2009-04-27 19:02:50 UTC (rev 846)
+++ trunk/engine/src/test/java/com/metamatrix/query/optimizer/xml/TestXMLPlanner.java 2009-04-28 17:36:46 UTC (rev 847)
@@ -923,8 +923,7 @@
XMLPlan plan = helpPlan(
"SELECT * FROM vm1.doc1 ORDER BY vm1.doc1.a0.a1.c1", //$NON-NLS-1$
example1());
- System.out.println((plan.getDescriptionProperties().get(Describable.PROP_CHILDREN)).toString());
- assertEquals("[{formatted=false, encoding=UTF-8, type=START DOCUMENT}, {tag=a0, type=ADD ELEMENT, namespaceDeclarations=[], namespace=}, {type=NEXT IN DOCUMENT}, {isStaging=true, resultSet=tm1.g1, type=Staging Table}, {sql=VM1.G1_1, isStaging=false, resultSet=VM1.G1_1, type=EXECUTE SQL}, {resultSet=VM1.G1_1, type=BLOCK}, {resultSet=VM1.G1_1, type=NEXT ROW}, {program={children=[{tag=a1, type=ADD ELEMENT, namespaceDeclarations=[], namespace=}, {type=NEXT IN DOCUMENT}, {tag=a1, dataCol=VM1.G1_1.e1, type=ADD ELEMENT, namespaceDeclarations=[], namespace=}, {tag=b1, dataCol=VM1.G1_1.e2, type=ADD ELEMENT, namespaceDeclarations=[], namespace=}, {tag=c1, dataCol=VM1.G1_1.e3, type=ADD ELEMENT, namespaceDeclarations=[], namespace=}, {type=UP IN DOCUMENT}, {resultSet=VM1.G1_1, type=NEXT ROW}], type=XML Program}, resultSet=VM1.G1_1, type=LOOP}, {resultSet=VM1.G1_1, type=CLOSE RESULTSET}, {type=UP IN DOCUMENT}, {type=END DOCUMENT}, {isStaging=true, resultSet=unload_tm1.g1, type=S!
taging Table}, {children=[{removeDups=false, sortCols=[#TM1_G1.E3 ASC], nodeCostEstimates=[Estimated Node Cardinality: -1.0], children=[{nodeCostEstimates=[Estimated Node Cardinality: -1.0], children=[{modelName=__TEMP__, sql=SELECT #TM1_G1.E1, #TM1_G1.E2, #TM1_G1.E3, #TM1_G1.E4 FROM #TM1_G1, nodeCostEstimates=[Estimated Node Cardinality: -1.0], children=[], type=Access, outputCols=[E1 (string), E2 (integer), E3 (boolean), E4 (double)]}], selectCols=[#TM1_G1.E1, #TM1_G1.E2, #TM1_G1.E3, #TM1_G1.E4], type=Project, outputCols=[E1 (string), E2 (integer), E3 (boolean), E4 (double)]}], type=Sort, outputCols=[E1 (string), E2 (integer), E3 (boolean), E4 (double)]}], type=Relational Plan, outputCols=[E1 (string), E2 (integer), E3 (boolean), E4 (double)]}]", plan.getDescriptionProperties().get(Describable.PROP_CHILDREN).toString());//$NON-NLS-1$
+ assertEquals("[{formatted=false, encoding=UTF-8, type=START DOCUMENT}, {tag=a0, type=ADD ELEMENT, namespaceDeclarations=[], namespace=}, {type=NEXT IN DOCUMENT}, {isStaging=true, resultSet=tm1.g1, type=Staging Table}, {sql=VM1.G1_1, isStaging=false, resultSet=VM1.G1_1, type=EXECUTE SQL}, {resultSet=VM1.G1_1, type=BLOCK}, {resultSet=VM1.G1_1, type=NEXT ROW}, {program={children=[{tag=a1, type=ADD ELEMENT, namespaceDeclarations=[], namespace=}, {type=NEXT IN DOCUMENT}, {tag=a1, dataCol=VM1.G1_1.e1, type=ADD ELEMENT, namespaceDeclarations=[], namespace=}, {tag=b1, dataCol=VM1.G1_1.e2, type=ADD ELEMENT, namespaceDeclarations=[], namespace=}, {tag=c1, dataCol=VM1.G1_1.e3, type=ADD ELEMENT, namespaceDeclarations=[], namespace=}, {type=UP IN DOCUMENT}, {resultSet=VM1.G1_1, type=NEXT ROW}], type=XML Program}, resultSet=VM1.G1_1, type=LOOP}, {resultSet=VM1.G1_1, type=CLOSE RESULTSET}, {type=UP IN DOCUMENT}, {type=END DOCUMENT}, {isStaging=true, resultSet=unload_tm1.g1, type=S!
taging Table}, {children=[{removeDups=SORT, sortCols=[#TM1_G1.E3 ASC], nodeCostEstimates=[Estimated Node Cardinality: -1.0], children=[{nodeCostEstimates=[Estimated Node Cardinality: -1.0], children=[{modelName=__TEMP__, sql=SELECT #TM1_G1.E1, #TM1_G1.E2, #TM1_G1.E3, #TM1_G1.E4 FROM #TM1_G1, nodeCostEstimates=[Estimated Node Cardinality: -1.0], children=[], type=Access, outputCols=[E1 (string), E2 (integer), E3 (boolean), E4 (double)]}], selectCols=[#TM1_G1.E1, #TM1_G1.E2, #TM1_G1.E3, #TM1_G1.E4], type=Project, outputCols=[E1 (string), E2 (integer), E3 (boolean), E4 (double)]}], type=Sort, outputCols=[E1 (string), E2 (integer), E3 (boolean), E4 (double)]}], type=Relational Plan, outputCols=[E1 (string), E2 (integer), E3 (boolean), E4 (double)]}]", plan.getDescriptionProperties().get(Describable.PROP_CHILDREN).toString());//$NON-NLS-1$
}
// ################################## TEST SUITE ################################
Modified: trunk/engine/src/test/java/com/metamatrix/query/processor/TestProcessor.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/processor/TestProcessor.java 2009-04-27 19:02:50 UTC (rev 846)
+++ trunk/engine/src/test/java/com/metamatrix/query/processor/TestProcessor.java 2009-04-28 17:36:46 UTC (rev 847)
@@ -7660,7 +7660,7 @@
0, // DependentAccess
0, // DependentSelect
0, // DependentProject
- 1, // DupRemove
+ 0, // DupRemove
0, // Grouping
0, // NestedLoopJoinStrategy
2, // MergeJoinStrategy
Modified: trunk/engine/src/test/java/com/metamatrix/query/processor/TestVirtualDepJoin.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/processor/TestVirtualDepJoin.java 2009-04-27 19:02:50 UTC (rev 846)
+++ trunk/engine/src/test/java/com/metamatrix/query/processor/TestVirtualDepJoin.java 2009-04-28 17:36:46 UTC (rev 847)
@@ -26,7 +26,6 @@
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
Modified: trunk/engine/src/test/java/com/metamatrix/query/processor/relational/TestSortNode.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/processor/relational/TestSortNode.java 2009-04-27 19:02:50 UTC (rev 846)
+++ trunk/engine/src/test/java/com/metamatrix/query/processor/relational/TestSortNode.java 2009-04-28 17:36:46 UTC (rev 847)
@@ -22,6 +22,8 @@
package com.metamatrix.query.processor.relational;
+import static org.junit.Assert.*;
+
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@@ -29,7 +31,7 @@
import java.util.List;
import java.util.Set;
-import junit.framework.TestCase;
+import org.junit.Test;
import com.metamatrix.api.exception.MetaMatrixComponentException;
import com.metamatrix.api.exception.MetaMatrixProcessingException;
@@ -39,24 +41,17 @@
import com.metamatrix.common.buffer.impl.SizeUtility;
import com.metamatrix.common.types.DataTypeManager;
import com.metamatrix.query.processor.relational.NodeTestUtil.TestableBufferManagerImpl;
+import com.metamatrix.query.processor.relational.SortUtility.Mode;
import com.metamatrix.query.sql.lang.OrderBy;
import com.metamatrix.query.sql.symbol.ElementSymbol;
import com.metamatrix.query.util.CommandContext;
-public class TestSortNode extends TestCase {
+public class TestSortNode {
public static final int BATCH_SIZE = 100;
public static final int INT_BATCH_SIZE = TestSortNode.getIntBatchSize(); //the size of 100 integers
- /**
- * Constructor for TestSortNode.
- * @param arg0
- */
- public TestSortNode(String arg0) {
- super(arg0);
- }
-
- private void helpTestSort(long bytesInMemory, List elements, List[] data, List sortElements, List sortTypes, List[] expected, Set blockOn, boolean removeDups) throws MetaMatrixComponentException, MetaMatrixProcessingException {
+ private void helpTestSort(long bytesInMemory, List elements, List[] data, List sortElements, List sortTypes, List[] expected, Set blockOn, Mode mode) throws MetaMatrixComponentException, MetaMatrixProcessingException {
BufferManager mgr = NodeTestUtil.getTestBufferManager(bytesInMemory);
TestableBufferManagerImpl impl = (TestableBufferManagerImpl) mgr;
impl.setBlockOn(blockOn);
@@ -69,14 +64,15 @@
dataNode.setElements(elements);
dataNode.initialize(context, mgr, null);
- SortNode sortNode = null;
- if (removeDups) {
- sortNode = new DupRemoveNode(1);
+ SortNode sortNode = new SortNode(1);
+ if (mode == Mode.DUP_REMOVE) {
+ sortTypes = Arrays.asList(new Boolean[elements.size()]);
+ Collections.fill(sortTypes, OrderBy.ASC);
+ sortNode.setSortElements(elements, sortTypes);
} else {
- sortNode = new SortNode(1);
+ sortNode.setSortElements(sortElements, sortTypes);
}
-
- sortNode.setSortElements(sortElements, sortTypes);
+ sortNode.setMode(mode);
sortNode.setElements(elements);
sortNode.addChild(dataNode);
sortNode.initialize(context, mgr, null);
@@ -87,26 +83,27 @@
while(true) {
try {
TupleBatch batch = sortNode.nextBatch();
-
- for(int row = currentRow; row <= batch.getEndRow(); row++) {
- assertEquals("Rows don't match at " + row, expected[row-1], batch.getTuple(row)); //$NON-NLS-1$
+ if (mode != Mode.DUP_REMOVE) {
+ for(int row = currentRow; row <= batch.getEndRow(); row++) {
+ assertEquals("Rows don't match at " + row, expected[row-1], batch.getTuple(row)); //$NON-NLS-1$
+ }
}
-
+ currentRow += batch.getRowCount();
if(batch.getTerminationFlag()) {
break;
}
- currentRow += batch.getRowCount();
} catch (BlockedOnMemoryException e) {
if (!impl.wasBlocked()) {
throw new BlockedOnMemoryException();
}
}
}
+ assertEquals(expected.length, currentRow - 1);
}
public static int getIntBatchSize() {
List[] expected = new List[] {
- Arrays.asList(new Object[] { new Integer(0) }), //$NON-NLS-1$ //$NON-NLS-2$
+ Arrays.asList(new Object[] { new Integer(0) }),
};
String[] types = { "integer" }; //$NON-NLS-1$
@@ -118,7 +115,7 @@
/*
* 1 batch all in memory
*/
- private void helpTestBasicSort(List[] expected, boolean removeDups) throws Exception {
+ private void helpTestBasicSort(List[] expected, Mode mode) throws Exception {
ElementSymbol es1 = new ElementSymbol("e1"); //$NON-NLS-1$
es1.setType(DataTypeManager.DefaultDataClasses.INTEGER);
@@ -157,11 +154,11 @@
if (i > 0) {
blockedOn.add(new Integer(i));
}
- helpTestSort(INT_BATCH_SIZE*2, elements, data, sortElements, sortTypes, expected, blockedOn, removeDups);
+ helpTestSort(INT_BATCH_SIZE*2, elements, data, sortElements, sortTypes, expected, blockedOn, mode);
}
}
- private void helpTestBiggerSort(int batches, int inMemoryBatches, boolean removeDups) throws Exception {
+ private void helpTestBiggerSort(int batches, int inMemoryBatches) throws Exception {
ElementSymbol es1 = new ElementSymbol("e1"); //$NON-NLS-1$
es1.setType(DataTypeManager.DefaultDataClasses.INTEGER);
@@ -193,30 +190,31 @@
expected[i].add(unsortedNumbers.get(i));
}
- /*
- * the following code will do four tests, blocking in a variety of places
- */
- for (int i = 0; i < 3; i++) {
- Set blockedOn = new HashSet();
- if (i > 0) {
- //block on a variety of positions
- blockedOn.add(new Integer(i));
- blockedOn.add(new Integer(inMemoryBatches*i));
- blockedOn.add(new Integer(batches*i));
- blockedOn.add(new Integer(batches*(i+1)));
- }
- //5 batches in memory out of 10 total
- helpTestSort(INT_BATCH_SIZE * inMemoryBatches, elements, data, sortElements, sortTypes, expected, null, removeDups);
+
+ for (Mode mode : Mode.values()) {
+ /*
+ * the following code will do four tests, blocking in a variety of places
+ */
+ for (int i = 0; i < 3; i++) {
+ Set blockedOn = new HashSet();
+ if (i > 0) {
+ //block on a variety of positions
+ blockedOn.add(new Integer(i));
+ blockedOn.add(new Integer(inMemoryBatches*i));
+ blockedOn.add(new Integer(batches*i));
+ blockedOn.add(new Integer(batches*(i+1)));
+ }
+ //5 batches in memory out of 10 total
+ helpTestSort(INT_BATCH_SIZE * inMemoryBatches, elements, data, sortElements, sortTypes, expected, blockedOn, mode);
+ }
}
}
- public void testNoSort() throws Exception {
- helpTestBiggerSort(0, 2, false);
-
- helpTestBiggerSort(0, 2, true);
+ @Test public void testNoSort() throws Exception {
+ helpTestBiggerSort(0, 2);
}
- public void testBasicSort() throws Exception {
+ @Test public void testBasicSort() throws Exception {
List[] expected = new List[] {
Arrays.asList(new Object[] { new Integer(0), "0" }), //$NON-NLS-1$
Arrays.asList(new Object[] { new Integer(0), "3" }), //$NON-NLS-1$
@@ -240,10 +238,14 @@
Arrays.asList(new Object[] { new Integer(10), "4" }) //$NON-NLS-1$
};
- helpTestBasicSort(expected, false);
+ helpTestBasicSort(expected, Mode.SORT);
}
- public void testBasicSortRemoveDup() throws Exception {
+ /**
+ * Note the ordering here is not stable
+ * @throws Exception
+ */
+ @Test public void testBasicSortRemoveDup() throws Exception {
List[] expected = new List[] {
Arrays.asList(new Object[] { new Integer(0), "0" }), //$NON-NLS-1$
Arrays.asList(new Object[] { new Integer(0), "3" }), //$NON-NLS-1$
@@ -266,30 +268,41 @@
Arrays.asList(new Object[] { new Integer(10), "9" }) //$NON-NLS-1$
};
-
- helpTestBasicSort(expected, true);
- }
+ helpTestBasicSort(expected, Mode.DUP_REMOVE);
+ }
- public void testBiggerSort() throws Exception {
- helpTestBiggerSort(10, 5, false);
-
- helpTestBiggerSort(10, 5, true);
+ @Test public void testBasicSortRemoveDupSort() throws Exception {
+ List[] expected = new List[] {
+ Arrays.asList(new Object[] { new Integer(0), "0" }), //$NON-NLS-1$
+ Arrays.asList(new Object[] { new Integer(0), "3" }), //$NON-NLS-1$
+ Arrays.asList(new Object[] { new Integer(1), "2" }), //$NON-NLS-1$
+ Arrays.asList(new Object[] { new Integer(1), "5" }), //$NON-NLS-1$
+ Arrays.asList(new Object[] { new Integer(2), "1" }), //$NON-NLS-1$
+ Arrays.asList(new Object[] { new Integer(2), "4" }), //$NON-NLS-1$
+ Arrays.asList(new Object[] { new Integer(3), "3" }), //$NON-NLS-1$
+ Arrays.asList(new Object[] { new Integer(3), "6" }), //$NON-NLS-1$
+ Arrays.asList(new Object[] { new Integer(4), "3" }), //$NON-NLS-1$
+ Arrays.asList(new Object[] { new Integer(5), "2" }), //$NON-NLS-1$
+ Arrays.asList(new Object[] { new Integer(5), "5" }), //$NON-NLS-1$
+ Arrays.asList(new Object[] { new Integer(6), "1" }), //$NON-NLS-1$
+ Arrays.asList(new Object[] { new Integer(6), "4" }), //$NON-NLS-1$
+ Arrays.asList(new Object[] { new Integer(7), "3" }), //$NON-NLS-1$
+ Arrays.asList(new Object[] { new Integer(8), "2" }), //$NON-NLS-1$
+ Arrays.asList(new Object[] { new Integer(9), "1" }), //$NON-NLS-1$
+ Arrays.asList(new Object[] { new Integer(9), "5" }), //$NON-NLS-1$
+ Arrays.asList(new Object[] { new Integer(10), "4" }), //$NON-NLS-1$
+ Arrays.asList(new Object[] { new Integer(10), "9" }) //$NON-NLS-1$
+ };
+
+ helpTestBasicSort(expected, Mode.DUP_REMOVE_SORT);
+ }
+
+ @Test public void testBiggerSort() throws Exception {
+ helpTestBiggerSort(10, 5);
}
- public void testBiggerSortLowMemory() throws Exception {
- try {
- helpTestBiggerSort(5, 1, false);
- fail("Expected exception"); //$NON-NLS-1$
- } catch (BlockedOnMemoryException e) {
- //expected
- }
-
- try {
- helpTestBiggerSort(5, 1, true);
- fail("Expected exception"); //$NON-NLS-1$
- } catch (BlockedOnMemoryException e) {
- //expected
- }
+ @Test(expected=BlockedOnMemoryException.class) public void testBiggerSortLowMemory() throws Exception {
+ helpTestBiggerSort(5, 1);
}
/**
@@ -297,10 +310,8 @@
*
* This is also a test of the multi-pass merge
*/
- public void testBiggerSortLowMemory2() throws Exception {
- helpTestBiggerSort(5, 2, false);
-
- helpTestBiggerSort(5, 2, true);
- }
-
+ @Test public void testBiggerSortLowMemory2() throws Exception {
+ helpTestBiggerSort(5, 2);
+ }
+
}
15 years, 8 months
teiid SVN: r846 - in trunk: engine/src/main/java/com/metamatrix/query/eval and 26 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2009-04-27 15:02:50 -0400 (Mon, 27 Apr 2009)
New Revision: 846
Added:
trunk/engine/src/main/java/com/metamatrix/query/processor/relational/SubqueryAwareEvaluator.java
trunk/engine/src/main/java/com/metamatrix/query/processor/relational/SubqueryAwareRelationalNode.java
Removed:
trunk/engine/src/main/java/com/metamatrix/query/eval/LookupEvaluator.java
trunk/engine/src/main/java/com/metamatrix/query/processor/proc/CommandInstruction.java
trunk/engine/src/main/java/com/metamatrix/query/processor/proc/ProcedureEnvironment.java
trunk/engine/src/main/java/com/metamatrix/query/processor/program/ProgramEnvironment.java
trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DependentProjectNode.java
trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DependentSelectNode.java
trunk/engine/src/main/java/com/metamatrix/query/processor/relational/SubqueryProcessorUtility.java
trunk/engine/src/main/java/org/teiid/dqp/internal/process/DataTierManager.java
trunk/engine/src/test/java/com/metamatrix/query/processor/relational/TestDependentSelectNode.java
Modified:
trunk/connector-metadata/src/test/java/com/metamatrix/connector/metadata/internal/FakeProcessorDataManager.java
trunk/engine/src/main/java/com/metamatrix/query/eval/Evaluator.java
trunk/engine/src/main/java/com/metamatrix/query/optimizer/proc/ProcedurePlanner.java
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/GenerateCanonical.java
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/PlanToProcessConverter.java
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/RelationalPlanner.java
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/plantree/NodeConstants.java
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/plantree/PlanNode.java
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/CapabilitiesUtil.java
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/FrameUtil.java
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/JoinUtil.java
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleAssignOutputElements.java
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleCollapseSource.java
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleCopyCriteria.java
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleMergeCriteria.java
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RulePlanProcedures.java
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RulePushSelectCriteria.java
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleRaiseAccess.java
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleRemoveOptionalJoins.java
trunk/engine/src/main/java/com/metamatrix/query/processor/ProcessorDataManager.java
trunk/engine/src/main/java/com/metamatrix/query/processor/TempTableDataManager.java
trunk/engine/src/main/java/com/metamatrix/query/processor/proc/AbstractAssignmentInstruction.java
trunk/engine/src/main/java/com/metamatrix/query/processor/proc/AssignmentInstruction.java
trunk/engine/src/main/java/com/metamatrix/query/processor/proc/BreakInstruction.java
trunk/engine/src/main/java/com/metamatrix/query/processor/proc/ContinueInstruction.java
trunk/engine/src/main/java/com/metamatrix/query/processor/proc/CreateCursorResultSetInstruction.java
trunk/engine/src/main/java/com/metamatrix/query/processor/proc/ExecDynamicSqlInstruction.java
trunk/engine/src/main/java/com/metamatrix/query/processor/proc/ExecSqlInstruction.java
trunk/engine/src/main/java/com/metamatrix/query/processor/proc/IfInstruction.java
trunk/engine/src/main/java/com/metamatrix/query/processor/proc/LoopInstruction.java
trunk/engine/src/main/java/com/metamatrix/query/processor/proc/ProcedurePlan.java
trunk/engine/src/main/java/com/metamatrix/query/processor/proc/RepeatedInstruction.java
trunk/engine/src/main/java/com/metamatrix/query/processor/proc/WhileInstruction.java
trunk/engine/src/main/java/com/metamatrix/query/processor/program/ProgramInstruction.java
trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DependentCriteriaProcessor.java
trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DependentProcedureAccessNode.java
trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DependentProcedureCriteriaProcessor.java
trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DependentProcedureExecutionNode.java
trunk/engine/src/main/java/com/metamatrix/query/processor/relational/JoinNode.java
trunk/engine/src/main/java/com/metamatrix/query/processor/relational/ProjectNode.java
trunk/engine/src/main/java/com/metamatrix/query/processor/relational/RelationalNode.java
trunk/engine/src/main/java/com/metamatrix/query/processor/relational/SelectNode.java
trunk/engine/src/main/java/com/metamatrix/query/resolver/command/UpdateProcedureResolver.java
trunk/engine/src/main/java/com/metamatrix/query/resolver/util/AccessPattern.java
trunk/engine/src/main/java/com/metamatrix/query/sql/lang/Command.java
trunk/engine/src/main/java/com/metamatrix/query/sql/proc/CreateUpdateProcedureCommand.java
trunk/engine/src/main/java/com/metamatrix/query/sql/util/SymbolMap.java
trunk/engine/src/main/java/com/metamatrix/query/sql/util/VariableContext.java
trunk/engine/src/main/java/com/metamatrix/query/sql/visitor/CommandCollectorVisitor.java
trunk/engine/src/main/java/com/metamatrix/query/sql/visitor/CorrelatedReferenceCollectorVisitor.java
trunk/engine/src/main/java/com/metamatrix/query/sql/visitor/EvaluateExpressionVisitor.java
trunk/engine/src/main/java/com/metamatrix/query/sql/visitor/ValueIteratorProviderCollectorVisitor.java
trunk/engine/src/main/java/com/metamatrix/query/validator/AbstractValidationVisitor.java
trunk/engine/src/main/java/com/metamatrix/query/validator/ValidationVisitor.java
trunk/engine/src/main/java/com/metamatrix/query/validator/Validator.java
trunk/engine/src/main/java/org/teiid/dqp/internal/process/DQPCore.java
trunk/engine/src/main/java/org/teiid/dqp/internal/process/DataTierManagerImpl.java
trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestLimit.java
trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestOptimizer.java
trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestRuleMergeVirtual.java
trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestSubqueryPushdown.java
trunk/engine/src/test/java/com/metamatrix/query/processor/FakeDataManager.java
trunk/engine/src/test/java/com/metamatrix/query/processor/HardcodedDataManager.java
trunk/engine/src/test/java/com/metamatrix/query/processor/eval/TestCriteriaEvaluator.java
trunk/engine/src/test/java/com/metamatrix/query/processor/eval/TestExpressionEvaluator.java
trunk/engine/src/test/java/com/metamatrix/query/processor/proc/TestProcedureProcessor.java
trunk/engine/src/test/java/com/metamatrix/query/processor/relational/TestAccessNode.java
trunk/engine/src/test/java/com/metamatrix/query/processor/relational/TestBatchedUpdateNode.java
trunk/engine/src/test/java/com/metamatrix/query/processor/relational/TestProjectIntoNode.java
trunk/engine/src/test/java/com/metamatrix/query/rewriter/TestQueryRewriter.java
trunk/engine/src/test/java/com/metamatrix/query/unittest/FakeMetadataFactory.java
trunk/engine/src/test/java/com/metamatrix/query/validator/TestValidator.java
trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestDataTierManager.java
trunk/test-integration/src/test/java/com/metamatrix/server/integration/TestTPCR.java
Log:
TEIID-535, TEIID-534, TEIID-82 rounding out support for subqueries. They are now supported in a much broader number of places. Also added a more appropriate check of join criteria pushdown support.
Modified: trunk/connector-metadata/src/test/java/com/metamatrix/connector/metadata/internal/FakeProcessorDataManager.java
===================================================================
--- trunk/connector-metadata/src/test/java/com/metamatrix/connector/metadata/internal/FakeProcessorDataManager.java 2009-04-27 16:49:34 UTC (rev 845)
+++ trunk/connector-metadata/src/test/java/com/metamatrix/connector/metadata/internal/FakeProcessorDataManager.java 2009-04-27 19:02:50 UTC (rev 846)
@@ -69,5 +69,10 @@
throws BlockedException, MetaMatrixComponentException {
return null;
}
+
+ @Override
+ public void clearCodeTables() {
+
+ }
}
Modified: trunk/engine/src/main/java/com/metamatrix/query/eval/Evaluator.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/eval/Evaluator.java 2009-04-27 16:49:34 UTC (rev 845)
+++ trunk/engine/src/main/java/com/metamatrix/query/eval/Evaluator.java 2009-04-27 19:02:50 UTC (rev 846)
@@ -39,24 +39,29 @@
import com.metamatrix.common.buffer.BlockedException;
import com.metamatrix.common.types.Sequencable;
import com.metamatrix.core.util.ArgCheck;
+import com.metamatrix.core.util.Assertion;
import com.metamatrix.core.util.EquivalenceUtil;
import com.metamatrix.query.QueryPlugin;
import com.metamatrix.query.function.FunctionDescriptor;
import com.metamatrix.query.function.FunctionLibrary;
import com.metamatrix.query.function.FunctionLibraryManager;
import com.metamatrix.query.function.metadata.FunctionMethod;
+import com.metamatrix.query.processor.ProcessorDataManager;
import com.metamatrix.query.sql.LanguageObject;
import com.metamatrix.query.sql.lang.AbstractSetCriteria;
import com.metamatrix.query.sql.lang.CollectionValueIterator;
import com.metamatrix.query.sql.lang.CompareCriteria;
import com.metamatrix.query.sql.lang.CompoundCriteria;
import com.metamatrix.query.sql.lang.Criteria;
+import com.metamatrix.query.sql.lang.DependentSetCriteria;
import com.metamatrix.query.sql.lang.ExistsCriteria;
import com.metamatrix.query.sql.lang.IsNullCriteria;
import com.metamatrix.query.sql.lang.MatchCriteria;
import com.metamatrix.query.sql.lang.NotCriteria;
import com.metamatrix.query.sql.lang.SetCriteria;
import com.metamatrix.query.sql.lang.SubqueryCompareCriteria;
+import com.metamatrix.query.sql.lang.SubqueryContainer;
+import com.metamatrix.query.sql.lang.SubquerySetCriteria;
import com.metamatrix.query.sql.symbol.AggregateSymbol;
import com.metamatrix.query.sql.symbol.CaseExpression;
import com.metamatrix.query.sql.symbol.Constant;
@@ -78,9 +83,10 @@
private final static MatchCriteria.PatternTranslator LIKE_TO_REGEX = new MatchCriteria.PatternTranslator(".*", ".", REGEX_RESERVED, '\\'); //$NON-NLS-1$ //$NON-NLS-2$
private Map elements;
- private LookupEvaluator dataMgr;
- private CommandContext context;
+ protected ProcessorDataManager dataMgr;
+ protected CommandContext context;
+
public static boolean evaluate(Criteria criteria) throws CriteriaEvaluationException, BlockedException, MetaMatrixComponentException {
return new Evaluator(Collections.emptyMap(), null, null).evaluate(criteria, Collections.emptyList());
}
@@ -89,11 +95,15 @@
return new Evaluator(Collections.emptyMap(), null, null).evaluate(expression, Collections.emptyList());
}
- public Evaluator(Map elements, LookupEvaluator dataMgr, CommandContext context) {
+ public Evaluator(Map elements, ProcessorDataManager dataMgr, CommandContext context) {
this.context = context;
this.dataMgr = dataMgr;
this.elements = elements;
}
+
+ public void setContext(CommandContext context) {
+ this.context = context;
+ }
public boolean evaluate(Criteria criteria, List tuple)
throws CriteriaEvaluationException, BlockedException, MetaMatrixComponentException {
@@ -131,34 +141,21 @@
List subCrits = criteria.getCriteria();
Iterator subCritIter = subCrits.iterator();
- if(criteria.getOperator() == CompoundCriteria.AND) {
- Boolean result = Boolean.TRUE;
- while(subCritIter.hasNext()) {
- Criteria subCrit = (Criteria) subCritIter.next();
- Boolean value = evaluateTVL(subCrit, tuple);
- if (value == null) {
- result = null;
- } else if (!value.booleanValue()) {
- return Boolean.FALSE;
- }
- }
- return result;
-
- }
- // CompoundCriteria.OR
- Boolean result = Boolean.FALSE;
+ boolean and = criteria.getOperator() == CompoundCriteria.AND;
+ Boolean result = and?Boolean.TRUE:Boolean.FALSE;
while(subCritIter.hasNext()) {
Criteria subCrit = (Criteria) subCritIter.next();
Boolean value = evaluateTVL(subCrit, tuple);
- if (value == null) {
- result = null;
- continue;
- }
- if (value.booleanValue()) {
- return Boolean.TRUE;
+ if (value == null) {
+ result = null;
+ } else if (!value.booleanValue()) {
+ if (and) {
+ return Boolean.FALSE;
+ }
+ } else if (!and) {
+ return Boolean.TRUE;
}
}
-
return result;
}
@@ -295,7 +292,7 @@
}
}
- public Boolean evaluate(AbstractSetCriteria criteria, List tuple)
+ private Boolean evaluate(AbstractSetCriteria criteria, List tuple)
throws CriteriaEvaluationException, BlockedException, MetaMatrixComponentException {
// Evaluate expression
@@ -315,9 +312,17 @@
ValueIterator valueIter = null;
if (criteria instanceof SetCriteria) {
valueIter = new CollectionValueIterator(((SetCriteria)criteria).getValues());
- } else {
+ } else if (criteria instanceof DependentSetCriteria){
ContextReference ref = (ContextReference)criteria;
valueIter = getContext(criteria).getValueIterator(ref);
+ } else if (criteria instanceof SubquerySetCriteria) {
+ try {
+ valueIter = evaluateSubquery((SubquerySetCriteria)criteria, tuple);
+ } catch (MetaMatrixProcessingException e) {
+ throw new CriteriaEvaluationException(e, e.getMessage());
+ }
+ } else {
+ Assertion.failed("unknown set criteria type"); //$NON-NLS-1$
}
while(valueIter.hasNext()) {
Object possibleValue = valueIter.next();
@@ -362,7 +367,7 @@
return (value == null ^ criteria.isNegated());
}
- public Boolean evaluate(SubqueryCompareCriteria criteria, List tuple)
+ private Boolean evaluate(SubqueryCompareCriteria criteria, List tuple)
throws CriteriaEvaluationException, BlockedException, MetaMatrixComponentException {
// Evaluate expression
@@ -388,7 +393,12 @@
result = Boolean.TRUE;
}
- ValueIterator valueIter = getContext(criteria).getValueIterator(criteria);
+ ValueIterator valueIter;
+ try {
+ valueIter = evaluateSubquery(criteria, tuple);
+ } catch (MetaMatrixProcessingException e) {
+ throw new CriteriaEvaluationException(e, e.getMessage());
+ }
while(valueIter.hasNext()) {
Object value = valueIter.next();
@@ -469,9 +479,14 @@
}
public boolean evaluate(ExistsCriteria criteria, List tuple)
- throws BlockedException, MetaMatrixComponentException {
+ throws BlockedException, MetaMatrixComponentException, CriteriaEvaluationException {
- ValueIterator valueIter = getContext(criteria).getValueIterator(criteria);
+ ValueIterator valueIter;
+ try {
+ valueIter = evaluateSubquery(criteria, tuple);
+ } catch (MetaMatrixProcessingException e) {
+ throw new CriteriaEvaluationException(e, e.getMessage());
+ }
if(valueIter.hasNext()) {
return true;
}
@@ -617,7 +632,12 @@
throws ExpressionEvaluationException, BlockedException, MetaMatrixComponentException {
Object result = null;
- ValueIterator valueIter = getContext(scalarSubquery).getValueIterator(scalarSubquery);
+ ValueIterator valueIter;
+ try {
+ valueIter = evaluateSubquery(scalarSubquery, tuple);
+ } catch (MetaMatrixProcessingException e) {
+ throw new ExpressionEvaluationException(e, e.getMessage());
+ }
if(valueIter.hasNext()) {
result = valueIter.next();
if(valueIter.hasNext()) {
@@ -628,12 +648,17 @@
}
return result;
}
+
+ protected ValueIterator evaluateSubquery(SubqueryContainer container, List tuple)
+ throws MetaMatrixProcessingException, BlockedException, MetaMatrixComponentException {
+ throw new UnsupportedOperationException("Subquery evaluation not possible with a base Evaluator"); //$NON-NLS-1$
+ }
private CommandContext getContext(LanguageObject expression) throws MetaMatrixComponentException {
if (context == null) {
throw new MetaMatrixComponentException(ErrorMessageKeys.PROCESSOR_0033, QueryPlugin.Util.getString(ErrorMessageKeys.PROCESSOR_0033, expression, "No value was available")); //$NON-NLS-1$
}
return context;
- }
+ }
}
Deleted: trunk/engine/src/main/java/com/metamatrix/query/eval/LookupEvaluator.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/eval/LookupEvaluator.java 2009-04-27 16:49:34 UTC (rev 845)
+++ trunk/engine/src/main/java/com/metamatrix/query/eval/LookupEvaluator.java 2009-04-27 19:02:50 UTC (rev 846)
@@ -1,58 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package com.metamatrix.query.eval;
-
-import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.api.exception.MetaMatrixProcessingException;
-import com.metamatrix.common.buffer.BlockedException;
-import com.metamatrix.query.util.CommandContext;
-
-/**
- * @since 5.0
- */
-public interface LookupEvaluator {
-
- /**
- * Lookup a value from a cached code table. If the code table is not loaded, it will be
- * loaded on the first query. Code tables should be cached based on a combination of
- * the codeTableName, returnElementName, and keyElementName. If the table is not loaded,
- * a request will be made and the method should throw a BlockedException.
- *
- * @param context Context for processing
- * @param codeTableName Name of the code table - must be a physical table
- * @param returnElementName Name of the element to be returned in the code table
- * @param keyElementName Name of the key element in the code table
- * @param keyValue Key value to look up
- * @return Return value for the specified key value, or null if not found
- * @throws BlockedException If code table must be loaded
- * @throws MetaMatrixComponentException If an unexpected error occurs
- * @throws MetaMatrixProcessingException
- */
- public abstract Object lookupCodeValue(CommandContext context,
- String codeTableName,
- String returnElementName,
- String keyElementName,
- Object keyValue) throws BlockedException,
- MetaMatrixComponentException, MetaMatrixProcessingException;
-
-}
\ No newline at end of file
Modified: trunk/engine/src/main/java/com/metamatrix/query/optimizer/proc/ProcedurePlanner.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/optimizer/proc/ProcedurePlanner.java 2009-04-27 16:49:34 UTC (rev 845)
+++ trunk/engine/src/main/java/com/metamatrix/query/optimizer/proc/ProcedurePlanner.java 2009-04-27 19:02:50 UTC (rev 846)
@@ -46,7 +46,6 @@
import com.metamatrix.query.processor.proc.ExecSqlInstruction;
import com.metamatrix.query.processor.proc.IfInstruction;
import com.metamatrix.query.processor.proc.LoopInstruction;
-import com.metamatrix.query.processor.proc.ProcedureEnvironment;
import com.metamatrix.query.processor.proc.ProcedurePlan;
import com.metamatrix.query.processor.proc.WhileInstruction;
import com.metamatrix.query.processor.program.Program;
@@ -131,9 +130,7 @@
}
// create plan from program and initialized environment
- ProcedureEnvironment env = new ProcedureEnvironment();
- env.getProgramStack().push(programBlock);
- ProcedurePlan plan = new ProcedurePlan(env);
+ ProcedurePlan plan = new ProcedurePlan(programBlock);
// propagate procedure parameters to the plan to allow runtime type checking
ProcedureContainer container = (ProcedureContainer)((CreateUpdateProcedureCommand) procCommand).getUserCommand();
@@ -144,9 +141,8 @@
plan.setMetadata(metadata);
}
- env.initialize(plan);
- env.setUpdateProcedure(((CreateUpdateProcedureCommand)procCommand).isUpdateProcedure());
- env.setOutputElements(((CreateUpdateProcedureCommand)procCommand).getProjectedSymbols());
+ plan.setUpdateProcedure(((CreateUpdateProcedureCommand)procCommand).isUpdateProcedure());
+ plan.setOutputElements(((CreateUpdateProcedureCommand)procCommand).getProjectedSymbols());
if(debug) {
analysisRecord.println("####################################################"); //$NON-NLS-1$
Modified: trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/GenerateCanonical.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/GenerateCanonical.java 2009-04-27 16:49:34 UTC (rev 845)
+++ trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/GenerateCanonical.java 2009-04-27 19:02:50 UTC (rev 846)
@@ -406,6 +406,7 @@
}
// Add groups to crit node
critNode.addGroups(GroupsUsedByElementsVisitor.getGroups(crit));
+ critNode.addGroups(GroupsUsedByElementsVisitor.getGroups(critNode.getCorrelatedReferenceElements()));
return critNode;
}
Modified: trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/PlanToProcessConverter.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/PlanToProcessConverter.java 2009-04-27 16:49:34 UTC (rev 845)
+++ trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/PlanToProcessConverter.java 2009-04-27 19:02:50 UTC (rev 846)
@@ -22,7 +22,6 @@
package com.metamatrix.query.optimizer.relational;
-import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
@@ -50,8 +49,6 @@
import com.metamatrix.query.processor.relational.DependentAccessNode;
import com.metamatrix.query.processor.relational.DependentProcedureAccessNode;
import com.metamatrix.query.processor.relational.DependentProcedureExecutionNode;
-import com.metamatrix.query.processor.relational.DependentProjectNode;
-import com.metamatrix.query.processor.relational.DependentSelectNode;
import com.metamatrix.query.processor.relational.DupRemoveNode;
import com.metamatrix.query.processor.relational.GroupingNode;
import com.metamatrix.query.processor.relational.JoinNode;
@@ -66,7 +63,6 @@
import com.metamatrix.query.processor.relational.RelationalPlan;
import com.metamatrix.query.processor.relational.SelectNode;
import com.metamatrix.query.processor.relational.SortNode;
-import com.metamatrix.query.processor.relational.SubqueryProcessorUtility;
import com.metamatrix.query.processor.relational.UnionAllNode;
import com.metamatrix.query.processor.relational.MergeJoinStrategy.SortOption;
import com.metamatrix.query.resolver.util.ResolverUtil;
@@ -76,9 +72,7 @@
import com.metamatrix.query.sql.lang.JoinType;
import com.metamatrix.query.sql.lang.Query;
import com.metamatrix.query.sql.lang.StoredProcedure;
-import com.metamatrix.query.sql.lang.SubqueryContainer;
import com.metamatrix.query.sql.lang.SetQuery.Operation;
-import com.metamatrix.query.sql.symbol.ContextReference;
import com.metamatrix.query.sql.symbol.Expression;
import com.metamatrix.query.sql.symbol.GroupSymbol;
import com.metamatrix.query.sql.util.SymbolMap;
@@ -191,16 +185,9 @@
} else {
List symbols = (List) node.getProperty(NodeConstants.Info.PROJECT_COLS);
- SubqueryProcessorUtility spu = createSubqueryProcessor(node);
- if (spu == null) {
- ProjectNode pnode = new ProjectNode(getID());
- processNode = pnode;
- } else {
- DependentProjectNode pnode = new DependentProjectNode(getID(), spu);
- processNode = pnode;
- }
-
- ((ProjectNode)processNode).setSelectSymbols(symbols);
+ ProjectNode pnode = new ProjectNode(getID());
+ pnode.setSelectSymbols(symbols);
+ processNode = pnode;
}
break;
@@ -323,18 +310,10 @@
case NodeConstants.Types.SELECT:
Criteria crit = (Criteria) node.getProperty(NodeConstants.Info.SELECT_CRITERIA);
- SubqueryProcessorUtility spu = createSubqueryProcessor(node);
- if (spu == null){
- // This is a normal select node
- SelectNode selnode = new SelectNode(getID());
- selnode.setCriteria(crit);
- processNode = selnode;
- } else {
- DependentSelectNode selnode = new DependentSelectNode(getID(), spu);
- selnode.setCriteria(crit);
- processNode = selnode;
- }
+ SelectNode selnode = new SelectNode(getID());
+ selnode.setCriteria(crit);
+ processNode = selnode;
possiblyDependentObject = crit;
break;
@@ -420,21 +399,6 @@
return processNode;
}
- private SubqueryProcessorUtility createSubqueryProcessor(PlanNode node) {
- List<SubqueryContainer> subqueries = node.getSubqueryContainers();
- if (subqueries.isEmpty()){
- return null;
- }
- SymbolMap correlatedReferences = (SymbolMap)node.getProperty(NodeConstants.Info.CORRELATED_REFERENCES);
- List<ProcessorPlan> plans = new ArrayList<ProcessorPlan>(subqueries.size());
- List<String> contextReferences = new ArrayList<String>(subqueries.size());
- for (SubqueryContainer subqueryContainer : subqueries) {
- plans.add(subqueryContainer.getCommand().getProcessorPlan());
- contextReferences.add(((ContextReference)subqueryContainer).getContextSymbol());
- }
- return new SubqueryProcessorUtility(plans, contextReferences, correlatedReferences);
- }
-
private RelationalNode correctProjectionForTempTable(PlanNode node,
AccessNode aNode,
LanguageObject possiblyDependentObject) throws QueryMetadataException,
Modified: trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/RelationalPlanner.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/RelationalPlanner.java 2009-04-27 16:49:34 UTC (rev 845)
+++ trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/RelationalPlanner.java 2009-04-27 19:02:50 UTC (rev 846)
@@ -157,41 +157,42 @@
return result;
}
- /**
- * <p>Find all SELECT or PROJECT type PlanNodes in plan tree,
- * see if the criteria or projected symbols
- * of that node have any SubqueryContainers in it.
- * If so, find the ProcessorPlan from the supplied
- * map of child plans, and create a new Map of ProcessorPlan to the
- * SubqueryContainer object, and place that new Map as a property on the
- * plan node. The Map will be used later during processing.</p>
- * @param plan PlanNode
- */
private static void connectSubqueryContainers(PlanNode plan) {
- Set<GroupSymbol> groupSymbols = new HashSet<GroupSymbol>();
- for (PlanNode source : NodeEditor.findAllNodes(plan, NodeConstants.Types.SOURCE)) {
- groupSymbols.addAll(source.getGroups());
- }
+ Set<GroupSymbol> groupSymbols = getGroupSymbols(plan);
- for (PlanNode node : NodeEditor.findAllNodes(plan, NodeConstants.Types.PROJECT | NodeConstants.Types.SELECT)) {
+ for (PlanNode node : NodeEditor.findAllNodes(plan, NodeConstants.Types.PROJECT | NodeConstants.Types.SELECT | NodeConstants.Types.JOIN)) {
List<SubqueryContainer> subqueryContainers = node.getSubqueryContainers();
if (subqueryContainers.isEmpty()){
continue;
}
- ArrayList<Reference> correlatedReferences = new ArrayList<Reference>();
+ Set<GroupSymbol> localGroupSymbols = groupSymbols;
+ if (node.getType() == NodeConstants.Types.JOIN) {
+ localGroupSymbols = getGroupSymbols(node);
+ }
for (SubqueryContainer container : subqueryContainers) {
+ ArrayList<Reference> correlatedReferences = new ArrayList<Reference>();
Command subCommand = container.getCommand();
- CorrelatedReferenceCollectorVisitor.collectReferences(subCommand, groupSymbols, correlatedReferences);
+ CorrelatedReferenceCollectorVisitor.collectReferences(subCommand, localGroupSymbols, correlatedReferences);
+ if (!correlatedReferences.isEmpty()) {
+ SymbolMap map = new SymbolMap();
+ for (Reference reference : correlatedReferences) {
+ map.addMapping(reference.getExpression(), reference.getExpression());
+ }
+ subCommand.setCorrelatedReferences(map);
+ }
}
- SymbolMap map = new SymbolMap();
- for (Reference reference : correlatedReferences) {
- map.addMapping(reference.getExpression(), reference.getExpression());
- }
- node.setProperty(NodeConstants.Info.CORRELATED_REFERENCES, map);
node.addGroups(GroupsUsedByElementsVisitor.getGroups(node.getCorrelatedReferenceElements()));
}
}
+ private static Set<GroupSymbol> getGroupSymbols(PlanNode plan) {
+ Set<GroupSymbol> groupSymbols = new HashSet<GroupSymbol>();
+ for (PlanNode source : NodeEditor.findAllNodes(plan, NodeConstants.Types.SOURCE)) {
+ groupSymbols.addAll(source.getGroups());
+ }
+ return groupSymbols;
+ }
+
/**
* Method connectChildPlans.
* @param plan
Modified: trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/plantree/NodeConstants.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/plantree/NodeConstants.java 2009-04-27 16:49:34 UTC (rev 845)
+++ trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/plantree/NodeConstants.java 2009-04-27 19:02:50 UTC (rev 846)
@@ -127,9 +127,6 @@
// Special constant used in converting plan to process for all nodes
OUTPUT_COLS, // List <SingleElementSymbol>
- // Plan node constants, common to any or multiple plan node types
- CORRELATED_REFERENCES, // SymbolMap
-
// Plan Node Cost Estimate Constants
EST_SET_SIZE, // Integer represents the estimated set size this node would produce for a sibling node as the indenpendent node in a dependent join scenario
EST_DEP_CARDINALITY, // Float value that represents the estimated cardinality (amount of rows) produced by this node as the dependent node in a dependent join scenario
Modified: trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/plantree/PlanNode.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/plantree/PlanNode.java 2009-04-27 16:49:34 UTC (rev 845)
+++ trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/plantree/PlanNode.java 2009-04-27 19:02:50 UTC (rev 846)
@@ -295,31 +295,55 @@
node.addLastChild(this);
}
+ public List<SymbolMap> getCorrelatedReferences() {
+ List<SubqueryContainer> containers = getSubqueryContainers();
+ if (containers.isEmpty()) {
+ return Collections.emptyList();
+ }
+ ArrayList<SymbolMap> result = new ArrayList<SymbolMap>(containers.size());
+ for (SubqueryContainer container : containers) {
+ SymbolMap map = container.getCommand().getCorrelatedReferences();
+ if (map != null) {
+ result.add(map);
+ }
+ }
+ return result;
+ }
+
public Set<ElementSymbol> getCorrelatedReferenceElements() {
- SymbolMap refs = (SymbolMap) this.getProperty(NodeConstants.Info.CORRELATED_REFERENCES);
+ List<SymbolMap> maps = getCorrelatedReferences();
- if(refs == null) {
+ if(maps.isEmpty()) {
return Collections.emptySet();
}
-
- List<Expression> values = refs.getValues();
- HashSet<ElementSymbol> result = new HashSet<ElementSymbol>(values.size());
- for (Expression expr : values) {
- ElementCollectorVisitor.getElements(expr, result);
+ HashSet<ElementSymbol> result = new HashSet<ElementSymbol>();
+ for (SymbolMap symbolMap : maps) {
+ List<Expression> values = symbolMap.getValues();
+ for (Expression expr : values) {
+ ElementCollectorVisitor.getElements(expr, result);
+ }
}
return result;
}
public List<SubqueryContainer> getSubqueryContainers() {
Collection<? extends LanguageObject> toSearch = Collections.emptyList();
- if (this.getType() == NodeConstants.Types.SELECT){
- Criteria criteria = (Criteria)this.getProperty(NodeConstants.Info.SELECT_CRITERIA);
- toSearch = Arrays.asList(criteria);
- }
- if (this.getType() == NodeConstants.Types.PROJECT) {
- toSearch = (Collection)this.getProperty(NodeConstants.Info.PROJECT_COLS);
+ switch (this.getType()) {
+ case NodeConstants.Types.SELECT: {
+ Criteria criteria = (Criteria) this.getProperty(NodeConstants.Info.SELECT_CRITERIA);
+ toSearch = Arrays.asList(criteria);
+ break;
+ }
+ case NodeConstants.Types.PROJECT: {
+ toSearch = (Collection) this.getProperty(NodeConstants.Info.PROJECT_COLS);
+ break;
+ }
+ case NodeConstants.Types.JOIN: {
+ toSearch = (List<Criteria>) this.getProperty(NodeConstants.Info.JOIN_CRITERIA);
+ break;
+ }
}
- return (List<SubqueryContainer>)ValueIteratorProviderCollectorVisitor.getValueIteratorProviders(toSearch);
+ return (List<SubqueryContainer>) ValueIteratorProviderCollectorVisitor.getValueIteratorProviders(toSearch);
}
}
Modified: trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/CapabilitiesUtil.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/CapabilitiesUtil.java 2009-04-27 16:49:34 UTC (rev 845)
+++ trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/CapabilitiesUtil.java 2009-04-27 19:02:50 UTC (rev 846)
@@ -22,7 +22,6 @@
package com.metamatrix.query.optimizer.relational.rules;
-import java.util.Collection;
import java.util.Iterator;
import java.util.List;
@@ -35,7 +34,6 @@
import com.metamatrix.query.optimizer.capabilities.SourceCapabilities;
import com.metamatrix.query.optimizer.capabilities.SourceCapabilities.Capability;
import com.metamatrix.query.sql.ReservedWords;
-import com.metamatrix.query.sql.lang.Criteria;
import com.metamatrix.query.sql.lang.JoinType;
import com.metamatrix.query.sql.lang.SetQuery.Operation;
import com.metamatrix.query.sql.symbol.AggregateSymbol;
@@ -44,7 +42,6 @@
import com.metamatrix.query.sql.symbol.Expression;
import com.metamatrix.query.sql.symbol.Function;
import com.metamatrix.query.sql.symbol.ScalarSubquery;
-import com.metamatrix.query.sql.visitor.FunctionCollectorVisitor;
/**
*/
@@ -293,40 +290,6 @@
return caps.supportsCapability(Capability.QUERY_ORDERBY);
}
- public static boolean supportsJoinExpression(Object modelID, List joinCriteria, QueryMetadataInterface metadata, CapabilitiesFinder capFinder)
- throws QueryMetadataException, MetaMatrixComponentException {
-
- if (metadata.isVirtualModel(modelID)){
- return false;
- }
-
- // Find capabilities
- SourceCapabilities caps = getCapabilities(modelID, metadata, capFinder);
-
- if(! caps.supportsCapability(Capability.FUNCTION)) {
- return false;
- }
-
- if(joinCriteria != null && joinCriteria.size() > 0) {
- Iterator iter = joinCriteria.iterator();
- while(iter.hasNext()) {
- Criteria crit = (Criteria) iter.next();
- Collection functions = FunctionCollectorVisitor.getFunctions(crit, false);
-
- Iterator funcIter = functions.iterator();
- while(funcIter.hasNext()) {
- Function function = (Function) funcIter.next();
- if(! supportsScalarFunction(modelID, function, metadata, capFinder)) {
- return false;
- }
- }
- }
- }
-
- // Found nothing unsupported
- return true;
- }
-
public static boolean supportsScalarSubquery(Object modelID, ScalarSubquery subquery, QueryMetadataInterface metadata, CapabilitiesFinder capFinder)
throws QueryMetadataException, MetaMatrixComponentException {
Modified: trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/FrameUtil.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/FrameUtil.java 2009-04-27 16:49:34 UTC (rev 845)
+++ trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/FrameUtil.java 2009-04-27 19:02:50 UTC (rev 846)
@@ -23,7 +23,6 @@
package com.metamatrix.query.optimizer.relational.rules;
import java.util.ArrayList;
-import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
@@ -66,7 +65,6 @@
import com.metamatrix.query.sql.visitor.ElementCollectorVisitor;
import com.metamatrix.query.sql.visitor.ExpressionMappingVisitor;
import com.metamatrix.query.sql.visitor.GroupsUsedByElementsVisitor;
-import com.metamatrix.query.sql.visitor.ValueIteratorProviderCollectorVisitor;
import com.metamatrix.query.util.ErrorMessageKeys;
public class FrameUtil {
@@ -103,9 +101,9 @@
return;
}
- for (Map.Entry<ElementSymbol, Expression> entry : new HashSet<Map.Entry<ElementSymbol, Expression>>(parentSymbolMap.asMap().entrySet())) {
- parentSymbolMap.addMapping(entry.getKey(), convertExpression(entry.getValue(), symbolMap));
- }
+ for (Map.Entry<ElementSymbol, Expression> entry : parentSymbolMap.asUpdatableMap().entrySet()) {
+ entry.setValue(convertExpression(entry.getValue(), symbolMap));
+ }
}
@@ -135,18 +133,17 @@
*/
private static void convertAccessPatterns(Map symbolMap,
PlanNode node) throws QueryPlannerException {
- List accessPatterns = (List)node.getProperty(NodeConstants.Info.ACCESS_PATTERNS);
+ List<AccessPattern> accessPatterns = (List<AccessPattern>)node.getProperty(NodeConstants.Info.ACCESS_PATTERNS);
if (accessPatterns != null) {
- for (Iterator i = accessPatterns.iterator(); i.hasNext();) {
- AccessPattern ap = (AccessPattern)i.next();
- Set newElements = new HashSet();
+ for (AccessPattern ap : accessPatterns) {
+ Set<ElementSymbol> newElements = new HashSet<ElementSymbol>();
for (Iterator elems = ap.getUnsatisfied().iterator(); elems.hasNext();) {
ElementSymbol symbol = (ElementSymbol)elems.next();
Expression mapped = convertExpression(symbol, symbolMap);
newElements.addAll(ElementCollectorVisitor.getElements(mapped, true));
}
ap.setUnsatisfied(newElements);
- Set newHistory = new HashSet();
+ Set<ElementSymbol> newHistory = new HashSet<ElementSymbol>();
for (Iterator elems = ap.getCurrentElements().iterator(); elems.hasNext();) {
ElementSymbol symbol = (ElementSymbol)elems.next();
Expression mapped = convertExpression(symbol, symbolMap);
@@ -173,6 +170,18 @@
int type = node.getType();
+ // Convert expressions from correlated subquery references;
+ List<SymbolMap> refMaps = node.getCorrelatedReferences();
+ boolean hasRefs = false;
+ for (SymbolMap refs : refMaps) {
+ for (Map.Entry<ElementSymbol, Expression> ref : refs.asUpdatableMap().entrySet()) {
+ hasRefs = true;
+ Expression expr = ref.getValue();
+ Expression convertedExpr = convertExpression(expr, symbolMap);
+ ref.setValue(convertedExpr);
+ }
+ }
+
if(newGroup != null) {
if (!hasOld) {
return;
@@ -182,20 +191,10 @@
groups.clear();
}
- // Convert expressions from correlated subquery references;
- // currently only for SELECT or PROJECT nodes
- SymbolMap refs = (SymbolMap)node.getProperty(NodeConstants.Info.CORRELATED_REFERENCES);
- if (refs != null){
- for (Map.Entry<ElementSymbol, Expression> ref : refs.asUpdatableMap().entrySet()) {
- Expression expr = ref.getValue();
- Expression convertedExpr = convertExpression(expr, symbolMap);
- ref.setValue(convertedExpr);
- if (newGroup == null) {
- GroupsUsedByElementsVisitor.getGroups(convertedExpr, groups);
- }
- }
+ if (hasRefs) {
+ groups.addAll(GroupsUsedByElementsVisitor.getGroups(node.getCorrelatedReferenceElements()));
}
-
+
if(type == NodeConstants.Types.SELECT) {
Criteria crit = (Criteria) node.getProperty(NodeConstants.Info.SELECT_CRITERIA);
crit = convertCriteria(crit, symbolMap);
@@ -346,12 +345,6 @@
return map;
}
- static boolean hasSubquery(PlanNode critNode) {
- Criteria crit = (Criteria)critNode.getProperty(NodeConstants.Info.SELECT_CRITERIA);
- Collection subCrits = ValueIteratorProviderCollectorVisitor.getValueIteratorProviders(crit);
- return (subCrits.size() > 0);
- }
-
/**
* Find the SOURCE, SET_OP, JOIN, or NULL node that originates the given groups (typically from a criteria node).
* In the case of join nodes the best fit will be found rather than just the first
Modified: trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/JoinUtil.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/JoinUtil.java 2009-04-27 16:49:34 UTC (rev 845)
+++ trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/JoinUtil.java 2009-04-27 19:02:50 UTC (rev 846)
@@ -72,7 +72,7 @@
* @return
*/
static final JoinType optimizeJoinType(PlanNode critNode, PlanNode joinNode, QueryMetadataInterface metadata) {
- if (critNode.getGroups().isEmpty() || !joinNode.getGroups().containsAll(critNode.getGroups()) || FrameUtil.hasSubquery(critNode)) {
+ if (critNode.getGroups().isEmpty() || !joinNode.getGroups().containsAll(critNode.getGroups())) {
return null;
}
Modified: trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleAssignOutputElements.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleAssignOutputElements.java 2009-04-27 16:49:34 UTC (rev 845)
+++ trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleAssignOutputElements.java 2009-04-27 19:02:50 UTC (rev 846)
@@ -54,7 +54,6 @@
import com.metamatrix.query.sql.symbol.Expression;
import com.metamatrix.query.sql.symbol.ExpressionSymbol;
import com.metamatrix.query.sql.symbol.GroupSymbol;
-import com.metamatrix.query.sql.symbol.Reference;
import com.metamatrix.query.sql.symbol.SingleElementSymbol;
import com.metamatrix.query.sql.util.SymbolMap;
import com.metamatrix.query.sql.visitor.AggregateSymbolCollectorVisitor;
@@ -431,8 +430,7 @@
// Gather elements from correlated subquery references;
// currently only for SELECT or PROJECT nodes
- SymbolMap refs = (SymbolMap)node.getProperty(NodeConstants.Info.CORRELATED_REFERENCES);
- if (refs != null){
+ for (SymbolMap refs : node.getCorrelatedReferences()) {
for (Expression expr : refs.asMap().values()) {
AggregateSymbolCollectorVisitor.getAggregates(expr, requiredSymbols, requiredSymbols);
}
Modified: trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleCollapseSource.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleCollapseSource.java 2009-04-27 16:49:34 UTC (rev 845)
+++ trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleCollapseSource.java 2009-04-27 19:02:50 UTC (rev 846)
@@ -68,6 +68,7 @@
import com.metamatrix.query.sql.symbol.SingleElementSymbol;
import com.metamatrix.query.sql.util.SymbolMap;
import com.metamatrix.query.sql.visitor.ExpressionMappingVisitor;
+import com.metamatrix.query.sql.visitor.ValueIteratorProviderCollectorVisitor;
import com.metamatrix.query.util.CommandContext;
public final class RuleCollapseSource implements OptimizerRule {
@@ -149,6 +150,7 @@
Query query = new Query();
Select select = new Select();
List<SingleElementSymbol> columns = (List<SingleElementSymbol>)node.getProperty(NodeConstants.Info.OUTPUT_COLS);
+ replaceCorrelatedReferences(ValueIteratorProviderCollectorVisitor.getValueIteratorProviders(columns));
select.addSymbols(columns);
query.setSelect(select);
query.setFrom(new From());
@@ -168,6 +170,7 @@
switch(node.getType()) {
case NodeConstants.Types.JOIN:
{
+ replaceCorrelatedReferences(node.getSubqueryContainers());
JoinType joinType = (JoinType) node.getProperty(NodeConstants.Info.JOIN_TYPE);
List crits = (List) node.getProperty(NodeConstants.Info.JOIN_CRITERIA);
@@ -245,34 +248,7 @@
case NodeConstants.Types.SELECT:
{
Criteria crit = (Criteria) node.getProperty(NodeConstants.Info.SELECT_CRITERIA);
- List<SubqueryContainer> containers = node.getSubqueryContainers();
- for (SubqueryContainer container : containers) {
- RelationalPlan subqueryPlan = (RelationalPlan)container.getCommand().getProcessorPlan();
- if (subqueryPlan == null) {
- continue;
- }
- AccessNode child = (AccessNode)subqueryPlan.getRootNode();
- Command command = child.getCommand();
- final SymbolMap map = (SymbolMap)node.getProperty(NodeConstants.Info.CORRELATED_REFERENCES);
- if (map != null) {
- ExpressionMappingVisitor visitor = new ExpressionMappingVisitor(null) {
- @Override
- public Expression replaceExpression(
- Expression element) {
- if (element instanceof Reference) {
- Reference ref = (Reference)element;
- Expression replacement = map.getMappedExpression(ref.getExpression());
- if (replacement != null) {
- return replacement;
- }
- }
- return element;
- }
- };
- DeepPostOrderNavigator.doVisit(command, visitor);
- }
- container.setCommand(command);
- }
+ replaceCorrelatedReferences(node.getSubqueryContainers());
if(!node.hasBooleanProperty(NodeConstants.Info.IS_HAVING)) {
query.setCriteria( CompoundCriteria.combineCriteria(query.getCriteria(), crit) );
} else {
@@ -306,6 +282,36 @@
}
}
+ private void replaceCorrelatedReferences(List<SubqueryContainer> containers) {
+ for (SubqueryContainer container : containers) {
+ RelationalPlan subqueryPlan = (RelationalPlan)container.getCommand().getProcessorPlan();
+ if (subqueryPlan == null) {
+ continue;
+ }
+ AccessNode child = (AccessNode)subqueryPlan.getRootNode();
+ Command command = child.getCommand();
+ final SymbolMap map = container.getCommand().getCorrelatedReferences();
+ if (map != null) {
+ ExpressionMappingVisitor visitor = new ExpressionMappingVisitor(null) {
+ @Override
+ public Expression replaceExpression(
+ Expression element) {
+ if (element instanceof Reference) {
+ Reference ref = (Reference)element;
+ Expression replacement = map.getMappedExpression(ref.getExpression());
+ if (replacement != null) {
+ return replacement;
+ }
+ }
+ return element;
+ }
+ };
+ DeepPostOrderNavigator.doVisit(command, visitor);
+ }
+ container.setCommand(command);
+ }
+ }
+
private void processLimit(PlanNode node,
QueryCommand query) {
Expression limit = (Expression)node.getProperty(NodeConstants.Info.MAX_TUPLE_LIMIT);
Modified: trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleCopyCriteria.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleCopyCriteria.java 2009-04-27 16:49:34 UTC (rev 845)
+++ trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleCopyCriteria.java 2009-04-27 19:02:50 UTC (rev 846)
@@ -346,7 +346,7 @@
Criteria crit = (Criteria) node.getProperty(NodeConstants.Info.SELECT_CRITERIA);
if(node.getGroups().size() == 1 && crit != null) {
- if(!node.hasBooleanProperty(NodeConstants.Info.IS_HAVING) && !FrameUtil.hasSubquery(node)) {
+ if(!node.hasBooleanProperty(NodeConstants.Info.IS_HAVING) && node.getSubqueryContainers().isEmpty()) {
if (!node.hasBooleanProperty(NodeConstants.Info.IS_COPIED)) {
toCopy.add(crit);
}
Modified: trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleMergeCriteria.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleMergeCriteria.java 2009-04-27 16:49:34 UTC (rev 845)
+++ trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleMergeCriteria.java 2009-04-27 19:02:50 UTC (rev 846)
@@ -23,7 +23,6 @@
package com.metamatrix.query.optimizer.relational.rules;
import java.util.ArrayList;
-import java.util.Iterator;
import java.util.List;
import com.metamatrix.api.exception.MetaMatrixComponentException;
@@ -39,7 +38,6 @@
import com.metamatrix.query.rewriter.QueryRewriter;
import com.metamatrix.query.sql.lang.CompoundCriteria;
import com.metamatrix.query.sql.lang.Criteria;
-import com.metamatrix.query.sql.util.SymbolMap;
import com.metamatrix.query.sql.visitor.GroupsUsedByElementsVisitor;
import com.metamatrix.query.util.CommandContext;
@@ -54,13 +52,11 @@
throws QueryPlannerException, MetaMatrixComponentException {
// Find strings of criteria and merge them, removing duplicates
- List criteriaChains = new ArrayList();
+ List<PlanNode> criteriaChains = new ArrayList<PlanNode>();
findCriteriaChains(plan, criteriaChains);
// Merge chains
- Iterator chainIter = criteriaChains.iterator();
- while(chainIter.hasNext()) {
- PlanNode critNode = (PlanNode) chainIter.next();
+ for (PlanNode critNode : criteriaChains) {
mergeChain(critNode);
}
@@ -72,7 +68,7 @@
* @param node Root node to search
* @param foundNodes Roots of criteria chains
*/
- void findCriteriaChains(PlanNode root, List foundNodes)
+ void findCriteriaChains(PlanNode root, List<PlanNode> foundNodes)
throws QueryPlannerException, MetaMatrixComponentException {
PlanNode recurseRoot = root;
@@ -100,7 +96,6 @@
// Remove all of chain except root, collect crit from each
CompoundCriteria critParts = new CompoundCriteria();
- SymbolMap correlatedReferences = new SymbolMap();
PlanNode current = chainRoot;
boolean isDependentSet = false;
while(current.getType() == NodeConstants.Types.SELECT) {
@@ -108,8 +103,6 @@
isDependentSet |= current.hasBooleanProperty(NodeConstants.Info.IS_DEPENDENT_SET);
- correlatedReferences.merge((SymbolMap)current.getProperty(NodeConstants.Info.CORRELATED_REFERENCES));
-
// Recurse
PlanNode last = current;
current = current.getLastChild();
@@ -129,9 +122,6 @@
// Replace criteria at root with new combined criteria
chainRoot.setProperty(NodeConstants.Info.SELECT_CRITERIA, combinedCrit);
- if (!correlatedReferences.asMap().isEmpty()){
- chainRoot.setProperty(NodeConstants.Info.CORRELATED_REFERENCES, correlatedReferences);
- }
// Reset group for node based on combined criteria
chainRoot.getGroups().clear();
@@ -140,23 +130,6 @@
chainRoot.addGroups(GroupsUsedByElementsVisitor.getGroups(chainRoot.getCorrelatedReferenceElements()));
}
- /**
- * Add the 'addToProps' List (if not null) to the 'props' List
- * (if not null).
- * @param props
- * @param addToProps
- * @return 'props' List, or else new List if 'props' was null
- */
- private static List addProperties(List props, List addToProps) {
- if (addToProps != null){
- if (props == null){
- props = new ArrayList();
- }
- props.addAll(addToProps);
- }
- return props;
- }
-
public String toString() {
return "MergeCriteria"; //$NON-NLS-1$
}
Modified: trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RulePlanProcedures.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RulePlanProcedures.java 2009-04-27 16:49:34 UTC (rev 845)
+++ trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RulePlanProcedures.java 2009-04-27 19:02:50 UTC (rev 846)
@@ -153,7 +153,7 @@
critNode = currentNode.getParent();
- if (FrameUtil.hasSubquery(currentNode) || !currentNode.getGroups().isEmpty()) {
+ if (!currentNode.getGroups().isEmpty()) {
continue;
}
Modified: trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RulePushSelectCriteria.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RulePushSelectCriteria.java 2009-04-27 16:49:34 UTC (rev 845)
+++ trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RulePushSelectCriteria.java 2009-04-27 19:02:50 UTC (rev 846)
@@ -104,7 +104,7 @@
boolean moved = false;
- if((critNode.getGroups().isEmpty() && !FrameUtil.hasSubquery(critNode)) || !atBoundary(critNode, sourceNode)) {
+ if((critNode.getGroups().isEmpty() && critNode.getSubqueryContainers().isEmpty()) || !atBoundary(critNode, sourceNode)) {
deadNodes.add(critNode);
continue;
}
@@ -136,7 +136,7 @@
private PlanNode findOriginatingNode(QueryMetadataInterface metadata,
CapabilitiesFinder capFinder, PlanNode critNode)
throws MetaMatrixComponentException, QueryMetadataException {
- if (critNode.getGroups().isEmpty() && FrameUtil.hasSubquery(critNode)) {
+ if (critNode.getGroups().isEmpty()) {
Object modelId = RuleRaiseAccess.isEligibleSubquery(critNode, null, metadata, capFinder);
if (modelId != null) {
for (PlanNode node : NodeEditor.findAllNodes(critNode, NodeConstants.Types.SOURCE)) {
@@ -159,10 +159,6 @@
* @return
*/
private boolean handleJoinCriteria(PlanNode joinNode, PlanNode critNode, QueryMetadataInterface metadata) {
- //we currently don't allow subqueries in join criteria
- if (FrameUtil.hasSubquery(critNode)) {
- return false;
- }
JoinType jt = (JoinType)joinNode.getProperty(NodeConstants.Info.JOIN_TYPE);
if (jt == JoinType.JOIN_CROSS || jt == JoinType.JOIN_INNER) {
@@ -313,7 +309,7 @@
if (child != null && child.getType() == NodeConstants.Types.SET_OP) {
//only allow criteria without subqueires - node cloning doesn't allow for the proper creation of
//multiple nodes with the same subqueries
- if (child == sourceNode.getFirstChild() && !FrameUtil.hasSubquery(critNode)) {
+ if (child == sourceNode.getFirstChild() && critNode.getSubqueryContainers().isEmpty()) {
return pushAcrossSetOp(critNode, child);
}
//this could be an access node in the middle of the source and set op,
@@ -443,10 +439,6 @@
Criteria copyCrit = (Criteria) crit.clone();
copyNode.setProperty(NodeConstants.Info.SELECT_CRITERIA, copyCrit);
copyNode.addGroups(critNode.getGroups());
- SymbolMap correlatedReferences = (SymbolMap)critNode.getProperty(NodeConstants.Info.CORRELATED_REFERENCES);
- if(correlatedReferences != null) {
- copyNode.setProperty(NodeConstants.Info.CORRELATED_REFERENCES, new SymbolMap(correlatedReferences));
- }
if(critNode.hasBooleanProperty(NodeConstants.Info.IS_DEPENDENT_SET)) {
copyNode.setProperty(NodeConstants.Info.IS_DEPENDENT_SET, Boolean.TRUE);
}
@@ -534,7 +526,7 @@
return false; //not convertable
}
- if (FrameUtil.hasSubquery(critNode)
+ if (!critNode.getSubqueryContainers().isEmpty()
&& checkConversion(symbolMap, critNode.getCorrelatedReferenceElements()) != null) {
return false; //not convertable, or has an aggregate for a correlated reference
}
Modified: trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleRaiseAccess.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleRaiseAccess.java 2009-04-27 16:49:34 UTC (rev 845)
+++ trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleRaiseAccess.java 2009-04-27 19:02:50 UTC (rev 846)
@@ -60,7 +60,6 @@
import com.metamatrix.query.sql.symbol.SingleElementSymbol;
import com.metamatrix.query.sql.util.SymbolMap;
import com.metamatrix.query.sql.visitor.EvaluateExpressionVisitor;
-import com.metamatrix.query.sql.visitor.FunctionCollectorVisitor;
import com.metamatrix.query.sql.visitor.GroupCollectorVisitor;
import com.metamatrix.query.sql.visitor.ValueIteratorProviderCollectorVisitor;
import com.metamatrix.query.util.CommandContext;
@@ -119,6 +118,10 @@
{
// Check that the PROJECT contains only functions that can be pushed
List projectCols = (List) parentNode.getProperty(NodeConstants.Info.PROJECT_COLS);
+
+ if(isEligibleSubquery(parentNode, modelID, metadata, capFinder) == null){
+ return null;
+ }
for (int i = 0; i < projectCols.size(); i++) {
SingleElementSymbol symbol = (SingleElementSymbol)projectCols.get(i);
@@ -322,10 +325,6 @@
return false;
}
- // Check criteria capabilities of source. Criteria (even
- // multi-group criteria) can possibly be pushed if model can
- // support everything in the criteria.
-
if(!CriteriaCapabilityValidatorVisitor.canPushLanguageObject(crit, modelID, metadata, capFinder) ) {
return false;
}
@@ -343,7 +342,10 @@
* Check whether the subquery in the node is eligible to be pushed.
*/
static Object isEligibleSubquery(PlanNode critNode, Object critNodeModelID, QueryMetadataInterface metadata, CapabilitiesFinder capFinder) throws MetaMatrixComponentException {
- List<SubqueryContainer> plans = critNode.getSubqueryContainers();
+ return isEligibleSubquery(critNode.getSubqueryContainers(), critNodeModelID, metadata, capFinder);
+ }
+
+ static Object isEligibleSubquery(List<SubqueryContainer> plans, Object critNodeModelID, QueryMetadataInterface metadata, CapabilitiesFinder capFinder) throws MetaMatrixComponentException {
for (SubqueryContainer subqueryContainer : plans) {
ProcessorPlan plan = subqueryContainer.getCommand().getProcessorPlan();
if(!(plan instanceof RelationalPlan)) {
@@ -384,19 +386,20 @@
}
// Check whether source supports correlated subqueries and if not, whether criteria has them
- SymbolMap refs = (SymbolMap) critNode.getProperty(NodeConstants.Info.CORRELATED_REFERENCES);
+ SymbolMap refs = subqueryContainer.getCommand().getCorrelatedReferences();
try {
if(refs != null && !refs.asMap().isEmpty()) {
if(! CapabilitiesUtil.supportsCorrelatedSubquery(critNodeModelID, metadata, capFinder)) {
return null;
}
-
+ //TODO: this check sees as correlated references as coming from the containing scope
+ //but this is only an issue with deeply nested subqueries
if (!CriteriaCapabilityValidatorVisitor.canPushLanguageObject(command, critNodeModelID, metadata, capFinder)) {
return null;
}
}
} catch(QueryMetadataException e) {
- throw new MetaMatrixComponentException(e, e.getMessage());
+ throw new MetaMatrixComponentException(e);
}
}
@@ -426,16 +429,9 @@
return false;
}
- if(inSelectClause && !(expr instanceof ElementSymbol)) {
- if(ValueIteratorProviderCollectorVisitor.getValueIteratorProviders(expr).size() > 0) {
- // Don't support for now
- return false;
-
- } else if(expr instanceof Constant || EvaluateExpressionVisitor.willBecomeConstant(expr)) {
- if(! CapabilitiesUtil.supportsSelectLiterals(modelID, metadata, capFinder)) {
- return false;
- }
- }
+ if(inSelectClause && !(expr instanceof ElementSymbol) && !CapabilitiesUtil.supportsSelectLiterals(modelID, metadata, capFinder)
+ && (expr instanceof Constant || EvaluateExpressionVisitor.willBecomeConstant(expr))) {
+ return false;
}
// By default, no reason we can't push
@@ -466,7 +462,7 @@
* @return The modelID if the raise can proceed and what common model these combined
* nodes will be sent to
*/
- Object canRaiseOverJoin(PlanNode joinNode, QueryMetadataInterface metadata, CapabilitiesFinder capFinder, boolean afterJoinPlanning)
+ private static Object canRaiseOverJoin(PlanNode joinNode, QueryMetadataInterface metadata, CapabilitiesFinder capFinder, boolean afterJoinPlanning)
throws QueryMetadataException, MetaMatrixComponentException {
List crits = (List) joinNode.getProperty(NodeConstants.Info.JOIN_CRITERIA);
@@ -495,7 +491,7 @@
static Object canRaiseOverJoin(List children,
QueryMetadataInterface metadata,
CapabilitiesFinder capFinder,
- List crits,
+ List<Criteria> crits,
JoinType type) throws QueryMetadataException,
MetaMatrixComponentException {
Object modelID = null;
@@ -527,9 +523,7 @@
boolean supportsSelfJoins = CapabilitiesUtil.supportsSelfJoins(accessModelID, metadata, capFinder);
if (!supportsSelfJoins) {
- Iterator groupIter = childNode.getGroups().iterator();
- while(groupIter.hasNext()) {
- GroupSymbol groupSymbol = (GroupSymbol) groupIter.next();
+ for (GroupSymbol groupSymbol : childNode.getGroups()) {
Object groupID = groupSymbol.getMetadataID();
if(!groupIDs.add(groupID)) {
// Already seen group - can't raise access over self join
@@ -553,21 +547,14 @@
// Check that model supports join expressions
if(crits != null && !crits.isEmpty()) {
- // Check whether has expression
- boolean hasExpression = false;
- Iterator critIter = crits.iterator();
- while(critIter.hasNext()) {
- Criteria crit = (Criteria) critIter.next();
- if(FunctionCollectorVisitor.getFunctions(crit, false).size() > 0) {
- hasExpression = true;
- break;
- }
+ for (Criteria crit : crits) {
+ if(!CriteriaCapabilityValidatorVisitor.canPushLanguageObject(crit, accessModelID, metadata, capFinder) ) {
+ return null;
+ }
}
-
- // If expression was found and capabilities don't support, abort this join
- if(hasExpression && ! CapabilitiesUtil.supportsJoinExpression(accessModelID, crits, metadata, capFinder)) {
- return null;
- }
+ if(isEligibleSubquery(ValueIteratorProviderCollectorVisitor.getValueIteratorProviders(crits), accessModelID, metadata, capFinder) == null){
+ return null;
+ }
}
modelID = accessModelID;
Modified: trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleRemoveOptionalJoins.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleRemoveOptionalJoins.java 2009-04-27 16:49:34 UTC (rev 845)
+++ trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleRemoveOptionalJoins.java 2009-04-27 19:02:50 UTC (rev 846)
@@ -51,7 +51,6 @@
import com.metamatrix.query.sql.symbol.ElementSymbol;
import com.metamatrix.query.sql.symbol.Expression;
import com.metamatrix.query.sql.symbol.GroupSymbol;
-import com.metamatrix.query.sql.symbol.Reference;
import com.metamatrix.query.sql.util.SymbolMap;
import com.metamatrix.query.sql.visitor.ElementCollectorVisitor;
import com.metamatrix.query.sql.visitor.GroupsUsedByElementsVisitor;
@@ -108,6 +107,7 @@
}
List crits = (List)node.getProperty(NodeConstants.Info.JOIN_CRITERIA);
ElementCollectorVisitor.getElements(crits, elements);
+ elements.addAll(node.getCorrelatedReferenceElements());
break;
}
case NodeConstants.Types.PROJECT:
Modified: trunk/engine/src/main/java/com/metamatrix/query/processor/ProcessorDataManager.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/processor/ProcessorDataManager.java 2009-04-27 16:49:34 UTC (rev 845)
+++ trunk/engine/src/main/java/com/metamatrix/query/processor/ProcessorDataManager.java 2009-04-27 19:02:50 UTC (rev 846)
@@ -24,12 +24,28 @@
import com.metamatrix.api.exception.MetaMatrixComponentException;
import com.metamatrix.api.exception.MetaMatrixProcessingException;
+import com.metamatrix.common.buffer.BlockedException;
import com.metamatrix.common.buffer.TupleSource;
-import com.metamatrix.query.eval.LookupEvaluator;
import com.metamatrix.query.sql.lang.Command;
+import com.metamatrix.query.util.CommandContext;
-public interface ProcessorDataManager extends LookupEvaluator {
+public interface ProcessorDataManager {
TupleSource registerRequest(Object processorId, Command command, String modelName, String connectorBindingId, int nodeID)
throws MetaMatrixComponentException, MetaMatrixProcessingException;
+
+ /**
+ * Lookup a value from a cached code table. If the code table is not loaded, it will be
+ * loaded on the first query. Code tables should be cached based on a combination of
+ * the codeTableName, returnElementName, and keyElementName. If the table is not loaded,
+ * a request will be made and the method should throw a BlockedException.
+ */
+ Object lookupCodeValue(CommandContext context,
+ String codeTableName,
+ String returnElementName,
+ String keyElementName,
+ Object keyValue) throws BlockedException,
+ MetaMatrixComponentException, MetaMatrixProcessingException;
+
+ void clearCodeTables();
}
Modified: trunk/engine/src/main/java/com/metamatrix/query/processor/TempTableDataManager.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/processor/TempTableDataManager.java 2009-04-27 16:49:34 UTC (rev 845)
+++ trunk/engine/src/main/java/com/metamatrix/query/processor/TempTableDataManager.java 2009-04-27 19:02:50 UTC (rev 846)
@@ -91,4 +91,9 @@
return this.processorDataManager.lookupCodeValue(context, codeTableName, returnElementName, keyElementName, keyValue);
}
+ @Override
+ public void clearCodeTables() {
+ this.processorDataManager.clearCodeTables();
+ }
+
}
Modified: trunk/engine/src/main/java/com/metamatrix/query/processor/proc/AbstractAssignmentInstruction.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/processor/proc/AbstractAssignmentInstruction.java 2009-04-27 16:49:34 UTC (rev 845)
+++ trunk/engine/src/main/java/com/metamatrix/query/processor/proc/AbstractAssignmentInstruction.java 2009-04-27 19:02:50 UTC (rev 846)
@@ -33,7 +33,7 @@
import com.metamatrix.common.buffer.BlockedException;
import com.metamatrix.query.execution.QueryExecPlugin;
import com.metamatrix.query.processor.ProcessorPlan;
-import com.metamatrix.query.processor.program.ProgramEnvironment;
+import com.metamatrix.query.processor.program.ProgramInstruction;
import com.metamatrix.query.sql.symbol.ElementSymbol;
import com.metamatrix.query.sql.symbol.Expression;
import com.metamatrix.query.sql.util.VariableContext;
@@ -45,7 +45,7 @@
* a expression or a command(stored as a processplan). The Processing of the command is
* expected to result in 1 column, 1 row tuple.</p>
*/
-public abstract class AbstractAssignmentInstruction extends CommandInstruction {
+public abstract class AbstractAssignmentInstruction extends ProgramInstruction {
// variable whose value is updated in the context
private ElementSymbol variable;
@@ -63,11 +63,9 @@
* @throws BlockedException
* @throws MetaMatrixComponentException if error processing command or expression on this instruction
*/
- public void process(ProgramEnvironment env) throws BlockedException,
+ public void process(ProcedurePlan procEnv) throws BlockedException,
MetaMatrixComponentException, MetaMatrixProcessingException {
- ProcedureEnvironment procEnv = (ProcedureEnvironment)env;
-
VariableContext varContext = procEnv.getCurrentVariableContext();
Object value = null;
if (this.getExpression() != null || this.getProcessorPlan() != null) {
Modified: trunk/engine/src/main/java/com/metamatrix/query/processor/proc/AssignmentInstruction.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/processor/proc/AssignmentInstruction.java 2009-04-27 16:49:34 UTC (rev 845)
+++ trunk/engine/src/main/java/com/metamatrix/query/processor/proc/AssignmentInstruction.java 2009-04-27 19:02:50 UTC (rev 846)
@@ -32,7 +32,7 @@
/**
* <p> This instruction updates the current variable context with a value for the Variable
- * defined using a DeclareInstruction, the vriable value is obtained by either processing
+ * defined using a DeclareInstruction, the variable value is obtained by either processing
* a expression or a command(stored as a processplan). The Processing of the command is
* expected to result in 1 column, 1 row tuple.</p>
*/
Modified: trunk/engine/src/main/java/com/metamatrix/query/processor/proc/BreakInstruction.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/processor/proc/BreakInstruction.java 2009-04-27 16:49:34 UTC (rev 845)
+++ trunk/engine/src/main/java/com/metamatrix/query/processor/proc/BreakInstruction.java 2009-04-27 19:02:50 UTC (rev 846)
@@ -38,7 +38,7 @@
return "BREAK INSTRUCTION"; //$NON-NLS-1$
}
- public void process(ProgramEnvironment env) throws MetaMatrixComponentException {
+ public void process(ProcedurePlan env) throws MetaMatrixComponentException {
super.process(env);
env.incrementProgramCounter();
}
Deleted: trunk/engine/src/main/java/com/metamatrix/query/processor/proc/CommandInstruction.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/processor/proc/CommandInstruction.java 2009-04-27 16:49:34 UTC (rev 845)
+++ trunk/engine/src/main/java/com/metamatrix/query/processor/proc/CommandInstruction.java 2009-04-27 19:02:50 UTC (rev 846)
@@ -1,37 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package com.metamatrix.query.processor.proc;
-
-import com.metamatrix.query.processor.program.ProgramInstruction;
-
-
-/**
- * This abstract base class has common methods for dealing with instructions that
- * have commands. In particular commands may have nested EXECs that have parameter
- * references, which require some special handling.
- *
- * @since 4.4
- */
-public abstract class CommandInstruction extends ProgramInstruction {
-
-}
Modified: trunk/engine/src/main/java/com/metamatrix/query/processor/proc/ContinueInstruction.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/processor/proc/ContinueInstruction.java 2009-04-27 16:49:34 UTC (rev 845)
+++ trunk/engine/src/main/java/com/metamatrix/query/processor/proc/ContinueInstruction.java 2009-04-27 19:02:50 UTC (rev 846)
@@ -37,7 +37,7 @@
return "CONTINUE INSTRUCTION"; //$NON-NLS-1$
}
- public void process(ProgramEnvironment env) throws MetaMatrixComponentException {
+ public void process(ProcedurePlan env) throws MetaMatrixComponentException {
Program parentProgram = env.peek();
//find the parent program that contains the loop/while instruction
Modified: trunk/engine/src/main/java/com/metamatrix/query/processor/proc/CreateCursorResultSetInstruction.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/processor/proc/CreateCursorResultSetInstruction.java 2009-04-27 16:49:34 UTC (rev 845)
+++ trunk/engine/src/main/java/com/metamatrix/query/processor/proc/CreateCursorResultSetInstruction.java 2009-04-27 19:02:50 UTC (rev 846)
@@ -34,11 +34,11 @@
import com.metamatrix.api.exception.MetaMatrixProcessingException;
import com.metamatrix.common.buffer.BlockedException;
import com.metamatrix.query.processor.ProcessorPlan;
-import com.metamatrix.query.processor.program.ProgramEnvironment;
+import com.metamatrix.query.processor.program.ProgramInstruction;
/**
*/
-public class CreateCursorResultSetInstruction extends CommandInstruction {
+public class CreateCursorResultSetInstruction extends ProgramInstruction {
protected String rsName;
protected ProcessorPlan plan;
@@ -56,11 +56,9 @@
* @throws BlockedException if this result set is not selecting from
* only temp groups
*/
- public void process(ProgramEnvironment env)
+ public void process(ProcedurePlan procEnv)
throws BlockedException, MetaMatrixComponentException, MetaMatrixProcessingException {
- ProcedureEnvironment procEnv = (ProcedureEnvironment)env;
-
if(procEnv.resultSetExists(rsName)) {
procEnv.removeResults(rsName);
}
Modified: trunk/engine/src/main/java/com/metamatrix/query/processor/proc/ExecDynamicSqlInstruction.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/processor/proc/ExecDynamicSqlInstruction.java 2009-04-27 16:49:34 UTC (rev 845)
+++ trunk/engine/src/main/java/com/metamatrix/query/processor/proc/ExecDynamicSqlInstruction.java 2009-04-27 19:02:50 UTC (rev 846)
@@ -49,7 +49,6 @@
import com.metamatrix.query.parser.QueryParser;
import com.metamatrix.query.processor.ProcessorPlan;
import com.metamatrix.query.processor.program.Program;
-import com.metamatrix.query.processor.program.ProgramEnvironment;
import com.metamatrix.query.processor.program.ProgramInstruction;
import com.metamatrix.query.resolver.QueryResolver;
import com.metamatrix.query.resolver.util.ResolveVirtualGroupCriteriaVisitor;
@@ -86,17 +85,15 @@
* immediately.
* </p>
*/
-public class ExecDynamicSqlInstruction extends CommandInstruction {
+public class ExecDynamicSqlInstruction extends ProgramInstruction {
private static class PopCallInstruction extends ProgramInstruction {
/**
- * @see com.metamatrix.query.processor.program.ProgramInstruction#process(com.metamatrix.query.processor.program.ProgramEnvironment)
+ * @see com.metamatrix.query.processor.program.ProgramInstruction#process(ProcedurePlan)
*/
- public void process(ProgramEnvironment env) throws MetaMatrixComponentException,
+ public void process(ProcedurePlan procEnv) throws MetaMatrixComponentException,
MetaMatrixProcessingException {
- ProcedureEnvironment procEnv = (ProcedureEnvironment) env;
-
procEnv.getContext().popCall();
}
@@ -146,11 +143,9 @@
* @throws BlockedException
* if this processing the plan throws a currentVarContext
*/
- public void process(ProgramEnvironment env) throws BlockedException,
+ public void process(ProcedurePlan procEnv) throws BlockedException,
MetaMatrixComponentException, MetaMatrixProcessingException {
- ProcedureEnvironment procEnv = (ProcedureEnvironment) env;
-
VariableContext localContext = procEnv.getCurrentVariableContext();
try {
@@ -240,7 +235,7 @@
* @throws MetaMatrixComponentException
* @throws MetaMatrixProcessingException
*/
- private void updateContextWithUsingValues(ProcedureEnvironment procEnv,
+ private void updateContextWithUsingValues(ProcedurePlan procEnv,
VariableContext localContext) throws MetaMatrixComponentException, MetaMatrixProcessingException {
if (dynamicCommand.getUsing() != null
&& !dynamicCommand.getUsing().isEmpty()) {
@@ -367,7 +362,7 @@
* @throws MetaMatrixComponentException
* @throws QueryProcessingException
*/
- private void validateDynamicCommand(ProcedureEnvironment procEnv,
+ private void validateDynamicCommand(ProcedurePlan procEnv,
Command command) throws MetaMatrixComponentException,
QueryProcessingException {
// validate project symbols
Modified: trunk/engine/src/main/java/com/metamatrix/query/processor/proc/ExecSqlInstruction.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/processor/proc/ExecSqlInstruction.java 2009-04-27 16:49:34 UTC (rev 845)
+++ trunk/engine/src/main/java/com/metamatrix/query/processor/proc/ExecSqlInstruction.java 2009-04-27 19:02:50 UTC (rev 846)
@@ -32,7 +32,7 @@
import com.metamatrix.api.exception.MetaMatrixProcessingException;
import com.metamatrix.common.buffer.BlockedException;
import com.metamatrix.query.processor.ProcessorPlan;
-import com.metamatrix.query.processor.program.ProgramEnvironment;
+import com.metamatrix.query.processor.program.ProgramInstruction;
import com.metamatrix.query.sql.symbol.GroupSymbol;
/**
@@ -40,7 +40,7 @@
* instruction does not modify the values of any of the variables, hence it's results are not
* important so they are removed immediately.</p>
*/
-public class ExecSqlInstruction extends CommandInstruction {
+public class ExecSqlInstruction extends ProgramInstruction {
public static final String RS_NAME = "EXECSQL_INSTRUCTION"; //$NON-NLS-1$
@@ -68,11 +68,9 @@
* counter is incremented after execution of the plan.</p>
* @throws BlockedException if this processing the plan throws a currentVarContext
*/
- public void process(ProgramEnvironment env)
+ public void process(ProcedurePlan procEnv)
throws BlockedException, MetaMatrixComponentException, MetaMatrixProcessingException {
- ProcedureEnvironment procEnv = (ProcedureEnvironment) env;
-
if(intoGroup != null && intoGroup.isTempGroupSymbol()){
procEnv.executePlan(commandPlan, intoGroup.getName());
}else{
Modified: trunk/engine/src/main/java/com/metamatrix/query/processor/proc/IfInstruction.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/processor/proc/IfInstruction.java 2009-04-27 16:49:34 UTC (rev 845)
+++ trunk/engine/src/main/java/com/metamatrix/query/processor/proc/IfInstruction.java 2009-04-27 19:02:50 UTC (rev 846)
@@ -34,7 +34,6 @@
import com.metamatrix.common.log.LogManager;
import com.metamatrix.dqp.util.LogConstants;
import com.metamatrix.query.processor.program.Program;
-import com.metamatrix.query.processor.program.ProgramEnvironment;
import com.metamatrix.query.processor.program.ProgramInstruction;
import com.metamatrix.query.sql.lang.Criteria;
@@ -87,13 +86,11 @@
* evaluate to true, this instruction will increment the program counter of the
* current program.
* @throws MetaMatrixProcessingException
- * @see ProgramInstruction#process(ProgramEnvironment)
+ * @see ProgramInstruction#process(ProcedurePlan)
*/
- public void process(ProgramEnvironment env)
+ public void process(ProcedurePlan procEnv)
throws BlockedException, MetaMatrixComponentException, MetaMatrixProcessingException {
- ProcedureEnvironment procEnv = (ProcedureEnvironment) env;
-
boolean evalValue = procEnv.evaluateCriteria(condition);
if(evalValue) {
Modified: trunk/engine/src/main/java/com/metamatrix/query/processor/proc/LoopInstruction.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/processor/proc/LoopInstruction.java 2009-04-27 16:49:34 UTC (rev 845)
+++ trunk/engine/src/main/java/com/metamatrix/query/processor/proc/LoopInstruction.java 2009-04-27 19:02:50 UTC (rev 846)
@@ -34,7 +34,6 @@
import com.metamatrix.api.exception.MetaMatrixProcessingException;
import com.metamatrix.query.processor.ProcessorPlan;
import com.metamatrix.query.processor.program.Program;
-import com.metamatrix.query.processor.program.ProgramEnvironment;
import com.metamatrix.query.sql.symbol.ElementSymbol;
import com.metamatrix.query.sql.symbol.SingleElementSymbol;
import com.metamatrix.query.sql.util.VariableContext;
@@ -54,9 +53,7 @@
this.loopProgram = loopProgram;
}
- public void process(ProgramEnvironment env) throws MetaMatrixComponentException {
- ProcedureEnvironment procEnv = (ProcedureEnvironment)env;
-
+ public void process(ProcedurePlan procEnv) throws MetaMatrixComponentException {
List currentRow = procEnv.getCurrentRow(rsName);
VariableContext varContext = procEnv.getCurrentVariableContext();
//set results to the variable context(the cursor.element is treated as variable)
@@ -111,7 +108,7 @@
/**
* @see com.metamatrix.query.processor.proc.RepeatedInstruction#testCondition(com.metamatrix.query.processor.proc.ProcedureEnvironment)
*/
- public boolean testCondition(ProcedureEnvironment procEnv) throws MetaMatrixComponentException, MetaMatrixProcessingException {
+ public boolean testCondition(ProcedurePlan procEnv) throws MetaMatrixComponentException, MetaMatrixProcessingException {
if(!procEnv.resultSetExists(rsName)) {
procEnv.executePlan(plan, rsName);
}
@@ -129,7 +126,7 @@
/**
* @see com.metamatrix.query.processor.proc.RepeatedInstruction#postInstruction(com.metamatrix.query.processor.proc.ProcedureEnvironment)
*/
- public void postInstruction(ProcedureEnvironment procEnv) throws MetaMatrixComponentException {
+ public void postInstruction(ProcedurePlan procEnv) throws MetaMatrixComponentException {
procEnv.removeResults(rsName);
}
Deleted: trunk/engine/src/main/java/com/metamatrix/query/processor/proc/ProcedureEnvironment.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/processor/proc/ProcedureEnvironment.java 2009-04-27 16:49:34 UTC (rev 845)
+++ trunk/engine/src/main/java/com/metamatrix/query/processor/proc/ProcedureEnvironment.java 2009-04-27 19:02:50 UTC (rev 846)
@@ -1,363 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package com.metamatrix.query.processor.proc;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.api.exception.MetaMatrixProcessingException;
-import com.metamatrix.common.buffer.BlockedException;
-import com.metamatrix.common.buffer.TupleSource;
-import com.metamatrix.common.buffer.TupleSourceID;
-import com.metamatrix.query.eval.Evaluator;
-import com.metamatrix.query.execution.QueryExecPlugin;
-import com.metamatrix.query.processor.NullTupleSource;
-import com.metamatrix.query.processor.ProcessorDataManager;
-import com.metamatrix.query.processor.ProcessorPlan;
-import com.metamatrix.query.processor.program.Program;
-import com.metamatrix.query.processor.program.ProgramEnvironment;
-import com.metamatrix.query.processor.program.ProgramInstruction;
-import com.metamatrix.query.sql.ProcedureReservedWords;
-import com.metamatrix.query.sql.lang.Criteria;
-import com.metamatrix.query.sql.symbol.ElementSymbol;
-import com.metamatrix.query.sql.symbol.Expression;
-import com.metamatrix.query.sql.util.VariableContext;
-import com.metamatrix.query.tempdata.TempTableStore;
-import com.metamatrix.query.util.CommandContext;
-import com.metamatrix.query.util.ErrorMessageKeys;
-
-/**
- * <p>This class defines the environment that procedure language programs run in
- * and what {@link ProgramInstruction}s can access during execution. This
- * environment holds references to the {@link VariableContext}, this variable
- * context is updated with new variables and their values upon execution of the
- * program instructions.</p>
- */
-public class ProcedureEnvironment extends ProgramEnvironment {
-
- private Map tupleSourceMap = new HashMap(); // rsName -> TupleSource
- private Map tupleSourceIDMap = new HashMap(); // rsName -> TupleSourceID
- private Map currentRowMap = new HashMap();
-
- private static ElementSymbol ROWS_UPDATED =
- new ElementSymbol(ProcedureReservedWords.VARIABLES+"."+ProcedureReservedWords.ROWS_UPDATED); //$NON-NLS-1$
-
- private static int NO_ROWS_UPDATED = 0;
- private ProcedurePlan plan;
- private VariableContext currentVarContext;
- private boolean isUpdateProcedure = true;
-
- private TupleSource lastTupleSource;
-
- private List outputElements;
-
- private TempTableStore tempTableStore;
-
- private LinkedList tempContext = new LinkedList();
-
- /**
- * Constructor for ProcedureEnvironment.
- */
- public ProcedureEnvironment() {
- super();
- this.currentVarContext = new VariableContext(true);
- this.currentVarContext.setValue(ROWS_UPDATED, new Integer(NO_ROWS_UPDATED));
- }
-
- /**
- * Initialize the environment with the procedure plan.
- */
- public void initialize(ProcessorPlan plan) {
- this.plan = (ProcedurePlan)plan;
- }
-
- private TupleSource getUpdateCountAsToupleSource() {
- Object rowCount = currentVarContext.getValue(ROWS_UPDATED);
- if(rowCount == null) {
- rowCount = new Integer(NO_ROWS_UPDATED);
- }
-
- final List updateResult = new ArrayList(1);
- updateResult.add(rowCount);
-
- return new UpdateCountTupleSource(updateResult);
- }
-
- /**
- * <p> Get the current <code>VariavleContext</code> on this environment.
- * The VariableContext is updated with variables and their values by
- * {@link ProgramInstruction}s that are part of the ProcedurePlan that use
- * this environment.</p>
- * @return The current <code>VariariableContext</code>.
- */
- public VariableContext getCurrentVariableContext() {
- return this.currentVarContext;
- }
-
- public void executePlan(ProcessorPlan command, String rsName)
- throws MetaMatrixComponentException, MetaMatrixProcessingException {
- boolean isExecSQLInstruction = rsName.equals(ExecSqlInstruction.RS_NAME);
- // Defect 14544: Close all non-final ExecSqlInstruction tuple sources before creating a new source.
- // This guarantees that the tuple source will be removed predictably from the buffer manager.
- if (isExecSQLInstruction) {
- removeResults(ExecSqlInstruction.RS_NAME);
- }
-
- TupleSourceID tsID = this.plan.registerRequest(command, this.currentVarContext);
- TupleSource source = this.plan.getResults(tsID);
- tupleSourceIDMap.put(rsName.toUpperCase(), tsID);
- tupleSourceMap.put(rsName.toUpperCase(), source);
- if(isExecSQLInstruction){
- //keep a reference to the tuple source
- //it may be the last one
- this.lastTupleSource = source;
- }
- }
-
- /**
- * @throws MetaMatrixComponentException
- * @see com.metamatrix.query.processor.program.ProgramEnvironment#pop()
- */
- public void pop() throws MetaMatrixComponentException {
- super.pop();
- if (this.currentVarContext.getParentContext() != null) {
- this.currentVarContext = this.currentVarContext.getParentContext();
- }
- Set current = getTempContext();
-
- Set tempTables = getLocalTempTables();
-
- tempTables.addAll(current);
-
- for (Iterator i = tempTables.iterator(); i.hasNext();) {
- removeResults((String)i.next());
- }
-
- this.tempContext.removeLast();
- }
-
- /**
- * @see com.metamatrix.query.processor.program.ProgramEnvironment#push(com.metamatrix.query.processor.program.Program)
- */
- public void push(Program program) {
- super.push(program);
- VariableContext context = new VariableContext(true);
- context.setParentContext(this.currentVarContext);
- this.currentVarContext = context;
-
- Set current = getTempContext();
-
- Set tempTables = getLocalTempTables();
-
- current.addAll(tempTables);
- this.tempContext.add(new HashSet());
- }
-
- /**
- * @see com.metamatrix.query.processor.program.ProgramEnvironment#incrementProgramCounter()
- */
- public void incrementProgramCounter() throws MetaMatrixComponentException {
- Program program = peek();
- ProgramInstruction instr = program.getCurrentInstruction();
- if (instr instanceof RepeatedInstruction) {
- RepeatedInstruction repeated = (RepeatedInstruction)instr;
- repeated.postInstruction(this);
- }
- super.incrementProgramCounter();
- }
-
- /**
- * @return
- */
- private Set getLocalTempTables() {
- Set tempTables = this.tempTableStore.getAllTempTables();
-
- //determine what was created in this scope
- for (int i = 0; i < tempContext.size() - 1; i++) {
- tempTables.removeAll((Set)tempContext.get(i));
- }
- return tempTables;
- }
-
- public Set getTempContext() {
- if (this.tempContext.isEmpty()) {
- tempContext.addLast(new HashSet());
- }
- return (Set)this.tempContext.getLast();
- }
-
- public List getCurrentRow(String rsName) {
- return (List) currentRowMap.get(rsName.toUpperCase());
- }
-
- public boolean iterateCursor(String rsName)
- throws MetaMatrixComponentException, MetaMatrixProcessingException {
-
- String rsKey = rsName.toUpperCase();
-
- TupleSource source = (TupleSource) tupleSourceMap.get(rsKey);
- if(source == null) {
- // TODO - throw exception?
- return false;
- }
-
- List row = source.nextTuple();
- currentRowMap.put(rsKey, row);
- return (row != null);
- }
-
- public void removeResults(String rsName) throws MetaMatrixComponentException {
- String rsKey = rsName.toUpperCase();
- TupleSource source = (TupleSource) tupleSourceMap.get(rsKey);
- if(source != null) {
- source.closeSource();
- TupleSourceID tsID = (TupleSourceID) tupleSourceIDMap.get(rsKey);
- this.plan.removeTupleSource(tsID);
- tupleSourceMap.remove(rsKey);
- tupleSourceIDMap.remove(rsKey);
- currentRowMap.remove(rsKey);
- this.tempTableStore.removeTempTableByName(rsKey);
- }
- }
-
-
- /**
- * Get the schema from the tuple source that
- * represents the columns in a result set
- * @param rsName the ResultSet name (not a temp group)
- * @return List of elements
- * @throws QueryProcessorException if the list of elements is null
- */
- public List getSchema(String rsName) throws MetaMatrixComponentException {
-
- // get the tuple source
- String rsKey = rsName.toUpperCase();
- TupleSource source = (TupleSource) tupleSourceMap.get(rsKey);
- if(source == null){
- throw new MetaMatrixComponentException(QueryExecPlugin.Util.getString(ErrorMessageKeys.PROCESSOR_0037, rsName));
- }
- // get the schema from the tuple source
- List schema = source.getSchema();
- if(schema == null){
- throw new MetaMatrixComponentException(QueryExecPlugin.Util.getString(ErrorMessageKeys.PROCESSOR_0038));
- }
-
- return schema;
- }
-
- public boolean resultSetExists(String rsName) {
- String rsKey = rsName.toUpperCase();
- boolean exists = this.tupleSourceMap.containsKey(rsKey);
- return exists;
- }
-
- public ProcessorDataManager getDataManager() {
- return this.plan.getDataManager();
- }
-
- public CommandContext getContext() {
- CommandContext context = this.plan.getContext();
- context.setVariableContext(currentVarContext);
- return context;
- }
-
- /**
- * @return
- */
- public boolean isUpdateProcedure() {
- return isUpdateProcedure;
- }
-
- /**
- * @param b
- */
- public void setUpdateProcedure(boolean b) {
- isUpdateProcedure = b;
- }
-
- /**
- * @return
- */
- public TupleSource getFinalTupleSource() {
- if(this.isUpdateProcedure){
- return this.getUpdateCountAsToupleSource();
- }
-
- if(lastTupleSource == null){
- return new NullTupleSource(null);
- }
- return lastTupleSource;
- }
-
- public List getOutputElements() {
- return outputElements;
- }
-
- public void setOutputElements(List outputElements) {
- this.outputElements = outputElements;
- }
-
- public void reset() {
- tupleSourceMap.clear();
- tupleSourceIDMap.clear();
- currentRowMap.clear();
- currentVarContext = new VariableContext();
- currentVarContext.setValue(ROWS_UPDATED, new Integer(NO_ROWS_UPDATED));
- lastTupleSource = null;
- }
-
-
- /**
- * @return Returns the tempTableStore.
- * @since 5.5
- */
- public TempTableStore getTempTableStore() {
- return this.tempTableStore;
- }
-
-
- /**
- * @param tempTableStore The tempTableStore to set.
- * @since 5.5
- */
- public void setTempTableStore(TempTableStore tempTableStore) {
- this.tempTableStore = tempTableStore;
- }
-
- boolean evaluateCriteria(Criteria condition) throws BlockedException, MetaMatrixProcessingException, MetaMatrixComponentException {
- return new Evaluator(Collections.emptyMap(), getDataManager(), getContext()).evaluate(condition, Collections.emptyList());
- }
-
- Object evaluateExpression(Expression expression) throws BlockedException, MetaMatrixProcessingException, MetaMatrixComponentException {
- return new Evaluator(Collections.emptyMap(), getDataManager(), getContext()).evaluate(expression, Collections.emptyList());
- }
-
-}
Modified: trunk/engine/src/main/java/com/metamatrix/query/processor/proc/ProcedurePlan.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/processor/proc/ProcedurePlan.java 2009-04-27 16:49:34 UTC (rev 845)
+++ trunk/engine/src/main/java/com/metamatrix/query/processor/proc/ProcedurePlan.java 2009-04-27 19:02:50 UTC (rev 846)
@@ -25,9 +25,14 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
import java.util.Iterator;
+import java.util.LinkedList;
import java.util.List;
import java.util.Map;
+import java.util.Set;
+import java.util.Stack;
import com.metamatrix.api.exception.MetaMatrixComponentException;
import com.metamatrix.api.exception.MetaMatrixProcessingException;
@@ -41,12 +46,12 @@
import com.metamatrix.common.log.LogManager;
import com.metamatrix.core.MetaMatrixCoreException;
import com.metamatrix.dqp.util.LogConstants;
-import com.metamatrix.query.eval.Evaluator;
import com.metamatrix.query.execution.QueryExecPlugin;
import com.metamatrix.query.metadata.QueryMetadataInterface;
import com.metamatrix.query.metadata.SupportConstants;
import com.metamatrix.query.processor.BaseProcessorPlan;
import com.metamatrix.query.processor.DescribableUtil;
+import com.metamatrix.query.processor.NullTupleSource;
import com.metamatrix.query.processor.ProcessorDataManager;
import com.metamatrix.query.processor.ProcessorPlan;
import com.metamatrix.query.processor.QueryProcessor;
@@ -54,6 +59,9 @@
import com.metamatrix.query.processor.program.Program;
import com.metamatrix.query.processor.program.ProgramInstruction;
import com.metamatrix.query.processor.program.ProgramUtil;
+import com.metamatrix.query.processor.relational.SubqueryAwareEvaluator;
+import com.metamatrix.query.sql.ProcedureReservedWords;
+import com.metamatrix.query.sql.lang.Criteria;
import com.metamatrix.query.sql.symbol.ElementSymbol;
import com.metamatrix.query.sql.symbol.Expression;
import com.metamatrix.query.sql.util.VariableContext;
@@ -65,9 +73,6 @@
*/
public class ProcedurePlan extends BaseProcessorPlan {
- // State passed during construction
- private ProcedureEnvironment env;
- //this reference should never be used for anything except toString method
private Program originalProgram;
// State initialized by processor
@@ -84,16 +89,41 @@
private int beginBatch = 1;
private List batchRows;
private boolean lastBatch = false;
- private Map params;
+ private Map<ElementSymbol, Expression> params;
private QueryMetadataInterface metadata;
+
+ private Map tupleSourceMap = new HashMap(); // rsName -> TupleSource
+ private Map tupleSourceIDMap = new HashMap(); // rsName -> TupleSourceID
+ private Map currentRowMap = new HashMap();
+ private static ElementSymbol ROWS_UPDATED =
+ new ElementSymbol(ProcedureReservedWords.VARIABLES+"."+ProcedureReservedWords.ROWS_UPDATED); //$NON-NLS-1$
+
+ private static int NO_ROWS_UPDATED = 0;
+ private VariableContext currentVarContext;
+ private boolean isUpdateProcedure = true;
+
+ private TupleSource lastTupleSource;
+
+ private List outputElements;
+
+ private TempTableStore tempTableStore;
+
+ private LinkedList tempContext = new LinkedList();
+ private SubqueryAwareEvaluator evaluator;
+
+ // Stack of programs, with current program on top
+ private Stack<Program> programs = new Stack<Program>();
+
+ private boolean evaluatedParams;
+
/**
* Constructor for ProcedurePlan.
*/
- public ProcedurePlan(ProcedureEnvironment env) {
- this.env = env;
- this.env.initialize(this);
- this.originalProgram = (Program)this.env.getProgramStack().peek();
+ public ProcedurePlan(Program originalProgram) {
+ this.originalProgram = originalProgram;
+ this.programs.add(originalProgram);
+ createVariableContext();
}
/**
@@ -102,15 +132,26 @@
public void initialize(CommandContext context, ProcessorDataManager dataMgr, BufferManager bufferMgr) {
this.bufferMgr = bufferMgr;
this.batchSize = bufferMgr.getProcessorBatchSize();
- TempTableStoreImpl tempTableStore = new TempTableStoreImpl(bufferMgr, context.getConnectionID(), (TempTableStore)context.getTempTableStore());
+ tempTableStore = new TempTableStoreImpl(bufferMgr, context.getConnectionID(), (TempTableStore)context.getTempTableStore());
this.dataMgr = new TempTableDataManager(dataMgr, tempTableStore);
- env.setTempTableStore(tempTableStore);
setContext(context);
+ if (evaluator == null) {
+ this.evaluator = new SubqueryAwareEvaluator(Collections.emptyMap(), getDataManager(), getContext(), this.bufferMgr);
+ }
}
public void reset() {
super.reset();
-
+ if (evaluator != null) {
+ evaluator.reset();
+ }
+ evaluatedParams = false;
+ tupleSourceMap.clear();
+ tupleSourceIDMap.clear();
+ currentRowMap.clear();
+ createVariableContext();
+ lastTupleSource = null;
+
done = false;
internalProcessor = null;
internalResultID = null;
@@ -122,10 +163,8 @@
//reset program stack
originalProgram.resetProgramCounter();
- if(env.getProgramStack().empty()){
- env.getProgramStack().push(originalProgram);
- }
- env.reset();
+ programs.clear();
+ programs.push(originalProgram);
LogManager.logTrace(LogConstants.CTX_DQP, "ProcedurePlan reset"); //$NON-NLS-1$
}
@@ -151,42 +190,29 @@
// Run query processor on command
CommandContext subContext = (CommandContext) getContext().clone();
subContext.setVariableContext(currentVariableContext);
- subContext.setTempTableStore(env.getTempTableStore());
+ subContext.setTempTableStore(getTempTableStore());
internalProcessor = new QueryProcessor(subPlan, subContext, this.bufferMgr, this.dataMgr);
this.internalResultID = this.internalProcessor.getResultsID();
return this.internalResultID;
}
- /**
- * Method for ProcessorEnvironment to remove a tuple source when it is done with it.
- */
- void removeTupleSource(TupleSourceID tupleSourceID)
- throws MetaMatrixComponentException {
- try {
- this.bufferMgr.removeTupleSource(tupleSourceID);
- } catch (TupleSourceNotFoundException e) {
- throw new MetaMatrixComponentException(e, ErrorMessageKeys.PROCESSOR_0021, QueryExecPlugin.Util.getString(ErrorMessageKeys.PROCESSOR_0021, (String)null));
- } catch (MetaMatrixComponentException e) {
- throw new MetaMatrixComponentException(e, ErrorMessageKeys.PROCESSOR_0022, QueryExecPlugin.Util.getString(ErrorMessageKeys.PROCESSOR_0022, (String) null));
- }
- LogManager.logTrace(LogConstants.CTX_DQP, new Object[]{"removed tuple source", tupleSourceID, "for result set"}); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- /**
- * Get list of resolved elements describing output columns for this plan.
- * @return List of SingleElementSymbol
- */
- public List getOutputElements() {
-// ArrayList output = new ArrayList(1);
-// ElementSymbol count = new ElementSymbol("Count"); //$NON-NLS-1$
-// count.setType(DataTypeManager.DefaultDataClasses.INTEGER);
-// output.add(count);
-// return output;
- return env.getOutputElements();
- }
-
public void open() throws MetaMatrixProcessingException, MetaMatrixComponentException {
- evaluateParams();
+ if (this.params != null && !this.evaluatedParams) {
+ for (Map.Entry<ElementSymbol, Expression> entry : this.params.entrySet()) {
+ ElementSymbol param = entry.getKey();
+ Expression expr = entry.getValue();
+
+ VariableContext context = getCurrentVariableContext();
+ Object value = this.evaluateExpression(expr);
+
+ //check constraint
+ if (value == null && !metadata.elementSupports(param.getMetadataID(), SupportConstants.Element.NULL)) {
+ throw new QueryValidatorException(QueryExecPlugin.Util.getString("ProcedurePlan.nonNullableParam", expr)); //$NON-NLS-1$
+ }
+ context.setValue(param, value);
+ }
+ }
+ this.evaluatedParams = true;
}
/**
@@ -247,37 +273,43 @@
// execute plan
ProgramInstruction inst = null;
- while (!this.env.getProgramStack().empty()){
- Program program = env.peek();
+ while (!this.programs.empty()){
+ Program program = peek();
inst = program.getCurrentInstruction();
if (inst == null){
LogManager.logTrace(LogConstants.CTX_DQP, "Finished program", program); //$NON-NLS-1$
- this.env.pop();
+ this.pop();
continue;
}
if (inst instanceof RepeatedInstruction) {
LogManager.logTrace(LogConstants.CTX_DQP, "Executing repeated instruction", inst); //$NON-NLS-1$
RepeatedInstruction loop = (RepeatedInstruction)inst;
- if (loop.testCondition(env)) {
+ if (loop.testCondition(this)) {
LogManager.logTrace(LogConstants.CTX_DQP, "Passed condition, executing program " + loop.getNestedProgram()); //$NON-NLS-1$
- inst.process(env);
- env.push(loop.getNestedProgram());
+ inst.process(this);
+ this.push(loop.getNestedProgram());
continue;
}
LogManager.logTrace(LogConstants.CTX_DQP, "Exiting repeated instruction", inst); //$NON-NLS-1$
- loop.postInstruction(env);
+ loop.postInstruction(this);
} else {
LogManager.logTrace(LogConstants.CTX_DQP, "Executing instruction", inst); //$NON-NLS-1$
- inst.process(this.env);
+ inst.process(this);
}
program.incrementProgramCounter();
}
- return this.env.getFinalTupleSource();
+ if(this.isUpdateProcedure){
+ return this.getUpdateCountAsToupleSource();
+ }
+
+ if(lastTupleSource == null){
+ return new NullTupleSource(null);
+ }
+ return lastTupleSource;
}
-
- public TupleSource getResults(TupleSourceID tupleID)
+ private TupleSource getResults()
throws MetaMatrixComponentException, BlockedException, MetaMatrixProcessingException {
TupleSource results;
@@ -313,35 +345,28 @@
// Ignore
}
}
- if(env.getTempTableStore()!=null) {
- env.getTempTableStore().removeTempTables();
+ if(getTempTableStore()!=null) {
+ getTempTableStore().removeTempTables();
}
+ if (this.evaluator != null) {
+ this.evaluator.close();
+ }
}
public String toString() {
return "ProcedurePlan:\n" + ProgramUtil.programToString(this.originalProgram); //$NON-NLS-1$
}
- /**
- * The plan is only clonable in the pre-execution stage, not the execution state
- * (things like program state, result sets, etc). It's only safe to call that
- * method in between query processings, inother words, it's only safe to call
- * clone() on a plan after nextTuple() returns null, meaning the plan has
- * finished processing.
- */
public Object clone(){
- ProcedureEnvironment clonedEnv = new ProcedureEnvironment();
- clonedEnv.getProgramStack().push(originalProgram.clone());
- clonedEnv.setUpdateProcedure(this.env.isUpdateProcedure());
- clonedEnv.setOutputElements(this.env.getOutputElements());
- ProcedurePlan plan = new ProcedurePlan(clonedEnv);
+ ProcedurePlan plan = new ProcedurePlan((Program)originalProgram.clone());
+ plan.setUpdateProcedure(this.isUpdateProcedure());
+ plan.setOutputElements(this.getOutputElements());
plan.setParams(params);
plan.setMetadata(metadata);
-
return plan;
}
- protected void addBatchRow(List row) {
+ private void addBatchRow(List row) {
if(this.batchRows == null) {
this.batchRows = new ArrayList(this.batchSize);
}
@@ -395,30 +420,257 @@
this.metadata = metadata;
}
- public void setParams( Map params ) {
+ public void setParams( Map<ElementSymbol, Expression> params ) {
this.params = params;
}
- public void evaluateParams() throws BlockedException, MetaMatrixComponentException, MetaMatrixProcessingException {
+ private void createVariableContext() {
+ this.currentVarContext = new VariableContext(true);
+ this.currentVarContext.setValue(ROWS_UPDATED, new Integer(NO_ROWS_UPDATED));
+ }
+
+ private TupleSource getUpdateCountAsToupleSource() {
+ Object rowCount = currentVarContext.getValue(ROWS_UPDATED);
+ if(rowCount == null) {
+ rowCount = new Integer(NO_ROWS_UPDATED);
+ }
+
+ final List updateResult = new ArrayList(1);
+ updateResult.add(rowCount);
+
+ return new UpdateCountTupleSource(updateResult);
+ }
+
+ /**
+ * <p> Get the current <code>VariavleContext</code> on this environment.
+ * The VariableContext is updated with variables and their values by
+ * {@link ProgramInstruction}s that are part of the ProcedurePlan that use
+ * this environment.</p>
+ * @return The current <code>VariariableContext</code>.
+ */
+ public VariableContext getCurrentVariableContext() {
+ return this.currentVarContext;
+ }
+
+ public void executePlan(ProcessorPlan command, String rsName)
+ throws MetaMatrixComponentException, MetaMatrixProcessingException {
+ boolean isExecSQLInstruction = rsName.equals(ExecSqlInstruction.RS_NAME);
+ // Defect 14544: Close all non-final ExecSqlInstruction tuple sources before creating a new source.
+ // This guarantees that the tuple source will be removed predictably from the buffer manager.
+ if (isExecSQLInstruction) {
+ removeResults(ExecSqlInstruction.RS_NAME);
+ }
- if ( params == null ) {
- return;
+ TupleSourceID tsID = registerRequest(command, this.currentVarContext);
+ TupleSource source = getResults();
+ tupleSourceIDMap.put(rsName.toUpperCase(), tsID);
+ tupleSourceMap.put(rsName.toUpperCase(), source);
+ if(isExecSQLInstruction){
+ //keep a reference to the tuple source
+ //it may be the last one
+ this.lastTupleSource = source;
}
+ }
+
+ /**
+ * @throws MetaMatrixComponentException
+ * @see com.metamatrix.query.processor.program.ProgramEnvironment#pop()
+ */
+ public void pop() throws MetaMatrixComponentException {
+ this.programs.pop();
+ if (this.currentVarContext.getParentContext() != null) {
+ this.currentVarContext = this.currentVarContext.getParentContext();
+ }
+ Set current = getTempContext();
+
+ Set tempTables = getLocalTempTables();
+
+ tempTables.addAll(current);
- for (Iterator iter = params.entrySet().iterator(); iter.hasNext();) {
- Map.Entry entry = (Map.Entry)iter.next();
- ElementSymbol param = (ElementSymbol)entry.getKey();
- Expression expr = (Expression)entry.getValue();
-
- VariableContext context = env.getCurrentVariableContext();
- Object value = new Evaluator(null, null, getContext()).evaluate(expr, null);
+ for (Iterator i = tempTables.iterator(); i.hasNext();) {
+ removeResults((String)i.next());
+ }
+
+ this.tempContext.removeLast();
+ }
+
+ /**
+ * @see com.metamatrix.query.processor.program.ProgramEnvironment#push(com.metamatrix.query.processor.program.Program)
+ */
+ public void push(Program program) {
+ program.resetProgramCounter();
+ this.programs.push(program);
+ VariableContext context = new VariableContext(true);
+ context.setParentContext(this.currentVarContext);
+ this.currentVarContext = context;
+
+ Set current = getTempContext();
+
+ Set tempTables = getLocalTempTables();
+
+ current.addAll(tempTables);
+ this.tempContext.add(new HashSet());
+ }
+
+ /**
+ * @see com.metamatrix.query.processor.program.ProgramEnvironment#incrementProgramCounter()
+ */
+ public void incrementProgramCounter() throws MetaMatrixComponentException {
+ Program program = peek();
+ ProgramInstruction instr = program.getCurrentInstruction();
+ if (instr instanceof RepeatedInstruction) {
+ RepeatedInstruction repeated = (RepeatedInstruction)instr;
+ repeated.postInstruction(this);
+ }
+ peek().incrementProgramCounter();
+ }
- //check constraint
- if (value == null && !metadata.elementSupports(param.getMetadataID(), SupportConstants.Element.NULL)) {
- throw new QueryValidatorException(QueryExecPlugin.Util.getString("ProcedurePlan.nonNullableParam", expr)); //$NON-NLS-1$
- }
- context.setValue(param, value);
- }
+ /**
+ * @return
+ */
+ private Set getLocalTempTables() {
+ Set tempTables = this.tempTableStore.getAllTempTables();
+
+ //determine what was created in this scope
+ for (int i = 0; i < tempContext.size() - 1; i++) {
+ tempTables.removeAll((Set)tempContext.get(i));
+ }
+ return tempTables;
+ }
+ public Set getTempContext() {
+ if (this.tempContext.isEmpty()) {
+ tempContext.addLast(new HashSet());
+ }
+ return (Set)this.tempContext.getLast();
}
+
+ public List getCurrentRow(String rsName) {
+ return (List) currentRowMap.get(rsName.toUpperCase());
+ }
+
+ public boolean iterateCursor(String rsName)
+ throws MetaMatrixComponentException, MetaMatrixProcessingException {
+
+ String rsKey = rsName.toUpperCase();
+
+ TupleSource source = (TupleSource) tupleSourceMap.get(rsKey);
+ if(source == null) {
+ // TODO - throw exception?
+ return false;
+ }
+
+ List row = source.nextTuple();
+ currentRowMap.put(rsKey, row);
+ return (row != null);
+ }
+
+ public void removeResults(String rsName) throws MetaMatrixComponentException {
+ String rsKey = rsName.toUpperCase();
+ TupleSource source = (TupleSource) tupleSourceMap.get(rsKey);
+ if(source != null) {
+ source.closeSource();
+ TupleSourceID tsID = (TupleSourceID) tupleSourceIDMap.get(rsKey);
+ try {
+ this.bufferMgr.removeTupleSource(tsID);
+ } catch (TupleSourceNotFoundException e) {
+ throw new MetaMatrixComponentException(e, ErrorMessageKeys.PROCESSOR_0021, QueryExecPlugin.Util.getString(ErrorMessageKeys.PROCESSOR_0021, (String)null));
+ } catch (MetaMatrixComponentException e) {
+ throw new MetaMatrixComponentException(e, ErrorMessageKeys.PROCESSOR_0022, QueryExecPlugin.Util.getString(ErrorMessageKeys.PROCESSOR_0022, (String) null));
+ }
+ LogManager.logTrace(LogConstants.CTX_DQP, new Object[]{"removed tuple source", tsID, "for result set"}); //$NON-NLS-1$ //$NON-NLS-2$
+ tupleSourceMap.remove(rsKey);
+ tupleSourceIDMap.remove(rsKey);
+ currentRowMap.remove(rsKey);
+ this.tempTableStore.removeTempTableByName(rsKey);
+ }
+ }
+
+
+ /**
+ * Get the schema from the tuple source that
+ * represents the columns in a result set
+ * @param rsName the ResultSet name (not a temp group)
+ * @return List of elements
+ * @throws QueryProcessorException if the list of elements is null
+ */
+ public List getSchema(String rsName) throws MetaMatrixComponentException {
+
+ // get the tuple source
+ String rsKey = rsName.toUpperCase();
+ TupleSource source = (TupleSource) tupleSourceMap.get(rsKey);
+ if(source == null){
+ throw new MetaMatrixComponentException(QueryExecPlugin.Util.getString(ErrorMessageKeys.PROCESSOR_0037, rsName));
+ }
+ // get the schema from the tuple source
+ List schema = source.getSchema();
+ if(schema == null){
+ throw new MetaMatrixComponentException(QueryExecPlugin.Util.getString(ErrorMessageKeys.PROCESSOR_0038));
+ }
+
+ return schema;
+ }
+
+ public boolean resultSetExists(String rsName) {
+ String rsKey = rsName.toUpperCase();
+ boolean exists = this.tupleSourceMap.containsKey(rsKey);
+ return exists;
+ }
+
+ public CommandContext getContext() {
+ CommandContext context = super.getContext();
+ if (evaluatedParams) {
+ context.setVariableContext(currentVarContext);
+ }
+ return context;
+ }
+
+ /**
+ * @return
+ */
+ public boolean isUpdateProcedure() {
+ return isUpdateProcedure;
+ }
+
+ /**
+ * @param b
+ */
+ public void setUpdateProcedure(boolean b) {
+ isUpdateProcedure = b;
+ }
+
+ public List getOutputElements() {
+ return outputElements;
+ }
+
+ public void setOutputElements(List outputElements) {
+ this.outputElements = outputElements;
+ }
+
+ /**
+ * @return Returns the tempTableStore.
+ * @since 5.5
+ */
+ public TempTableStore getTempTableStore() {
+ return this.tempTableStore;
+ }
+
+ boolean evaluateCriteria(Criteria condition) throws BlockedException, MetaMatrixProcessingException, MetaMatrixComponentException {
+ evaluator.setContext(getContext());
+ boolean result = evaluator.evaluate(condition, Collections.emptyList());
+ this.evaluator.close();
+ return result;
+ }
+
+ Object evaluateExpression(Expression expression) throws BlockedException, MetaMatrixProcessingException, MetaMatrixComponentException {
+ evaluator.setContext(getContext());
+ Object result = evaluator.evaluate(expression, Collections.emptyList());
+ this.evaluator.close();
+ return result;
+ }
+
+ public Program peek() {
+ return programs.peek();
+ }
+
}
Modified: trunk/engine/src/main/java/com/metamatrix/query/processor/proc/RepeatedInstruction.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/processor/proc/RepeatedInstruction.java 2009-04-27 16:49:34 UTC (rev 845)
+++ trunk/engine/src/main/java/com/metamatrix/query/processor/proc/RepeatedInstruction.java 2009-04-27 19:02:50 UTC (rev 846)
@@ -28,10 +28,10 @@
public interface RepeatedInstruction {
- public boolean testCondition(ProcedureEnvironment procEnv) throws MetaMatrixComponentException, MetaMatrixProcessingException;
+ public boolean testCondition(ProcedurePlan procEnv) throws MetaMatrixComponentException, MetaMatrixProcessingException;
public Program getNestedProgram();
- public void postInstruction(ProcedureEnvironment procEnv) throws MetaMatrixComponentException;
+ public void postInstruction(ProcedurePlan procEnv) throws MetaMatrixComponentException;
}
Modified: trunk/engine/src/main/java/com/metamatrix/query/processor/proc/WhileInstruction.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/processor/proc/WhileInstruction.java 2009-04-27 16:49:34 UTC (rev 845)
+++ trunk/engine/src/main/java/com/metamatrix/query/processor/proc/WhileInstruction.java 2009-04-27 19:02:50 UTC (rev 846)
@@ -31,7 +31,6 @@
import com.metamatrix.api.exception.MetaMatrixComponentException;
import com.metamatrix.api.exception.MetaMatrixProcessingException;
import com.metamatrix.query.processor.program.Program;
-import com.metamatrix.query.processor.program.ProgramEnvironment;
import com.metamatrix.query.processor.program.ProgramInstruction;
import com.metamatrix.query.sql.lang.Criteria;
@@ -49,7 +48,7 @@
this.condition = condition;
}
- public void process(ProgramEnvironment env) throws MetaMatrixComponentException {
+ public void process(ProcedurePlan env) throws MetaMatrixComponentException {
//do nothing
}
@@ -88,7 +87,7 @@
* @throws MetaMatrixProcessingException
* @see com.metamatrix.query.processor.proc.RepeatedInstruction#testCondition(com.metamatrix.query.processor.proc.ProcedureEnvironment)
*/
- public boolean testCondition(ProcedureEnvironment procEnv) throws MetaMatrixComponentException, MetaMatrixProcessingException {
+ public boolean testCondition(ProcedurePlan procEnv) throws MetaMatrixComponentException, MetaMatrixProcessingException {
return procEnv.evaluateCriteria(condition);
}
@@ -102,7 +101,7 @@
/**
* @see com.metamatrix.query.processor.proc.RepeatedInstruction#postInstruction(com.metamatrix.query.processor.proc.ProcedureEnvironment)
*/
- public void postInstruction(ProcedureEnvironment procEnv) throws MetaMatrixComponentException {
+ public void postInstruction(ProcedurePlan procEnv) throws MetaMatrixComponentException {
}
}
Deleted: trunk/engine/src/main/java/com/metamatrix/query/processor/program/ProgramEnvironment.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/processor/program/ProgramEnvironment.java 2009-04-27 16:49:34 UTC (rev 845)
+++ trunk/engine/src/main/java/com/metamatrix/query/processor/program/ProgramEnvironment.java 2009-04-27 19:02:50 UTC (rev 846)
@@ -1,86 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package com.metamatrix.query.processor.program;
-
-import java.util.Stack;
-
-import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.query.processor.ProcessorPlan;
-
-/**
- * This interface defines the environment that programs run in and what
- * {@link ProgramInstruction}s can access during execution.
- */
-public abstract class ProgramEnvironment {
-
- // Stack of programs, with current program on top
- private Stack programs = new Stack();
-
-
- /**
- * Default constructor
- */
- public ProgramEnvironment() {
- }
-
- /**
- * Connect an XMLPlan to the environment
- * @param plan XMLPlan
- */
- public abstract void initialize(ProcessorPlan plan);
-
- /**
- * Get the Stack of Program objects, with the currently running
- * Program on top.
- * @return Stack of currently running {@link Program Programs},
- * with the current Program on top.
- */
- public Stack getProgramStack() {
- return programs;
- }
-
- public Program peek() {
- return (Program)programs.peek();
- }
-
- public void pop() throws MetaMatrixComponentException {
- this.programs.pop();
- }
-
- public void push(Program program) {
- program.resetProgramCounter();
- this.programs.push(program);
- }
-
- public void incrementProgramCounter() throws MetaMatrixComponentException {
- peek().incrementProgramCounter();
- }
-
- /**
- * Remove the a data source from the environment.
- * @param rsName The name of the result set.
- * @throws MetaMatrixComponentException
- */
- public abstract void removeResults(String rsName)
- throws MetaMatrixComponentException;
-}
Modified: trunk/engine/src/main/java/com/metamatrix/query/processor/program/ProgramInstruction.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/processor/program/ProgramInstruction.java 2009-04-27 16:49:34 UTC (rev 845)
+++ trunk/engine/src/main/java/com/metamatrix/query/processor/program/ProgramInstruction.java 2009-04-27 19:02:50 UTC (rev 846)
@@ -29,6 +29,7 @@
import com.metamatrix.api.exception.MetaMatrixComponentException;
import com.metamatrix.api.exception.MetaMatrixProcessingException;
import com.metamatrix.query.processor.Describable;
+import com.metamatrix.query.processor.proc.ProcedurePlan;
/**
* <p>Abstract superclass of all program instructions.</p>
@@ -52,7 +53,7 @@
* Program#incrementProgramCounter increment} the program counter of the current program, but specialized
* instructions may add sub programs to the stack or not increment the counter (so that they are executed again.)
*/
- public abstract void process(ProgramEnvironment env)
+ public abstract void process(ProcedurePlan env)
throws MetaMatrixComponentException, MetaMatrixProcessingException;
/**
Modified: trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DependentCriteriaProcessor.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DependentCriteriaProcessor.java 2009-04-27 16:49:34 UTC (rev 845)
+++ trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DependentCriteriaProcessor.java 2009-04-27 19:02:50 UTC (rev 846)
@@ -38,7 +38,6 @@
import com.metamatrix.common.buffer.BlockedException;
import com.metamatrix.common.buffer.TupleSource;
import com.metamatrix.common.buffer.TupleSourceNotFoundException;
-import com.metamatrix.query.eval.Evaluator;
import com.metamatrix.query.rewriter.QueryRewriter;
import com.metamatrix.query.sql.lang.AbstractSetCriteria;
import com.metamatrix.query.sql.lang.CollectionValueIterator;
@@ -141,12 +140,13 @@
private LinkedList<Integer> restartIndexes = new LinkedList<Integer>();
private int currentIndex;
private boolean hasNextCommand;
-
+ protected SubqueryAwareEvaluator eval;
public DependentCriteriaProcessor(int maxSetSize, RelationalNode dependentNode, Criteria dependentCriteria) throws ExpressionEvaluationException, MetaMatrixComponentException {
this.maxSetSize = maxSetSize;
this.dependentNode = dependentNode;
this.dependentCrit = dependentCriteria;
+ this.eval = new SubqueryAwareEvaluator(Collections.emptyMap(), dependentNode.getDataManager(), dependentNode.getContext(), dependentNode.getBufferManager());
queryCriteria = Criteria.separateCriteriaByAnd(dependentCrit);
for (int i = 0; i < queryCriteria.size(); i++) {
@@ -162,10 +162,9 @@
}
SetState state = new SetState();
setStates.put(i, state);
- Evaluator evaluator = new Evaluator(Collections.emptyMap(), dependentNode.getDataManager(), dependentNode.getContext());
LinkedHashSet<Object> values = new LinkedHashSet<Object>();
for (Expression expr : (Collection<Expression>)setCriteria.getValues()) {
- values.add(evaluator.evaluate(expr, null));
+ values.add(eval.evaluate(expr, null));
}
state.valueIterator = new CollectionValueIterator(values);
sources.add(Arrays.asList(state));
@@ -193,6 +192,9 @@
state.close();
}
}
+ if (this.eval != null) {
+ this.eval.close();
+ }
}
public Criteria prepareCriteria() throws MetaMatrixComponentException {
Modified: trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DependentProcedureAccessNode.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DependentProcedureAccessNode.java 2009-04-27 16:49:34 UTC (rev 845)
+++ trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DependentProcedureAccessNode.java 2009-04-27 19:02:50 UTC (rev 846)
@@ -27,7 +27,6 @@
import com.metamatrix.api.exception.MetaMatrixComponentException;
import com.metamatrix.api.exception.MetaMatrixProcessingException;
-import com.metamatrix.query.eval.Evaluator;
import com.metamatrix.query.sql.lang.Command;
import com.metamatrix.query.sql.lang.Criteria;
import com.metamatrix.query.sql.util.VariableContext;
@@ -105,7 +104,7 @@
protected boolean prepareNextCommand(Command atomicCommand) throws MetaMatrixComponentException, MetaMatrixProcessingException {
if (this.criteriaProcessor == null) {
- this.criteriaProcessor = new DependentProcedureCriteriaProcessor(this, (Criteria)inputCriteria.clone(), inputReferences, inputDefaults, new Evaluator(null, null, getContext()));
+ this.criteriaProcessor = new DependentProcedureCriteriaProcessor(this, (Criteria)inputCriteria.clone(), inputReferences, inputDefaults);
}
if (criteriaProcessor.prepareNextCommand(this.getContext().getVariableContext())) {
Modified: trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DependentProcedureCriteriaProcessor.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DependentProcedureCriteriaProcessor.java 2009-04-27 16:49:34 UTC (rev 845)
+++ trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DependentProcedureCriteriaProcessor.java 2009-04-27 19:02:50 UTC (rev 846)
@@ -31,7 +31,6 @@
import com.metamatrix.common.buffer.BlockedException;
import com.metamatrix.common.buffer.TupleSourceNotFoundException;
import com.metamatrix.core.util.Assertion;
-import com.metamatrix.query.eval.Evaluator;
import com.metamatrix.query.rewriter.QueryRewriter;
import com.metamatrix.query.sql.lang.CompareCriteria;
import com.metamatrix.query.sql.lang.Criteria;
@@ -46,15 +45,12 @@
private List inputReferences;
private List inputDefaults;
private Criteria critInProgress;
- private Evaluator eval;
public DependentProcedureCriteriaProcessor(RelationalNode dependentNode,
Criteria dependentCriteria,
List references,
- List defaults,
- Evaluator eval) throws ExpressionEvaluationException, MetaMatrixComponentException {
+ List defaults) throws ExpressionEvaluationException, MetaMatrixComponentException {
super(1, dependentNode, dependentCriteria);
- this.eval = eval;
this.inputDefaults = defaults;
this.inputReferences = references;
}
Modified: trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DependentProcedureExecutionNode.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DependentProcedureExecutionNode.java 2009-04-27 16:49:34 UTC (rev 845)
+++ trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DependentProcedureExecutionNode.java 2009-04-27 19:02:50 UTC (rev 846)
@@ -29,7 +29,6 @@
import com.metamatrix.api.exception.MetaMatrixProcessingException;
import com.metamatrix.common.buffer.BlockedException;
import com.metamatrix.common.buffer.TupleSourceNotFoundException;
-import com.metamatrix.query.eval.Evaluator;
import com.metamatrix.query.sql.lang.Criteria;
import com.metamatrix.query.util.CommandContext;
@@ -97,7 +96,7 @@
MetaMatrixComponentException, MetaMatrixProcessingException {
if (this.criteriaProcessor == null) {
- this.criteriaProcessor = new DependentProcedureCriteriaProcessor(this, (Criteria)inputCriteria.clone(), inputReferences, inputDefaults, new Evaluator(null, null, getContext()));
+ this.criteriaProcessor = new DependentProcedureCriteriaProcessor(this, (Criteria)inputCriteria.clone(), inputReferences, inputDefaults);
}
return criteriaProcessor.prepareNextCommand(this.getProcessorPlan().getContext().getVariableContext());
Deleted: trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DependentProjectNode.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DependentProjectNode.java 2009-04-27 16:49:34 UTC (rev 845)
+++ trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DependentProjectNode.java 2009-04-27 19:02:50 UTC (rev 846)
@@ -1,120 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package com.metamatrix.query.processor.relational;
-
-import java.util.List;
-import java.util.Map;
-
-import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.api.exception.MetaMatrixProcessingException;
-import com.metamatrix.common.buffer.BlockedException;
-
-/**
- * A project node containing one or more scalar subqueries.
- * These subqueries must be processed first before the
- * ScalarSubquery expression can be evaluated and the
- * project can proceed.
- */
-public class DependentProjectNode extends ProjectNode {
-
- private SubqueryProcessorUtility subqueryProcessor;
-
- /**
- * @param nodeID
- */
- public DependentProjectNode(int nodeID, SubqueryProcessorUtility spu) {
- super(nodeID);
- this.subqueryProcessor = spu;
- }
-
- public void reset() {
- super.reset();
- this.subqueryProcessor.reset();
- }
-
- /**
- * Calls super.open(), then initializes subquery processor
- */
- public void open()
- throws MetaMatrixComponentException, MetaMatrixProcessingException {
-
- super.open();
- this.subqueryProcessor.open(this);
- }
-
- /**
- * Closes the subquery processor (which removes the temporary tuple
- * sources of the subquery results)
- * @see com.metamatrix.query.processor.relational.RelationalNode#close()
- */
- public void close()
- throws MetaMatrixComponentException {
- if (!isClosed()) {
- super.close();
- this.subqueryProcessor.close(this.getBufferManager());
- }
- }
-
- /**
- * This subclass will execute any subqueries which the projection is
- * dependent on; if any subqueries are correlated, this class will
- * use the current tuple to execute correlated subqueries
- * @param elementMap Map of ElementSymbol elements to Integer indices into
- * the currentTuple parameter
- * @param currentTuple the current tuple about to be processed by
- * this node
- * @see com.metamatrix.query.processor.relational.ProjectNode#prepareToProcessTuple
- */
- protected void prepareToProcessTuple(Map elementMap, List currentTuple)
- throws BlockedException, MetaMatrixComponentException, MetaMatrixProcessingException {
-
- this.subqueryProcessor.process(this, elementMap, currentTuple);
- }
-
- /**
- * Returns a deep clone
- * @return deep clone of this object
- * @see java.lang.Object#clone()
- */
- public Object clone(){
- DependentProjectNode clonedNode = new DependentProjectNode(super.getID(), this.subqueryProcessor.clone());
- super.copy(this, clonedNode);
- return clonedNode;
- }
-
- public Map getDescriptionProperties() {
- // Default implementation - should be overridden
- Map props = super.getDescriptionProperties();
- props.put(PROP_TYPE, "Dependent Project"); //$NON-NLS-1$
- return props;
- }
-
- /**
- * @see com.metamatrix.query.processor.relational.RelationalNode#getSubPlans()
- * @since 4.2
- */
- public List getChildPlans() {
- return this.subqueryProcessor.getSubqueryPlans();
- }
-
-}
Deleted: trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DependentSelectNode.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DependentSelectNode.java 2009-04-27 16:49:34 UTC (rev 845)
+++ trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DependentSelectNode.java 2009-04-27 19:02:50 UTC (rev 846)
@@ -1,132 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package com.metamatrix.query.processor.relational;
-
-import java.util.List;
-import java.util.Map;
-
-import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.api.exception.MetaMatrixProcessingException;
-import com.metamatrix.common.buffer.BlockedException;
-
-/**
- * This node represents a Select node for the case where the criteria
- * is or is composed of one or more SubqueryContainer criteria objects (for
- * subqueries in the criteria). In
- * that case, all the corresponding "child" or "sub" ProcessorPlans
- * (one for each SubqueryContainer criteria) must be processed before the
- * entire criteria can be evaluated.
- */
-public class DependentSelectNode extends SelectNode {
-
- private SubqueryProcessorUtility subqueryProcessor;
-
- /**
- * Constructor for DependentSelectNode.
- * @param nodeID
- */
- public DependentSelectNode(int nodeID, SubqueryProcessorUtility subqueryProcessorUtility) {
- super(nodeID);
- this.subqueryProcessor = subqueryProcessorUtility;
- }
-
- /** for unit testing */
- SubqueryProcessorUtility getSubqueryProcessorUtility(){
- return this.subqueryProcessor;
- }
-
- public void reset() {
- super.reset();
- this.subqueryProcessor.reset();
- }
-
- /**
- * Calls super.open(), then initializes subquery processor
- */
- public void open()
- throws MetaMatrixComponentException, MetaMatrixProcessingException {
-
- super.open();
- this.subqueryProcessor.open(this);
- }
-
- /**
- * Closes the subquery processor (which removes the temporary tuple
- * sources of the subquery results)
- * @see com.metamatrix.query.processor.relational.RelationalNode#close()
- */
- public void close()
- throws MetaMatrixComponentException {
- if (!isClosed()) {
- super.close();
- this.subqueryProcessor.close(this.getBufferManager());
- }
- }
-
- /**
- * This subclass will execute any subqueries which the criteria is
- * dependent on; if any subqueries are correlated, this class will
- * use the current tuple to execute correlated subqueries
- * @param elementMap Map of ElementSymbol elements to Integer indices into
- * the currentTuple parameter
- * @param currentTuple the current tuple about to be processed by
- * this node
- * @see com.metamatrix.query.processor.relational.SelectNode#prepareToProcessTuple
- */
- protected void prepareToProcessTuple(Map elementMap, List currentTuple)
- throws BlockedException, MetaMatrixComponentException, MetaMatrixProcessingException {
-
- this.subqueryProcessor.process(this, elementMap, currentTuple);
- }
-
- /**
- * Returns a deep clone
- * @return deep clone of this object
- * @see java.lang.Object#clone()
- */
- public Object clone(){
- DependentSelectNode clonedNode = new DependentSelectNode(super.getID(), subqueryProcessor.clone());
- super.copy(this, clonedNode);
- return clonedNode;
- }
-
- /*
- * @see com.metamatrix.query.processor.Describable#getDescriptionProperties()
- */
- public Map getDescriptionProperties() {
- // Default implementation - should be overridden
- Map props = super.getDescriptionProperties();
- props.put(PROP_TYPE, "Dependent Select"); //$NON-NLS-1$
- props.put(PROP_CRITERIA, getCriteria().toString());
- return props;
- }
-
- /**
- * @see com.metamatrix.query.processor.relational.RelationalNode#getSubPlans()
- * @since 4.2
- */
- public List getChildPlans() {
- return this.subqueryProcessor.getSubqueryPlans();
- }
-
-}
Modified: trunk/engine/src/main/java/com/metamatrix/query/processor/relational/JoinNode.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/processor/relational/JoinNode.java 2009-04-27 16:49:34 UTC (rev 845)
+++ trunk/engine/src/main/java/com/metamatrix/query/processor/relational/JoinNode.java 2009-04-27 19:02:50 UTC (rev 846)
@@ -23,6 +23,9 @@
package com.metamatrix.query.processor.relational;
import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
import java.util.List;
import java.util.Map;
@@ -30,17 +33,20 @@
import com.metamatrix.api.exception.MetaMatrixProcessingException;
import com.metamatrix.api.exception.query.CriteriaEvaluationException;
import com.metamatrix.common.buffer.BlockedException;
+import com.metamatrix.common.buffer.BufferManager;
import com.metamatrix.common.buffer.TupleBatch;
import com.metamatrix.common.buffer.TupleSourceID;
import com.metamatrix.common.buffer.TupleSourceNotFoundException;
-import com.metamatrix.query.eval.Evaluator;
+import com.metamatrix.query.processor.ProcessorDataManager;
+import com.metamatrix.query.sql.LanguageObject;
import com.metamatrix.query.sql.lang.Criteria;
import com.metamatrix.query.sql.lang.JoinType;
+import com.metamatrix.query.util.CommandContext;
/**
* @since 4.2
*/
-public class JoinNode extends RelationalNode {
+public class JoinNode extends SubqueryAwareRelationalNode {
private enum State { LOAD_LEFT, LOAD_RIGHT, EXECUTE }
private State state = State.LOAD_LEFT;
@@ -52,12 +58,10 @@
private JoinType joinType;
private String dependentValueSource;
- // Set up state - need to be cloned but not reset
private List leftExpressions;
private List rightExpressions;
private Criteria joinCriteria;
- // Cached state - do not need to be cloned or reset
private Map combinedElementMap;
public JoinNode(int nodeID) {
@@ -94,7 +98,18 @@
this.leftOpened = false;
this.rightOpened = false;
}
-
+
+ @Override
+ public void initialize(CommandContext context, BufferManager bufferManager,
+ ProcessorDataManager dataMgr) {
+ super.initialize(context, bufferManager, dataMgr);
+
+ // Create element lookup map for evaluating project expressions
+ List combinedElements = new ArrayList(getChildren()[0].getElements());
+ combinedElements.addAll(getChildren()[1].getElements());
+ this.combinedElementMap = createLookupMap(combinedElements);
+ }
+
public void open()
throws MetaMatrixComponentException, MetaMatrixProcessingException {
@@ -110,10 +125,6 @@
this.rightOpened = true;
}
- // Create element lookup map for evaluating project expressions
- List combinedElements = new ArrayList(getChildren()[0].getElements());
- combinedElements.addAll(getChildren()[1].getElements());
- this.combinedElementMap = createLookupMap(combinedElements);
this.state = State.LOAD_LEFT;
// Set Up Join Strategy
this.joinStrategy.initialize(this);
@@ -274,7 +285,7 @@
}
boolean matchesCriteria(List outputTuple) throws BlockedException, MetaMatrixComponentException, CriteriaEvaluationException {
- return (this.joinCriteria == null || new Evaluator(this.combinedElementMap, this.getDataManager(), this.getContext()).evaluate(this.joinCriteria, outputTuple));
+ return (this.joinCriteria == null || getEvaluator(this.combinedElementMap).evaluate(this.joinCriteria, outputTuple));
}
public List getLeftExpressions() {
@@ -284,5 +295,13 @@
public List getRightExpressions() {
return this.rightExpressions;
}
+
+ @Override
+ public Collection<? extends LanguageObject> getLanguageObjects() {
+ if (this.joinCriteria == null) {
+ return Collections.emptyList();
+ }
+ return Arrays.asList(this.joinCriteria);
+ }
}
Modified: trunk/engine/src/main/java/com/metamatrix/query/processor/relational/ProjectNode.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/processor/relational/ProjectNode.java 2009-04-27 16:49:34 UTC (rev 845)
+++ trunk/engine/src/main/java/com/metamatrix/query/processor/relational/ProjectNode.java 2009-04-27 19:02:50 UTC (rev 846)
@@ -24,6 +24,7 @@
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -32,19 +33,22 @@
import com.metamatrix.api.exception.MetaMatrixProcessingException;
import com.metamatrix.api.exception.query.ExpressionEvaluationException;
import com.metamatrix.common.buffer.BlockedException;
+import com.metamatrix.common.buffer.BufferManager;
import com.metamatrix.common.buffer.TupleBatch;
import com.metamatrix.core.util.Assertion;
-import com.metamatrix.query.eval.Evaluator;
import com.metamatrix.query.execution.QueryExecPlugin;
+import com.metamatrix.query.processor.ProcessorDataManager;
+import com.metamatrix.query.sql.LanguageObject;
import com.metamatrix.query.sql.symbol.AggregateSymbol;
import com.metamatrix.query.sql.symbol.AliasSymbol;
import com.metamatrix.query.sql.symbol.ElementSymbol;
import com.metamatrix.query.sql.symbol.Expression;
import com.metamatrix.query.sql.symbol.ExpressionSymbol;
import com.metamatrix.query.sql.symbol.SelectSymbol;
+import com.metamatrix.query.util.CommandContext;
import com.metamatrix.query.util.ErrorMessageKeys;
-public class ProjectNode extends RelationalNode {
+public class ProjectNode extends SubqueryAwareRelationalNode {
private List selectSymbols;
@@ -55,7 +59,6 @@
// Saved state when blocked on evaluating a row - must be reset
private TupleBatch currentBatch;
private int currentRow;
- private boolean blockedOnPrepare = false;
public ProjectNode(int nodeID) {
super(nodeID);
@@ -63,13 +66,10 @@
public void reset() {
super.reset();
-
- elementMap = null;
needsProject = true;
currentBatch = null;
currentRow = 0;
- blockedOnPrepare = false;
}
/**
@@ -83,13 +83,12 @@
public void setSelectSymbols(List symbols) {
this.selectSymbols = symbols;
}
+
+ @Override
+ public void initialize(CommandContext context, BufferManager bufferManager,
+ ProcessorDataManager dataMgr) {
+ super.initialize(context, bufferManager, dataMgr);
- public void open()
- throws MetaMatrixComponentException, MetaMatrixProcessingException {
-
- // Open the child source
- super.open();
-
// Do this lazily as the node may be reset and re-used and this info doesn't change
if(elementMap == null) {
//in the case of select with no from, there is no child node
@@ -143,7 +142,7 @@
}
}
}
-
+
public TupleBatch nextBatchDirect()
throws BlockedException, MetaMatrixComponentException, MetaMatrixProcessingException {
@@ -156,12 +155,6 @@
TupleBatch batch = this.currentBatch;
int beginRow = this.currentRow;
- // Call "prepareToProcessTuple" if there is no temporary batch state
- // (indicating this is the first call to get a next batch) or
- // if the blockedOnPrepare variable indicates that
- // "prepareToProcessTuple" threw the BlockedException
- boolean doPrepareToProcessTuple = (this.currentBatch == null || this.blockedOnPrepare);
-
if(batch == null) {
// There was no saved batch, so get a new one
//in the case of select with no from, should return only
@@ -186,25 +179,11 @@
// There was a saved batch, but we grabbed the state so it can now be removed
this.currentBatch = null;
this.currentRow = 0;
- this.blockedOnPrepare = false;
}
for(int row = beginRow; row <= batch.getEndRow(); row++) {
List tuple = batch.getTuple(row);
- if (doPrepareToProcessTuple){
- try {
- // Hook for subclasses
- this.prepareToProcessTuple(this.elementMap, tuple);
- } catch(BlockedException e) {
- // Expression blocked, so save state and rethrow
- this.blockedOnPrepare = true;
- this.currentBatch = batch;
- this.currentRow = row;
- throw e;
- }
- }
-
List projectedTuple = new ArrayList(selectSymbols.size());
// Walk through symbols
@@ -232,23 +211,6 @@
return pullBatch();
}
- /**
- * This method is called by {@link #nextBatch} just after the current
- * tuple is pulled from the child processor node and just before any
- * processing is done (in this case, before the tuple is projected).
- * This gives subclasses a chance to do any custom processing - for example,
- * to examine the current tuple in order to execute correlated subqueries.
- * @param elementMap Map of ElementSymbol elements to Integer indices into
- * the currentTuple parameter
- * @param currentTuple the current tuple about to be processed by
- * this node
- * @throws MetaMatrixProcessingException for exception due to user input or modeling
- */
- protected void prepareToProcessTuple(Map elementMap, List currentTuple)
- throws BlockedException, MetaMatrixComponentException, MetaMatrixProcessingException {
- //Nothing done here
- }
-
private void updateTuple(SelectSymbol symbol, List values, List tuple)
throws BlockedException, MetaMatrixComponentException, ExpressionEvaluationException {
@@ -268,7 +230,7 @@
tuple.add(values.get(index.intValue()));
} else if(symbol instanceof ExpressionSymbol) {
Expression expression = ((ExpressionSymbol)symbol).getExpression();
- tuple.add(new Evaluator(elementMap, getDataManager(), getContext()).evaluate(expression, values));
+ tuple.add(getEvaluator(this.elementMap).evaluate(expression, values));
} else {
Assertion.failed(QueryExecPlugin.Util.getString(ErrorMessageKeys.PROCESSOR_0034, symbol.getClass().getName()));
}
@@ -305,5 +267,10 @@
return props;
}
-
+
+ @Override
+ public Collection<LanguageObject> getLanguageObjects() {
+ return this.getSelectSymbols();
+ }
+
}
Modified: trunk/engine/src/main/java/com/metamatrix/query/processor/relational/RelationalNode.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/processor/relational/RelationalNode.java 2009-04-27 16:49:34 UTC (rev 845)
+++ trunk/engine/src/main/java/com/metamatrix/query/processor/relational/RelationalNode.java 2009-04-27 19:02:50 UTC (rev 846)
@@ -23,9 +23,11 @@
package com.metamatrix.query.processor.relational;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
+import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@@ -40,8 +42,12 @@
import com.metamatrix.query.processor.Describable;
import com.metamatrix.query.processor.DescribableUtil;
import com.metamatrix.query.processor.ProcessorDataManager;
+import com.metamatrix.query.processor.ProcessorPlan;
+import com.metamatrix.query.sql.LanguageObject;
+import com.metamatrix.query.sql.lang.SubqueryContainer;
import com.metamatrix.query.sql.symbol.AliasSymbol;
import com.metamatrix.query.sql.symbol.SingleElementSymbol;
+import com.metamatrix.query.sql.visitor.ValueIteratorProviderCollectorVisitor;
import com.metamatrix.query.util.CommandContext;
import com.metamatrix.query.util.ErrorMessageKeys;
@@ -483,9 +489,27 @@
* @since 4.2
*/
public List getChildPlans() {
- return null;
+ Collection<? extends LanguageObject> objs = getLanguageObjects();
+ if (objs == null || objs.isEmpty()) {
+ return null;
+ }
+ Collection<SubqueryContainer> containers = ValueIteratorProviderCollectorVisitor.getValueIteratorProviders(objs);
+ if (containers.isEmpty()) {
+ return null;
+ }
+ List<ProcessorPlan> plans = new LinkedList<ProcessorPlan>();
+ for (SubqueryContainer container : containers) {
+ if (container.getCommand().getProcessorPlan() != null) {
+ plans.add(container.getCommand().getProcessorPlan());
+ }
+ }
+ return plans;
}
-
+
+ public Collection<? extends LanguageObject> getLanguageObjects() {
+ return null;
+ }
+
/*
* @see com.metamatrix.query.processor.Describable#getDescriptionProperties()
*/
Modified: trunk/engine/src/main/java/com/metamatrix/query/processor/relational/SelectNode.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/processor/relational/SelectNode.java 2009-04-27 16:49:34 UTC (rev 845)
+++ trunk/engine/src/main/java/com/metamatrix/query/processor/relational/SelectNode.java 2009-04-27 19:02:50 UTC (rev 846)
@@ -22,17 +22,22 @@
package com.metamatrix.query.processor.relational;
+import java.util.Arrays;
+import java.util.Collection;
import java.util.List;
import java.util.Map;
import com.metamatrix.api.exception.MetaMatrixComponentException;
import com.metamatrix.api.exception.MetaMatrixProcessingException;
import com.metamatrix.common.buffer.BlockedException;
+import com.metamatrix.common.buffer.BufferManager;
import com.metamatrix.common.buffer.TupleBatch;
-import com.metamatrix.query.eval.Evaluator;
+import com.metamatrix.query.processor.ProcessorDataManager;
+import com.metamatrix.query.sql.LanguageObject;
import com.metamatrix.query.sql.lang.Criteria;
+import com.metamatrix.query.util.CommandContext;
-public class SelectNode extends RelationalNode {
+public class SelectNode extends SubqueryAwareRelationalNode {
private Criteria criteria;
@@ -44,7 +49,6 @@
private boolean blockedOnPrepare = false;
private TupleBatch blockedBatch = null;
private int blockedRow = 0;
- private Evaluator evaluator;
public SelectNode(int nodeID) {
super(nodeID);
@@ -57,7 +61,6 @@
blockedOnPrepare = false;
blockedBatch = null;
blockedRow = 0;
- evaluator = null;
}
public void setCriteria(Criteria criteria) {
@@ -68,18 +71,16 @@
return this.criteria;
}
- public void open()
- throws MetaMatrixComponentException, MetaMatrixProcessingException {
-
- super.open();
-
+ @Override
+ public void initialize(CommandContext context, BufferManager bufferManager,
+ ProcessorDataManager dataMgr) {
+ super.initialize(context, bufferManager, dataMgr);
// Create element lookup map for evaluating project expressions
if(this.elementMap == null) {
this.elementMap = createLookupMap(this.getChildren()[0].getElements());
}
- this.evaluator = new Evaluator(elementMap, getDataManager(), getContext());
}
-
+
/**
* @see com.metamatrix.query.processor.relational.RelationalNode#nextBatchDirect()
*/
@@ -91,7 +92,6 @@
batch = this.getChildren()[0].nextBatch();
}
- boolean doPrepareToProcessTuple = !blockedOnCriteria;
int row = blockedRow;
if(! blockedOnCriteria && ! blockedOnPrepare) {
row = batch.getBeginRow();
@@ -106,22 +106,9 @@
for(; row <= batch.getEndRow(); row++) {
List tuple = batch.getTuple(row);
- if (doPrepareToProcessTuple){
- try {
- // Hook for subclasses
- this.prepareToProcessTuple(this.elementMap, tuple);
- } catch(BlockedException e) {
- // Save state and rethrow
- blockedOnPrepare = true;
- blockedBatch = batch;
- blockedRow = row;
- throw e;
- }
- }
-
// Evaluate criteria with tuple
try {
- if(evaluator.evaluate(this.criteria, tuple)) {
+ if(getEvaluator(this.elementMap).evaluate(this.criteria, tuple)) {
addBatchRow( projectTuple(elementMap, tuple, getElements()) );
}
} catch(BlockedException e) {
@@ -140,23 +127,6 @@
return pullBatch();
}
- /**
- * This method is called by {@link #nextBatch} just after the current
- * tuple is pulled from the child processor node and just before any
- * processing is done (in this case, before the criteria is evaluated).
- * This gives subclasses a chance to do any custom processing - for example,
- * to examine the current tuple in order to execute correlated subqueries.
- * @param elementMap Map of ElementSymbol elements to Integer indices into
- * the currentTuple parameter
- * @param currentTuple the current tuple about to be processed by
- * this node
- * @throws MetaMatrixProcessingException for exception due to user input
- */
- protected void prepareToProcessTuple(Map elementMap, List currentTuple)
- throws BlockedException, MetaMatrixComponentException, MetaMatrixProcessingException {
- //Nothing done here
- }
-
protected void getNodeString(StringBuffer str) {
super.getNodeString(str);
str.append(criteria);
@@ -185,4 +155,9 @@
return props;
}
+ @Override
+ public Collection<? extends LanguageObject> getLanguageObjects() {
+ return Arrays.asList(this.criteria);
+ }
+
}
Copied: trunk/engine/src/main/java/com/metamatrix/query/processor/relational/SubqueryAwareEvaluator.java (from rev 837, trunk/engine/src/main/java/com/metamatrix/query/processor/relational/SubqueryProcessorUtility.java)
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/processor/relational/SubqueryAwareEvaluator.java (rev 0)
+++ trunk/engine/src/main/java/com/metamatrix/query/processor/relational/SubqueryAwareEvaluator.java 2009-04-27 19:02:50 UTC (rev 846)
@@ -0,0 +1,141 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package com.metamatrix.query.processor.relational;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import com.metamatrix.api.exception.MetaMatrixComponentException;
+import com.metamatrix.api.exception.MetaMatrixProcessingException;
+import com.metamatrix.common.buffer.BlockedException;
+import com.metamatrix.common.buffer.BufferManager;
+import com.metamatrix.common.buffer.TupleSourceID;
+import com.metamatrix.common.buffer.TupleSourceNotFoundException;
+import com.metamatrix.core.MetaMatrixCoreException;
+import com.metamatrix.query.eval.Evaluator;
+import com.metamatrix.query.processor.ProcessorDataManager;
+import com.metamatrix.query.processor.ProcessorPlan;
+import com.metamatrix.query.processor.QueryProcessor;
+import com.metamatrix.query.sql.lang.SubqueryContainer;
+import com.metamatrix.query.sql.symbol.ContextReference;
+import com.metamatrix.query.sql.symbol.ElementSymbol;
+import com.metamatrix.query.sql.symbol.Expression;
+import com.metamatrix.query.sql.util.ValueIterator;
+import com.metamatrix.query.sql.util.VariableContext;
+import com.metamatrix.query.util.CommandContext;
+
+/**
+ * <p>This utility handles the work of processing a subquery; certain types
+ * of processor nodes will use an instance of this class to do that work.
+ */
+public class SubqueryAwareEvaluator extends Evaluator {
+
+ public class SubqueryState {
+ QueryProcessor processor;
+ boolean done;
+ List<?> tuple;
+ ProcessorPlan plan;
+
+ void close() throws MetaMatrixComponentException {
+ if (processor == null) {
+ return;
+ }
+ try {
+ processor.closeProcessing();
+ TupleSourceID id = processor.getResultsID();
+ manager.removeTupleSource(id);
+ } catch (TupleSourceNotFoundException e) {
+
+ }
+ processor = null;
+ this.done = false;
+ }
+ }
+
+ //environment
+ private BufferManager manager;
+
+ //processing state
+ private Map<String, SubqueryState> subqueries = new HashMap<String, SubqueryState>();
+
+ public SubqueryAwareEvaluator(Map elements, ProcessorDataManager dataMgr,
+ CommandContext context, BufferManager manager) {
+ super(elements, dataMgr, context);
+ this.manager = manager;
+ }
+
+ public void reset() {
+ for (SubqueryState subQueryState : subqueries.values()) {
+ subQueryState.plan.reset();
+ }
+ }
+
+ public void close() throws MetaMatrixComponentException {
+ for (SubqueryState state : subqueries.values()) {
+ state.close();
+ }
+ }
+
+ @Override
+ protected ValueIterator evaluateSubquery(SubqueryContainer container,
+ List tuple) throws MetaMatrixProcessingException, BlockedException,
+ MetaMatrixComponentException {
+ ContextReference ref = (ContextReference)container;
+ String key = (ref).getContextSymbol();
+ SubqueryState state = this.subqueries.get(key);
+ if (state == null) {
+ state = new SubqueryState();
+ state.plan = (ProcessorPlan)container.getCommand().getProcessorPlan().clone();
+ this.subqueries.put(key, state);
+ }
+ if ((tuple == null && state.tuple != null) || (tuple != null && !tuple.equals(state.tuple))) {
+ if (container.getCommand().getCorrelatedReferences() != null) {
+ state.close();
+ }
+ state.tuple = tuple;
+ }
+ if (!state.done) {
+ if (state.processor == null) {
+ CommandContext subContext = (CommandContext) context.clone();
+ state.processor = new QueryProcessor(state.plan, subContext, manager, this.dataMgr);
+ if (container.getCommand().getCorrelatedReferences() != null) {
+ VariableContext currentContext = new VariableContext();
+ for (Map.Entry<ElementSymbol, Expression> entry : container.getCommand().getCorrelatedReferences().asMap().entrySet()) {
+ currentContext.setValue(entry.getKey(), evaluate(entry.getValue(), tuple));
+ }
+ state.processor.getContext().pushVariableContext(currentContext);
+ }
+ }
+ try {
+ state.processor.process(Integer.MAX_VALUE);
+ } catch (MetaMatrixCoreException e) {
+ throw new MetaMatrixComponentException(e);
+ }
+ state.done = true;
+ state.processor.getProcessorPlan().reset();
+ }
+ return new DependentValueSource(state.processor.getResultsID(), this.manager).getValueIterator(ref.getValueExpression());
+ }
+
+}
Property changes on: trunk/engine/src/main/java/com/metamatrix/query/processor/relational/SubqueryAwareEvaluator.java
___________________________________________________________________
Name: svn:mergeinfo
+
Added: trunk/engine/src/main/java/com/metamatrix/query/processor/relational/SubqueryAwareRelationalNode.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/processor/relational/SubqueryAwareRelationalNode.java (rev 0)
+++ trunk/engine/src/main/java/com/metamatrix/query/processor/relational/SubqueryAwareRelationalNode.java 2009-04-27 19:02:50 UTC (rev 846)
@@ -0,0 +1,41 @@
+package com.metamatrix.query.processor.relational;
+
+import java.util.Map;
+
+import com.metamatrix.api.exception.MetaMatrixComponentException;
+import com.metamatrix.query.eval.Evaluator;
+
+public abstract class SubqueryAwareRelationalNode extends RelationalNode {
+
+ private SubqueryAwareEvaluator evaluator;
+
+ public SubqueryAwareRelationalNode(int nodeID) {
+ super(nodeID);
+ }
+
+ protected Evaluator getEvaluator(Map elementMap) {
+ if (this.evaluator == null) {
+ this.evaluator = new SubqueryAwareEvaluator(elementMap, getDataManager(), getContext(), getBufferManager());
+ } else {
+ this.evaluator.setContext(getContext());
+ }
+ return this.evaluator;
+ }
+
+ @Override
+ public void reset() {
+ super.reset();
+ if (evaluator != null) {
+ evaluator.reset();
+ }
+ }
+
+ @Override
+ public void close() throws MetaMatrixComponentException {
+ super.close();
+ if (evaluator != null) {
+ evaluator.close();
+ }
+ }
+
+}
Property changes on: trunk/engine/src/main/java/com/metamatrix/query/processor/relational/SubqueryAwareRelationalNode.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Deleted: trunk/engine/src/main/java/com/metamatrix/query/processor/relational/SubqueryProcessorUtility.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/processor/relational/SubqueryProcessorUtility.java 2009-04-27 16:49:34 UTC (rev 845)
+++ trunk/engine/src/main/java/com/metamatrix/query/processor/relational/SubqueryProcessorUtility.java 2009-04-27 19:02:50 UTC (rev 846)
@@ -1,211 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package com.metamatrix.query.processor.relational;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.api.exception.MetaMatrixProcessingException;
-import com.metamatrix.common.buffer.BlockedException;
-import com.metamatrix.common.buffer.BufferManager;
-import com.metamatrix.common.buffer.TupleSourceID;
-import com.metamatrix.common.buffer.TupleSourceNotFoundException;
-import com.metamatrix.core.MetaMatrixCoreException;
-import com.metamatrix.query.eval.Evaluator;
-import com.metamatrix.query.processor.ProcessorPlan;
-import com.metamatrix.query.processor.QueryProcessor;
-import com.metamatrix.query.sql.symbol.ElementSymbol;
-import com.metamatrix.query.sql.symbol.Expression;
-import com.metamatrix.query.sql.util.SymbolMap;
-import com.metamatrix.query.sql.util.VariableContext;
-import com.metamatrix.query.util.CommandContext;
-
-/**
- * <p>This utility handles the work of processing a subquery; certain types
- * of processor nodes will use an instance of this class to do that work.
- */
-public class SubqueryProcessorUtility {
-
- private List<? extends ProcessorPlan> processorPlans;
- private List<String> contextReferences;
- private SymbolMap correlatedReferences;
-
- private List<QueryProcessor> processors = new ArrayList<QueryProcessor>();
-
- // "Placeholder" state, for resuming processing after
- // a BlockedException - not cloned
- private int currentIndex = 0;
- private QueryProcessor currentProcessor;
-
- // List <TupleSourceID> - same index-matchup as other two Lists
- // Need to clean up on close()
- private List<TupleSourceID> tupleSources = new ArrayList<TupleSourceID>();
-
- private VariableContext currentContext;
-
- public SubqueryProcessorUtility(List<? extends ProcessorPlan> valList, List<String> contextReferences, SymbolMap references) {
- this.processorPlans = valList;
- this.contextReferences = contextReferences;
- if (references != null && !references.asMap().isEmpty()) {
- this.correlatedReferences = references;
- }
- }
-
- public SubqueryProcessorUtility clone() {
- List<ProcessorPlan> plans = new ArrayList<ProcessorPlan>(processorPlans.size());
- for (ProcessorPlan processorPlan : processorPlans) {
- plans.add((ProcessorPlan)processorPlan.clone());
- }
- return new SubqueryProcessorUtility(plans, contextReferences, correlatedReferences);
- }
-
- List<? extends ProcessorPlan> getSubqueryPlans(){
- return this.processorPlans;
- }
-
- void reset() {
- this.currentIndex = 0;
- currentProcessor = null;
- // Reset internal plans
- for(int i=0; i<processorPlans.size(); i++) {
- ProcessorPlan plan = processorPlans.get(i);
- plan.reset();
- }
- }
-
- /**
- * initializes each subquery ProcessorPlan
- * @throws MetaMatrixComponentException
- */
- void open(RelationalNode parent) throws MetaMatrixComponentException {
- // Open subquery processor plans
- for (ProcessorPlan plan : this.processorPlans) {
- CommandContext subContext = (CommandContext) parent.getContext().clone();
- QueryProcessor processor = new QueryProcessor(plan, subContext, parent.getBufferManager(), parent.getDataManager());
- this.processors.add(processor);
- this.tupleSources.add(processor.getResultsID());
- }
- }
-
- /**
- * Removes the temporary tuple sources of the subquery results
- */
- void close(BufferManager bufferManager)
- throws MetaMatrixComponentException {
-
- for (QueryProcessor processor : this.processors) {
- try {
- processor.closeProcessing();
- } catch (TupleSourceNotFoundException e) {
- }
- }
- this.processors.clear();
-
- for (TupleSourceID tsID : this.tupleSources) {
- try {
- bufferManager.removeTupleSource(tsID);
- } catch (TupleSourceNotFoundException e) {
- //ignore
- }
- }
-
- this.tupleSources.clear();
- }
-
- /**
- * <p>Processes processor plans (each key), stores as TupleSource Iterators in
- * each ValueIteratorProvider (each value). Continues synchronously until
- * all processing is completed or until a BlockedException is thrown. This
- * method can be called after a BlockedException and will resume processing
- * where it left off.</p>
- *
- * <p>After this method completes (including after multiple method calls
- * that resulted in a BlockedException), if this method is called again,
- * it will start processing over ONLY IF this instance has any correlated subquery
- * references. The assumption is that it will not be called again until
- * a new outer currentTuple is being passed in.</p>
- *
- * @param elementMap Map of ElementSymbol elements to Integer indices into
- * the currentTuple parameter
- * @param currentTuple current tuple of the containing query
- * @param bufferManager BufferManager
- * @param groupName String group name of client processor node
- * @throws BlockedException potentially at any time during processing
- * @throws MetaMatrixComponentException for unexpected exception
- * @throws MetaMatrixProcessingException for exception due to user input or modeling
- */
- void process(RelationalNode parent, Map elementMap, List currentTuple)
- throws BlockedException, MetaMatrixComponentException, MetaMatrixProcessingException {
-
- // This IF block is only intended to be run when the outer query tuple has changed,
- // so it should not be run when this instance is resuming processing after a BlockedException
- if (this.currentContext == null && this.currentProcessor == null && this.correlatedReferences != null){
- // Close old tuple sources
- this.close(parent.getBufferManager());
- this.open(parent);
- this.currentContext = new VariableContext();
- for (Map.Entry<ElementSymbol, Expression> entry : this.correlatedReferences.asMap().entrySet()) {
- this.currentContext.setValue(entry.getKey(), new Evaluator(elementMap, parent.getDataManager(), parent.getContext()).evaluate(entry.getValue(), currentTuple));
- }
- }
-
- while (this.currentProcessor != null || this.currentIndex < this.processorPlans.size()){
- //Initialize current ProcessorPlan tuple source, if necessary
- if (this.currentProcessor == null){
- this.currentProcessor = this.processors.get(currentIndex);
- if (this.currentContext != null) {
- this.currentProcessor.getContext().pushVariableContext(this.currentContext);
- }
- }
-
- // Process the results
- try {
- this.currentProcessor.process(Integer.MAX_VALUE);
- this.currentProcessor.getProcessorPlan().reset();
- } catch (MetaMatrixProcessingException e) {
- throw e;
- } catch (MetaMatrixComponentException e) {
- throw e;
- } catch (MetaMatrixCoreException e) {
- throw new MetaMatrixComponentException(e);
- }
-
- // Set the results on the ValueIteratorProviders
- parent.getContext().getVariableContext().setGlobalValue(this.contextReferences.get(this.currentIndex), new DependentValueSource(this.currentProcessor.getResultsID(), parent.getBufferManager()));
-
- this.currentProcessor = null;
- this.currentIndex++;
- }
-
- if (this.correlatedReferences != null){
- // If correlated references are present, re-zero currentIndex -
- // If we've made it this far, then the next time
- // this method is called, it should be for a new outer tuple
- currentIndex = 0;
- }
- this.currentContext = null;
- }
-
-}
Modified: trunk/engine/src/main/java/com/metamatrix/query/resolver/command/UpdateProcedureResolver.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/resolver/command/UpdateProcedureResolver.java 2009-04-27 16:49:34 UTC (rev 845)
+++ trunk/engine/src/main/java/com/metamatrix/query/resolver/command/UpdateProcedureResolver.java 2009-04-27 19:02:50 UTC (rev 846)
@@ -56,6 +56,7 @@
import com.metamatrix.query.sql.lang.Criteria;
import com.metamatrix.query.sql.lang.DynamicCommand;
import com.metamatrix.query.sql.lang.GroupContext;
+import com.metamatrix.query.sql.lang.SubqueryContainer;
import com.metamatrix.query.sql.proc.AssignmentStatement;
import com.metamatrix.query.sql.proc.Block;
import com.metamatrix.query.sql.proc.CommandStatement;
@@ -70,6 +71,7 @@
import com.metamatrix.query.sql.symbol.GroupSymbol;
import com.metamatrix.query.sql.symbol.SingleElementSymbol;
import com.metamatrix.query.sql.util.SymbolMap;
+import com.metamatrix.query.sql.visitor.ValueIteratorProviderCollectorVisitor;
import com.metamatrix.query.util.ErrorMessageKeys;
import com.metamatrix.query.util.LogConstants;
@@ -195,6 +197,9 @@
case Statement.TYPE_IF:
IfStatement ifStmt = (IfStatement) statement;
Criteria ifCrit = ifStmt.getCondition();
+ for (SubqueryContainer container : ValueIteratorProviderCollectorVisitor.getValueIteratorProviders(ifCrit)) {
+ resolveEmbeddedCommand(metadata, externalGroups, container.getCommand(), expandCommand, analysis);
+ }
ResolverVisitor.resolveLanguageObject(ifCrit, null, externalGroups, metadata);
resolveBlock(command, ifStmt.getIfBlock(), externalGroups, metadata, expandCommand, isUpdateProcedure, analysis);
if(ifStmt.hasElseBlock()) {
@@ -249,6 +254,9 @@
resolveEmbeddedCommand(metadata, externalGroups, cmd, expandCommand, analysis);
} else if (assStmt.hasExpression()) {
Expression expr = assStmt.getExpression();
+ for (SubqueryContainer container : ValueIteratorProviderCollectorVisitor.getValueIteratorProviders(expr)) {
+ resolveEmbeddedCommand(metadata, externalGroups, container.getCommand(), expandCommand, analysis);
+ }
ResolverVisitor.resolveLanguageObject(expr, null, externalGroups, metadata);
}
}
@@ -282,6 +290,9 @@
case Statement.TYPE_WHILE:
WhileStatement whileStmt = (WhileStatement) statement;
Criteria whileCrit = whileStmt.getCondition();
+ for (SubqueryContainer container : ValueIteratorProviderCollectorVisitor.getValueIteratorProviders(whileCrit)) {
+ resolveEmbeddedCommand(metadata, externalGroups, container.getCommand(), expandCommand, analysis);
+ }
ResolverVisitor.resolveLanguageObject(whileCrit, null, externalGroups, metadata);
resolveBlock(command, whileStmt.getBlock(), externalGroups, metadata, expandCommand, isUpdateProcedure, analysis);
break;
Modified: trunk/engine/src/main/java/com/metamatrix/query/resolver/util/AccessPattern.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/resolver/util/AccessPattern.java 2009-04-27 16:49:34 UTC (rev 845)
+++ trunk/engine/src/main/java/com/metamatrix/query/resolver/util/AccessPattern.java 2009-04-27 19:02:50 UTC (rev 846)
@@ -27,49 +27,51 @@
import java.util.LinkedList;
import java.util.Set;
+import com.metamatrix.query.sql.symbol.ElementSymbol;
+
/**
* This class represents both virtual and physical access patterns.
*
- * If a virtual access pattern is initially unstatisfied, it may be
+ * If a virtual access pattern is initially unsatisfied, it may be
* transformed by RuleMergeVirtual. In this case, the history of the
* access pattern will contain its previous definitions.
*/
-public class AccessPattern implements Comparable, Cloneable {
+public class AccessPattern implements Comparable<AccessPattern>, Cloneable {
- private Set unsatisfied = new HashSet();
- private LinkedList history = new LinkedList();
+ private Set<ElementSymbol> unsatisfied = new HashSet<ElementSymbol>();
+ private LinkedList<Collection<ElementSymbol>> history = new LinkedList<Collection<ElementSymbol>>();
- public AccessPattern(Collection elements) {
+ public AccessPattern(Collection<ElementSymbol> elements) {
unsatisfied.addAll(elements);
history.add(elements);
}
- public Collection getCurrentElements() {
- return (Collection)history.getFirst();
+ public Collection<ElementSymbol> getCurrentElements() {
+ return history.getFirst();
}
- public void addElementHistory(Collection elements) {
+ public void addElementHistory(Collection<ElementSymbol> elements) {
this.history.addFirst(elements);
}
/**
* @return Returns the history.
*/
- public LinkedList getHistory() {
+ public LinkedList<Collection<ElementSymbol>> getHistory() {
return this.history;
}
/**
- * @return Returns the unstaisfied.
+ * @return Returns the unsatisfied.
*/
- public Set getUnsatisfied() {
+ public Set<ElementSymbol> getUnsatisfied() {
return this.unsatisfied;
}
/**
- * @param unstaisfied The unstaisfied to set.
+ * @param unstaisfied The unsatisfied to set.
*/
- public void setUnsatisfied(Set unstaisfied) {
+ public void setUnsatisfied(Set<ElementSymbol> unstaisfied) {
this.unsatisfied = unstaisfied;
}
@@ -84,13 +86,9 @@
sb.append(history);
return sb.toString();
}
-
- /**
- * @see java.lang.Comparable#compareTo(java.lang.Object)
- */
- public int compareTo(Object o) {
- AccessPattern other = (AccessPattern)o;
-
+
+ @Override
+ public int compareTo(AccessPattern other) {
if (this.unsatisfied.size() > other.unsatisfied.size()){
return 1;
} else if (this.unsatisfied.size() < other.unsatisfied.size()){
Modified: trunk/engine/src/main/java/com/metamatrix/query/sql/lang/Command.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/sql/lang/Command.java 2009-04-27 16:49:34 UTC (rev 845)
+++ trunk/engine/src/main/java/com/metamatrix/query/sql/lang/Command.java 2009-04-27 19:02:50 UTC (rev 846)
@@ -22,7 +22,14 @@
package com.metamatrix.query.sql.lang;
-import java.util.*;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
import com.metamatrix.api.exception.MetaMatrixComponentException;
import com.metamatrix.common.types.DataTypeManager;
@@ -32,6 +39,7 @@
import com.metamatrix.query.sql.symbol.ElementSymbol;
import com.metamatrix.query.sql.symbol.GroupSymbol;
import com.metamatrix.query.sql.symbol.SingleElementSymbol;
+import com.metamatrix.query.sql.util.SymbolMap;
import com.metamatrix.query.sql.visitor.CommandCollectorVisitor;
import com.metamatrix.query.sql.visitor.SQLStringVisitor;
@@ -126,12 +134,26 @@
private Option option;
private ProcessorPlan plan;
+
+ private SymbolMap correlatedReferences;
/**
* Return type of command to make it easier to build switch statements by command type.
* @return Type from TYPE constants
*/
public abstract int getType();
+
+ /**
+ * Get the correlated references to the containing scope only
+ * @return
+ */
+ public SymbolMap getCorrelatedReferences() {
+ return correlatedReferences;
+ }
+
+ public void setCorrelatedReferences(SymbolMap correlatedReferences) {
+ this.correlatedReferences = correlatedReferences;
+ }
/**
* Gets the subCommands (both embedded and non-embedded) under this command. In general the returned list
@@ -222,6 +244,9 @@
copy.setIsResolved(this.isResolved());
copy.plan = this.plan;
+ if (this.correlatedReferences != null) {
+ copy.correlatedReferences = this.correlatedReferences.clone();
+ }
}
/**
@@ -323,12 +348,10 @@
return getSubCommandsUpdatingModelCount(this, metadata);
}
- public static int getSubCommandsUpdatingModelCount(LanguageObject object, QueryMetadataInterface metadata) throws MetaMatrixComponentException {
- List subCommands = CommandCollectorVisitor.getCommands(object);
+ public static int getSubCommandsUpdatingModelCount(Command object, QueryMetadataInterface metadata) throws MetaMatrixComponentException {
+ List<Command> subCommands = CommandCollectorVisitor.getCommands(object);
int numCommands = subCommands.size();
- Iterator iter = subCommands.iterator();
- while(iter.hasNext()) {
- Command command = (Command)iter.next();
+ for (Command command : subCommands) {
if (numCommands == 1) {
return command.updatingModelCount(metadata);
}
Modified: trunk/engine/src/main/java/com/metamatrix/query/sql/proc/CreateUpdateProcedureCommand.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/sql/proc/CreateUpdateProcedureCommand.java 2009-04-27 16:49:34 UTC (rev 845)
+++ trunk/engine/src/main/java/com/metamatrix/query/sql/proc/CreateUpdateProcedureCommand.java 2009-04-27 19:02:50 UTC (rev 846)
@@ -25,7 +25,6 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -292,16 +291,25 @@
}
public int updatingModelCount(QueryMetadataInterface metadata) throws MetaMatrixComponentException {
- for (final Iterator iterator = block.getStatements().iterator(); iterator.hasNext();) {
- final Statement statement = (Statement)iterator.next();
- int count = Command.getSubCommandsUpdatingModelCount(statement, metadata);
- if (!iterator.hasNext() && statement instanceof CommandStatement) {
- return count;
+ List<Command> subCommands = getSubCommands();
+ if (subCommands.isEmpty()) {
+ return 0;
+ }
+ Command lastCommand = null;
+ Statement statement = (Statement)block.getStatements().get(block.getStatements().size() - 1);
+ if (statement instanceof CommandStatement) {
+ CommandStatement cmdStatement = (CommandStatement)statement;
+ lastCommand = cmdStatement.getCommand();
+ }
+ for (Command command : subCommands) {
+ int count = command.updatingModelCount(metadata);
+ if (command == lastCommand) {
+ return count;
}
if (count > 0) {
return 2;
}
- }
+ }
return 0;
}
Modified: trunk/engine/src/main/java/com/metamatrix/query/sql/util/SymbolMap.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/sql/util/SymbolMap.java 2009-04-27 16:49:34 UTC (rev 845)
+++ trunk/engine/src/main/java/com/metamatrix/query/sql/util/SymbolMap.java 2009-04-27 19:02:50 UTC (rev 846)
@@ -47,18 +47,14 @@
public SymbolMap() {
}
- public SymbolMap(SymbolMap other) {
- //todo clone;
- this.map.putAll(other.map);
+ public SymbolMap clone() {
+ SymbolMap clonedMap = new SymbolMap();
+ for (Map.Entry<ElementSymbol, Expression> entry : map.entrySet()) {
+ clonedMap.addMapping((ElementSymbol)entry.getKey().clone(), (Expression)entry.getValue().clone());
+ }
+ return clonedMap;
}
- public SymbolMap merge(SymbolMap other) {
- if (other != null) {
- this.map.putAll(other.map);
- }
- return this;
- }
-
/**
* @return true if the map did not already contained the given symbol
*/
Modified: trunk/engine/src/main/java/com/metamatrix/query/sql/util/VariableContext.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/sql/util/VariableContext.java 2009-04-27 16:49:34 UTC (rev 845)
+++ trunk/engine/src/main/java/com/metamatrix/query/sql/util/VariableContext.java 2009-04-27 19:02:50 UTC (rev 846)
@@ -172,4 +172,9 @@
return this.variableMap.remove(symbol);
}
+ @Override
+ public String toString() {
+ return this.variableMap.toString();
+ }
+
}
Modified: trunk/engine/src/main/java/com/metamatrix/query/sql/visitor/CommandCollectorVisitor.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/sql/visitor/CommandCollectorVisitor.java 2009-04-27 16:49:34 UTC (rev 845)
+++ trunk/engine/src/main/java/com/metamatrix/query/sql/visitor/CommandCollectorVisitor.java 2009-04-27 19:02:50 UTC (rev 846)
@@ -33,7 +33,6 @@
import com.metamatrix.query.sql.lang.Command;
import com.metamatrix.query.sql.lang.ExistsCriteria;
import com.metamatrix.query.sql.lang.ProcedureContainer;
-import com.metamatrix.query.sql.lang.QueryCommand;
import com.metamatrix.query.sql.lang.SetQuery;
import com.metamatrix.query.sql.lang.SubqueryCompareCriteria;
import com.metamatrix.query.sql.lang.SubqueryFromClause;
@@ -42,7 +41,6 @@
import com.metamatrix.query.sql.navigator.PreOrderNavigator;
import com.metamatrix.query.sql.proc.AssignmentStatement;
import com.metamatrix.query.sql.proc.CommandStatement;
-import com.metamatrix.query.sql.proc.DeclareStatement;
import com.metamatrix.query.sql.proc.LoopStatement;
import com.metamatrix.query.sql.symbol.ScalarSubquery;
@@ -186,15 +184,15 @@
* @param obj Language object
* @param elements Collection to collect commands in
*/
- public static final List<Command> getCommands(LanguageObject obj) {
+ public static final List<Command> getCommands(Command obj) {
return getCommands(obj, true, true);
}
- public static final List<Command> getCommands(LanguageObject obj, boolean embeddedOnly) {
+ public static final List<Command> getCommands(Command obj, boolean embeddedOnly) {
return getCommands(obj, true, !embeddedOnly);
}
- private static final List<Command> getCommands(LanguageObject obj, boolean embedded, boolean nonEmbedded) {
+ private static final List<Command> getCommands(Command command, boolean embedded, boolean nonEmbedded) {
HashSet<Mode> modes = new HashSet<Mode>();
if (embedded) {
modes.add(Mode.EMBEDDED);
@@ -203,39 +201,23 @@
modes.add(Mode.NON_EMBEDDED);
}
CommandCollectorVisitor visitor = new CommandCollectorVisitor(modes);
-
- //we need a special navigator here to prevent subcommands in statements from being picked up
- //by the wrong parent
+ final boolean visitCommands = command instanceof SetQuery;
PreOrderNavigator navigator = new PreOrderNavigator(visitor) {
- public void visit(LoopStatement obj) {
- preVisitVisitor(obj);
- visitNode(obj.getBlock());
- }
-
- public void visit(CommandStatement obj) {
- preVisitVisitor(obj);
- }
-
- public void visit(AssignmentStatement obj) {
- preVisitVisitor(obj);
- if (obj.hasExpression()) {
- visitNode(obj.getExpression());
- }
- }
- public void visit(DeclareStatement obj) {
- preVisitVisitor(obj);
- if (obj.hasExpression()) {
- visitNode(obj.getExpression());
- }
- }
-
+ @Override
+ protected void visitNode(LanguageObject obj) {
+ if (!visitCommands && obj instanceof Command) {
+ return;
+ }
+ super.visitNode(obj);
+ }
+
};
- obj.acceptVisitor(navigator);
+ command.acceptVisitor(navigator);
return visitor.getCommands();
}
- public static final List<Command> getNonEmbeddedCommands(LanguageObject obj) {
+ public static final List<Command> getNonEmbeddedCommands(Command obj) {
return getCommands(obj, false, true);
}
Modified: trunk/engine/src/main/java/com/metamatrix/query/sql/visitor/CorrelatedReferenceCollectorVisitor.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/sql/visitor/CorrelatedReferenceCollectorVisitor.java 2009-04-27 16:49:34 UTC (rev 845)
+++ trunk/engine/src/main/java/com/metamatrix/query/sql/visitor/CorrelatedReferenceCollectorVisitor.java 2009-04-27 19:02:50 UTC (rev 846)
@@ -35,21 +35,21 @@
* correspond to correlated subquery references.</p>
*
* <p>The easiest way to use this visitor is to call the static method which creates the
- * the visitor by passing it the Langiuage Object and the variable context to be looked up.
+ * the visitor by passing it the Language Object and the variable context to be looked up.
* The public visit() methods should NOT be called directly.</p>
*/
public class CorrelatedReferenceCollectorVisitor extends LanguageVisitor {
// index of the reference on the language object
- private Collection groupSymbols;
- private List references;
+ private Collection<GroupSymbol> groupSymbols;
+ private List<Reference> references;
- public CorrelatedReferenceCollectorVisitor(Collection groupSymbols, List correlatedReferences) {
+ public CorrelatedReferenceCollectorVisitor(Collection<GroupSymbol> groupSymbols, List<Reference> correlatedReferences) {
this.groupSymbols = groupSymbols;
this.references = correlatedReferences;
}
- public List getReferences(){
+ public List<Reference> getReferences(){
return this.references;
}
@@ -61,14 +61,14 @@
* @param obj Language object
*/
public void visit(Reference obj) {
- Expression expr = obj.getExpression();
- if (expr instanceof ElementSymbol){
- ElementSymbol e = (ElementSymbol)expr;
- GroupSymbol g = e.getGroupSymbol();
- if (this.groupSymbols.contains(g) && e.isExternalReference()){
- this.references.add(obj);
- }
+ ElementSymbol e = obj.getExpression();
+ if (e == null) {
+ return;
}
+ GroupSymbol g = e.getGroupSymbol();
+ if (this.groupSymbols.contains(g) && e.isExternalReference()){
+ this.references.add(obj);
+ }
}
/**
@@ -78,7 +78,7 @@
* that the client (outer query) is interested in references to from the correlated subquery
* @param correlatedReferences List of References collected
*/
- public static final void collectReferences(LanguageObject obj, Collection groupSymbols, List correlatedReferences){
+ public static final void collectReferences(LanguageObject obj, Collection<GroupSymbol> groupSymbols, List<Reference> correlatedReferences){
CorrelatedReferenceCollectorVisitor visitor =
new CorrelatedReferenceCollectorVisitor(groupSymbols, correlatedReferences);
Modified: trunk/engine/src/main/java/com/metamatrix/query/sql/visitor/EvaluateExpressionVisitor.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/sql/visitor/EvaluateExpressionVisitor.java 2009-04-27 16:49:34 UTC (rev 845)
+++ trunk/engine/src/main/java/com/metamatrix/query/sql/visitor/EvaluateExpressionVisitor.java 2009-04-27 19:02:50 UTC (rev 846)
@@ -29,7 +29,7 @@
import com.metamatrix.api.exception.query.ExpressionEvaluationException;
import com.metamatrix.core.MetaMatrixRuntimeException;
import com.metamatrix.query.eval.Evaluator;
-import com.metamatrix.query.eval.LookupEvaluator;
+import com.metamatrix.query.processor.ProcessorDataManager;
import com.metamatrix.query.sql.LanguageObject;
import com.metamatrix.query.sql.navigator.DeepPostOrderNavigator;
import com.metamatrix.query.sql.navigator.PostOrderNavigator;
@@ -51,7 +51,7 @@
public class EvaluateExpressionVisitor extends ExpressionMappingVisitor {
private CommandContext context;
- private LookupEvaluator dataMgr;
+ private ProcessorDataManager dataMgr;
EvaluateExpressionVisitor() {
super(null);
@@ -106,7 +106,7 @@
return EvaluatableVisitor.isEvaluatable(obj, duringPlanning?EvaluationLevel.PLANNING:EvaluationLevel.PROCESSING);
}
- public static final void replaceExpressions(LanguageObject obj, boolean deep, LookupEvaluator dataMgr, CommandContext context)
+ public static final void replaceExpressions(LanguageObject obj, boolean deep, ProcessorDataManager dataMgr, CommandContext context)
throws ExpressionEvaluationException, MetaMatrixComponentException {
EvaluateExpressionVisitor visitor = new EvaluateExpressionVisitor();
visitor.setContext(context);
Modified: trunk/engine/src/main/java/com/metamatrix/query/sql/visitor/ValueIteratorProviderCollectorVisitor.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/sql/visitor/ValueIteratorProviderCollectorVisitor.java 2009-04-27 16:49:34 UTC (rev 845)
+++ trunk/engine/src/main/java/com/metamatrix/query/sql/visitor/ValueIteratorProviderCollectorVisitor.java 2009-04-27 19:02:50 UTC (rev 846)
@@ -24,7 +24,7 @@
import java.util.ArrayList;
import java.util.Collection;
-import java.util.Iterator;
+import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
@@ -32,6 +32,7 @@
import com.metamatrix.query.sql.LanguageVisitor;
import com.metamatrix.query.sql.lang.ExistsCriteria;
import com.metamatrix.query.sql.lang.SubqueryCompareCriteria;
+import com.metamatrix.query.sql.lang.SubqueryContainer;
import com.metamatrix.query.sql.lang.SubquerySetCriteria;
import com.metamatrix.query.sql.navigator.PreOrderNavigator;
import com.metamatrix.query.sql.symbol.ScalarSubquery;
@@ -49,14 +50,14 @@
*/
public class ValueIteratorProviderCollectorVisitor extends LanguageVisitor {
- private List valueIteratorProviders;
+ private List<SubqueryContainer> valueIteratorProviders;
/**
* Construct a new visitor with the default collection type, which is a
* {@link java.util.ArrayList}.
*/
public ValueIteratorProviderCollectorVisitor() {
- this.valueIteratorProviders = new ArrayList();
+ this.valueIteratorProviders = new ArrayList<SubqueryContainer>();
}
/**
@@ -64,7 +65,7 @@
* ValueIteratorProvider instances
* @param valueIteratorProviders Collection to accumulate found
*/
- ValueIteratorProviderCollectorVisitor(List valueIteratorProviders) {
+ ValueIteratorProviderCollectorVisitor(List<SubqueryContainer> valueIteratorProviders) {
this.valueIteratorProviders = valueIteratorProviders;
}
@@ -74,7 +75,7 @@
* @return Collection of {@link com.metamatrix.sql.util.ValueIteratorProvider}
* (by default, this is a java.util.ArrayList)
*/
- public List getValueIteratorProviders() {
+ public List<SubqueryContainer> getValueIteratorProviders() {
return this.valueIteratorProviders;
}
@@ -119,23 +120,24 @@
* @param obj Language object
* @return java.util.ArrayList of found ValueIteratorProvider
*/
- public static final List getValueIteratorProviders(LanguageObject obj) {
+ public static final List<SubqueryContainer> getValueIteratorProviders(LanguageObject obj) {
ValueIteratorProviderCollectorVisitor visitor = new ValueIteratorProviderCollectorVisitor();
PreOrderNavigator.doVisit(obj, visitor);
return visitor.getValueIteratorProviders();
}
- public static final void getValueIteratorProviders(LanguageObject obj, List valueIteratorProviders) {
+ public static final void getValueIteratorProviders(LanguageObject obj, List<SubqueryContainer> valueIteratorProviders) {
ValueIteratorProviderCollectorVisitor visitor = new ValueIteratorProviderCollectorVisitor(valueIteratorProviders);
PreOrderNavigator.doVisit(obj, visitor);
}
- public static final List getValueIteratorProviders(Collection<? extends LanguageObject> languageObjects) {
- List result = new LinkedList();
+ public static final List<SubqueryContainer> getValueIteratorProviders(Collection<? extends LanguageObject> languageObjects) {
+ if (languageObjects == null || languageObjects.isEmpty()) {
+ return Collections.emptyList();
+ }
+ List<SubqueryContainer> result = new LinkedList<SubqueryContainer>();
ValueIteratorProviderCollectorVisitor visitor = new ValueIteratorProviderCollectorVisitor(result);
- Iterator i = languageObjects.iterator();
- while (i.hasNext()) {
- LanguageObject obj = (LanguageObject)i.next();
+ for (LanguageObject obj : languageObjects) {
PreOrderNavigator.doVisit(obj, visitor);
}
return result;
Modified: trunk/engine/src/main/java/com/metamatrix/query/validator/AbstractValidationVisitor.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/validator/AbstractValidationVisitor.java 2009-04-27 16:49:34 UTC (rev 845)
+++ trunk/engine/src/main/java/com/metamatrix/query/validator/AbstractValidationVisitor.java 2009-04-27 19:02:50 UTC (rev 846)
@@ -48,6 +48,8 @@
private QueryMetadataInterface metadata;
+ protected Command currentCommand;
+
public AbstractValidationVisitor() {
this.report = new ValidatorReport();
}
@@ -65,7 +67,7 @@
* not wipe the report.
*/
public void reset() {
- //nothing to do here
+ this.currentCommand = null;
}
// ######################### Store results info #########################
Modified: trunk/engine/src/main/java/com/metamatrix/query/validator/ValidationVisitor.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/validator/ValidationVisitor.java 2009-04-27 16:49:34 UTC (rev 845)
+++ trunk/engine/src/main/java/com/metamatrix/query/validator/ValidationVisitor.java 2009-04-27 19:02:50 UTC (rev 846)
@@ -76,7 +76,6 @@
import com.metamatrix.query.sql.lang.SetQuery.Operation;
import com.metamatrix.query.sql.navigator.PreOrderNavigator;
import com.metamatrix.query.sql.proc.AssignmentStatement;
-import com.metamatrix.query.sql.proc.CommandStatement;
import com.metamatrix.query.sql.proc.CreateUpdateProcedureCommand;
import com.metamatrix.query.sql.proc.CriteriaSelector;
import com.metamatrix.query.sql.proc.DeclareStatement;
@@ -92,7 +91,6 @@
import com.metamatrix.query.sql.symbol.ExpressionSymbol;
import com.metamatrix.query.sql.symbol.Function;
import com.metamatrix.query.sql.symbol.GroupSymbol;
-import com.metamatrix.query.sql.symbol.Reference;
import com.metamatrix.query.sql.symbol.SingleElementSymbol;
import com.metamatrix.query.sql.util.SymbolMap;
import com.metamatrix.query.sql.visitor.AggregateSymbolCollectorVisitor;
@@ -112,13 +110,9 @@
// update procedure being validated
private CreateUpdateProcedureCommand updateProc;
- // current procedure subCommand being visited that
- // may contain TranslateCriteria
- private Command transCommand;
public void reset() {
super.reset();
- this.transCommand = null;
this.isXML = false;
this.updateProc = null;
}
@@ -335,11 +329,8 @@
}
if(obj.hasCommand()) {
- // set state command on this may contain translate criteria
- this.transCommand = obj.getCommand();
+ Collection projSymbols = obj.getCommand().getProjectedSymbols();
- Collection projSymbols = transCommand.getProjectedSymbols();
-
//The command execution should result is a value that is assigned to the variable
// there cannot be more than one column in its results
if(projSymbols.size() != 1) {
@@ -352,18 +343,9 @@
handleValidationError(QueryPlugin.Util.getString(ErrorMessageKeys.VALIDATOR_0014), obj);
}
}
- } else if (obj.hasExpression()) {
- if (!CommandCollectorVisitor.getCommands(obj.getExpression()).isEmpty()) {
- handleValidationError(QueryPlugin.Util.getString("ValidationVisitor.assignment_subquery"), obj); //$NON-NLS-1$
- }
- }
+ }
}
- public void visit(CommandStatement obj) {
- // set state command on this may contain translate criteria
- this.transCommand = obj.getCommand();
- }
-
public void visit(CreateUpdateProcedureCommand obj) {
if(!obj.isUpdateProcedure()){
//Every virtual procedure should have at least one query.
@@ -430,10 +412,6 @@
}
}
}
-
- if (!CommandCollectorVisitor.getCommands(criteria).isEmpty()) {
- handleValidationError(QueryPlugin.Util.getString("ValidationVisitor.if_subquery"), obj); //$NON-NLS-1$
- }
}
public void visit(TranslateCriteria obj) {
@@ -504,8 +482,7 @@
* the translated criteria.
*/
protected void validateTranslateCriteria(TranslateCriteria obj) {
- // only possibility, used in If statement which will be invalidated during visitation process
- if(this.transCommand == null) {
+ if(this.currentCommand == null) {
return;
}
Map symbolMap = this.updateProc.getSymbolMap();
@@ -532,7 +509,7 @@
}
Collection transleElmnts = ElementCollectorVisitor.getElements(obj, true);
- Collection groups = GroupCollectorVisitor.getGroups(this.transCommand, true);
+ Collection groups = GroupCollectorVisitor.getGroups(this.currentCommand, true);
int selectType = obj.getSelector().getSelectorType();
Iterator critIter = PredicateCollectorVisitor.getPredicates(userCrit).iterator();
@@ -1034,9 +1011,6 @@
if (obj.getIntoGroup() != null) {
validateInto(obj, obj.getAsColumns(), obj.getIntoGroup());
}
- if (!CommandCollectorVisitor.getCommands(obj).isEmpty()) {
- handleValidationError(QueryPlugin.Util.getString("ValidationVisitor.assignment_subquery"), obj); //$NON-NLS-1$
- }
if (obj.getUsing() != null) {
validateSetClauseList(obj.getUsing());
}
Modified: trunk/engine/src/main/java/com/metamatrix/query/validator/Validator.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/validator/Validator.java 2009-04-27 16:49:34 UTC (rev 845)
+++ trunk/engine/src/main/java/com/metamatrix/query/validator/Validator.java 2009-04-27 19:02:50 UTC (rev 846)
@@ -56,7 +56,7 @@
}
// Recursively validate subcommands
- Iterator iter = CommandCollectorVisitor.getCommands(object, validateOnlyEmbedded).iterator();
+ Iterator iter = CommandCollectorVisitor.getCommands((Command)object, validateOnlyEmbedded).iterator();
while(iter.hasNext()) {
Command subCommand = (Command) iter.next();
validate(subCommand, metadata, visitor, validateOnlyEmbedded);
@@ -83,7 +83,7 @@
protected void visitNode(LanguageObject obj) {
QueryMetadataInterface previous = visitor.getMetadata();
- setTempMetadata(metadata, visitor, obj);
+ setTempMetadata(metadata, visitor, obj);
super.visitNode(obj);
visitor.setMetadata(previous);
}
@@ -102,7 +102,8 @@
final AbstractValidationVisitor visitor,
LanguageObject obj) {
if (obj instanceof Command) {
- Command command = (Command)obj;
+ Command command = (Command)obj;
+ visitor.currentCommand = command;
Map tempMetadata = command.getTemporaryMetadata();
if(tempMetadata != null && !tempMetadata.isEmpty()) {
visitor.setMetadata(new TempMetadataAdapter(metadata, new TempMetadataStore(tempMetadata)));
Modified: trunk/engine/src/main/java/org/teiid/dqp/internal/process/DQPCore.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/internal/process/DQPCore.java 2009-04-27 16:49:34 UTC (rev 845)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/process/DQPCore.java 2009-04-27 19:02:50 UTC (rev 846)
@@ -84,6 +84,7 @@
import com.metamatrix.dqp.util.LogConstants;
import com.metamatrix.query.metadata.QueryMetadataInterface;
import com.metamatrix.query.optimizer.capabilities.SourceCapabilities;
+import com.metamatrix.query.processor.ProcessorDataManager;
import com.metamatrix.query.sql.lang.Command;
import com.metamatrix.server.serverapi.RequestInfo;
import com.metamatrix.vdb.runtime.VDBKey;
@@ -130,7 +131,7 @@
// Resources
private ConnectorCapabilitiesCache connectorCapabilitiesCache = new ConnectorCapabilitiesCache();
private BufferManager bufferManager;
- private DataTierManager dataTierMgr;
+ private ProcessorDataManager dataTierMgr;
private PreparedPlanCache prepPlanCache;
private TrackingService tracker;
private TransactionService transactionService;
@@ -539,11 +540,11 @@
rowCount);
}
- DataTierManager getDataTierManager() {
+ ProcessorDataManager getDataTierManager() {
return this.dataTierMgr;
}
- public void setDataTierManager(DataTierManager dataTierMgr) {
+ public void setDataTierManager(ProcessorDataManager dataTierMgr) {
this.dataTierMgr = dataTierMgr;
}
@@ -634,7 +635,6 @@
dataTierMgr = new DataTierManagerImpl(this,
(DataService) env.findService(DQPServiceNames.DATA_SERVICE),
- (MetadataService) env.findService(DQPServiceNames.METADATA_SERVICE),
(VDBService) env.findService(DQPServiceNames.VDB_SERVICE),
(BufferService) env.findService(DQPServiceNames.BUFFER_SERVICE),
this.maxCodeTables,
Deleted: trunk/engine/src/main/java/org/teiid/dqp/internal/process/DataTierManager.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/internal/process/DataTierManager.java 2009-04-27 16:49:34 UTC (rev 845)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/process/DataTierManager.java 2009-04-27 19:02:50 UTC (rev 846)
@@ -1,31 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package org.teiid.dqp.internal.process;
-
-import com.metamatrix.query.processor.ProcessorDataManager;
-
-public interface DataTierManager extends ProcessorDataManager {
-
- void clearCodeTables();
-
-}
\ No newline at end of file
Modified: trunk/engine/src/main/java/org/teiid/dqp/internal/process/DataTierManagerImpl.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/internal/process/DataTierManagerImpl.java 2009-04-27 16:49:34 UTC (rev 845)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/process/DataTierManagerImpl.java 2009-04-27 19:02:50 UTC (rev 846)
@@ -44,15 +44,15 @@
import com.metamatrix.dqp.message.RequestMessage;
import com.metamatrix.dqp.service.BufferService;
import com.metamatrix.dqp.service.DataService;
-import com.metamatrix.dqp.service.MetadataService;
import com.metamatrix.dqp.service.VDBService;
import com.metamatrix.dqp.util.LogConstants;
+import com.metamatrix.query.processor.ProcessorDataManager;
import com.metamatrix.query.processor.QueryProcessor;
import com.metamatrix.query.sql.ReservedWords;
import com.metamatrix.query.sql.lang.Command;
import com.metamatrix.query.util.CommandContext;
-public class DataTierManagerImpl implements DataTierManager {
+public class DataTierManagerImpl implements ProcessorDataManager {
// Resources
private DQPCore requestMgr;
@@ -67,9 +67,8 @@
private CodeTableCache codeTableCache;
public DataTierManagerImpl(DQPCore requestMgr,
- DataService dataService, MetadataService metadataService, VDBService vdbService,
- BufferService bufferService, int maxCodeTables,
- int maxCodeTableRecords) {
+ DataService dataService, VDBService vdbService, BufferService bufferService,
+ int maxCodeTables, int maxCodeTableRecords) {
this.requestMgr = requestMgr;
this.dataService = dataService;
Modified: trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestLimit.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestLimit.java 2009-04-27 16:49:34 UTC (rev 845)
+++ trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestLimit.java 2009-04-27 19:02:50 UTC (rev 846)
@@ -29,6 +29,8 @@
import com.metamatrix.common.types.DataTypeManager;
import com.metamatrix.query.mapping.relational.QueryNode;
+import com.metamatrix.query.optimizer.TestOptimizer.DependentProjectNode;
+import com.metamatrix.query.optimizer.TestOptimizer.DependentSelectNode;
import com.metamatrix.query.optimizer.capabilities.BasicSourceCapabilities;
import com.metamatrix.query.optimizer.capabilities.FakeCapabilitiesFinder;
import com.metamatrix.query.optimizer.capabilities.SourceCapabilities.Capability;
@@ -37,8 +39,6 @@
import com.metamatrix.query.processor.TestProcessor;
import com.metamatrix.query.processor.relational.AccessNode;
import com.metamatrix.query.processor.relational.DependentAccessNode;
-import com.metamatrix.query.processor.relational.DependentProjectNode;
-import com.metamatrix.query.processor.relational.DependentSelectNode;
import com.metamatrix.query.processor.relational.DupRemoveNode;
import com.metamatrix.query.processor.relational.GroupingNode;
import com.metamatrix.query.processor.relational.LimitNode;
@@ -79,7 +79,7 @@
0 // UnionAll
};
- public static final Class[] NODE_TYPES = new Class[] {
+ public static final Class<?>[] NODE_TYPES = new Class[] {
AccessNode.class,
DependentAccessNode.class,
DependentSelectNode.class,
Modified: trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestOptimizer.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestOptimizer.java 2009-04-27 16:49:34 UTC (rev 845)
+++ trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestOptimizer.java 2009-04-27 19:02:50 UTC (rev 846)
@@ -30,10 +30,10 @@
import java.util.List;
import java.util.Set;
-import org.teiid.connector.api.SourceSystemFunctions;
-
import junit.framework.TestCase;
+import org.teiid.connector.api.SourceSystemFunctions;
+
import com.metamatrix.api.exception.MetaMatrixComponentException;
import com.metamatrix.api.exception.MetaMatrixException;
import com.metamatrix.api.exception.query.QueryParserException;
@@ -58,8 +58,6 @@
import com.metamatrix.query.processor.ProcessorPlan;
import com.metamatrix.query.processor.relational.AccessNode;
import com.metamatrix.query.processor.relational.DependentAccessNode;
-import com.metamatrix.query.processor.relational.DependentProjectNode;
-import com.metamatrix.query.processor.relational.DependentSelectNode;
import com.metamatrix.query.processor.relational.DupRemoveNode;
import com.metamatrix.query.processor.relational.GroupingNode;
import com.metamatrix.query.processor.relational.JoinNode;
@@ -80,6 +78,7 @@
import com.metamatrix.query.sql.lang.Command;
import com.metamatrix.query.sql.symbol.GroupSymbol;
import com.metamatrix.query.sql.visitor.GroupCollectorVisitor;
+import com.metamatrix.query.sql.visitor.ValueIteratorProviderCollectorVisitor;
import com.metamatrix.query.unittest.FakeMetadataFacade;
import com.metamatrix.query.unittest.FakeMetadataFactory;
import com.metamatrix.query.unittest.FakeMetadataObject;
@@ -91,6 +90,8 @@
public class TestOptimizer extends TestCase {
public interface DependentJoin {}
+ public interface DependentSelectNode {}
+ public interface DependentProjectNode {}
public static final int[] FULL_PUSHDOWN = new int[] {
1, // Access
@@ -417,8 +418,8 @@
* @param relationalNode
* @return int[]
*/
- public static void collectCounts(RelationalNode relationalNode, int[] counts, Class[] types) {
- Class nodeType = relationalNode.getClass();
+ public static void collectCounts(RelationalNode relationalNode, int[] counts, Class<?>[] types) {
+ Class<?> nodeType = relationalNode.getClass();
if(nodeType.equals(JoinNode.class)) {
if (((JoinNode)relationalNode).getJoinStrategy() instanceof NestedLoopJoinStrategy) {
updateCounts(NestedLoopJoinStrategy.class, counts, types);
@@ -428,7 +429,19 @@
if (((JoinNode)relationalNode).isDependent()) {
updateCounts(DependentJoin.class, counts, types);
}
- }else {
+ }else if (nodeType.equals(ProjectNode.class)){
+ if (ValueIteratorProviderCollectorVisitor.getValueIteratorProviders(((ProjectNode)relationalNode).getSelectSymbols()).isEmpty()) {
+ updateCounts(ProjectNode.class, counts, types);
+ } else {
+ updateCounts(DependentProjectNode.class, counts, types);
+ }
+ }else if (nodeType.equals(SelectNode.class)){
+ if (ValueIteratorProviderCollectorVisitor.getValueIteratorProviders(((SelectNode)relationalNode).getCriteria()).isEmpty()) {
+ updateCounts(SelectNode.class, counts, types);
+ } else {
+ updateCounts(DependentSelectNode.class, counts, types);
+ }
+ } else {
updateCounts(nodeType, counts, types);
}
@@ -1862,7 +1875,7 @@
public void testPushOuterJoin1() {
FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
- BasicSourceCapabilities caps = new BasicSourceCapabilities();
+ BasicSourceCapabilities caps = getTypicalCapabilities();
caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN, true);
caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_OUTER, true);
capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
@@ -6585,47 +6598,6 @@
checkSubPlanCount(plan, 0);
}
- /*
- * Expressions containing subqueries cannot be pushed down
- */
- public void testCase4306() {
- FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
- FakeMetadataFacade metadata = example1();
-
- BasicSourceCapabilities caps = getTypicalCapabilities();
- caps.setCapabilitySupport(Capability.QUERY_WHERE, true);
- caps.setCapabilitySupport(Capability.QUERY_SUBQUERIES_CORRELATED, true);
- caps.setCapabilitySupport(Capability.QUERY_SUBQUERIES_SCALAR, true);
- caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
- caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_MAX, true);
- caps.setCapabilitySupport(Capability.FUNCTION, true);
- caps.setFunctionSupport("+", true); //$NON-NLS-1$
- caps.setFunctionSupport("convert", true); //$NON-NLS-1$
- capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
-
- ProcessorPlan plan = helpPlan("select pm1.g1.e1, convert((select max(vm1.g1.e1) from vm1.g1), integer) + 1 from pm1.g1", metadata, //$NON-NLS-1$
- null, capFinder,
- new String[] { "SELECT pm1.g1.e1 FROM pm1.g1" }, SHOULD_SUCCEED); //$NON-NLS-1$
- checkNodeTypes(plan, new int[] {
- 1, // Access
- 0, // DependentAccess
- 0, // DependentSelect
- 1, // DependentProject
- 0, // DupRemove
- 0, // Grouping
- 0, // Join
- 0, // MergeJoin
- 0, // Null
- 0, // PlanExecution
- 0, // Project
- 0, // Select
- 0, // Sort
- 0 // UnionAll
- });
-
- checkSubPlanCount(plan, 1);
- }
-
public void testCase4312() {
FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
BasicSourceCapabilities caps = getTypicalCapabilities();
@@ -6818,7 +6790,7 @@
*/
public void testSameConnector() {
FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
- BasicSourceCapabilities caps = new BasicSourceCapabilities();
+ BasicSourceCapabilities caps = getTypicalCapabilities();
caps.setCapabilitySupport(Capability.QUERY_WHERE, true);
caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN, true);
caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_OUTER, true);
Modified: trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestRuleMergeVirtual.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestRuleMergeVirtual.java 2009-04-27 16:49:34 UTC (rev 845)
+++ trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestRuleMergeVirtual.java 2009-04-27 19:02:50 UTC (rev 846)
@@ -354,7 +354,7 @@
// Create capabilities
FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
- BasicSourceCapabilities caps = new BasicSourceCapabilities();
+ BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_COUNT, true);
caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_COUNT_STAR, true);
Modified: trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestSubqueryPushdown.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestSubqueryPushdown.java 2009-04-27 16:49:34 UTC (rev 845)
+++ trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestSubqueryPushdown.java 2009-04-27 19:02:50 UTC (rev 846)
@@ -173,7 +173,7 @@
"(c37s.stringkey = ('1' || (m37s.intkey || '0'))) AND " + //$NON-NLS-1$
"(m37s.stringkey = m37n.stringkey) ))"; //$NON-NLS-1$
- String sqlOut = "SELECT c37n.intkey FROM bqt1.mediuma AS c37n, bqt1.smallb AS m37n WHERE (c37n.datevalue = (SELECT MAX(c37s.datevalue) FROM bqt1.mediuma AS c37s, bqt1.smallb AS m37s WHERE (c37s.stringkey = ('1' || (m37s.intkey || '0'))) AND (m37s.stringkey LIKE '%0') AND (m37s.stringkey = m37n.stringkey))) AND (c37n.stringkey = ('1' || (m37n.intkey || '0'))) AND (m37n.stringkey LIKE '%0')"; //$NON-NLS-1$
+ String sqlOut = "SELECT g_0.intkey FROM bqt1.mediuma AS g_0, bqt1.smallb AS g_1 WHERE (g_0.stringkey = concat('1', concat(g_1.intkey, '0'))) AND (g_0.datevalue = (SELECT MAX(g_2.datevalue) FROM bqt1.mediuma AS g_2, bqt1.smallb AS g_3 WHERE (g_2.stringkey = concat('1', concat(g_3.intkey, '0'))) AND (g_3.stringkey LIKE '%0') AND (g_3.stringkey = g_1.stringkey))) AND (g_1.stringkey LIKE '%0')"; //$NON-NLS-1$
ProcessorPlan plan = helpPlan(sqlIn, FakeMetadataFactory.exampleBQTCached(),
null, capFinder,
@@ -716,5 +716,32 @@
new String[] { "SELECT g_0.intkey FROM bqt1.smalla AS g_0 WHERE (g_0.intkey = (SELECT MAX(g_1.intkey) FROM bqt1.smallb AS g_1 WHERE g_1.stringkey = g_0.stringkey)) OR (g_0.intkey = (SELECT MIN(g_2.IntKey) FROM bqt1.smallb AS g_2 WHERE g_2.StringKey = g_0.stringkey))" }, SHOULD_SUCCEED); //$NON-NLS-1$
checkNodeTypes(plan, FULL_PUSHDOWN);
}
+
+ /*
+ * Expressions containing subqueries can be pushed down
+ */
+ @Test public void testProjectSubqueryPushdown() {
+ FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+ FakeMetadataFacade metadata = example1();
+
+ BasicSourceCapabilities caps = getTypicalCapabilities();
+ caps.setCapabilitySupport(Capability.QUERY_WHERE, true);
+ caps.setCapabilitySupport(Capability.QUERY_SUBQUERIES_CORRELATED, true);
+ caps.setCapabilitySupport(Capability.QUERY_SUBQUERIES_SCALAR, true);
+ caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
+ caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_MAX, true);
+ caps.setCapabilitySupport(Capability.FUNCTION, true);
+ caps.setFunctionSupport("+", true); //$NON-NLS-1$
+ caps.setFunctionSupport("convert", true); //$NON-NLS-1$
+ capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+ ProcessorPlan plan = helpPlan("select pm1.g1.e1, convert((select max(vm1.g1.e1) from vm1.g1), integer) + 1 from pm1.g1", metadata, //$NON-NLS-1$
+ null, capFinder,
+ new String[] { "SELECT g_0.e1, (convert((SELECT MAX(g_1.e1) FROM pm1.g1 AS g_1), integer) + 1) FROM pm1.g1 AS g_0" }, SHOULD_SUCCEED); //$NON-NLS-1$
+ checkNodeTypes(plan, FULL_PUSHDOWN);
+
+ checkSubPlanCount(plan, 0);
+ }
+
}
Modified: trunk/engine/src/test/java/com/metamatrix/query/processor/FakeDataManager.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/processor/FakeDataManager.java 2009-04-27 16:49:34 UTC (rev 845)
+++ trunk/engine/src/test/java/com/metamatrix/query/processor/FakeDataManager.java 2009-04-27 19:02:50 UTC (rev 846)
@@ -23,13 +23,10 @@
package com.metamatrix.query.processor;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
-import java.util.Set;
import com.metamatrix.api.exception.MetaMatrixComponentException;
import com.metamatrix.api.exception.query.CriteriaEvaluationException;
@@ -354,5 +351,10 @@
public void setBlockOnce() {
blockOnce = true;
}
+
+ @Override
+ public void clearCodeTables() {
+
+ }
}
\ No newline at end of file
Modified: trunk/engine/src/test/java/com/metamatrix/query/processor/HardcodedDataManager.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/processor/HardcodedDataManager.java 2009-04-27 16:49:34 UTC (rev 845)
+++ trunk/engine/src/test/java/com/metamatrix/query/processor/HardcodedDataManager.java 2009-04-27 19:02:50 UTC (rev 846)
@@ -29,8 +29,6 @@
import java.util.Map;
import java.util.Set;
-import org.teiid.dqp.internal.process.DataTierManager;
-
import com.metamatrix.api.exception.MetaMatrixComponentException;
import com.metamatrix.common.buffer.BlockedException;
import com.metamatrix.common.buffer.TupleSource;
@@ -42,7 +40,7 @@
* @since 4.2
*/
public class HardcodedDataManager implements
- DataTierManager {
+ ProcessorDataManager {
// sql string to data
private Map data = new HashMap();
Modified: trunk/engine/src/test/java/com/metamatrix/query/processor/eval/TestCriteriaEvaluator.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/processor/eval/TestCriteriaEvaluator.java 2009-04-27 16:49:34 UTC (rev 845)
+++ trunk/engine/src/test/java/com/metamatrix/query/processor/eval/TestCriteriaEvaluator.java 2009-04-27 19:02:50 UTC (rev 846)
@@ -33,6 +33,7 @@
import junit.framework.TestCase;
import com.metamatrix.api.exception.MetaMatrixComponentException;
+import com.metamatrix.api.exception.MetaMatrixProcessingException;
import com.metamatrix.api.exception.query.CriteriaEvaluationException;
import com.metamatrix.common.buffer.BlockedException;
import com.metamatrix.query.eval.Evaluator;
@@ -44,8 +45,8 @@
import com.metamatrix.query.sql.lang.Query;
import com.metamatrix.query.sql.lang.SetCriteria;
import com.metamatrix.query.sql.lang.SubqueryCompareCriteria;
+import com.metamatrix.query.sql.lang.SubqueryContainer;
import com.metamatrix.query.sql.symbol.Constant;
-import com.metamatrix.query.sql.symbol.ContextReference;
import com.metamatrix.query.sql.symbol.ElementSymbol;
import com.metamatrix.query.sql.util.ValueIterator;
import com.metamatrix.query.util.CommandContext;
@@ -101,14 +102,16 @@
elementMap.put(e1, new Integer(0));
List tuple = Arrays.asList(new String[]{"a"}); //$NON-NLS-1$
- CommandContext cc = new CommandContext() {
+ CommandContext cc = new CommandContext();
+ assertEquals(expectedResult, new Evaluator(elementMap, null, cc) {
@Override
- public ValueIterator getValueIterator(ContextReference ref)
- throws MetaMatrixComponentException {
+ protected ValueIterator evaluateSubquery(
+ SubqueryContainer container, List tuple)
+ throws MetaMatrixProcessingException, BlockedException,
+ MetaMatrixComponentException {
return new CollectionValueIterator(values);
}
- };
- assertEquals(expectedResult, new Evaluator(elementMap, null, cc).evaluate(crit, tuple));
+ }.evaluate(crit, tuple));
}
private SubqueryCompareCriteria helpGetCompareSubqueryCriteria(int operator, int predicateQuantifier){
Modified: trunk/engine/src/test/java/com/metamatrix/query/processor/eval/TestExpressionEvaluator.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/processor/eval/TestExpressionEvaluator.java 2009-04-27 16:49:34 UTC (rev 845)
+++ trunk/engine/src/test/java/com/metamatrix/query/processor/eval/TestExpressionEvaluator.java 2009-04-27 19:02:50 UTC (rev 846)
@@ -34,6 +34,7 @@
import com.metamatrix.api.exception.MetaMatrixComponentException;
import com.metamatrix.api.exception.MetaMatrixException;
+import com.metamatrix.api.exception.MetaMatrixProcessingException;
import com.metamatrix.api.exception.query.ExpressionEvaluationException;
import com.metamatrix.common.buffer.BlockedException;
import com.metamatrix.query.eval.Evaluator;
@@ -44,6 +45,7 @@
import com.metamatrix.query.sql.ReservedWords;
import com.metamatrix.query.sql.lang.CollectionValueIterator;
import com.metamatrix.query.sql.lang.Query;
+import com.metamatrix.query.sql.lang.SubqueryContainer;
import com.metamatrix.query.sql.symbol.AggregateSymbol;
import com.metamatrix.query.sql.symbol.CaseExpression;
import com.metamatrix.query.sql.symbol.Constant;
@@ -275,14 +277,16 @@
throws BlockedException,
MetaMatrixComponentException, ExpressionEvaluationException {
final CollectionValueIterator valueIter = new CollectionValueIterator(values);
- CommandContext cc = new CommandContext() {
+ CommandContext cc = new CommandContext();
+ assertEquals(expected, new Evaluator(Collections.emptyMap(), null, cc) {
@Override
- public ValueIterator getValueIterator(ContextReference ref)
- throws MetaMatrixComponentException {
+ protected ValueIterator evaluateSubquery(
+ SubqueryContainer container, List tuple)
+ throws MetaMatrixProcessingException, BlockedException,
+ MetaMatrixComponentException {
return valueIter;
}
- };
- assertEquals(expected, new Evaluator(Collections.emptyMap(), null, cc).evaluate(expr, null) );
+ }.evaluate(expr, null) );
}
public void testScalarSubquery2() throws Exception{
Modified: trunk/engine/src/test/java/com/metamatrix/query/processor/proc/TestProcedureProcessor.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/processor/proc/TestProcedureProcessor.java 2009-04-27 16:49:34 UTC (rev 845)
+++ trunk/engine/src/test/java/com/metamatrix/query/processor/proc/TestProcedureProcessor.java 2009-04-27 19:02:50 UTC (rev 846)
@@ -2580,6 +2580,58 @@
List[] expected = new List[] {Arrays.asList(new Object[] {new Integer(3)})};
helpTestProcess(plan, expected, dataMgr);
}
+
+ public void testDefect8693() throws Exception {
+ String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
+ procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
+ procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
+ procedure = procedure + "var1 = Select pm1.g1.e2 from pm1.g1 where e2 = 5;\n"; //$NON-NLS-1$
+ procedure = procedure + "if (5 in (select 5 from pm1.g1))\n"; //$NON-NLS-1$
+ procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
+ procedure = procedure + "ROWS_UPDATED = ROWS_UPDATED + var1;\n"; //$NON-NLS-1$
+ procedure = procedure + "END\n"; //$NON-NLS-1$
+ procedure = procedure + "END"; //$NON-NLS-1$
+
+ String userUpdateStr = "UPDATE vm1.g1 SET e1='x'"; //$NON-NLS-1$
+ FakeMetadataFacade metadata = FakeMetadataFactory.exampleUpdateProc(FakeMetadataObject.Props.UPDATE_PROCEDURE, procedure);
+ FakeDataManager dataMgr = exampleDataManager(metadata);
+ ProcessorPlan plan = getProcedurePlan(userUpdateStr, metadata);
+ helpTestProcess(plan, 5, dataMgr);
+ }
+
+ public void testWhileWithSubquery() throws Exception {
+ String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
+ procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
+ procedure = procedure + "DECLARE integer var1 = 2;\n"; //$NON-NLS-1$
+ procedure = procedure + "WHILE (5 in (select var1 from pm1.g1))\n"; //$NON-NLS-1$
+ procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
+ procedure = procedure + "ROWS_UPDATED = ROWS_UPDATED + var1;\n"; //$NON-NLS-1$
+ procedure = procedure + "END\n"; //$NON-NLS-1$
+ procedure = procedure + "END"; //$NON-NLS-1$
+
+ String userUpdateStr = "UPDATE vm1.g1 SET e1='x'"; //$NON-NLS-1$
+
+ FakeMetadataFacade metadata = FakeMetadataFactory.exampleUpdateProc(FakeMetadataObject.Props.UPDATE_PROCEDURE, procedure);
+ FakeDataManager dataMgr = exampleDataManager(metadata);
+ ProcessorPlan plan = getProcedurePlan(userUpdateStr, metadata);
+ helpTestProcess(plan, 0, dataMgr);
+ }
+
+ public void testDefect18404() throws Exception {
+ String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
+ procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
+ procedure = procedure + "DECLARE integer var1 = 5 + (select count(e2) from pm1.g1);\n"; //$NON-NLS-1$
+ procedure = procedure + "ROWS_UPDATED = ROWS_UPDATED + var1;\n"; //$NON-NLS-1$
+ procedure = procedure + "END"; //$NON-NLS-1$
+
+ String userUpdateStr = "UPDATE vm1.g1 SET e1='x'"; //$NON-NLS-1$
+
+ FakeMetadataFacade metadata = FakeMetadataFactory.exampleUpdateProc(FakeMetadataObject.Props.UPDATE_PROCEDURE, procedure);
+ FakeDataManager dataMgr = exampleDataManager(metadata);
+ ProcessorPlan plan = getProcedurePlan(userUpdateStr, metadata);
+ helpTestProcess(plan, 8, dataMgr);
+ }
+
private static final boolean DEBUG = false;
}
Modified: trunk/engine/src/test/java/com/metamatrix/query/processor/relational/TestAccessNode.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/processor/relational/TestAccessNode.java 2009-04-27 16:49:34 UTC (rev 845)
+++ trunk/engine/src/test/java/com/metamatrix/query/processor/relational/TestAccessNode.java 2009-04-27 19:02:50 UTC (rev 846)
@@ -110,6 +110,10 @@
assertEquals(expectedCommand, command.toString());
return null;
}
+ @Override
+ public void clearCodeTables() {
+
+ }
}
public void testShouldExecuteUpdate() throws Exception {
Modified: trunk/engine/src/test/java/com/metamatrix/query/processor/relational/TestBatchedUpdateNode.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/processor/relational/TestBatchedUpdateNode.java 2009-04-27 16:49:34 UTC (rev 845)
+++ trunk/engine/src/test/java/com/metamatrix/query/processor/relational/TestBatchedUpdateNode.java 2009-04-27 19:02:50 UTC (rev 846)
@@ -212,6 +212,10 @@
actualCommands.add(command);
return new FakeTupleSource(numExecutedCommands);
}
+ @Override
+ public void clearCodeTables() {
+
+ }
}
private static final class FakeTupleSource implements TupleSource {
private int currentTuple = 0;
Deleted: trunk/engine/src/test/java/com/metamatrix/query/processor/relational/TestDependentSelectNode.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/processor/relational/TestDependentSelectNode.java 2009-04-27 16:49:34 UTC (rev 845)
+++ trunk/engine/src/test/java/com/metamatrix/query/processor/relational/TestDependentSelectNode.java 2009-04-27 19:02:50 UTC (rev 846)
@@ -1,222 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package com.metamatrix.query.processor.relational;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import junit.framework.TestCase;
-
-import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.common.buffer.BlockedException;
-import com.metamatrix.common.buffer.BufferManager;
-import com.metamatrix.common.buffer.TupleBatch;
-import com.metamatrix.common.buffer.TupleSource;
-import com.metamatrix.query.processor.ProcessorDataManager;
-import com.metamatrix.query.processor.ProcessorPlan;
-import com.metamatrix.query.sql.lang.Command;
-import com.metamatrix.query.sql.lang.CompoundCriteria;
-import com.metamatrix.query.sql.lang.Criteria;
-import com.metamatrix.query.sql.lang.ExistsCriteria;
-import com.metamatrix.query.sql.lang.From;
-import com.metamatrix.query.sql.lang.Query;
-import com.metamatrix.query.sql.lang.Select;
-import com.metamatrix.query.sql.lang.SubqueryCompareCriteria;
-import com.metamatrix.query.sql.lang.SubquerySetCriteria;
-import com.metamatrix.query.sql.symbol.Constant;
-import com.metamatrix.query.sql.symbol.ElementSymbol;
-import com.metamatrix.query.sql.symbol.GroupSymbol;
-import com.metamatrix.query.util.CommandContext;
-
-/**
- * Tests {@link DependentSelectNode DependentSelectNode} class
- */
-public class TestDependentSelectNode extends TestCase {
-
- /**
- * Constructor for TestDependentSelectNode.
- * @param name
- */
- public TestDependentSelectNode(String name) {
- super(name);
- }
-
- //Just for testing clone() method of DependentSelectNode
- private static class DoNothingProcessorPlan implements ProcessorPlan{
- private DoNothingProcessorPlan original;
- public DoNothingProcessorPlan(){}
- public DoNothingProcessorPlan(DoNothingProcessorPlan original){
- this.original = original;
- }
- public Object clone() {return new DoNothingProcessorPlan(this);}
- public void close() throws MetaMatrixComponentException {}
- public void connectTupleSource(TupleSource source, int dataRequestID) {}
- public List getAndClearWarnings() {return null;}
- public List getOutputElements() {return null;}
- public void initialize(
- CommandContext context,
- ProcessorDataManager dataMgr,
- BufferManager bufferMgr) {}
- public CommandContext getContext() { return null; }
- public TupleBatch nextBatch()throws BlockedException, MetaMatrixComponentException{return null;}
- public void open() throws MetaMatrixComponentException {}
- public void reset() {}
- /* (non-Javadoc)
- * @see com.metamatrix.query.processor.ProcessorPlan#getUpdateCount()
- */
- public int getUpdateCount() {
- // TODO Auto-generated method stub
- return 0;
- }
- public Map getDescriptionProperties() {
- return new HashMap();
- }
- public Collection getChildPlans() {
- return Collections.EMPTY_LIST;
- }
-
- }
-
- private List helpMakeFakeProcessorPlans(int count){
- List result = new ArrayList(count);
- for (int i=0; i<count; i++){
- result.add(new DoNothingProcessorPlan());
- }
- return result;
- }
-
- private Command helpMakeCommand(){
- Select select = new Select();
- ElementSymbol element = new ElementSymbol("e2"); //$NON-NLS-1$
- select.addSymbol(element);
- From from = new From();
- GroupSymbol pm1g2 = new GroupSymbol("pm1.g2"); //$NON-NLS-1$
- from.addGroup(pm1g2);
- Query query = new Query();
- query.setSelect(select);
- query.setFrom(from);
- return query;
- }
-
- private Command helpMakeCommand2(){
- Select select = new Select();
- ElementSymbol element = new ElementSymbol("e3"); //$NON-NLS-1$
- select.addSymbol(element);
- From from = new From();
- GroupSymbol pm1g2 = new GroupSymbol("pm4.g5"); //$NON-NLS-1$
- from.addGroup(pm1g2);
- Query query = new Query();
- query.setSelect(select);
- query.setFrom(from);
- return query;
- }
-
- /**
- * Tests clone() method of DependentSelectNode
- */
- public void testClone(){
- int id = 1;
- Command subCommand = helpMakeCommand();
- subCommand.setProcessorPlan(new DoNothingProcessorPlan());
- Criteria subCrit = new SubquerySetCriteria(new Constant("3"), subCommand); //$NON-NLS-1$
- Command subCommand2 = helpMakeCommand2();
- subCommand2.setProcessorPlan(new DoNothingProcessorPlan());
- Criteria subCrit2 = new SubquerySetCriteria(new ElementSymbol("f"), subCommand2); //$NON-NLS-1$
- DependentSelectNode node = new DependentSelectNode(id, new SubqueryProcessorUtility(Arrays.asList(new DoNothingProcessorPlan(), new DoNothingProcessorPlan()), null, null));
- //Set up criteria
- CompoundCriteria crit = new CompoundCriteria();
- crit.addCriteria(subCrit);
- crit.addCriteria(subCrit2);
- crit.setOperator(CompoundCriteria.AND);
-// Criteria otherCrit = new IsNullCriteria(new ElementSymbol("fakeElement"));
-// crit.addCriteria(otherCrit);
- node.setCriteria(crit);
-
- //Test clone
- DependentSelectNode cloned = (DependentSelectNode)node.clone();
-
- List<? extends ProcessorPlan> originalProcessorPlans = node.getSubqueryProcessorUtility().getSubqueryPlans();
- List clonedProcessorPlans = cloned.getSubqueryProcessorUtility().getSubqueryPlans();
- assertTrue(clonedProcessorPlans.size() == 2);
- assertEquals(originalProcessorPlans.size(), clonedProcessorPlans.size());
- for (int i=0; i<originalProcessorPlans.size(); i++){
- //Check ProcessorPlans
- ProcessorPlan originalPlan = originalProcessorPlans.get(i);
- DoNothingProcessorPlan clonedPlan = (DoNothingProcessorPlan)clonedProcessorPlans.get(i);
- assertNotNull(clonedPlan.original);
- assertSame(originalPlan, clonedPlan.original);
- }
-
- }
-
- /**
- * Tests clone() method of DependentSelectNode
- */
- public void testClone2(){
- int id = 1;
- Command subCommand = helpMakeCommand();
- subCommand.setProcessorPlan(new DoNothingProcessorPlan());
- Criteria subCrit = new SubqueryCompareCriteria(new ElementSymbol("f"), subCommand, SubqueryCompareCriteria.EQ, SubqueryCompareCriteria.ANY); //$NON-NLS-1$
-
- Command subCommand2 = helpMakeCommand2();
- subCommand2.setProcessorPlan(new DoNothingProcessorPlan());
- Criteria subCrit2 = new ExistsCriteria(subCommand2);
-
- //Set up DependentSelectNode data
- List crits = new ArrayList(2);
- crits.add(subCrit);
- crits.add(subCrit2);
-
- DependentSelectNode node = new DependentSelectNode(id, new SubqueryProcessorUtility(Arrays.asList(new DoNothingProcessorPlan(), new DoNothingProcessorPlan()), null, null));
-
- //Set up criteria
- CompoundCriteria crit = new CompoundCriteria();
- crit.addCriteria(subCrit);
- crit.addCriteria(subCrit2);
- crit.setOperator(CompoundCriteria.AND);
-// Criteria otherCrit = new IsNullCriteria(new ElementSymbol("fakeElement"));
-// crit.addCriteria(otherCrit);
- node.setCriteria(crit);
-
- //Test clone
- DependentSelectNode cloned = (DependentSelectNode)node.clone();
-
- List originalProcessorPlans = node.getSubqueryProcessorUtility().getSubqueryPlans();
- List clonedProcessorPlans = cloned.getSubqueryProcessorUtility().getSubqueryPlans();
- assertTrue(clonedProcessorPlans.size() == 2);
- assertEquals(originalProcessorPlans.size(), clonedProcessorPlans.size());
- for (int i=0; i<originalProcessorPlans.size(); i++){
- //Check ProcessorPlans
- Object originalPlan = originalProcessorPlans.get(i);
- DoNothingProcessorPlan clonedPlan = (DoNothingProcessorPlan)clonedProcessorPlans.get(i);
- assertNotNull(clonedPlan.original);
- assertSame(originalPlan, clonedPlan.original);
- }
- }
-
-}
Modified: trunk/engine/src/test/java/com/metamatrix/query/processor/relational/TestProjectIntoNode.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/processor/relational/TestProjectIntoNode.java 2009-04-27 16:49:34 UTC (rev 845)
+++ trunk/engine/src/test/java/com/metamatrix/query/processor/relational/TestProjectIntoNode.java 2009-04-27 19:02:50 UTC (rev 846)
@@ -189,6 +189,10 @@
Object val = row.get(0);
assertEquals(new Integer(value), val);
}
+ @Override
+ public void clearCodeTables() {
+
+ }
}
private static final class FakeDataTupleSource implements TupleSource {
Modified: trunk/engine/src/test/java/com/metamatrix/query/rewriter/TestQueryRewriter.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/rewriter/TestQueryRewriter.java 2009-04-27 16:49:34 UTC (rev 845)
+++ trunk/engine/src/test/java/com/metamatrix/query/rewriter/TestQueryRewriter.java 2009-04-27 19:02:50 UTC (rev 846)
@@ -61,6 +61,7 @@
import com.metamatrix.query.sql.symbol.ElementSymbol;
import com.metamatrix.query.sql.symbol.ExpressionSymbol;
import com.metamatrix.query.sql.symbol.GroupSymbol;
+import com.metamatrix.query.sql.symbol.Reference;
import com.metamatrix.query.sql.symbol.SingleElementSymbol;
import com.metamatrix.query.sql.visitor.CorrelatedReferenceCollectorVisitor;
import com.metamatrix.query.unittest.FakeMetadataFacade;
@@ -1925,9 +1926,9 @@
Query query = (Query)helpTestRewriteCommand(sql, expected);
- List refs = new LinkedList();
+ List<Reference> refs = new LinkedList<Reference>();
- CorrelatedReferenceCollectorVisitor.collectReferences(query, Arrays.asList(new Object[] {new GroupSymbol("pm1.g1")}), refs);//$NON-NLS-1$
+ CorrelatedReferenceCollectorVisitor.collectReferences(query, Arrays.asList(new GroupSymbol("pm1.g1")), refs);//$NON-NLS-1$
assertEquals(1, refs.size());
}
Modified: trunk/engine/src/test/java/com/metamatrix/query/unittest/FakeMetadataFactory.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/unittest/FakeMetadataFactory.java 2009-04-27 16:49:34 UTC (rev 845)
+++ trunk/engine/src/test/java/com/metamatrix/query/unittest/FakeMetadataFactory.java 2009-04-27 19:02:50 UTC (rev 846)
@@ -30,6 +30,7 @@
import java.util.List;
import com.metamatrix.common.types.DataTypeManager;
+import com.metamatrix.common.types.DataTypeManager.DefaultDataClasses;
import com.metamatrix.dqp.message.ParameterInfo;
import com.metamatrix.query.mapping.relational.QueryNode;
import com.metamatrix.query.mapping.xml.MappingAttribute;
@@ -1043,7 +1044,7 @@
QueryNode vspqn48 = new QueryNode("vsp48", "CREATE VIRTUAL PROCEDURE BEGIN DECLARE string x; SELECT e1 FROM (EXEC pm1.sq2(pm1.vsp48.in)) as e; END"); //$NON-NLS-1$ //$NON-NLS-2$
FakeMetadataObject vsp48 = createVirtualProcedure("pm1.vsp48", pm1, Arrays.asList(new FakeMetadataObject[] { vsp48p1, vsp48p2 }), vspqn48); //$NON-NLS-1$
- FakeMetadataObject vsp49rs = createResultSet("pm1vsp49.rs", pm1, new String[] { "e1" }, new String[] { DataTypeManager.DefaultDataTypes.STRING }); //$NON-NLS-1$ //$NON-NLS-2$
+ FakeMetadataObject vsp49rs = createResultSet("pm1vsp49.rs", pm1, new String[] { "e1", "e2" }, new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.INTEGER }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
FakeMetadataObject vsp49p1 = createParameter("ret", 1, ParameterInfo.RESULT_SET, DataTypeManager.DefaultDataTypes.OBJECT, vsp49rs); //$NON-NLS-1$
QueryNode vspqn49 = new QueryNode("vsp49", "CREATE VIRTUAL PROCEDURE BEGIN DECLARE string x; x = 'b'; EXEC pm1.sq2(x); END"); //$NON-NLS-1$ //$NON-NLS-2$
FakeMetadataObject vsp49 = createVirtualProcedure("pm1.vsp49", pm1, Arrays.asList(new FakeMetadataObject[] { vsp49p1 }), vspqn49); //$NON-NLS-1$
Modified: trunk/engine/src/test/java/com/metamatrix/query/validator/TestValidator.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/validator/TestValidator.java 2009-04-27 16:49:34 UTC (rev 845)
+++ trunk/engine/src/test/java/com/metamatrix/query/validator/TestValidator.java 2009-04-27 19:02:50 UTC (rev 846)
@@ -419,12 +419,9 @@
// Get invalid objects from report
Collection actualObjs = new ArrayList();
report.collectInvalidObjects(actualObjs);
- //System.out.println(report);
- if(actualObjs.size() == 0) {
- fail("Expected some failures but got none for procedure = " + procedure); //$NON-NLS-1$
- }
+ assertTrue("Expected some failures but got none for procedure = " + procedure, !actualObjs.isEmpty()); //$NON-NLS-1$
} catch(MetaMatrixException e) {
- fail("Exception during validation (" + e.getClass().getName() + "): " + e.getMessage()); //$NON-NLS-1$ //$NON-NLS-2$
+ throw new RuntimeException(e);
}
}
@@ -1881,51 +1878,8 @@
store.addObject(virtualResultSet);
store.addObject(virtualStoredProcedure);
return new FakeMetadataFacade(store);
- }
+ }
- public void testDefect8693() throws Exception {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
- procedure = procedure + "var1 = Select pm1.g1.e2 from pm1.g1 where e2 = 5;\n"; //$NON-NLS-1$
- procedure = procedure + "if (5 in (select 5 from pm1.g1))\n"; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "ROWS_UPDATED = ROWS_UPDATED + var1;\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
- procedure = procedure + "END"; //$NON-NLS-1$
-
- String userUpdateStr = "UPDATE vm1.g1 SET e1='x'"; //$NON-NLS-1$
-
- helpFailProcedure(procedure, userUpdateStr, FakeMetadataObject.Props.UPDATE_PROCEDURE);
- }
-
- public void testWhileWithSubquery() throws Exception {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
- procedure = procedure + "WHILE (5 in (select 5 from pm1.g1))\n"; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "ROWS_UPDATED = ROWS_UPDATED + var1;\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
- procedure = procedure + "END"; //$NON-NLS-1$
-
- String userUpdateStr = "UPDATE vm1.g1 SET e1='x'"; //$NON-NLS-1$
-
- helpFailProcedure(procedure, userUpdateStr, FakeMetadataObject.Props.UPDATE_PROCEDURE);
- }
-
- public void testDefect18404() throws Exception {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "DECLARE integer var1 = 5 + (select count(e2) from pm1.g1);\n"; //$NON-NLS-1$
- procedure = procedure + "ROWS_UPDATED = ROWS_UPDATED + var1;\n"; //$NON-NLS-1$
- procedure = procedure + "END"; //$NON-NLS-1$
-
- String userUpdateStr = "UPDATE vm1.g1 SET e1='x'"; //$NON-NLS-1$
-
- helpFailProcedure(procedure, userUpdateStr, FakeMetadataObject.Props.UPDATE_PROCEDURE);
- }
-
public void testSelectIntoWithNull() {
helpValidate("SELECT null, null, null, null INTO pm1.g1 FROM pm1.g2", new String[] {}, FakeMetadataFactory.example1Cached()); //$NON-NLS-1$
}
Modified: trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestDataTierManager.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestDataTierManager.java 2009-04-27 16:49:34 UTC (rev 845)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestDataTierManager.java 2009-04-27 19:02:50 UTC (rev 846)
@@ -108,7 +108,6 @@
dtm = new DataTierManagerImpl(rm,
dataService,
- new MockSingleMetadataService(metadata),
vdbService,
bs,
1000,
Modified: trunk/test-integration/src/test/java/com/metamatrix/server/integration/TestTPCR.java
===================================================================
--- trunk/test-integration/src/test/java/com/metamatrix/server/integration/TestTPCR.java 2009-04-27 16:49:34 UTC (rev 845)
+++ trunk/test-integration/src/test/java/com/metamatrix/server/integration/TestTPCR.java 2009-04-27 19:02:50 UTC (rev 846)
@@ -212,7 +212,7 @@
ProcessorPlan plan = TestOptimizer.helpPlan("select S_ACCTBAL, S_NAME, N_NAME, P_PARTKEY, P_MFGR, S_ADDRESS, S_PHONE, S_COMMENT from (SELECT SUPPLIER.S_ACCTBAL, SUPPLIER.S_NAME, NATION.N_NAME, PART.P_PARTKEY, PART.P_MFGR, SUPPLIER.S_ADDRESS, SUPPLIER.S_PHONE, SUPPLIER.S_COMMENT FROM PART, SUPPLIER, PARTSUPP, NATION, REGION WHERE (PART.P_PARTKEY = PS_PARTKEY) AND (S_SUPPKEY = PS_SUPPKEY) AND (P_SIZE = 15) AND (P_TYPE LIKE '%BRASS') AND (S_NATIONKEY = N_NATIONKEY) AND (N_REGIONKEY = R_REGIONKEY) AND (R_NAME = 'EUROPE') AND (PS_SUPPLYCOST = (SELECT MIN(PS_SUPPLYCOST) FROM PARTSUPP, SUPPLIER, NATION, REGION WHERE (PART.P_PARTKEY = PS_PARTKEY) AND (S_SUPPKEY = PS_SUPPKEY) AND (S_NATIONKEY = N_NATIONKEY) AND (N_REGIONKEY = R_REGIONKEY) AND (R_NAME = 'EUROPE'))) ORDER BY SUPPLIER.S_ACCTBAL DESC, NATION.N_NAME, SUPPLIER.S_NAME, PART.P_PARTKEY) as x", //$NON-NLS-1$
METADATA, null, finder,
- new String[] {"SELECT g_1.S_ACCTBAL, g_1.S_NAME, g_3.N_NAME, g_0.P_PARTKEY, g_0.P_MFGR, g_1.S_ADDRESS, g_1.S_PHONE, g_1.S_COMMENT FROM TPCR_Oracle_9i.PART AS g_0, TPCR_Oracle_9i.SUPPLIER AS g_1, TPCR_Oracle_9i.PARTSUPP AS g_2, TPCR_Oracle_9i.NATION AS g_3, TPCR_Oracle_9i.REGION AS g_4 WHERE (g_2.PS_SUPPLYCOST = (SELECT MIN(g_5.PS_SUPPLYCOST) FROM TPCR_Oracle_9i.PARTSUPP AS g_5, TPCR_Oracle_9i.SUPPLIER AS g_6, TPCR_Oracle_9i.NATION AS g_7, TPCR_Oracle_9i.REGION AS g_8 WHERE (g_7.N_REGIONKEY = g_8.R_REGIONKEY) AND (g_8.R_NAME = 'EUROPE') AND (g_6.S_NATIONKEY = g_7.N_NATIONKEY) AND (g_6.S_SUPPKEY = g_5.PS_SUPPKEY) AND (g_5.PS_PARTKEY = g_0.P_PARTKEY))) AND (g_0.P_PARTKEY = g_2.PS_PARTKEY) AND (g_0.P_SIZE = 15.0) AND (g_0.P_TYPE LIKE '%BRASS') AND (g_1.S_NATIONKEY = g_3.N_NATIONKEY) AND (g_1.S_SUPPKEY = g_2.PS_SUPPKEY) AND (g_3.N_REGIONKEY = g_4.R_REGIONKEY) AND (g_4.R_NAME = 'EUROPE')"}, true); //$NON-NLS-1$
+ new String[] {"SELECT g_1.S_ACCTBAL, g_1.S_NAME, g_3.N_NAME, g_0.P_PARTKEY, g_0.P_MFGR, g_1.S_ADDRESS, g_1.S_PHONE, g_1.S_COMMENT FROM TPCR_Oracle_9i.PART AS g_0, TPCR_Oracle_9i.SUPPLIER AS g_1, TPCR_Oracle_9i.PARTSUPP AS g_2, TPCR_Oracle_9i.NATION AS g_3, TPCR_Oracle_9i.REGION AS g_4 WHERE (g_0.P_PARTKEY = g_2.PS_PARTKEY) AND (g_2.PS_SUPPLYCOST = (SELECT MIN(g_5.PS_SUPPLYCOST) FROM TPCR_Oracle_9i.PARTSUPP AS g_5, TPCR_Oracle_9i.SUPPLIER AS g_6, TPCR_Oracle_9i.NATION AS g_7, TPCR_Oracle_9i.REGION AS g_8 WHERE (g_7.N_REGIONKEY = g_8.R_REGIONKEY) AND (g_8.R_NAME = 'EUROPE') AND (g_6.S_NATIONKEY = g_7.N_NATIONKEY) AND (g_6.S_SUPPKEY = g_5.PS_SUPPKEY) AND (g_5.PS_PARTKEY = g_0.P_PARTKEY))) AND (g_0.P_SIZE = 15.0) AND (g_0.P_TYPE LIKE '%BRASS') AND (g_1.S_NATIONKEY = g_3.N_NATIONKEY) AND (g_1.S_SUPPKEY = g_2.PS_SUPPKEY) AND (g_3.N_REGIONKEY = g_4.R_REGIONKEY) AND (g_4.R_NAME = 'EUROPE')"}, true); //$NON-NLS-1$
TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);
}
15 years, 8 months
teiid SVN: r845 - trunk/soap/src/main/java/com/metamatrix/soap/servlet.
by teiid-commits@lists.jboss.org
Author: tejones
Date: 2009-04-27 12:49:34 -0400 (Mon, 27 Apr 2009)
New Revision: 845
Modified:
trunk/soap/src/main/java/com/metamatrix/soap/servlet/MMDiscoverWSDLServlet.java
trunk/soap/src/main/java/com/metamatrix/soap/servlet/MMGetVDBResourceServlet.java
trunk/soap/src/main/java/com/metamatrix/soap/servlet/MMGetWSDLServlet.java
Log:
TEIID-530 Modified import URL building to properly format for any WSDL creation scenario (pre-configured or dynamic).
Modified: trunk/soap/src/main/java/com/metamatrix/soap/servlet/MMDiscoverWSDLServlet.java
===================================================================
--- trunk/soap/src/main/java/com/metamatrix/soap/servlet/MMDiscoverWSDLServlet.java 2009-04-27 02:01:23 UTC (rev 844)
+++ trunk/soap/src/main/java/com/metamatrix/soap/servlet/MMDiscoverWSDLServlet.java 2009-04-27 16:49:34 UTC (rev 845)
@@ -83,7 +83,7 @@
List wsdlUrls = WebServiceUtil.getWSDLUrls(req.getScheme(),
req.getServerName(),
Integer.toString(req.getServerPort()),
- req.getContextPath(),
+ getApplicationContext(req.getContextPath()),
WebServiceUtil.WSDLUSER,
WebServiceUtil.WSDLPASSWORD,
serverInfo);
Modified: trunk/soap/src/main/java/com/metamatrix/soap/servlet/MMGetVDBResourceServlet.java
===================================================================
--- trunk/soap/src/main/java/com/metamatrix/soap/servlet/MMGetVDBResourceServlet.java 2009-04-27 02:01:23 UTC (rev 844)
+++ trunk/soap/src/main/java/com/metamatrix/soap/servlet/MMGetVDBResourceServlet.java 2009-04-27 16:49:34 UTC (rev 845)
@@ -214,16 +214,28 @@
* @param httpTypeString
* @return urlPrefix
*/
- private String buildUrlPrefix(HttpServletRequest req) {
+ protected String buildUrlPrefix(HttpServletRequest req) {
StringBuffer urlPrefix = new StringBuffer();
if (req.isSecure()){
- urlPrefix.append(WSDLServletUtil.HTTPS).append("://").append(req.getServerName()).append(":").append(WSDLServletUtil.getHttpsPort()); //$NON-NLS-1$ //$NON-NLS-2$
+ urlPrefix.append(WSDLServletUtil.HTTPS).append("://").append(req.getServerName()).append(":").append(WSDLServletUtil.getHttpsPort() + "/"); //$NON-NLS-1$ //$NON-NLS-2$
}else{
- urlPrefix.append(WSDLServletUtil.HTTP).append("://").append(req.getServerName()).append(":").append(WSDLServletUtil.getHttpPort()); //$NON-NLS-1$ //$NON-NLS-2$
- }
- urlPrefix.append(req.getContextPath());
+ urlPrefix.append(WSDLServletUtil.HTTP).append("://").append(req.getServerName()).append(":").append(WSDLServletUtil.getHttpPort() + "/"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ urlPrefix.append(getApplicationContext(req.getContextPath()));
+
return urlPrefix.toString();
- }
+ }
+
+ /**
+ * Returns the application context name value without slashes.
+ * @param context
+ * @return
+ */
+ public String getApplicationContext(String context) {
+
+ return context.replaceAll("/", "");
+ }
/**
* Get a JDBC connection. Will create a connection. It takes Userid, Password,
Modified: trunk/soap/src/main/java/com/metamatrix/soap/servlet/MMGetWSDLServlet.java
===================================================================
--- trunk/soap/src/main/java/com/metamatrix/soap/servlet/MMGetWSDLServlet.java 2009-04-27 02:01:23 UTC (rev 844)
+++ trunk/soap/src/main/java/com/metamatrix/soap/servlet/MMGetWSDLServlet.java 2009-04-27 16:49:34 UTC (rev 845)
@@ -146,11 +146,11 @@
serverProperties = new StringBuffer(
escapeAttributeEntities(serverProperties.toString()));
- StringBuffer urlPrefix = new StringBuffer();
- urlPrefix.append(webProtocol)
- .append("://").append(webServer).append(":").append(webPortInt); //$NON-NLS-1$ //$NON-NLS-2$
+ String urlPrefix = new String();
+
+ urlPrefix = buildUrlPrefix(req);
- String servletPath = urlPrefix + "/" + WSDLServletUtil.SERVLET_PATH; //$NON-NLS-1$
+ String servletPath = urlPrefix + WSDLServletUtil.SERVLET_PATH; //$NON-NLS-1$
String result = escapeAttributeEntities(suffix.toString());
15 years, 8 months
teiid SVN: r844 - in trunk/console/src/main/java/com/metamatrix/console/ui/views/deploy: model and 1 other directory.
by teiid-commits@lists.jboss.org
Author: vhalbert(a)redhat.com
Date: 2009-04-26 22:01:23 -0400 (Sun, 26 Apr 2009)
New Revision: 844
Modified:
trunk/console/src/main/java/com/metamatrix/console/ui/views/deploy/DeployedProcessPanel.java
trunk/console/src/main/java/com/metamatrix/console/ui/views/deploy/model/ConfigurationTreeModel.java
Log:
TEIID 323 - on the deployment panel don't show the services/connectors in the tree node below the process.
Modified: trunk/console/src/main/java/com/metamatrix/console/ui/views/deploy/DeployedProcessPanel.java
===================================================================
--- trunk/console/src/main/java/com/metamatrix/console/ui/views/deploy/DeployedProcessPanel.java 2009-04-24 20:16:30 UTC (rev 843)
+++ trunk/console/src/main/java/com/metamatrix/console/ui/views/deploy/DeployedProcessPanel.java 2009-04-27 02:01:23 UTC (rev 844)
@@ -108,24 +108,10 @@
// CONSTANTS
///////////////////////////////////////////////////////////////////////////
- private static final String NO_PSC =
- DeployPkgUtils.getString("drp.nodeployedpsc"); //$NON-NLS-1$
+// private static final String NO_PSC =
+// DeployPkgUtils.getString("drp.nodeployedpsc"); //$NON-NLS-1$
-// private static /*final*/ String[] SVC_HDRS;
-// private static final int SVC_COL = 0;
-// private static final int ENABLED_COL = 1;
-
///////////////////////////////////////////////////////////////////////////
- // INITIALIZER
- ///////////////////////////////////////////////////////////////////////////
-
-// static {
-// SVC_HDRS = new String[2];
-// SVC_HDRS[SVC_COL] = DeployPkgUtils.getString("drp.service.hdr"); //$NON-NLS-1$
-// SVC_HDRS[ENABLED_COL] = DeployPkgUtils.getString("drp.enabled.hdr"); //$NON-NLS-1$
-// }
-
- ///////////////////////////////////////////////////////////////////////////
// CONTROLS
///////////////////////////////////////////////////////////////////////////
@@ -602,18 +588,6 @@
initTable();
// populate PSC column
prodRowMap.clear();
-// Collection pscs = getConfigurationManager().getDeployedPscs(process);
-// if (pscs != null) {
-// Iterator pscItr = pscs.iterator();
-// while (pscItr.hasNext()) {
-// ProductServiceConfig psc = (ProductServiceConfig)pscItr.next();
-//
-// ProductType product = BasicProductType.PRODUCT_TYPE;
-// // getConfigurationManager().getProduct(psc);
-// //tblModel.setValueAt(psc, findProductRow(product), PSC_COL);
-// prodRowMap.put(product, psc);
-// }
-// }
tblSvcs.sizeColumnsToFitData();
}
catch (Exception theException) {
@@ -654,14 +628,6 @@
}
}
-// public void setMMLEnabled(boolean theEnableFlag) {
-// pnlProps.setReadOnlyForced(!theEnableFlag);
-// pnlProps.refreshDisplay();
-//
-// if (!theEnableFlag) {
-// tblPscs.editingStopped(new ChangeEvent(this));
-// }
-// }
///////////////////////////////////////////////////////////////////////////
// INNER CLASSES
Modified: trunk/console/src/main/java/com/metamatrix/console/ui/views/deploy/model/ConfigurationTreeModel.java
===================================================================
--- trunk/console/src/main/java/com/metamatrix/console/ui/views/deploy/model/ConfigurationTreeModel.java 2009-04-24 20:16:30 UTC (rev 843)
+++ trunk/console/src/main/java/com/metamatrix/console/ui/views/deploy/model/ConfigurationTreeModel.java 2009-04-27 02:01:23 UTC (rev 844)
@@ -71,9 +71,6 @@
public static final String DEPLOYMENTS_HDR =
DeployPkgUtils.getString("dtm.deploymentshdrnode"); //$NON-NLS-1$
- /** The text of all the PSC definitions header nodes. */
-// public static final String PSC_DEFS_HDR =
-// DeployPkgUtils.getString("dtm.pscdefshdrnode"); //$NON-NLS-1$
///////////////////////////////////////////////////////////////////////////
// FIELDS
@@ -82,26 +79,9 @@
//key=object, value=DefaultTreeNode
private HashMap objNodeMap = new HashMap();
- //key=ConfigurationID, value=DefaultTreeNode for Deployments Header
-// private HashMap configDeployHdrMap = new HashMap();
-
- //key=ConfigurationID, value=DefaultTreeNode for PSC Definitions Header
- // private HashMap configPscDefHdrMap = new HashMap();
-
//key=hostID, value=HashMap (key=ConfigurationID, value=node-HostWrapper as content)
private HashMap hostConfigMap = new HashMap();
- //key=ComponentTypeID of product, value=HashMap (key=ConfigurationID, value=DefaultTreeNode)
-// private HashMap prodConfigMap = new HashMap();
-
- // deployed pscs
- //key=VMComponentDefnID, value=(key=ProductServiceConfig ID,value=node-PscWrapper)
- // private HashMap procPscMap = new HashMap();
-
- // psc defns
- //key=ProductServiceConfigID, value=(key=ConfigurationID, value=node-PscWrapper)
- private HashMap pscConfigMap = new HashMap();
-
/** The root node. This node will not be shown. */
private DefaultTreeNode root;
@@ -135,12 +115,12 @@
VMComponentDefn vm = vmit.next();
this.addDeployedProcess(vm, h, theConfig, false);
- Collection svcs = theConfig.getDeployedServicesForVM(vm);
- for (Iterator<DeployedComponent> svcit=svcs.iterator(); svcit.hasNext();) {
- DeployedComponent dep = svcit.next();
- this.addDeployedService(dep, vm, h, theConfig, false);
-
- }
+// Collection svcs = theConfig.getDeployedServicesForVM(vm);
+// for (Iterator<DeployedComponent> svcit=svcs.iterator(); svcit.hasNext();) {
+// DeployedComponent dep = svcit.next();
+// this.addDeployedService(dep, vm, h, theConfig, false);
+//
+// }
}
@@ -160,16 +140,6 @@
// create configuration node
SortableChildrenNode configNode = createNode(theConfig, root);
- // add deployments header
-// SortableChildrenNode deployHdrNode = new SortableChildrenNode(DEPLOYMENTS_HDR, theConfig);
-// configNode.addChild(deployHdrNode);
-// configDeployHdrMap.put(theConfig.getID(), deployHdrNode);
-
- // add psc defs header
-// SortableChildrenNode pscDefsHdrNode = new SortableChildrenNode(PSC_DEFS_HDR, theConfig);
-// configNode.addChild(pscDefsHdrNode);
-// configPscDefHdrMap.put(theConfig.getID(), pscDefsHdrNode);
-
// notify tree model listeners
if (fireevent) {
ConfigurationTreeModelEvent event =
@@ -208,8 +178,6 @@
private void addDeloyedHost(Host theHost, Configuration theConfig, boolean fireevent) {
DefaultTreeNode configNode = getUserObjectNode(theConfig);
-// DefaultTreeNode deployHdrNode =
-// (DefaultTreeNode)configDeployHdrMap.get(theConfig.getID());
DefaultTreeNode hostNode =
createHostNode(theHost, theConfig, configNode);
HashMap map = (HashMap)hostConfigMap.get(theHost.getID());
@@ -268,106 +236,6 @@
}
/**
- * Adds a deployed PSC node to the model.
- *
- * @param thePsc the user object of the deployed PSC node being created
- * @param theProcess the user object of the new node's process ancestor node
- * @param theHost the user object of the new node's host ancestor node
- * @param theConfig the user object of the new node's configuration ancestor
- * node
- */
-// public void addDeployedPsc(
-// ProductServiceConfig thePsc,
-// VMComponentDefn theProcess,
-// Host theHost,
-// Configuration theConfig) {
-//
-// // event fired by the createPscNode method
-// createPscNode(thePsc, theProcess, theHost, theConfig);
-// }
-
- /**
- * Adds a deployed service node to the model.
- * @param theService the user object of the deployed service node being
- * created
- * @param thePsc the user object of the new node's deployed PSC ancestor node
- * @param theProcess the user object of the new node's process ancestor node
- * @param theConfig the user object of the new node's configuration ancestor
- * node
- */
-// public void addDeployedService(
-// DeployedComponent theService,
-// VMComponentDefn theProcess,
-// Host theHost,
-// Configuration theConfig) {
-//
-// DefaultTreeNode pscNode = getPscNode(thePsc, theProcess);
-// DefaultTreeNode serviceNode = createNode(theService, pscNode);
-// DefaultTreeNode processNode = serviceNode.getParent();
-// DefaultTreeNode hostNode = processNode.getParent();
-// DefaultTreeNode configNode = getUserObjectNode(theConfig);
-//
-// // notify tree model listeners
-// ConfigurationTreeModelEvent event =
-// new ConfigurationTreeModelEvent(ConfigurationTreeModelEvent.NEW,
-// serviceNode,
-// configNode,
-// new DefaultTreeNode[] {pscNode,
-// processNode,
-// hostNode,
-// configNode});
-// fireConfigurationChange(event);
-// }
-
- /**
- * Adds a product node to the model.
- * @param theProduct the user object of the product node being created
- * @param theConfig the user object of the new node's configuration
- * ancestor node
- */
-// private void addProduct(
-// ProductType theProduct,
-// Configuration theConfig) {
-//
-// DefaultTreeNode configNode = getUserObjectNode(theConfig);
-// DefaultTreeNode pscDefHdrNode =
-// (DefaultTreeNode)configPscDefHdrMap.get(theConfig.getID());
-// DefaultTreeNode productNode = createNode(theProduct, pscDefHdrNode);
-//
-// HashMap map = (HashMap)prodConfigMap.get(theProduct.getID());
-// if (map == null) {
-// // has no PSCs for any config
-// map = new HashMap();
-// prodConfigMap.put(theProduct.getID(), map);
-// }
-// map.put(theConfig.getID(), productNode);
-//
-// // notify tree model listeners
-// ConfigurationTreeModelEvent event =
-// new ConfigurationTreeModelEvent(ConfigurationTreeModelEvent.NEW,
-// productNode,
-// configNode,
-// new DefaultTreeNode[] {configNode});
-// fireConfigurationChange(event);
-// }
-
- /**
- * Adds a PSC definition node to the model.
- * @param thePsc the user object of the PSC definition node being created
- * @param theProduct the user object of the new node's product ancestor node
- * @param theConfig the user object of the new node's configuration
- * ancestor node
- */
-// public void addPscDefn(
-// ProductServiceConfig thePsc,
-// ProductType theProduct,
-// Configuration theConfig) {
-//
-// // event fired by the createPscNode method
-// createPscNode(thePsc, theProduct, theConfig);
-// }
-
- /**
* Adds a service definition node to the model.
* @param theService the user object of the deployed service definition node
* being created
@@ -392,13 +260,11 @@
Configuration theConfig,
boolean fireevent) {
- // DefaultTreeNode pscNode = getPscNode(thePsc, theConfig);
-
+
DefaultTreeNode processNode = getUserObjectNode(theProcess);
DefaultTreeNode serviceNode = createNode(theService, processNode);
DefaultTreeNode hostNode = getHostNode(theHost, theConfig);
-// DefaultTreeNode productNode = serviceNode.getParent();
DefaultTreeNode configNode = getUserObjectNode(theConfig);
// notify tree model listeners
@@ -436,20 +302,12 @@
theEvent.getHost(),
config);
}
-// else if (theEvent.isPscDefinitionChange()) {
-// addPscDefn(theEvent.getPscDefinition(),
-// theEvent.getProduct(),
-// config);
+// else if (theEvent.isDeployedServiceChange()) {
+// addDeployedService(theEvent.getDeployedService(),
+// theEvent.getProcess(),
+// theEvent.getHost(),
+// config);
// }
- else if (theEvent.isDeployedServiceChange()) {
- addDeployedService(theEvent.getDeployedService(),
- theEvent.getProcess(),
- theEvent.getHost(),
- config);
- }
-// else if (theEvent.isProductChange()) {
-// addProduct(theEvent.getProduct(), config);
-// }
}
else if (theEvent.isDeleted()) {
if (theEvent.isHostChange()) {
@@ -460,17 +318,12 @@
theEvent.getHost(),
config);
}
-// else if (theEvent.isPscDefinitionChange()) {
-// deletePscDefintion(theEvent.getPscDefinition(),
-// theEvent.getProduct(),
-// config);
-// }
- else if (theEvent.isDeployedServiceChange()) {
- deleteDeployedService(theEvent.getDeployedService(),
- theEvent.getProcess(),
- theEvent.getHost(),
- theEvent.getConfiguration());
- }
+// else if (theEvent.isDeployedServiceChange()) {
+// deleteDeployedService(theEvent.getDeployedService(),
+// theEvent.getProcess(),
+// theEvent.getHost(),
+// theEvent.getConfiguration());
+// }
}
else if (theEvent.isModified()) {
if (theEvent.isHostChange()) {
@@ -528,87 +381,8 @@
return createNode(wrap, theParent);
}
- /**
- * Creates a PSC tree node used for PSC definitions.
- * @param thePsc the user object of the new node
- * @param theProduct the user object of the new node's parent node
- * @param theConfig the user object of the new node's configuration node
- */
-// private void createPscNode(
-// ProductServiceConfig thePsc,
-// ProductType theProduct,
-// Configuration theConfig) {
-//
-// PscWrapper wrapper = new PscWrapper(thePsc, theConfig);
-//
-// HashMap map = (HashMap)prodConfigMap.get(theProduct.getID());
-// DefaultTreeNode productNode =
-// (DefaultTreeNode)map.get(theConfig.getID());
-// DefaultTreeNode pscNode = createNode(wrapper, productNode);
-// DefaultTreeNode configNode = getUserObjectNode(theConfig);
-//
-// map = (HashMap)pscConfigMap.get(thePsc.getID());
-// if (map == null) {
-// // new psc
-// map = new HashMap();
-// pscConfigMap.put(thePsc.getID(), map);
-// }
-// map.put(theConfig.getID(), pscNode);
-//
-// // notify tree model listeners
-// ConfigurationTreeModelEvent event =
-// new ConfigurationTreeModelEvent(ConfigurationTreeModelEvent.NEW,
-// pscNode,
-// configNode,
-// new DefaultTreeNode[] {productNode,
-// configNode});
-// fireConfigurationChange(event);
-// }
/**
- * Creates a PSC tree node used for deployed PSCs.
- * @param thePsc the user object of the new node
- * @param theProcess the user object of the new node's parent node
- * @param theHost the user object of the new node's host ancestor node
- * @param theConfig the user object of the new node's configuration ancestor
- * node
- */
-// private void createPscNode(
-// ProductServiceConfig thePsc,
-// VMComponentDefn theProcess,
-// Host theHost,
-// Configuration theConfig) {
-//
-// PscWrapper wrapper = new PscWrapper(thePsc, theProcess);
-// DefaultTreeNode processNode = getUserObjectNode(theProcess);
-// if (processNode == null) {
-// return;
-// }
-//
-// DefaultTreeNode pscNode = createNode(wrapper, processNode);
-// DefaultTreeNode hostNode = pscNode.getParent();
-// DefaultTreeNode configNode = getUserObjectNode(theConfig);
-//
-// HashMap map = (HashMap)procPscMap.get(theProcess.getID());
-// if (map == null) {
-// // process doesn't have any PSCs yet
-// map = new HashMap();
-// procPscMap.put(theProcess.getID(), map);
-// }
-// map.put(thePsc.getID(), pscNode);
-//
-// // notify tree model listeners
-// ConfigurationTreeModelEvent event =
-// new ConfigurationTreeModelEvent(ConfigurationTreeModelEvent.NEW,
-// pscNode,
-// configNode,
-// new DefaultTreeNode[] {processNode,
-// hostNode,
-// configNode});
-// fireConfigurationChange(event);
-// }
-
- /**
* Deletes a host node from the model.
* @param theHost the user object of the host node being deleted
* @param theConfig the user object of the deleted node's configuration
@@ -664,70 +438,8 @@
fireConfigurationChange(event);
}
+
/**
- * Deletes a deployed Deployed Service node from the model.
- * @param thePsc the user object of the deployed PSC node being created
- * @param theProcess the user object of the deleted node's process
- * ancestor node
- * @param theHost the user object of the deleted node's host ancestor node
- * @param theConfig the user object of the deleted node's configuration
- * ancestor node
- */
- public void deleteDeployedService(
- DeployedComponent theService,
- VMComponentDefn theProcess,
- Host theHost,
- Configuration theConfig) {
-
- DefaultTreeNode serviceNode = getUserObjectNode(theService);
-
- DefaultTreeNode processNode = serviceNode.getParent();
- DefaultTreeNode hostNode = processNode.getParent();
- DefaultTreeNode configNode = getUserObjectNode(theConfig);
-
-
- // notify tree model listeners
- ConfigurationTreeModelEvent event =
- new ConfigurationTreeModelEvent(ConfigurationTreeModelEvent.DELETED,
- serviceNode,
- configNode,
- new DefaultTreeNode[] {processNode,
- hostNode,
- configNode});
- fireConfigurationChange(event);
- }
-
- /**
- * Deletes a PSC definition node from the model.
- * @param thePsc the user object of the PSC definition node being deleted
- * @param theProduct the user object of the deleted node's product
- * ancestor node
- * @param theConfig the user object of the deleted node's configuration
- * ancestor node
- */
-// public void deletePscDefintion(
-// ProductServiceConfig thePsc,
-// ProductType theProduct,
-// Configuration theConfig) {
-//
-// DefaultTreeNode pscNode = getPscNode(thePsc, theConfig);
-// DefaultTreeNode productNode = pscNode.getParent();
-// DefaultTreeNode configNode = getUserObjectNode(theConfig);
-//
-// // delete from model
-// removeUserObject(pscNode.getContent());
-//
-// // notify tree model listeners
-// ConfigurationTreeModelEvent event =
-// new ConfigurationTreeModelEvent(ConfigurationTreeModelEvent.DELETED,
-// pscNode,
-// configNode,
-// new DefaultTreeNode[] {productNode,
-// configNode});
-// fireConfigurationChange(event);
-// }
-
- /**
* Notifies all registered {@link ConfigurationChangeListener}s that the
* tree model has changed.
* @param theEvent the event being sent to the listeners
@@ -743,16 +455,8 @@
}
}
+
/**
- * Gets the deployments header node for the given configuration.
- * @param theConfig the configuration whose header node is being requested
- * @return the deployments header node
- */
-// public DefaultTreeNode getDeploymentsHeaderNode(Configuration theConfig) {
-// return (DefaultTreeNode)configDeployHdrMap.get(theConfig.getID());
-// }
-
- /**
* Gets the host node of the given configuration.
* May return null if <code>theHost</code> is null.
* @param theHost the host whose node is being requested
@@ -772,43 +476,6 @@
}
/**
- * Gets the PSC definitions header node for the given configuration.
- * @param theConfig the configuration whose header node is being requested
- * @return the PSC definitions header node
- */
-// public DefaultTreeNode getPscDefinitionsHeaderNode(Configuration theConfig) {
-// return (DefaultTreeNode)configPscDefHdrMap.get(theConfig.getID());
-// }
-
- /**
- * Gets the requested PSC definition node.
- * @param thePsc the user object of the PSC definition node
- * @param theConfig the user object of the PSC definition node's configuration
- * ancestor node
- */
-// public DefaultTreeNode getPscNode(
-// ProductServiceConfig thePsc,
-// Configuration theConfig) {
-//
-// HashMap map = (HashMap)pscConfigMap.get(thePsc.getID());
-// return (DefaultTreeNode)map.get(theConfig.getID());
-// }
-
- /**
- * Gets the requested deployed PSC node.
- * @param thePsc the user object of the deployed PSC node
- * @param theProcess the user object of the deployed PSC node's process
- * ancestor node
- */
-// public DefaultTreeNode getPscNode(
-// ProductServiceConfig thePsc,
-// VMComponentDefn theProcess) {
-//
-// HashMap map = (HashMap)procPscMap.get(theProcess.getID());
-// return (DefaultTreeNode)map.get(thePsc.getID());
-// }
-
- /**
* Gets the requested user object's node.
* @param theUserObject the user object whose node is being requested
* @return the requested user object's node
@@ -826,31 +493,10 @@
*/
public boolean isHeaderNode(DefaultTreeNode theNode) {
return (theNode == root);
- // return (isDeploymentsHeaderNode(theNode));
-// || isPscDefinitionsHeaderNode(theNode));
- }
+ }
- /**
- * Indicates if the given node is a deployments header node.
- * @param theNode the node being checked
- * @return <code>true</code> if the node is a deployments header node;
- * <code>false</code> otherwise.
- */
-// public boolean isDeploymentsHeaderNode(DefaultTreeNode theNode) {
-// return configDeployHdrMap.containsValue(theNode);
-// }
/**
- * Indicates if the given node is a PSC definitions header node.
- * @param theNode the node being checked
- * @return <code>true</code> if the node is a PSC definitions header node;
- * <code>false</code> otherwise.
- */
-// public boolean isPscDefinitionsHeaderNode(DefaultTreeNode theNode) {
-// return configPscDefHdrMap.containsValue(theNode);
-// }
-
- /**
* Modifies a deployed host node in the model.
* @param theProcess the user object of the node being modified
* @param theHost the user object of the modified node's host ancestor node
@@ -894,21 +540,6 @@
}
}
- /**
- * Modifies a PSC definitions node in the model.
- * @param thePsc the user object of the node being modified
- * @param theProduct the user object of the modified node's product
- * ancestor node
- * @param theConfig the user object of the modified node's configuration
- * ancestor node
- */
-// public void modifyPscDefinition(
-// ProductServiceConfig thePsc,
-// ProductType theProduct,
-// Configuration theConfig) {
-//
-// // not sure if anything needs to be done here
-// }
/**
* Modifies a service definitions node in the model.
@@ -953,12 +584,7 @@
public void refresh() {
root.removeAllChildren();
objNodeMap.clear();
- // configDeployHdrMap.clear();
- // configPscDefHdrMap.clear();
hostConfigMap.clear();
- // prodConfigMap.clear();
- // procPscMap.clear();
- pscConfigMap.clear();
fireModelChangedEvent(this, root);
}
@@ -994,142 +620,6 @@
// PscWrapper INNER CLASS
///////////////////////////////////////////////////////////////////////////
- /**
- * The <code>PscWrapper</code> class wraps a {@link ProductServiceConfig} so
- * that PSC definitions and deployed PSCs can be distinguished.
- */
-// public class PscWrapper {
-//
-// ///////////////////////////////////////////////////////////////////////
-// // FIELDS
-// ///////////////////////////////////////////////////////////////////////
-//
-// private ProductServiceConfig psc;
-// private VMComponentDefn proc;
-// private Configuration config;
-//
-// ///////////////////////////////////////////////////////////////////////
-// // CONSTRUCTORS
-// ///////////////////////////////////////////////////////////////////////
-//
-// /**
-// * Constructs a <code>PscWrapper</code> that wraps a deployed PSC.
-// * @param thePsc the user object of the deployed PSC
-// * @param theProcess the user object of the deployed PSC's process
-// */
-// public PscWrapper(
-// ProductServiceConfig thePsc,
-// VMComponentDefn theProcess) {
-//
-// psc = thePsc;
-// proc = theProcess;
-// }
-//
-// /**
-// * Constructs a <code>PscWrapper</code> that wraps a PSC definition.
-// * @param thePsc the user object of the deployed PSC
-// * @param theConfig the user object of the deployed PSC's configuration
-// */
-// public PscWrapper(
-// ProductServiceConfig thePsc,
-// Configuration theConfig) {
-//
-// psc = thePsc;
-// config = theConfig;
-// }
-//
-// ///////////////////////////////////////////////////////////////////////
-// // METHODS
-// ///////////////////////////////////////////////////////////////////////
-//
-// /**
-// * Indicates if the given input parameter is equal to this object.
-// * @param theObject the object being compared
-// * @return <code>true</code> if equal; <code>false</code> otherwise.
-// */
-// public boolean equals(Object theObject) {
-// if (theObject instanceof PscWrapper) {
-// PscWrapper otherObj = (PscWrapper)theObject;
-// if (psc.equals(otherObj.getPsc())) {
-// if (isDefinition() == otherObj.isDefinition()) {
-// if (isDefinition()) {
-// return (config.equals(otherObj.getConfig()));
-// }
-// return (proc.equals(otherObj.getProcess()));
-// }
-// }
-// return false;
-//
-// }
-// return false;
-// }
-//
-// /**
-// * Gets the associated configuration. Only used if wrapping a PSC
-// * definition.
-// * @return the associated configuration of the PSC definition or
-// * <code>null</code> if wrapping a deployed PSC.
-// */
-// public Configuration getConfig() {
-// return config;
-// }
-//
-// /**
-// * Gets the associated process. Only used if wrapping a deployed PSC.
-// * @return the associated process of the deployed PSC or
-// * <code>null</code> if wrapping a PSC definition.
-// */
-// public VMComponentDefn getProcess() {
-// return proc;
-// }
-//
-// /**
-// * Gets the wrapped PSC object.
-// * @return the wrapped PSC object
-// */
-// public ProductServiceConfig getPsc() {
-// return psc;
-// }
-//
-// /**
-// * Indicates if this object wraps a PSC definition.
-// * @return <code>true</code> if this object wraps a PSC definition;
-// * <code>false</code> otherwise.
-// */
-// public boolean isDefinition() {
-// return (config != null);
-// }
-//
-// /**
-// * Indicates if this object wraps a deployed PSC.
-// * @return <code>true</code> if this object wraps a deployed PSC;
-// * <code>false</code> otherwise.
-// */
-// public boolean isDeployed() {
-// return (proc != null);
-// }
-//
-// /**
-// * Gets a hash code value.
-// * @return a hash code value
-// */
-// public int hashCode() {
-// int result = psc.hashCode();
-// if (isDefinition()) {
-// return result + config.hashCode();
-// }
-// return result + proc.hashCode();
-// }
-//
-// /**
-// * Gets this object's string representation which is it's associated
-// * {@link ProductServiceConfig}'s <code>toString</code>.
-// * @return the string representation
-// */
-// public String toString() {
-// return psc.toString();
-// }
-// }
///////////////////////////////////////////////////////////////////////////
// HostWrapper INNER CLASS
15 years, 8 months