teiid SVN: r823 - trunk/connectors/connector-salesforce/src/main/resources.
by teiid-commits@lists.jboss.org
Author: twalsh(a)redhat.com
Date: 2009-04-22 04:13:51 -0400 (Wed, 22 Apr 2009)
New Revision: 823
Modified:
trunk/connectors/connector-salesforce/src/main/resources/connector-salesforce.xml
Log:
https://jira.jboss.org/jira/browse/TEIID-55
Modified: trunk/connectors/connector-salesforce/src/main/resources/connector-salesforce.xml
===================================================================
--- trunk/connectors/connector-salesforce/src/main/resources/connector-salesforce.xml 2009-04-22 08:12:47 UTC (rev 822)
+++ trunk/connectors/connector-salesforce/src/main/resources/connector-salesforce.xml 2009-04-22 08:13:51 UTC (rev 823)
@@ -9,4 +9,58 @@
<PropertyDefinition Name="password" DisplayName="Password" ShortDescription="Password value for Salesforce authentication" DefaultValue="" Multiplicity="1" IsMasked="true" IsPreferred="true" />
<PropertyDefinition Name="URL" DisplayName="Salesforce URL" ShortDescription="URL for connecting to Salesforce" DefaultValue="" IsExpert="true" />
<PropertyDefinition Name="ConnectorCapabilities" DisplayName="Connector Capabilities Class" ShortDescription="The class to use to provide the Connector Capabilities" DefaultValue="com.metamatrix.connector.salesforce.SalesforceCapabilities" IsConstrainedToAllowedValues="false" IsExpert="true" />
+
+ <PropertyDefinition
+ Name="com.metamatrix.data.pool.max_connections_for_each_id"
+ DisplayName="Pool Maximum Connections for Each ID"
+ ShortDescription="Set the maximum number of connections for each connector ID for the connection pool"
+ DefaultValue="5" Multiplicity="1" PropertyType="Integer"
+ ValueDelimiter="," IsConstrainedToAllowedValues="true" IsExpert="true"
+ IsHidden="false" IsMasked="false" IsModifiable="false" IsPreferred="false" />
+ <PropertyDefinition Name="ResultSetCacheScope"
+ DisplayName="ResultSet Cache Scope" ShortDescription=""
+ DefaultValue="vdb" Multiplicity="0..1" PropertyType="String"
+ ValueDelimiter="," IsConstrainedToAllowedValues="true" IsExpert="true"
+ IsHidden="false" IsMasked="false" IsModifiable="true" IsPreferred="false">
+ <AllowedValue>vdb</AllowedValue>
+ <AllowedValue>session</AllowedValue>
+ </PropertyDefinition>
+ <PropertyDefinition Name="ResultSetCacheMaxAge"
+ DisplayName="ResultSet Cache Maximum Age" ShortDescription=""
+ DefaultValue="0" Multiplicity="0..1" PropertyType="Long"
+ ValueDelimiter="," IsConstrainedToAllowedValues="true" IsExpert="true"
+ IsHidden="false" IsMasked="false" IsModifiable="true" IsPreferred="false" />
+ <PropertyDefinition Name="com.metamatrix.data.pool.wait_for_source_time"
+ DisplayName="Pool Connection Waiting Time"
+ ShortDescription="Set the time to wait if the connection is not available"
+ DefaultValue="120000" Multiplicity="0..1" PropertyType="Integer"
+ ValueDelimiter="," IsConstrainedToAllowedValues="true" IsExpert="true"
+ IsHidden="false" IsMasked="false" IsModifiable="true" IsPreferred="false" />
+ <PropertyDefinition Name="com.metamatrix.data.pool.live_and_unused_time"
+ DisplayName="Pool Connection Idle Time"
+ ShortDescription="Set the idle time of the connection before it should be closed if pool shrinking is enabled"
+ DefaultValue="60" Multiplicity="0..1" PropertyType="Integer"
+ ValueDelimiter="," IsConstrainedToAllowedValues="true" IsExpert="true"
+ IsHidden="false" IsMasked="false" IsModifiable="true" IsPreferred="false" />
+ <PropertyDefinition Name="ResultSetCacheMaxSize"
+ DisplayName="ResultSet Cache Maximum Size" ShortDescription=""
+ DefaultValue="0" Multiplicity="0..1" PropertyType="Integer"
+ ValueDelimiter="," IsConstrainedToAllowedValues="true" IsExpert="true"
+ IsHidden="false" IsMasked="false" IsModifiable="true" IsPreferred="false" />
+ <PropertyDefinition Name="com.metamatrix.data.pool.cleaning_interval"
+ DisplayName="Pool cleaning Interval" ShortDescription="Set the interval to cleaning the pool"
+ DefaultValue="60" Multiplicity="0..1" PropertyType="Integer"
+ ValueDelimiter="," IsConstrainedToAllowedValues="true" IsExpert="true"
+ IsHidden="false" IsMasked="false" IsModifiable="true" IsPreferred="false" />
+ <PropertyDefinition Name="SetCriteriaBatchSize"
+ DisplayName="SetCriteria Batch Size"
+ ShortDescription="Max number of values in a SetCriteria before batching into multiple queries. A value <= 0 indicates batching is OFF."
+ DefaultValue="0" Multiplicity="0..1" PropertyType="Integer"
+ ValueDelimiter="," IsConstrainedToAllowedValues="false" IsExpert="true"
+ IsHidden="false" IsMasked="false" IsModifiable="true" IsPreferred="false" />
+ <PropertyDefinition Name="ResultSetCacheEnabled"
+ DisplayName="ResultSet Cache Enabled" ShortDescription=""
+ DefaultValue="false" Multiplicity="0..1" PropertyType="Boolean"
+ ValueDelimiter="," IsConstrainedToAllowedValues="true" IsExpert="true"
+ IsHidden="false" IsMasked="false" IsModifiable="true" IsPreferred="false" />
</ComponentType>
\ No newline at end of file
15 years, 8 months
teiid SVN: r822 - trunk/connectors/connector-salesforce/src/main/java/com/metamatrix/connector/salesforce.
by teiid-commits@lists.jboss.org
Author: twalsh(a)redhat.com
Date: 2009-04-22 04:12:47 -0400 (Wed, 22 Apr 2009)
New Revision: 822
Modified:
trunk/connectors/connector-salesforce/src/main/java/com/metamatrix/connector/salesforce/Connector.java
Log:
https://jira.jboss.org/jira/browse/TEIID-96
Modified: trunk/connectors/connector-salesforce/src/main/java/com/metamatrix/connector/salesforce/Connector.java
===================================================================
--- trunk/connectors/connector-salesforce/src/main/java/com/metamatrix/connector/salesforce/Connector.java 2009-04-22 08:10:24 UTC (rev 821)
+++ trunk/connectors/connector-salesforce/src/main/java/com/metamatrix/connector/salesforce/Connector.java 2009-04-22 08:12:47 UTC (rev 822)
@@ -121,7 +121,7 @@
}
try {
String inLimitString = env.getProperties().getProperty("InLimit", Integer.toString(-1));
- int inLimit = Integer.decode(inLimitString).intValue();
+ int inLimit = inLimitString == null ? -1 : Integer.decode(inLimitString).intValue();
salesforceCapabilites.setMaxInCriteriaSize(inLimit);
} catch (NumberFormatException e) {
throw new ConnectorException(Messages.getString("SalesforceConnection.bad.IN.value"));
15 years, 8 months
teiid SVN: r821 - trunk/connectors/connector-salesforce/src/main/java/com/metamatrix/connector/salesforce/connection/impl.
by teiid-commits@lists.jboss.org
Author: twalsh(a)redhat.com
Date: 2009-04-22 04:10:24 -0400 (Wed, 22 Apr 2009)
New Revision: 821
Modified:
trunk/connectors/connector-salesforce/src/main/java/com/metamatrix/connector/salesforce/connection/impl/ConnectionImpl.java
Log:
https://jira.jboss.org/jira/browse/TEIID-100
Modified: trunk/connectors/connector-salesforce/src/main/java/com/metamatrix/connector/salesforce/connection/impl/ConnectionImpl.java
===================================================================
--- trunk/connectors/connector-salesforce/src/main/java/com/metamatrix/connector/salesforce/connection/impl/ConnectionImpl.java 2009-04-22 00:11:55 UTC (rev 820)
+++ trunk/connectors/connector-salesforce/src/main/java/com/metamatrix/connector/salesforce/connection/impl/ConnectionImpl.java 2009-04-22 08:10:24 UTC (rev 821)
@@ -51,6 +51,7 @@
import com.sforce.soap.partner.SoapBindingStub;
import com.sforce.soap.partner.fault.ApiFault;
import com.sforce.soap.partner.fault.UnexpectedErrorFault;
+import com.sforce.soap.partner.fault.InvalidQueryLocatorFault;
import com.sforce.soap.partner.sobject.SObject;
public class ConnectionImpl {
@@ -184,6 +185,8 @@
public QueryResult queryMore(String queryLocator) throws ConnectorException {
try {
return binding.queryMore(queryLocator);
+ } catch ( InvalidQueryLocatorFault e ) {
+ throw new ConnectorException(e.getMessage());
} catch (UnexpectedErrorFault e) {
throw new ConnectorException(e.getMessage());
} catch (ApiFault e) {
15 years, 8 months
teiid SVN: r819 - trunk/soap/src/main/webapp/WEB-INF.
by teiid-commits@lists.jboss.org
Author: tejones
Date: 2009-04-21 18:23:03 -0400 (Tue, 21 Apr 2009)
New Revision: 819
Modified:
trunk/soap/src/main/webapp/WEB-INF/web.xml
Log:
TEIID-523 Added missing servlet mapping and def,
Modified: trunk/soap/src/main/webapp/WEB-INF/web.xml
===================================================================
--- trunk/soap/src/main/webapp/WEB-INF/web.xml 2009-04-21 20:37:26 UTC (rev 818)
+++ trunk/soap/src/main/webapp/WEB-INF/web.xml 2009-04-21 22:23:03 UTC (rev 819)
@@ -98,6 +98,12 @@
<display-name>MetaMatrix VDB Resource Servlet</display-name>
<servlet-class>com.metamatrix.soap.servlet.MMGetVDBResourceServlet</servlet-class>
</servlet>
+
+ <servlet>
+ <servlet-name>MMDiscoverWSDLServlet</servlet-name>
+ <display-name>MetaMatrix Discover WSDL URLs Servlet</display-name>
+ <servlet-class>com.metamatrix.soap.servlet.MMDiscoverWSDLServlet</servlet-class>
+ </servlet>
<servlet>
<servlet-name>MMWSDLURLGenerator</servlet-name>
@@ -105,6 +111,12 @@
<servlet-class>com.metamatrix.soap.servlet.WSDLURLGenerator</servlet-class>
</servlet>
+ <servlet>
+ <servlet-name>MMGetWSDLServlet</servlet-name>
+ <display-name>MetaMatrix Get WSDL Servlet</display-name>
+ <servlet-class>com.metamatrix.soap.servlet.MMGetWSDLServlet</servlet-class>
+ </servlet>
+
<servlet-mapping>
<servlet-name>MMGetVDBResource</servlet-name>
<url-pattern>/servlet/ArtifactDocumentService/*</url-pattern>
@@ -115,11 +127,10 @@
<url-pattern>/servlet/WSDLURLGenerator</url-pattern>
</servlet-mapping>
- <servlet>
- <servlet-name>MMDiscoverWSDLServlet</servlet-name>
- <display-name>MetaMatrix Discover WSDL URLs Servlet</display-name>
- <servlet-class>com.metamatrix.soap.servlet.MMDiscoverWSDLServlet</servlet-class>
- </servlet>
+ <servlet-mapping>
+ <servlet-name>MMGetWSDLServlet</servlet-name>
+ <url-pattern>/wsdl/*</url-pattern>
+ </servlet-mapping>
<servlet-mapping>
<servlet-name>AxisServlet</servlet-name>
15 years, 8 months
teiid SVN: r818 - in trunk/engine/src: test/java/org/teiid/dqp/internal/process and 1 other directory.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2009-04-21 16:37:26 -0400 (Tue, 21 Apr 2009)
New Revision: 818
Modified:
trunk/engine/src/main/java/org/teiid/dqp/internal/process/CachedRequestWorkItem.java
trunk/engine/src/main/java/org/teiid/dqp/internal/process/DQPCore.java
trunk/engine/src/main/java/org/teiid/dqp/internal/process/RequestWorkItem.java
trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestDQPCoreRequestHandling.java
trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestDataTierManager.java
trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestMetaDataProcessor.java
Log:
TEIID-524 fix of tracking regression
Modified: trunk/engine/src/main/java/org/teiid/dqp/internal/process/CachedRequestWorkItem.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/internal/process/CachedRequestWorkItem.java 2009-04-21 19:43:28 UTC (rev 817)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/process/CachedRequestWorkItem.java 2009-04-21 20:37:26 UTC (rev 818)
@@ -93,7 +93,7 @@
@Override
protected void attemptClose() {
this.isClosed = true;
- dqpCore.logMMCommand(requestMsg, false, false, -1);
+ dqpCore.logMMCommand(this, false, false, -1);
this.dqpCore.removeRequest(this);
}
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-21 19:43:28 UTC (rev 817)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/process/DQPCore.java 2009-04-21 20:37:26 UTC (rev 818)
@@ -37,6 +37,7 @@
import javax.transaction.SystemException;
import javax.transaction.xa.Xid;
+import org.teiid.connector.xa.api.TransactionContext;
import org.teiid.dqp.internal.cache.CacheID;
import org.teiid.dqp.internal.cache.DQPContextCache;
import org.teiid.dqp.internal.cache.ResultSetCache;
@@ -228,8 +229,6 @@
public ResultsFuture<ResultsMessage> executeRequest(long reqID,
RequestMessage requestMsg) {
- logMMCommand(requestMsg, true, false, 0); //TODO: there is no transaction at this point
-
DQPWorkContext workContext = DQPWorkContext.getWorkContext();
RequestID requestID = workContext.getRequestID(reqID);
requestMsg.markProcessingStart();
@@ -260,6 +259,7 @@
workItem = new RequestWorkItem(this, requestMsg, request, resultsFuture.getResultsReceiver(), requestID, workContext);
}
+ logMMCommand(workItem, true, false, 0); //TODO: there is no transaction at this point
addRequest(requestID, workItem);
this.addWork(workItem);
@@ -452,7 +452,7 @@
markCancelled = workItem.requestCancel();
}
if (markCancelled) {
- logMMCommand(workItem.requestMsg, false, true, 0);
+ logMMCommand(workItem, false, true, 0);
} else {
LogManager.logDetail(LogConstants.CTX_DQP, DQPPlugin.Util.getString("DQPCore.failed_to_cancel")); //$NON-NLS-1$
}
@@ -499,17 +499,22 @@
}
}
- void logMMCommand(RequestMessage msg, boolean isBegin, boolean isCancel, int rowCount) {
- if(this.tracker == null || msg == null || !tracker.willRecordMMCmd()){
+ void logMMCommand(RequestWorkItem workItem, boolean isBegin, boolean isCancel, int rowCount) {
+ if(this.tracker == null || !tracker.willRecordMMCmd()){
return;
}
+ RequestMessage msg = workItem.requestMsg;
DQPWorkContext workContext = DQPWorkContext.getWorkContext();
RequestID rID = new RequestID(workContext.getConnectionID(), msg.getExecutionId());
String command = null;
- String txnID = null;
if(isBegin && !isCancel){
command = msg.getCommandString();
}
+ String txnID = null;
+ TransactionContext tc = workItem.getTransactionContext();
+ if (tc != null) {
+ txnID = tc.getTxnID();
+ }
String appName = workContext.getAppName();
// Log to request log
short point = isBegin? TrackerLogConstants.CMD_POINT.BEGIN:TrackerLogConstants.CMD_POINT.END;
@@ -549,6 +554,10 @@
TrackingService getTracker() {
return tracker;
}
+
+ void setTracker(TrackingService tracker) {
+ this.tracker = tracker;
+ }
public TransactionService getTransactionService() {
if (transactionService == null) {
Modified: trunk/engine/src/main/java/org/teiid/dqp/internal/process/RequestWorkItem.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/internal/process/RequestWorkItem.java 2009-04-21 19:43:28 UTC (rev 817)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/process/RequestWorkItem.java 2009-04-21 20:37:26 UTC (rev 818)
@@ -361,7 +361,7 @@
if (this.processingException != null) {
sendError();
} else {
- dqpCore.logMMCommand(requestMsg, false, false, this.processor.getHighestRow());
+ dqpCore.logMMCommand(this, false, false, this.processor.getHighestRow());
}
}
@@ -710,6 +710,10 @@
return transactionContext;
}
+ void setTransactionContext(TransactionContext transactionContext) {
+ this.transactionContext = transactionContext;
+ }
+
Collection<DataTierTupleSource> getConnectorRequests() {
return new LinkedList<DataTierTupleSource>(this.connectorInfo.values());
}
Modified: trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestDQPCoreRequestHandling.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestDQPCoreRequestHandling.java 2009-04-21 19:43:28 UTC (rev 817)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestDQPCoreRequestHandling.java 2009-04-21 20:37:26 UTC (rev 818)
@@ -26,6 +26,8 @@
import java.util.HashSet;
import java.util.Set;
+import org.mockito.Mockito;
+import org.teiid.connector.xa.api.TransactionContext;
import org.teiid.dqp.internal.process.DQPCore;
import org.teiid.dqp.internal.process.DQPWorkContext;
import org.teiid.dqp.internal.process.DataTierTupleSource;
@@ -34,16 +36,14 @@
import junit.framework.TestCase;
import com.metamatrix.api.exception.MetaMatrixException;
-import com.metamatrix.common.buffer.TupleSourceID;
import com.metamatrix.dqp.exception.SourceWarning;
import com.metamatrix.dqp.internal.datamgr.ConnectorID;
import com.metamatrix.dqp.message.AtomicRequestMessage;
import com.metamatrix.dqp.message.RequestID;
import com.metamatrix.dqp.message.RequestMessage;
+import com.metamatrix.dqp.service.TrackingService;
import com.metamatrix.platform.security.api.MetaMatrixSessionID;
import com.metamatrix.platform.security.api.SessionToken;
-import com.metamatrix.query.analysis.AnalysisRecord;
-import com.metamatrix.query.processor.QueryProcessor;
import com.metamatrix.query.sql.lang.Command;
import com.metamatrix.server.serverapi.RequestInfo;
@@ -92,7 +92,7 @@
private RequestID addRequest(DQPCore rm, String sessionId, int executionId) {
RequestMessage r0 = new RequestMessage("test command"); //$NON-NLS-1$
RequestID id = new RequestID(sessionId, executionId);
- addRequest(rm, r0, id, null, null, new TupleSourceID("ts-1"), null, null, null); //$NON-NLS-1$
+ addRequest(rm, r0, id, null, null); //$NON-NLS-1$
return id;
}
@@ -119,7 +119,7 @@
DQPCore rm = new DQPCore();
RequestMessage r0 = new RequestMessage("foo"); //$NON-NLS-1$
RequestID requestID = new RequestID(SESSION_STRING, 1);
- RequestWorkItem workItem = addRequest(rm, r0, requestID, null, null, new TupleSourceID("ts-1"), null, null, null); //$NON-NLS-1$
+ RequestWorkItem workItem = addRequest(rm, r0, requestID, null, null); //$NON-NLS-1$
assertTrue(workItem.resultsCursor.resultsRequested);
}
@@ -128,7 +128,7 @@
RequestMessage r0 = new RequestMessage("foo"); //$NON-NLS-1$
RequestID requestID = new RequestID(SESSION_STRING, 1);
- RequestWorkItem workItem = addRequest(rm, r0, requestID, null, null, new TupleSourceID("ts-1"), null, null, null); //$NON-NLS-1$
+ RequestWorkItem workItem = addRequest(rm, r0, requestID, null, null); //$NON-NLS-1$
workItem.addSourceFailureDetails(getSourceFailures("Model1", "Binding1", "Warning1")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
workItem.addSourceFailureDetails(getSourceFailures("Model2", "Binding2", "Warning2")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
@@ -141,10 +141,7 @@
RequestMessage requestMsg,
RequestID id,
Command originalCommand,
- QueryProcessor processor,
- TupleSourceID resultsID,
- AnalysisRecord analysisRecord,
- Collection schemas, DQPWorkContext workContext) {
+ DQPWorkContext workContext) {
if (workContext == null) {
workContext = new DQPWorkContext();
@@ -160,7 +157,7 @@
DQPCore rm = new DQPCore();
RequestMessage r0 = new RequestMessage("foo"); //$NON-NLS-1$
RequestID requestID = new RequestID(SESSION_STRING, 1);
- RequestWorkItem workItem = addRequest(rm, r0, requestID, null, null, null, null, null, null);
+ RequestWorkItem workItem = addRequest(rm, r0, requestID, null, null);
AtomicRequestMessage atomicReq = new AtomicRequestMessage(workItem.requestMsg, workItem.dqpWorkContext, 1);
DataTierTupleSource info = new DataTierTupleSource(null, atomicReq, null, new ConnectorID("connID"), workItem); //$NON-NLS-1$
@@ -174,7 +171,7 @@
DQPCore rm = new DQPCore();
RequestMessage r0 = new RequestMessage("foo"); //$NON-NLS-1$
RequestID requestID = new RequestID(SESSION_STRING, 1);
- RequestWorkItem workItem = addRequest(rm, r0, requestID, null, null, null, null, null, null);
+ RequestWorkItem workItem = addRequest(rm, r0, requestID, null, null);
AtomicRequestMessage atomicReq = new AtomicRequestMessage(workItem.requestMsg, workItem.dqpWorkContext, 1);
DataTierTupleSource info = new DataTierTupleSource(null, atomicReq, null, new ConnectorID("connID"), workItem); //$NON-NLS-1$
@@ -186,4 +183,19 @@
assertNull(arInfo);
}
+ public void testLogTxnID() {
+ DQPCore rm = new DQPCore();
+ TrackingService ts = Mockito.mock(TrackingService.class);
+ Mockito.stub(ts.willRecordMMCmd()).toReturn(true);
+ rm.setTracker(ts);
+ RequestMessage r0 = new RequestMessage("foo"); //$NON-NLS-1$
+ RequestID requestID = new RequestID(SESSION_STRING, 1);
+ RequestWorkItem workItem = addRequest(rm, r0, requestID, null, null);
+ TransactionContext tc = Mockito.mock(TransactionContext.class);
+ Mockito.stub(tc.getTxnID()).toReturn("mytxnid"); //$NON-NLS-1$
+ workItem.setTransactionContext(tc);
+ rm.logMMCommand(workItem, true, true, -1);
+ Mockito.verify(ts, Mockito.times(1)).log("C.0", "mytxnid", (short)1, (short)1, null, null, null, null, null, null, -1); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
}
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-21 19:43:28 UTC (rev 817)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestDataTierManager.java 2009-04-21 20:37:26 UTC (rev 818)
@@ -130,7 +130,7 @@
context.setVdbVersion("1"); //$NON-NLS-1$
context.setQueryProcessorFactory(new SimpleQueryProcessorFactory(bs.getBufferManager(), dtm, new DefaultCapabilitiesFinder(), null, metadata));
processor = new QueryProcessor(new FakeProcessorPlan(), context, bs.getBufferManager(), dtm);
- workItem = TestDQPCoreRequestHandling.addRequest(rm, original, requestID, null, processor, null, null, null, workContext);
+ workItem = TestDQPCoreRequestHandling.addRequest(rm, original, requestID, null, workContext);
request = new AtomicRequestMessage(original, workContext, nodeId);
request.setCommand(command);
Modified: trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestMetaDataProcessor.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestMetaDataProcessor.java 2009-04-21 19:43:28 UTC (rev 817)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestMetaDataProcessor.java 2009-04-21 20:37:26 UTC (rev 818)
@@ -79,7 +79,7 @@
// Initialize components
RequestID requestID = workContext.getRequestID(1);
RequestMessage requestMsg = new RequestMessage(sql);
- TestDQPCoreRequestHandling.addRequest(requestMgr, requestMsg, requestID, command, null, null, AnalysisRecord.createNonRecordingRecord(), null, null); //$NON-NLS-1$
+ TestDQPCoreRequestHandling.addRequest(requestMgr, requestMsg, requestID, command, null); //$NON-NLS-1$
ApplicationEnvironment env = new ApplicationEnvironment();
FakeVDBService vdbService = new FakeVDBService();
15 years, 8 months
teiid SVN: r817 - in trunk/common-internal/src/test: resources and 1 other directory.
by teiid-commits@lists.jboss.org
Author: tejones
Date: 2009-04-21 15:43:28 -0400 (Tue, 21 Apr 2009)
New Revision: 817
Added:
trunk/common-internal/src/test/resources/BooksWebService_VDB.vdb
Modified:
trunk/common-internal/src/test/java/com/metamatrix/common/vdb/api/TestVDBArchive.java
Log:
TEIID-523 Added test for the setting of the wsdlAvailable flag.
Modified: trunk/common-internal/src/test/java/com/metamatrix/common/vdb/api/TestVDBArchive.java
===================================================================
--- trunk/common-internal/src/test/java/com/metamatrix/common/vdb/api/TestVDBArchive.java 2009-04-21 18:48:10 UTC (rev 816)
+++ trunk/common-internal/src/test/java/com/metamatrix/common/vdb/api/TestVDBArchive.java 2009-04-21 19:43:28 UTC (rev 817)
@@ -37,6 +37,23 @@
/*
+ * Test the setting of the WSDL Defined flag
+ */
+ public void testWSDLVDBArchive() throws Exception {
+
+ FileUtils.copy(UnitTestUtil.getTestDataPath()+"/BooksWebService_VDB.vdb", vdbPath);
+
+ File vdbFile = new File(vdbPath);
+
+ VDBArchive archive = new VDBArchive(vdbFile);
+
+ assertEquals(true, archive.def.hasWSDLDefined());
+
+ archive.close();
+ vdbFile.delete();
+ }
+
+ /*
* Updates based on the File VDB
*/
public void testFileVDBArchive() throws Exception {
Added: trunk/common-internal/src/test/resources/BooksWebService_VDB.vdb
===================================================================
(Binary files differ)
Property changes on: trunk/common-internal/src/test/resources/BooksWebService_VDB.vdb
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
15 years, 8 months
teiid SVN: r816 - trunk/common-internal/src/main/java/com/metamatrix/common/vdb/api.
by teiid-commits@lists.jboss.org
Author: tejones
Date: 2009-04-21 14:48:10 -0400 (Tue, 21 Apr 2009)
New Revision: 816
Modified:
trunk/common-internal/src/main/java/com/metamatrix/common/vdb/api/VDBArchive.java
Log:
TEIID-523 Added code to set the wsdlAvailable flag.
Modified: trunk/common-internal/src/main/java/com/metamatrix/common/vdb/api/VDBArchive.java
===================================================================
--- trunk/common-internal/src/main/java/com/metamatrix/common/vdb/api/VDBArchive.java 2009-04-21 18:38:33 UTC (rev 815)
+++ trunk/common-internal/src/main/java/com/metamatrix/common/vdb/api/VDBArchive.java 2009-04-21 18:48:10 UTC (rev 816)
@@ -171,6 +171,7 @@
} else {
appendManifest(this.def, manifest);
}
+ this.def.setHasWSDLDefined(this.wsdlAvailable);
} finally {
archive.close();
15 years, 8 months
teiid SVN: r815 - in trunk/engine/src: main/java/com/metamatrix/query/optimizer/relational/rules and 5 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2009-04-21 14:38:33 -0400 (Tue, 21 Apr 2009)
New Revision: 815
Modified:
trunk/engine/src/main/java/com/metamatrix/query/function/FunctionLibrary.java
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RulePushAggregates.java
trunk/engine/src/main/java/com/metamatrix/query/resolver/command/ExecResolver.java
trunk/engine/src/main/java/com/metamatrix/query/resolver/command/InsertResolver.java
trunk/engine/src/main/java/com/metamatrix/query/resolver/command/SimpleQueryResolver.java
trunk/engine/src/main/java/com/metamatrix/query/resolver/util/ResolverUtil.java
trunk/engine/src/main/java/com/metamatrix/query/resolver/util/ResolverVisitor.java
trunk/engine/src/main/java/com/metamatrix/query/resolver/util/ResolverVisitorUtil.java
trunk/engine/src/main/java/com/metamatrix/query/sql/navigator/AbstractNavigator.java
trunk/engine/src/test/java/com/metamatrix/query/function/TestFunctionLibrary.java
trunk/engine/src/test/java/com/metamatrix/query/resolver/TestFunctionResolving.java
trunk/engine/src/test/java/com/metamatrix/query/resolver/TestResolver.java
Log:
TEIID-235 improved resolution of functions when a parameter type is unknown.
Modified: trunk/engine/src/main/java/com/metamatrix/query/function/FunctionLibrary.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/function/FunctionLibrary.java 2009-04-21 16:32:23 UTC (rev 814)
+++ trunk/engine/src/main/java/com/metamatrix/query/function/FunctionLibrary.java 2009-04-21 18:38:33 UTC (rev 815)
@@ -201,25 +201,26 @@
* In other cases the list will contain one or more non-null values where the value
* is a conversion function that can be used to convert to the proper types for
* executing the function.
- * @param name Name of function
- * @param types Existing types passed to the function
+ * @param name Name of function
+ * @param returnType
+ * @param types Existing types passed to the function
* @return Null if no conversion could be found, otherwise an array of conversions
* to apply to each argument. The list should match 1-to-1 with the parameters.
* Parameters that do not need a conversion are null; parameters that do are
* FunctionDescriptors.
* @throws QueryResolverException
*/
- public FunctionDescriptor[] determineNecessaryConversions(String name, Class[] types, boolean hasUnknownType) {
+ public FunctionDescriptor[] determineNecessaryConversions(String name, Class<?> returnType, Class<?>[] types, boolean hasUnknownType) {
// Check for no args - no conversion necessary
if(types.length == 0) {
return new FunctionDescriptor[0];
}
// Construct results array
- FunctionDescriptor[] results = null;
+ FunctionDescriptor[] results = null;
//First find existing functions with same name and same number of parameters
- final Collection functionMethods = new LinkedList();
+ final Collection<FunctionMethod> functionMethods = new LinkedList<FunctionMethod>();
functionMethods.addAll( this.systemFunctions.findFunctionMethods(name , types.length) );
functionMethods.addAll( this.userFunctions.findFunctionMethods(name , types.length) );
@@ -227,11 +228,10 @@
//Score of current method (lower score means better match with less converts
//Current best score (lower score is best. Higher score results in more implicit conversions
int bestScore = Integer.MAX_VALUE;
- boolean ambiguous = false;
-
- for (Iterator matchingMethods = functionMethods.iterator(); matchingMethods.hasNext(); ) {
+ boolean ambiguous = false;
+
+ for (FunctionMethod nextMethod : functionMethods) {
int currentScore = 0;
- final FunctionMethod nextMethod = (FunctionMethod)matchingMethods.next();
final FunctionParameter[] methodTypes = nextMethod.getInputParameters();
//Holder for current signature with converts where required
FunctionDescriptor[] currentSignature = new FunctionDescriptor[types.length];
@@ -242,9 +242,9 @@
for(; i < types.length; i++) {
//treat all varags as the same type
final String tmpTypeName = methodTypes[Math.min(i, methodTypes.length - 1)].getType();
- Class targetType = DataTypeManager.getDataTypeClass(tmpTypeName);
+ Class<?> targetType = DataTypeManager.getDataTypeClass(tmpTypeName);
- Class sourceType = types[i];
+ Class<?> sourceType = types[i];
if (sourceType == null) {
FunctionDescriptor fd = findTypedConversionFunction(DataTypeManager.DefaultDataClasses.NULL, targetType);
currentSignature[i] = fd;
@@ -252,32 +252,37 @@
continue;
}
- final String sourceTypeName = DataTypeManager.getDataTypeName(sourceType);
- final String targetTypeName = DataTypeManager.getDataTypeName(targetType);
- //If exact match no conversion neccessary
- if(sourceTypeName.equals(targetTypeName)) {
- continue;
- }
- //Else see if an implicit conversion is possible.
- if(!DataTypeManager.isImplicitConversion(sourceTypeName, targetTypeName)){
- break;
- }
- //Else no conversion is available and the current method is not a valid match
- final FunctionDescriptor fd = findTypedConversionFunction(sourceType, targetType);
- if(fd == null) {
- break;
- }
- currentScore++;
- currentSignature[i] = fd;
+ try {
+ FunctionDescriptor fd = getConvertFunctionDescriptor(sourceType, targetType);
+ if (fd != null) {
+ currentScore++;
+ currentSignature[i] = fd;
+ }
+ } catch (InvalidFunctionException e) {
+ break;
+ }
}
//If the method is valid match and it is the current best score, capture those values as current best match
if (i != types.length || currentScore > bestScore) {
continue;
- }
+ }
+
+ if (hasUnknownType) {
+ if (returnType != null) {
+ try {
+ FunctionDescriptor fd = getConvertFunctionDescriptor(DataTypeManager.getDataTypeClass(nextMethod.getOutputParameter().getType()), returnType);
+ if (fd != null) {
+ currentScore++;
+ }
+ } catch (InvalidFunctionException e) {
+ //there still may be a common type, but use any other valid conversion over this one
+ currentScore += (types.length + 1);
+ }
+ }
+ ambiguous = currentScore == bestScore;
+ }
- ambiguous = hasUnknownType && currentScore == bestScore;
-
if (currentScore < bestScore) {
if (currentScore == 0) {
@@ -286,7 +291,7 @@
}
bestScore = currentScore;
- results = currentSignature;
+ results = currentSignature;
}
}
@@ -295,6 +300,25 @@
}
return results;
+ }
+
+ private FunctionDescriptor getConvertFunctionDescriptor(Class<?> sourceType, Class<?> targetType) throws InvalidFunctionException {
+ final String sourceTypeName = DataTypeManager.getDataTypeName(sourceType);
+ final String targetTypeName = DataTypeManager.getDataTypeName(targetType);
+ //If exact match no conversion necessary
+ if(sourceTypeName.equals(targetTypeName)) {
+ return null;
+ }
+ //Else see if an implicit conversion is possible.
+ if(!DataTypeManager.isImplicitConversion(sourceTypeName, targetTypeName)){
+ throw new InvalidFunctionException();
+ }
+ //Else no conversion is available and the current method is not a valid match
+ final FunctionDescriptor fd = findTypedConversionFunction(sourceType, targetType);
+ if(fd == null) {
+ throw new InvalidFunctionException();
+ }
+ return fd;
}
/**
Modified: trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RulePushAggregates.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RulePushAggregates.java 2009-04-21 16:32:23 UTC (rev 814)
+++ trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RulePushAggregates.java 2009-04-21 18:38:33 UTC (rev 815)
@@ -48,6 +48,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.resolver.util.ResolverVisitor;
import com.metamatrix.query.resolver.util.ResolverVisitorUtil;
import com.metamatrix.query.sql.ReservedWords;
import com.metamatrix.query.sql.lang.CompareCriteria;
@@ -384,7 +385,7 @@
Function convertFunc = new Function(FunctionLibrary.CONVERT, new Expression[] {
newAgg, convertTargetType
});
- ResolverVisitorUtil.resolveFunction(convertFunc, metadata);
+ ResolverVisitor.resolveLanguageObject(convertFunc, metadata);
newExpression = convertFunc;
nestedAggregates.add(partitionAgg);
@@ -397,7 +398,7 @@
AggregateSymbol sumCountAgg = new AggregateSymbol("stagedAgg", ReservedWords.SUM, false, countAgg); //$NON-NLS-1$
Function divideFunc = new Function("/", new Expression[] {sumSumAgg, sumCountAgg}); //$NON-NLS-1$
- ResolverVisitorUtil.resolveFunction(divideFunc, metadata);
+ ResolverVisitor.resolveLanguageObject(divideFunc, metadata);
newExpression = divideFunc;
nestedAggregates.add(countAgg);
Modified: trunk/engine/src/main/java/com/metamatrix/query/resolver/command/ExecResolver.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/resolver/command/ExecResolver.java 2009-04-21 16:32:23 UTC (rev 814)
+++ trunk/engine/src/main/java/com/metamatrix/query/resolver/command/ExecResolver.java 2009-04-21 18:38:33 UTC (rev 815)
@@ -289,7 +289,7 @@
ResolverVisitor.resolveLanguageObject(expr, null, externalGroups, metadata);
Class paramType = param.getClassType();
- ResolverUtil.setTypeIfReference(expr, paramType, storedProcedureCommand);
+ ResolverUtil.setDesiredType(expr, paramType, storedProcedureCommand);
// Compare type of parameter expression against parameter type
// and add implicit conversion if necessary
Modified: trunk/engine/src/main/java/com/metamatrix/query/resolver/command/InsertResolver.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/resolver/command/InsertResolver.java 2009-04-21 16:32:23 UTC (rev 814)
+++ trunk/engine/src/main/java/com/metamatrix/query/resolver/command/InsertResolver.java 2009-04-21 18:38:33 UTC (rev 815)
@@ -166,7 +166,7 @@
ElementSymbol element = (ElementSymbol) varIter.next();
if (!usingQuery) {
- ResolverUtil.setTypeIfReference(expression, element.getType(), insert);
+ ResolverUtil.setDesiredType(expression, element.getType(), insert);
}
if(element.getType() != null && expression.getType() != null) {
Modified: trunk/engine/src/main/java/com/metamatrix/query/resolver/command/SimpleQueryResolver.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/resolver/command/SimpleQueryResolver.java 2009-04-21 16:32:23 UTC (rev 814)
+++ trunk/engine/src/main/java/com/metamatrix/query/resolver/command/SimpleQueryResolver.java 2009-04-21 18:38:33 UTC (rev 815)
@@ -298,6 +298,8 @@
try {
QueryResolverVisitor qrv = new QueryResolverVisitor(query, metadata, useMetadataCommands, analysis);
qrv.visit(query);
+ ResolverVisitor visitor = (ResolverVisitor)qrv.getVisitor();
+ visitor.throwException(true);
} catch (MetaMatrixRuntimeException e) {
if (e.getChild() instanceof QueryMetadataException) {
throw (QueryMetadataException)e.getChild();
@@ -362,12 +364,13 @@
protected void postVisitVisitor(LanguageObject obj) {
super.postVisitVisitor(obj);
ResolverVisitor visitor = (ResolverVisitor)getVisitor();
- if (visitor.getComponentException() != null) {
- throw new MetaMatrixRuntimeException(visitor.getComponentException());
- }
- if (visitor.getResolverException() != null) {
- throw new MetaMatrixRuntimeException(visitor.getResolverException());
- }
+ try {
+ visitor.throwException(false);
+ } catch (QueryResolverException e) {
+ throw new MetaMatrixRuntimeException(e);
+ } catch (MetaMatrixComponentException e) {
+ throw new MetaMatrixRuntimeException(e);
+ }
}
/**
Modified: trunk/engine/src/main/java/com/metamatrix/query/resolver/util/ResolverUtil.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/resolver/util/ResolverUtil.java 2009-04-21 16:32:23 UTC (rev 814)
+++ trunk/engine/src/main/java/com/metamatrix/query/resolver/util/ResolverUtil.java 2009-04-21 18:38:33 UTC (rev 815)
@@ -213,10 +213,10 @@
private static Expression getConversion(Expression sourceExpression,
String sourceTypeName,
String targetTypeName) {
- Class srcType = DataTypeManager.getDataTypeClass(sourceTypeName);
+ Class<?> srcType = DataTypeManager.getDataTypeClass(sourceTypeName);
FunctionLibrary library = FunctionLibraryManager.getFunctionLibrary();
- FunctionDescriptor fd = library.findFunction(FunctionLibrary.CONVERT, new Class[] { srcType, DataTypeManager.DefaultDataClasses.STRING });
+ FunctionDescriptor fd = library.findTypedConversionFunction(srcType, DataTypeManager.getDataTypeClass(targetTypeName));
Function conversion = new Function(fd.getName(), new Expression[] { sourceExpression, new Constant(targetTypeName) });
conversion.setType(DataTypeManager.getDataTypeClass(targetTypeName));
@@ -232,12 +232,20 @@
* @param targetType the target type, if the expression's type is null.
* @throws QueryResolverException if unable to set the reference type to the target type.
*/
- public static void setTypeIfReference(Expression expression, Class<?> targetType, LanguageObject surroundingExpression) throws QueryResolverException {
- if ((expression instanceof Reference) && ((Reference)expression).isPositional()) {
- if (targetType == null) {
- throw new QueryResolverException(ErrorMessageKeys.RESOLVER_0026, QueryPlugin.Util.getString(ErrorMessageKeys.RESOLVER_0026, surroundingExpression));
+ public static void setDesiredType(Expression expression, Class<?> targetType, LanguageObject surroundingExpression) throws QueryResolverException {
+ if (expression instanceof Reference) {
+ Reference ref = (Reference)expression;
+ if (ref.isPositional() && ref.getType() == null) {
+ if (targetType == null) {
+ throw new QueryResolverException(ErrorMessageKeys.RESOLVER_0026, QueryPlugin.Util.getString(ErrorMessageKeys.RESOLVER_0026, surroundingExpression));
+ }
+ ref.setType(targetType);
}
- ((Reference)expression).setType(targetType);
+ } else if (expression instanceof Function) {
+ Function f = (Function)expression;
+ if (f.getType() == null) {
+ f.setType(targetType);
+ }
}
}
@@ -550,9 +558,9 @@
public static void resolveLimit(Limit limit) throws QueryResolverException {
if (limit.getOffset() != null) {
- setTypeIfReference(limit.getOffset(), DataTypeManager.DefaultDataClasses.INTEGER, limit);
+ setDesiredType(limit.getOffset(), DataTypeManager.DefaultDataClasses.INTEGER, limit);
}
- setTypeIfReference(limit.getRowLimit(), DataTypeManager.DefaultDataClasses.INTEGER, limit);
+ setDesiredType(limit.getRowLimit(), DataTypeManager.DefaultDataClasses.INTEGER, limit);
}
public static void resolveImplicitTempGroup(TempMetadataAdapter metadata, GroupSymbol symbol, List symbols)
@@ -629,7 +637,7 @@
((ScalarSubquery)expr).setType(replacement);
} else {
try {
- ResolverUtil.setTypeIfReference(expr, replacement, symbol);
+ ResolverUtil.setDesiredType(expr, replacement, symbol);
} catch (QueryResolverException e) {
//cannot happen
}
Modified: trunk/engine/src/main/java/com/metamatrix/query/resolver/util/ResolverVisitor.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/resolver/util/ResolverVisitor.java 2009-04-21 16:32:23 UTC (rev 814)
+++ trunk/engine/src/main/java/com/metamatrix/query/resolver/util/ResolverVisitor.java 2009-04-21 18:38:33 UTC (rev 815)
@@ -22,18 +22,30 @@
package com.metamatrix.query.resolver.util;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
+import java.util.IdentityHashMap;
import java.util.Iterator;
import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import net.sf.saxon.trans.XPathException;
+
import com.metamatrix.api.exception.MetaMatrixComponentException;
import com.metamatrix.api.exception.query.QueryMetadataException;
import com.metamatrix.api.exception.query.QueryResolverException;
import com.metamatrix.api.exception.query.UnresolvedSymbolDescription;
import com.metamatrix.common.types.DataTypeManager;
+import com.metamatrix.common.types.DataTypeManager.DefaultDataClasses;
import com.metamatrix.core.util.Assertion;
+import com.metamatrix.internal.core.xml.XPathHelper;
import com.metamatrix.query.QueryPlugin;
+import com.metamatrix.query.function.FunctionDescriptor;
+import com.metamatrix.query.function.FunctionForm;
+import com.metamatrix.query.function.FunctionLibrary;
+import com.metamatrix.query.function.FunctionLibraryManager;
import com.metamatrix.query.metadata.GroupInfo;
import com.metamatrix.query.metadata.QueryMetadataInterface;
import com.metamatrix.query.sql.LanguageObject;
@@ -48,10 +60,14 @@
import com.metamatrix.query.sql.lang.SubqueryCompareCriteria;
import com.metamatrix.query.sql.lang.SubquerySetCriteria;
import com.metamatrix.query.sql.navigator.PostOrderNavigator;
+import com.metamatrix.query.sql.symbol.AggregateSymbol;
import com.metamatrix.query.sql.symbol.CaseExpression;
+import com.metamatrix.query.sql.symbol.Constant;
import com.metamatrix.query.sql.symbol.ElementSymbol;
+import com.metamatrix.query.sql.symbol.Expression;
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.SearchedCaseExpression;
import com.metamatrix.query.util.ErrorMessageKeys;
@@ -67,31 +83,25 @@
}
}
- private Collection groups;
+ private Collection<GroupSymbol> groups;
private GroupContext externalContext;
protected QueryMetadataInterface metadata;
private MetaMatrixComponentException componentException;
private QueryResolverException resolverException;
+ private Map<Function, QueryResolverException> unresolvedFunctions;
/**
* Constructor for ResolveElementsVisitor.
*
* External groups are ordered from inner to outer most
*/
- public ResolverVisitor(QueryMetadataInterface metadata, Collection internalGroups, GroupContext externalContext) {
+ public ResolverVisitor(QueryMetadataInterface metadata, Collection<GroupSymbol> internalGroups, GroupContext externalContext) {
this.groups = internalGroups;
this.externalContext = externalContext;
this.metadata = metadata;
}
- /**
- * Constructor for ResolveElementsVisitor.
- */
- public ResolverVisitor(QueryMetadataInterface metadata, Collection internalGroups) {
- this(metadata, internalGroups, null);
- }
-
- public void setGroups(Collection groups) {
+ public void setGroups(Collection<GroupSymbol> groups) {
this.groups = groups;
}
@@ -149,7 +159,7 @@
}
} else {
try {
- LinkedList matchedGroups = new LinkedList();
+ LinkedList<GroupSymbol> matchedGroups = new LinkedList<GroupSymbol>();
if (groupContext != null) {
//assume that this is fully qualified
@@ -169,7 +179,7 @@
LinkedList<ElementMatch> matches = new LinkedList<ElementMatch>();
String shortCanonicalName = elementShortName.toUpperCase();
while (root != null) {
- Collection matchedGroups = ResolverUtil.findMatchingGroups(groupContext, root.getGroups(), metadata);
+ Collection<GroupSymbol> matchedGroups = ResolverUtil.findMatchingGroups(groupContext, root.getGroups(), metadata);
if (matchedGroups != null && !matchedGroups.isEmpty()) {
groupMatched = true;
@@ -217,10 +227,10 @@
private void resolveUsingUUID(String potentialID,
String elementShortName,
LinkedList<ElementMatch> matches,
- Collection matchedGroups) throws MetaMatrixComponentException,
+ Collection<GroupSymbol> matchedGroups) throws MetaMatrixComponentException,
QueryMetadataException {
Assertion.assertTrue(matchedGroups.size() == 1);
- GroupSymbol group = (GroupSymbol)matchedGroups.iterator().next();
+ GroupSymbol group = matchedGroups.iterator().next();
ElementSymbol resolvedSymbol = new ElementSymbol(potentialID);
resolvedSymbol.setGroupSymbol(group);
String elementID = metadata.getFullElementName( metadata.getFullName(group.getMetadataID()), elementShortName );
@@ -230,11 +240,9 @@
}
private void resolveAgainstGroups(String elementShortName,
- Collection matchedGroups, LinkedList<ElementMatch> matches) throws QueryMetadataException,
+ Collection<GroupSymbol> matchedGroups, LinkedList<ElementMatch> matches) throws QueryMetadataException,
MetaMatrixComponentException {
- for (Iterator i = matchedGroups.iterator(); i.hasNext();) {
- GroupSymbol group = (GroupSymbol)i.next();
-
+ for (GroupSymbol group : matchedGroups) {
GroupInfo groupInfo = ResolverUtil.getGroupInfo(group, metadata);
ElementSymbol result = groupInfo.getSymbol(elementShortName);
@@ -246,15 +254,17 @@
public void visit(BetweenCriteria obj) {
try {
- ResolverVisitorUtil.resolveBetweenCriteria(obj);
+ resolveBetweenCriteria(obj);
} catch(QueryResolverException e) {
handleException(e);
+ } catch(MetaMatrixComponentException e) {
+ handleException(e);
}
}
public void visit(CompareCriteria obj) {
try {
- ResolverVisitorUtil.resolveCompareCriteria(obj);
+ resolveCompareCriteria(obj);
} catch(QueryResolverException e) {
handleException(e);
}
@@ -262,7 +272,7 @@
public void visit(MatchCriteria obj) {
try {
- ResolverVisitorUtil.resolveMatchCriteria(obj);
+ resolveMatchCriteria(obj);
} catch(QueryResolverException e) {
handleException(e);
}
@@ -270,7 +280,7 @@
public void visit(SetCriteria obj) {
try {
- ResolverVisitorUtil.resolveSetCriteria(obj);
+ resolveSetCriteria(obj);
} catch(QueryResolverException e) {
handleException(e);
}
@@ -295,7 +305,7 @@
public void visit(IsNullCriteria obj) {
try {
- ResolverVisitorUtil.resolveIsNullCriteria(obj);
+ setDesiredType(obj.getExpression(), DefaultDataClasses.OBJECT, obj);
} catch(QueryResolverException e) {
handleException(e);
}
@@ -303,9 +313,12 @@
public void visit(Function obj) {
try {
- ResolverVisitorUtil.resolveFunction(obj, metadata);
+ resolveFunction(obj);
} catch(QueryResolverException e) {
- handleException(e);
+ if (unresolvedFunctions == null) {
+ unresolvedFunctions = new IdentityHashMap<Function, QueryResolverException>();
+ }
+ unresolvedFunctions.put(obj, e);
} catch(MetaMatrixComponentException e) {
handleException(e);
}
@@ -313,28 +326,27 @@
public void visit(CaseExpression obj) {
try {
- ResolverVisitorUtil.resolveCaseExpression(obj);
-
+ resolveCaseExpression(obj);
} catch(QueryResolverException e) {
handleException(e);
- }
+ }
}
public void visit(SearchedCaseExpression obj) {
try {
- ResolverVisitorUtil.resolveSearchedCaseExpression(obj);
+ resolveSearchedCaseExpression(obj);
} catch(QueryResolverException e) {
handleException(e);
- }
+ }
}
public void visit(SetClause obj) {
String type = DataTypeManager.getDataTypeName(obj.getSymbol().getType());
try {
- ResolverUtil.setTypeIfReference(obj.getValue(), obj.getSymbol().getType(), obj);
+ setDesiredType(obj.getValue(), obj.getSymbol().getType(), obj);
obj.setValue(ResolverUtil.convertExpression(obj.getValue(), type));
} catch(QueryResolverException e) {
- handleException(new QueryResolverException(e, QueryPlugin.Util.getString("SetClause.resolvingError", new Object[] {obj.getValue(), obj.getSymbol(), type})));
+ handleException(new QueryResolverException(e, QueryPlugin.Util.getString("SetClause.resolvingError", new Object[] {obj.getValue(), obj.getSymbol(), type}))); //$NON-NLS-1$
}
}
@@ -360,34 +372,576 @@
setAbort(true);
}
- public static void resolveLanguageObject(LanguageObject obj, QueryMetadataInterface metadata)
- throws MetaMatrixComponentException, QueryResolverException {
- ResolverVisitor.resolveLanguageObject(obj, null, metadata);
- }
+ public void throwException(boolean includeUnresolvedFunctions)
+ throws MetaMatrixComponentException, QueryResolverException {
+ if(getComponentException() != null) {
+ throw getComponentException();
+ }
- public static void resolveLanguageObject(LanguageObject obj, Collection groups, QueryMetadataInterface metadata)
- throws MetaMatrixComponentException, QueryResolverException {
- ResolverVisitor.resolveLanguageObject(obj, groups, null, metadata);
- }
+ if(getResolverException() != null) {
+ throw getResolverException();
+ }
+
+ if (includeUnresolvedFunctions
+ && unresolvedFunctions != null && !unresolvedFunctions.isEmpty()) {
+ throw unresolvedFunctions.values().iterator().next();
+ }
+ }
- public static void resolveLanguageObject(LanguageObject obj, Collection groups, GroupContext externalContext, QueryMetadataInterface metadata)
- throws MetaMatrixComponentException, QueryResolverException {
+ /**
+ * Resolve function such that all functions are resolved and type-safe.
+ */
+ void resolveFunction(Function function)
+ throws QueryResolverException, MetaMatrixComponentException {
+
+ // Check whether this function is already resolved
+ if(function.getFunctionDescriptor() != null) {
+ return;
+ }
+
+ // Look up types for all args
+ boolean hasArgWithoutType = false;
+ Expression[] args = function.getArgs();
+ Class[] types = new Class[args.length];
+ for(int i=0; i<args.length; i++) {
+ types[i] = args[i].getType();
+ if(types[i] == null) {
+ if(!(args[i] instanceof Reference)){
+ throw new QueryResolverException(ErrorMessageKeys.RESOLVER_0035, QueryPlugin.Util.getString(ErrorMessageKeys.RESOLVER_0035, new Object[] {args[i], function}));
+ }
+ hasArgWithoutType = true;
+ }
+ }
+
+ FunctionLibrary library = FunctionLibraryManager.getFunctionLibrary();
+
+ //special case handling for convert of an untyped reference
+ if (FunctionLibrary.isConvert(function) && hasArgWithoutType) {
+ Constant constant = (Constant)function.getArg(1);
+ Class<?> type = DataTypeManager.getDataTypeClass((String)constant.getValue());
+
+ setDesiredType(function.getArg(0), type, function);
+ types[0] = type;
+ hasArgWithoutType = false;
+ }
+
+ // Attempt to get exact match of function for this signature
+ FunctionDescriptor fd = findWithImplicitConversions(library, function, args, types, hasArgWithoutType);
+
+ // Function did not resolve - determine reason and throw exception
+ if(fd == null) {
+ FunctionForm form = library.findFunctionForm(function.getName(), args.length);
+ if(form == null) {
+ // Unknown function form
+ throw new QueryResolverException(ErrorMessageKeys.RESOLVER_0039, QueryPlugin.Util.getString(ErrorMessageKeys.RESOLVER_0039, function));
+ }
+ // Known function form - but without type information
+ if (hasArgWithoutType) {
+ throw new QueryResolverException(ErrorMessageKeys.RESOLVER_0036, QueryPlugin.Util.getString(ErrorMessageKeys.RESOLVER_0036, function));
+ }
+ // Known function form - unable to find implicit conversions
+ throw new QueryResolverException(ErrorMessageKeys.RESOLVER_0040, QueryPlugin.Util.getString(ErrorMessageKeys.RESOLVER_0040, function));
+ }
+
+ if(fd.getName().equalsIgnoreCase(FunctionLibrary.CONVERT) || fd.getName().equalsIgnoreCase(FunctionLibrary.CAST)) {
+ String dataType = (String) ((Constant)args[1]).getValue();
+ Class dataTypeClass = DataTypeManager.getDataTypeClass(dataType);
+ fd = library.findTypedConversionFunction(args[0].getType(), dataTypeClass);
+
+ // Verify that the type conversion from src to type is even valid
+ Class srcTypeClass = args[0].getType();
+ if(srcTypeClass != null && dataTypeClass != null &&
+ !srcTypeClass.equals(dataTypeClass) &&
+ !DataTypeManager.isTransformable(srcTypeClass, dataTypeClass)) {
+
+ throw new QueryResolverException(ErrorMessageKeys.RESOLVER_0037, QueryPlugin.Util.getString(ErrorMessageKeys.RESOLVER_0037, new Object[] {DataTypeManager.getDataTypeName(srcTypeClass), dataType}));
+ }
+ } else if(fd.getName().equalsIgnoreCase(FunctionLibrary.LOOKUP)) {
+ ResolverVisitorUtil.ResolvedLookup lookup = ResolverVisitorUtil.resolveLookup(function, metadata);
+ fd = library.copyFunctionChangeReturnType(fd, lookup.getReturnElement().getType());
+ } else if(fd.getName().equalsIgnoreCase(FunctionLibrary.XPATHVALUE)) {
+ // Validate the xpath value is valid
+ if(args[1] != null && args[1] instanceof Constant) {
+ Constant xpathConst = (Constant) args[1];
+ if(xpathConst.getType().equals(DataTypeManager.DefaultDataClasses.STRING)) {
+ String value = (String) xpathConst.getValue();
+ if(value == null) {
+ throw new QueryResolverException(QueryPlugin.Util.getString("QueryResolver.invalid_xpath", QueryPlugin.Util.getString("ResolveFunctionsVisitor.xpath_cant_be_null"))); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ try {
+ XPathHelper.validateXpath(value);
+ } catch(XPathException e) {
+ throw new QueryResolverException(QueryPlugin.Util.getString("QueryResolver.invalid_xpath", e.getMessage())); //$NON-NLS-1$
+ }
+ }
+ }
+ }
+
+ // Resolve the function
+ function.setFunctionDescriptor(fd);
+ function.setType(fd.getReturnType());
+ }
- if(obj == null) {
- return;
- }
+ /**
+ * Find possible matches based on implicit conversions of the arguments.
+ * NOTE: This method has the side-effect of explicitly inserting conversions into the function arguments,
+ * and thereby changing the structure of the function call.
+ * @param library
+ * @param function
+ * @param types
+ * @return
+ * @throws MetaMatrixComponentException
+ * @since 4.3
+ */
+ private FunctionDescriptor findWithImplicitConversions(FunctionLibrary library, Function function, Expression[] args, Class<?>[] types, boolean hasArgWithoutType) throws QueryResolverException, MetaMatrixComponentException {
+
+ // Try to find implicit conversion path to still perform this function
+ FunctionDescriptor[] conversions = library.determineNecessaryConversions(function.getName(), function.getType(), types, hasArgWithoutType);
+
+ if(conversions == null) {
+ return null;
+ }
+ // Insert new conversion functions as necessary, while building new signature
+ Class<?>[] newSignature = new Class[conversions.length];
+ for(int i=0; i<conversions.length; i++) {
+
+ Class<?> newType = types[i];
+
+ if(conversions[i] != null) {
+ newType = conversions[i].getReturnType();
+
+ setDesiredType(args[i], newType, function);
+
+ //only currently typed expressions need conversions
+ if (types[i] != null) {
+ function.insertConversion(i, conversions[i]);
+ }
+ }
+
+ newSignature[i] = newType;
+ }
+
+ // Now resolve using the new signature to get the function's descriptor
+ return library.findFunction(function.getName(), newSignature);
+ }
- // Resolve elements, deal with errors
- ResolverVisitor elementsVisitor = new ResolverVisitor(metadata, groups, externalContext);
- PostOrderNavigator.doVisit(obj, elementsVisitor);
- if(elementsVisitor.getComponentException() != null) {
- throw elementsVisitor.getComponentException();
- }
+ /**
+ * Resolves criteria "a BETWEEN b AND c". If type conversions are necessary,
+ * this method attempts the following implicit conversions:
+ * <br/>
+ * <ol type="1" start="1">
+ * <li>convert the lower and upper expressions to the criteria expression's type, or</li>
+ * <li>convert the criteria and upper expressions to the lower expression's type, or</li>
+ * <li>convert the criteria and lower expressions to the upper expression's type, or</li>
+ * <li>convert all expressions to a common type to which all three expressions' types can be implicitly converted.</li>
+ * </ol>
+ * @param criteria
+ * @throws QueryResolverException
+ * @throws MetaMatrixComponentException
+ * @throws MetaMatrixComponentException
+ */
+ void resolveBetweenCriteria(BetweenCriteria criteria)
+ throws QueryResolverException, MetaMatrixComponentException {
+
+ Expression exp = criteria.getExpression();
+ Expression lower = criteria.getLowerExpression();
+ Expression upper = criteria.getUpperExpression();
+
+ // invariants: none of the expressions is an aggregate symbol
+ setDesiredType(exp,
+ (lower.getType() == null)
+ ? upper.getType()
+ : lower.getType(), criteria);
+ // invariants: exp.getType() != null
+ setDesiredType(lower, exp.getType(), criteria);
+ setDesiredType(upper, exp.getType(), criteria);
+ // invariants: none of the types is null
+
+ String expTypeName = DataTypeManager.getDataTypeName(exp.getType());
+ String lowerTypeName = DataTypeManager.getDataTypeName(lower.getType());
+ String upperTypeName = DataTypeManager.getDataTypeName(upper.getType());
+ if (exp.getType().equals(lower.getType()) && exp.getType().equals(upper.getType())) {
+ return;
+ }
+
+ String commonType = ResolverUtil.getCommonType(new String[] {expTypeName, lowerTypeName, upperTypeName});
+ if (commonType != null) {
+ criteria.setExpression(ResolverUtil.convertExpression(exp, expTypeName, commonType));
+ criteria.setLowerExpression(ResolverUtil.convertExpression(lower, lowerTypeName, commonType));
+ criteria.setUpperExpression(ResolverUtil.convertExpression(upper, upperTypeName, commonType));
+ } else {
+ // Couldn't find a common type to implicitly convert to
+ throw new QueryResolverException(ErrorMessageKeys.RESOLVER_0027, QueryPlugin.Util.getString(ErrorMessageKeys.RESOLVER_0027, expTypeName, lowerTypeName, criteria));
+ }
+ // invariants: exp.getType() == lower.getType() == upper.getType()
+ }
- if(elementsVisitor.getResolverException() != null) {
- throw elementsVisitor.getResolverException();
- }
+ void resolveCompareCriteria(CompareCriteria ccrit)
+ throws QueryResolverException {
+
+ Expression leftExpression = ccrit.getLeftExpression();
+ Expression rightExpression = ccrit.getRightExpression();
+
+ // Check typing between expressions
+ setDesiredType(leftExpression, rightExpression.getType(), ccrit);
+ setDesiredType(rightExpression, leftExpression.getType(), ccrit);
+
+ if(leftExpression.getType().equals(rightExpression.getType()) ) {
+ return;
+ }
+
+ // Try to apply an implicit conversion from one side to the other
+ String leftTypeName = DataTypeManager.getDataTypeName(leftExpression.getType());
+ String rightTypeName = DataTypeManager.getDataTypeName(rightExpression.getType());
+
+ // Special cases when right expression is a constant
+ if(rightExpression instanceof Constant) {
+ // Auto-convert constant string on right to expected type on left
+ try {
+ ccrit.setRightExpression(ResolverUtil.convertExpression(rightExpression, rightTypeName, leftTypeName));
+ return;
+ } catch (QueryResolverException qre) {
+ //ignore
+ }
+ }
+
+ // Special cases when left expression is a constant
+ if(leftExpression instanceof Constant) {
+ // Auto-convert constant string on left to expected type on right
+ try {
+ ccrit.setLeftExpression(ResolverUtil.convertExpression(leftExpression, leftTypeName, rightTypeName));
+ return;
+ } catch (QueryResolverException qre) {
+ //ignore
+ }
+ }
+
+ // Try to apply a conversion generically
+
+ if(ResolverUtil.canImplicitlyConvert(leftTypeName, rightTypeName)) {
+ ccrit.setLeftExpression(ResolverUtil.convertExpression(leftExpression, leftTypeName, rightTypeName) );
+ return;
+ }
+
+ if(ResolverUtil.canImplicitlyConvert(rightTypeName, leftTypeName)) {
+ ccrit.setRightExpression(ResolverUtil.convertExpression(rightExpression, rightTypeName, leftTypeName) );
+ return;
+ }
+
+ String commonType = ResolverUtil.getCommonType(new String[] {leftTypeName, rightTypeName});
+
+ if (commonType == null) {
+ // Neither are aggs, but types can't be reconciled
+ throw new QueryResolverException(ErrorMessageKeys.RESOLVER_0027, QueryPlugin.Util.getString(ErrorMessageKeys.RESOLVER_0027, new Object[] { leftTypeName, rightTypeName, ccrit }));
+ }
+ ccrit.setLeftExpression(ResolverUtil.convertExpression(leftExpression, leftTypeName, commonType) );
+ ccrit.setRightExpression(ResolverUtil.convertExpression(rightExpression, rightTypeName, commonType) );
+ }
- }
+ void resolveMatchCriteria(MatchCriteria mcrit)
+ throws QueryResolverException {
+
+ setDesiredType(mcrit.getLeftExpression(), mcrit.getRightExpression().getType(), mcrit);
+ mcrit.setLeftExpression(resolveMatchCriteriaExpression(mcrit, mcrit.getLeftExpression()));
+
+ setDesiredType(mcrit.getRightExpression(), mcrit.getLeftExpression().getType(), mcrit);
+ mcrit.setRightExpression(resolveMatchCriteriaExpression(mcrit, mcrit.getRightExpression()));
+ }
+
+ /**
+ * Checks one side of a LIKE Criteria; implicitly converts to a String or CLOB if necessary.
+ * @param mcrit the Match Criteria
+ * @param expr either left or right expression
+ * @return either 'expr' itself, or a new implicit type conversion wrapping expr
+ * @throws QueryResolverException if no implicit type conversion is available
+ */
+ Expression resolveMatchCriteriaExpression(MatchCriteria mcrit, Expression expr)
+ throws QueryResolverException {
+ // Check left expression == string or CLOB
+ String type = DataTypeManager.getDataTypeName(expr.getType());
+ Expression result = expr;
+ if(type != null) {
+ if (! type.equals(DataTypeManager.DefaultDataTypes.STRING) &&
+ ! type.equals(DataTypeManager.DefaultDataTypes.CLOB)) {
+
+ if(!(expr instanceof AggregateSymbol) &&
+ ResolverUtil.canImplicitlyConvert(type, DataTypeManager.DefaultDataTypes.STRING)) {
+
+ result = ResolverUtil.convertExpression(expr, type, DataTypeManager.DefaultDataTypes.STRING);
+
+ } else if (!(expr instanceof AggregateSymbol) &&
+ ResolverUtil.canImplicitlyConvert(type, DataTypeManager.DefaultDataTypes.CLOB)){
+
+ result = ResolverUtil.convertExpression(expr, type, DataTypeManager.DefaultDataTypes.CLOB);
+
+ } else {
+ throw new QueryResolverException(ErrorMessageKeys.RESOLVER_0029, QueryPlugin.Util.getString(ErrorMessageKeys.RESOLVER_0029, mcrit));
+ }
+ }
+ }
+ return result;
+ }
+
+ void resolveSetCriteria(SetCriteria scrit)
+ throws QueryResolverException {
+
+ // Check that each of the values are the same type as expression
+ Class exprType = scrit.getExpression().getType();
+ if(exprType == null) {
+ throw new QueryResolverException(ErrorMessageKeys.RESOLVER_0030, QueryPlugin.Util.getString(ErrorMessageKeys.RESOLVER_0030, scrit.getExpression()));
+ }
+
+ String exprTypeName = DataTypeManager.getDataTypeName(exprType);
+ boolean changed = false;
+ List newVals = new ArrayList();
+
+ boolean convertLeft = false;
+ Class setType = null;
+
+ Iterator valIter = scrit.getValues().iterator();
+ while(valIter.hasNext()) {
+ Expression value = (Expression) valIter.next();
+ setDesiredType(value, exprType, scrit);
+ if(! value.getType().equals(exprType)) {
+ if(value instanceof AggregateSymbol) {
+ throw new QueryResolverException(ErrorMessageKeys.RESOLVER_0031, QueryPlugin.Util.getString(ErrorMessageKeys.RESOLVER_0031, scrit));
+ }
+ // try to apply cast
+ String valTypeName = DataTypeManager.getDataTypeName(value.getType());
+ if(ResolverUtil.canImplicitlyConvert(valTypeName, exprTypeName)) {
+ // Apply cast and replace current value
+ newVals.add(ResolverUtil.convertExpression(value, valTypeName, exprTypeName) );
+ changed = true;
+ } else {
+ convertLeft = true;
+ setType = value.getType();
+ break;
+ }
+ } else {
+ newVals.add(value);
+ }
+ }
+
+ // If no convert found for first element, check whether everything in the
+ // set is the same and the convert can be placed on the left side
+ if(convertLeft) {
+ // Is there a possible conversion from left to right?
+ String setTypeName = DataTypeManager.getDataTypeName(setType);
+ if(ResolverUtil.canImplicitlyConvert(exprTypeName, setTypeName)) {
+ valIter = scrit.getValues().iterator();
+ while(valIter.hasNext()) {
+ Expression value = (Expression) valIter.next();
+ if(value.getType() == null) {
+ throw new QueryResolverException(ErrorMessageKeys.RESOLVER_0030, QueryPlugin.Util.getString(ErrorMessageKeys.RESOLVER_0030, value));
+ } else if(! value.getType().equals(setType)) {
+ throw new QueryResolverException(ErrorMessageKeys.RESOLVER_0031, QueryPlugin.Util.getString(ErrorMessageKeys.RESOLVER_0031, scrit));
+ }
+ }
+
+ // Convert left expression to type of values in the set
+ scrit.setExpression(ResolverUtil.convertExpression(scrit.getExpression(), exprTypeName, setTypeName ));
+
+ } else {
+ throw new QueryResolverException(ErrorMessageKeys.RESOLVER_0031, QueryPlugin.Util.getString(ErrorMessageKeys.RESOLVER_0031, scrit));
+ }
+ }
+
+ if(changed) {
+ scrit.setValues(newVals);
+ }
+ }
+
+ void resolveCaseExpression(CaseExpression obj) throws QueryResolverException {
+ // If already resolved, do nothing
+ if (obj.getType() != null) {
+ return;
+ }
+ final int whenCount = obj.getWhenCount();
+ Expression expr = obj.getExpression();
+
+ Class whenType = null;
+ Class thenType = null;
+ // Get the WHEN and THEN types, and get a candidate type for each (for the next step)
+ for (int i = 0; i < whenCount; i++) {
+ if (whenType == null) {
+ whenType = obj.getWhenExpression(i).getType();
+ }
+ if (thenType == null) {
+ thenType = obj.getThenExpression(i).getType();
+ }
+ }
+
+ Expression elseExpr = obj.getElseExpression();
+ if (elseExpr != null) {
+ if (thenType == null) {
+ thenType = elseExpr.getType();
+ }
+ }
+ // Invariant: All the expressions contained in the obj are resolved (except References)
+
+ // 2. Attempt to set the target types of all contained expressions,
+ // and collect their type names for the next step
+ ArrayList whenTypeNames = new ArrayList(whenCount + 1);
+ ArrayList thenTypeNames = new ArrayList(whenCount + 1);
+ setDesiredType(expr, whenType, obj);
+ // Add the expression's type to the WHEN types
+ whenTypeNames.add(DataTypeManager.getDataTypeName(expr.getType()));
+ Expression when = null;
+ Expression then = null;
+ // Set the types of the WHEN and THEN parts
+ for (int i = 0; i < whenCount; i++) {
+ when = obj.getWhenExpression(i);
+ then = obj.getThenExpression(i);
+
+ setDesiredType(when, expr.getType(), obj);
+ setDesiredType(then, thenType, obj);
+
+ if (!whenTypeNames.contains(DataTypeManager.getDataTypeName(when.getType()))) {
+ whenTypeNames.add(DataTypeManager.getDataTypeName(when.getType()));
+ }
+ if (!thenTypeNames.contains(DataTypeManager.getDataTypeName(then.getType()))) {
+ thenTypeNames.add(DataTypeManager.getDataTypeName(then.getType()));
+ }
+ }
+ // Set the type of the else expression
+ if (elseExpr != null) {
+ setDesiredType(elseExpr, thenType, obj);
+ if (!thenTypeNames.contains(DataTypeManager.getDataTypeName(elseExpr.getType()))) {
+ thenTypeNames.add(DataTypeManager.getDataTypeName(elseExpr.getType()));
+ }
+ }
+
+ // Invariants: all the expressions' types are non-null
+
+ // 3. Perform implicit type conversions
+ String whenTypeName = ResolverUtil.getCommonType((String[])whenTypeNames.toArray(new String[whenTypeNames.size()]));
+ if (whenTypeName == null) {
+ throw new QueryResolverException(ErrorMessageKeys.RESOLVER_0068, QueryPlugin.Util.getString(ErrorMessageKeys.RESOLVER_0068, "WHEN", obj)); //$NON-NLS-1$
+ }
+ String thenTypeName = ResolverUtil.getCommonType((String[])thenTypeNames.toArray(new String[thenTypeNames.size()]));
+ if (thenTypeName == null) {
+ throw new QueryResolverException(ErrorMessageKeys.RESOLVER_0068, QueryPlugin.Util.getString(ErrorMessageKeys.RESOLVER_0068, "THEN/ELSE", obj)); //$NON-NLS-1$
+ }
+ obj.setExpression(ResolverUtil.convertExpression(obj.getExpression(), whenTypeName));
+ ArrayList whens = new ArrayList(whenCount);
+ ArrayList thens = new ArrayList(whenCount);
+ for (int i = 0; i < whenCount; i++) {
+ whens.add(ResolverUtil.convertExpression(obj.getWhenExpression(i), whenTypeName));
+ thens.add(ResolverUtil.convertExpression(obj.getThenExpression(i), thenTypeName));
+ }
+ obj.setWhen(whens, thens);
+ if (elseExpr != null) {
+ obj.setElseExpression(ResolverUtil.convertExpression(elseExpr, thenTypeName));
+ }
+ // Set this CASE expression's type to the common THEN type, and we're done.
+ obj.setType(DataTypeManager.getDataTypeClass(thenTypeName));
+ }
+
+ private void setDesiredType(Expression obj, Class<?> type, LanguageObject surrounding) throws QueryResolverException {
+ ResolverUtil.setDesiredType(obj, type, surrounding);
+ //second pass resolving for functions
+ if (!(obj instanceof Function)) {
+ return;
+ }
+ if (unresolvedFunctions != null) {
+ Function f = (Function)obj;
+ if (f.getFunctionDescriptor() != null) {
+ return;
+ }
+ unresolvedFunctions.remove(obj);
+ obj.acceptVisitor(this);
+ QueryResolverException e = unresolvedFunctions.get(obj);
+ if (e != null) {
+ throw e;
+ }
+ }
+ }
+
+ void resolveSearchedCaseExpression(SearchedCaseExpression obj) throws QueryResolverException {
+ // If already resolved, do nothing
+ if (obj.getType() != null) {
+ return;
+ }
+ final int whenCount = obj.getWhenCount();
+ // 1. Call recursively to resolve any contained CASE expressions
+
+ Class thenType = null;
+ // Get the WHEN and THEN types, and get a candidate type for each (for the next step)
+ for (int i = 0; i < whenCount; i++) {
+ if (thenType == null) {
+ thenType = obj.getThenExpression(i).getType();
+ }
+ }
+
+ Expression elseExpr = obj.getElseExpression();
+ if (elseExpr != null) {
+ if (thenType == null) {
+ thenType = elseExpr.getType();
+ }
+ }
+ // Invariant: All the expressions contained in the obj are resolved (except References)
+
+ // 2. Attempt to set the target types of all contained expressions,
+ // and collect their type names for the next step
+ ArrayList thenTypeNames = new ArrayList(whenCount + 1);
+ Expression then = null;
+ // Set the types of the WHEN and THEN parts
+ for (int i = 0; i < whenCount; i++) {
+ then = obj.getThenExpression(i);
+ setDesiredType(then, thenType, obj);
+ if (!thenTypeNames.contains(DataTypeManager.getDataTypeName(then.getType()))) {
+ thenTypeNames.add(DataTypeManager.getDataTypeName(then.getType()));
+ }
+ }
+ // Set the type of the else expression
+ if (elseExpr != null) {
+ setDesiredType(elseExpr, thenType, obj);
+ if (!thenTypeNames.contains(DataTypeManager.getDataTypeName(elseExpr.getType()))) {
+ thenTypeNames.add(DataTypeManager.getDataTypeName(elseExpr.getType()));
+ }
+ }
+
+ // Invariants: all the expressions' types are non-null
+
+ // 3. Perform implicit type conversions
+ String thenTypeName = ResolverUtil.getCommonType((String[])thenTypeNames.toArray(new String[thenTypeNames.size()]));
+ if (thenTypeName == null) {
+ throw new QueryResolverException(ErrorMessageKeys.RESOLVER_0068, QueryPlugin.Util.getString(ErrorMessageKeys.RESOLVER_0068, "THEN/ELSE", obj)); //$NON-NLS-1$
+ }
+ ArrayList thens = new ArrayList(whenCount);
+ for (int i = 0; i < whenCount; i++) {
+ thens.add(ResolverUtil.convertExpression(obj.getThenExpression(i), thenTypeName));
+ }
+ obj.setWhen(obj.getWhen(), thens);
+ if (elseExpr != null) {
+ obj.setElseExpression(ResolverUtil.convertExpression(elseExpr, thenTypeName));
+ }
+ // Set this CASE expression's type to the common THEN type, and we're done.
+ obj.setType(DataTypeManager.getDataTypeClass(thenTypeName));
+ }
+
+ public static void resolveLanguageObject(LanguageObject obj, QueryMetadataInterface metadata)
+ throws MetaMatrixComponentException, QueryResolverException {
+ ResolverVisitor.resolveLanguageObject(obj, null, metadata);
+ }
+
+ public static void resolveLanguageObject(LanguageObject obj, Collection<GroupSymbol> groups, QueryMetadataInterface metadata)
+ throws MetaMatrixComponentException, QueryResolverException {
+ ResolverVisitor.resolveLanguageObject(obj, groups, null, metadata);
+ }
+
+ public static void resolveLanguageObject(LanguageObject obj, Collection<GroupSymbol> groups, GroupContext externalContext, QueryMetadataInterface metadata)
+ throws MetaMatrixComponentException, QueryResolverException {
+
+ if(obj == null) {
+ return;
+ }
+
+ // Resolve elements, deal with errors
+ ResolverVisitor elementsVisitor = new ResolverVisitor(metadata, groups, externalContext);
+ PostOrderNavigator.doVisit(obj, elementsVisitor);
+ elementsVisitor.throwException(true);
+ }
}
Modified: trunk/engine/src/main/java/com/metamatrix/query/resolver/util/ResolverVisitorUtil.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/resolver/util/ResolverVisitorUtil.java 2009-04-21 16:32:23 UTC (rev 814)
+++ trunk/engine/src/main/java/com/metamatrix/query/resolver/util/ResolverVisitorUtil.java 2009-04-21 18:38:33 UTC (rev 815)
@@ -22,44 +22,26 @@
package com.metamatrix.query.resolver.util;
-import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
-import java.util.Iterator;
import java.util.List;
-import net.sf.saxon.trans.XPathException;
import com.metamatrix.api.exception.MetaMatrixComponentException;
import com.metamatrix.api.exception.query.QueryMetadataException;
import com.metamatrix.api.exception.query.QueryResolverException;
import com.metamatrix.api.exception.query.UnresolvedSymbolDescription;
import com.metamatrix.common.types.DataTypeManager;
-import com.metamatrix.common.types.DataTypeManager.DefaultDataClasses;
-import com.metamatrix.internal.core.xml.XPathHelper;
import com.metamatrix.query.QueryPlugin;
-import com.metamatrix.query.function.FunctionDescriptor;
-import com.metamatrix.query.function.FunctionForm;
-import com.metamatrix.query.function.FunctionLibrary;
-import com.metamatrix.query.function.FunctionLibraryManager;
import com.metamatrix.query.metadata.QueryMetadataInterface;
import com.metamatrix.query.metadata.StoredProcedureInfo;
import com.metamatrix.query.metadata.TempMetadataID;
-import com.metamatrix.query.sql.lang.BetweenCriteria;
-import com.metamatrix.query.sql.lang.CompareCriteria;
-import com.metamatrix.query.sql.lang.IsNullCriteria;
-import com.metamatrix.query.sql.lang.MatchCriteria;
-import com.metamatrix.query.sql.lang.SetCriteria;
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;
import com.metamatrix.query.sql.symbol.ElementSymbol;
import com.metamatrix.query.sql.symbol.Expression;
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.SearchedCaseExpression;
import com.metamatrix.query.util.ErrorMessageKeys;
public class ResolverVisitorUtil {
@@ -90,231 +72,6 @@
}
/**
- * Resolves criteria "a BETWEEN b AND c". If type conversions are necessary,
- * this method attempts the following implicit conversions:
- * <br/>
- * <ol type="1" start="1">
- * <li>convert the lower and upper expressions to the criteria expression's type, or</li>
- * <li>convert the criteria and upper expressions to the lower expression's type, or</li>
- * <li>convert the criteria and lower expressions to the upper expression's type, or</li>
- * <li>convert all expressions to a common type to which all three expressions' types can be implicitly converted.</li>
- * </ol>
- * @param criteria
- * @throws QueryResolverException
- * @throws MetaMatrixComponentException
- */
- static void resolveBetweenCriteria(BetweenCriteria criteria)
- throws QueryResolverException {
-
- Expression exp = criteria.getExpression();
- Expression lower = criteria.getLowerExpression();
- Expression upper = criteria.getUpperExpression();
-
- // invariants: none of the expressions is an aggregate symbol
- ResolverUtil.setTypeIfReference(exp,
- (lower.getType() == null)
- ? upper.getType()
- : lower.getType(), criteria);
- // invariants: exp.getType() != null
- ResolverUtil.setTypeIfReference(lower, exp.getType(), criteria);
- ResolverUtil.setTypeIfReference(upper, exp.getType(), criteria);
- // invariants: none of the types is null
-
- String expTypeName = DataTypeManager.getDataTypeName(exp.getType());
- String lowerTypeName = DataTypeManager.getDataTypeName(lower.getType());
- String upperTypeName = DataTypeManager.getDataTypeName(upper.getType());
- if (exp.getType().equals(lower.getType()) && exp.getType().equals(upper.getType())) {
- return;
- }
-
- String commonType = ResolverUtil.getCommonType(new String[] {expTypeName, lowerTypeName, upperTypeName});
- if (commonType != null) {
- criteria.setExpression(ResolverUtil.convertExpression(exp, expTypeName, commonType));
- criteria.setLowerExpression(ResolverUtil.convertExpression(lower, lowerTypeName, commonType));
- criteria.setUpperExpression(ResolverUtil.convertExpression(upper, upperTypeName, commonType));
- } else {
- // Couldn't find a common type to implicitly convert to
- throw new QueryResolverException(ErrorMessageKeys.RESOLVER_0027, QueryPlugin.Util.getString(ErrorMessageKeys.RESOLVER_0027, expTypeName, lowerTypeName, criteria));
- }
- // invariants: exp.getType() == lower.getType() == upper.getType()
- }
-
- static void resolveCompareCriteria(CompareCriteria ccrit)
- throws QueryResolverException {
-
- Expression leftExpression = ccrit.getLeftExpression();
- Expression rightExpression = ccrit.getRightExpression();
-
- // Check typing between expressions
- ResolverUtil.setTypeIfReference(leftExpression, rightExpression.getType(), ccrit);
- ResolverUtil.setTypeIfReference(rightExpression, leftExpression.getType(), ccrit);
-
- if(leftExpression.getType().equals(rightExpression.getType()) ) {
- return;
- }
-
- // Try to apply an implicit conversion from one side to the other
- String leftTypeName = DataTypeManager.getDataTypeName(leftExpression.getType());
- String rightTypeName = DataTypeManager.getDataTypeName(rightExpression.getType());
-
- // Special cases when right expression is a constant
- if(rightExpression instanceof Constant) {
- // Auto-convert constant string on right to expected type on left
- try {
- ccrit.setRightExpression(ResolverUtil.convertExpression(rightExpression, rightTypeName, leftTypeName));
- return;
- } catch (QueryResolverException qre) {
- //ignore
- }
- }
-
- // Special cases when left expression is a constant
- if(leftExpression instanceof Constant) {
- // Auto-convert constant string on left to expected type on right
- try {
- ccrit.setLeftExpression(ResolverUtil.convertExpression(leftExpression, leftTypeName, rightTypeName));
- return;
- } catch (QueryResolverException qre) {
- //ignore
- }
- }
-
- // Try to apply a conversion generically
-
- if(ResolverUtil.canImplicitlyConvert(leftTypeName, rightTypeName)) {
- ccrit.setLeftExpression(ResolverUtil.convertExpression(leftExpression, leftTypeName, rightTypeName) );
- return;
- }
-
- if(ResolverUtil.canImplicitlyConvert(rightTypeName, leftTypeName)) {
- ccrit.setRightExpression(ResolverUtil.convertExpression(rightExpression, rightTypeName, leftTypeName) );
- return;
- }
-
- String commonType = ResolverUtil.getCommonType(new String[] {leftTypeName, rightTypeName});
-
- if (commonType == null) {
- // Neither are aggs, but types can't be reconciled
- throw new QueryResolverException(ErrorMessageKeys.RESOLVER_0027, QueryPlugin.Util.getString(ErrorMessageKeys.RESOLVER_0027, new Object[] { leftTypeName, rightTypeName, ccrit }));
- }
- ccrit.setLeftExpression(ResolverUtil.convertExpression(leftExpression, leftTypeName, commonType) );
- ccrit.setRightExpression(ResolverUtil.convertExpression(rightExpression, rightTypeName, commonType) );
- }
-
- static void resolveMatchCriteria(MatchCriteria mcrit)
- throws QueryResolverException {
-
- ResolverUtil.setTypeIfReference(mcrit.getLeftExpression(), mcrit.getRightExpression().getType(), mcrit);
- mcrit.setLeftExpression(resolveMatchCriteriaExpression(mcrit, mcrit.getLeftExpression()));
-
- ResolverUtil.setTypeIfReference(mcrit.getRightExpression(), mcrit.getLeftExpression().getType(), mcrit);
- mcrit.setRightExpression(resolveMatchCriteriaExpression(mcrit, mcrit.getRightExpression()));
- }
-
- /**
- * Checks one side of a LIKE Criteria; implicitly converts to a String or CLOB if necessary.
- * @param mcrit the Match Criteria
- * @param expr either left or right expression
- * @return either 'expr' itself, or a new implicit type conversion wrapping expr
- * @throws QueryResolverException if no implicit type conversion is available
- */
- static Expression resolveMatchCriteriaExpression(MatchCriteria mcrit, Expression expr)
- throws QueryResolverException {
- // Check left expression == string or CLOB
- String type = DataTypeManager.getDataTypeName(expr.getType());
- Expression result = expr;
- if(type != null) {
- if (! type.equals(DataTypeManager.DefaultDataTypes.STRING) &&
- ! type.equals(DataTypeManager.DefaultDataTypes.CLOB)) {
-
- if(!(expr instanceof AggregateSymbol) &&
- ResolverUtil.canImplicitlyConvert(type, DataTypeManager.DefaultDataTypes.STRING)) {
-
- result = ResolverUtil.convertExpression(expr, type, DataTypeManager.DefaultDataTypes.STRING);
-
- } else if (!(expr instanceof AggregateSymbol) &&
- ResolverUtil.canImplicitlyConvert(type, DataTypeManager.DefaultDataTypes.CLOB)){
-
- result = ResolverUtil.convertExpression(expr, type, DataTypeManager.DefaultDataTypes.CLOB);
-
- } else {
- throw new QueryResolverException(ErrorMessageKeys.RESOLVER_0029, QueryPlugin.Util.getString(ErrorMessageKeys.RESOLVER_0029, mcrit));
- }
- }
- }
- return result;
- }
-
- static void resolveSetCriteria(SetCriteria scrit)
- throws QueryResolverException {
-
- // Check that each of the values are the same type as expression
- Class exprType = scrit.getExpression().getType();
- if(exprType == null) {
- throw new QueryResolverException(ErrorMessageKeys.RESOLVER_0030, QueryPlugin.Util.getString(ErrorMessageKeys.RESOLVER_0030, scrit.getExpression()));
- }
-
- String exprTypeName = DataTypeManager.getDataTypeName(exprType);
- boolean changed = false;
- List newVals = new ArrayList();
-
- boolean convertLeft = false;
- Class setType = null;
-
- Iterator valIter = scrit.getValues().iterator();
- while(valIter.hasNext()) {
- Expression value = (Expression) valIter.next();
- ResolverUtil.setTypeIfReference(value, exprType, scrit);
- if(! value.getType().equals(exprType)) {
- if(value instanceof AggregateSymbol) {
- throw new QueryResolverException(ErrorMessageKeys.RESOLVER_0031, QueryPlugin.Util.getString(ErrorMessageKeys.RESOLVER_0031, scrit));
- }
- // try to apply cast
- String valTypeName = DataTypeManager.getDataTypeName(value.getType());
- if(ResolverUtil.canImplicitlyConvert(valTypeName, exprTypeName)) {
- // Apply cast and replace current value
- newVals.add(ResolverUtil.convertExpression(value, valTypeName, exprTypeName) );
- changed = true;
- } else {
- convertLeft = true;
- setType = value.getType();
- break;
- }
- } else {
- newVals.add(value);
- }
- }
-
- // If no convert found for first element, check whether everything in the
- // set is the same and the convert can be placed on the left side
- if(convertLeft) {
- // Is there a possible conversion from left to right?
- String setTypeName = DataTypeManager.getDataTypeName(setType);
- if(ResolverUtil.canImplicitlyConvert(exprTypeName, setTypeName)) {
- valIter = scrit.getValues().iterator();
- while(valIter.hasNext()) {
- Expression value = (Expression) valIter.next();
- if(value.getType() == null) {
- throw new QueryResolverException(ErrorMessageKeys.RESOLVER_0030, QueryPlugin.Util.getString(ErrorMessageKeys.RESOLVER_0030, value));
- } else if(! value.getType().equals(setType)) {
- throw new QueryResolverException(ErrorMessageKeys.RESOLVER_0031, QueryPlugin.Util.getString(ErrorMessageKeys.RESOLVER_0031, scrit));
- }
- }
-
- // Convert left expression to type of values in the set
- scrit.setExpression(ResolverUtil.convertExpression(scrit.getExpression(), exprTypeName, setTypeName ));
-
- } else {
- throw new QueryResolverException(ErrorMessageKeys.RESOLVER_0031, QueryPlugin.Util.getString(ErrorMessageKeys.RESOLVER_0031, scrit));
- }
- }
-
- if(changed) {
- scrit.setValues(newVals);
- }
- }
-
- /**
* Check the type of the (left) expression and the type of the single
* projected symbol of the subquery. If they are not the same, try to find
* an implicit conversion from the former type to the latter type, and wrap
@@ -353,257 +110,6 @@
return result;
}
- static void resolveIsNullCriteria(IsNullCriteria crit)
- throws QueryResolverException {
-
- ResolverUtil.setTypeIfReference(crit.getExpression(), DefaultDataClasses.OBJECT, crit);
- }
-
- static void resolveCaseExpression(CaseExpression obj) throws QueryResolverException {
- // If already resolved, do nothing
- if (obj.getType() != null) {
- return;
- }
- final int whenCount = obj.getWhenCount();
- Expression expr = obj.getExpression();
-
- Class whenType = null;
- Class thenType = null;
- // Get the WHEN and THEN types, and get a candidate type for each (for the next step)
- for (int i = 0; i < whenCount; i++) {
- if (whenType == null) {
- whenType = obj.getWhenExpression(i).getType();
- }
- if (thenType == null) {
- thenType = obj.getThenExpression(i).getType();
- }
- }
-
- Expression elseExpr = obj.getElseExpression();
- if (elseExpr != null) {
- if (thenType == null) {
- thenType = elseExpr.getType();
- }
- }
- // Invariant: All the expressions contained in the obj are resolved (except References)
-
- // 2. Attempt to set the target types of all contained expressions,
- // and collect their type names for the next step
- ArrayList whenTypeNames = new ArrayList(whenCount + 1);
- ArrayList thenTypeNames = new ArrayList(whenCount + 1);
- // Set the type of the expression
- ResolverUtil.setTypeIfReference(expr, whenType, obj);
- // Add the expression's type to the WHEN types
- whenTypeNames.add(DataTypeManager.getDataTypeName(expr.getType()));
- Expression when = null;
- Expression then = null;
- // Set the types of the WHEN and THEN parts
- for (int i = 0; i < whenCount; i++) {
- when = obj.getWhenExpression(i);
- then = obj.getThenExpression(i);
-
- ResolverUtil.setTypeIfReference(when, expr.getType(), obj);
- ResolverUtil.setTypeIfReference(then, thenType, obj);
-
- if (!whenTypeNames.contains(DataTypeManager.getDataTypeName(when.getType()))) {
- whenTypeNames.add(DataTypeManager.getDataTypeName(when.getType()));
- }
- if (!thenTypeNames.contains(DataTypeManager.getDataTypeName(then.getType()))) {
- thenTypeNames.add(DataTypeManager.getDataTypeName(then.getType()));
- }
- }
- // Set the type of the else expression
- if (elseExpr != null) {
- ResolverUtil.setTypeIfReference(elseExpr, thenType, obj);
- if (!thenTypeNames.contains(DataTypeManager.getDataTypeName(elseExpr.getType()))) {
- thenTypeNames.add(DataTypeManager.getDataTypeName(elseExpr.getType()));
- }
- }
-
- // Invariants: all the expressions' types are non-null
-
- // 3. Perform implicit type conversions
- String whenTypeName = ResolverUtil.getCommonType((String[])whenTypeNames.toArray(new String[whenTypeNames.size()]));
- if (whenTypeName == null) {
- throw new QueryResolverException(ErrorMessageKeys.RESOLVER_0068, QueryPlugin.Util.getString(ErrorMessageKeys.RESOLVER_0068, "WHEN", obj)); //$NON-NLS-1$
- }
- String thenTypeName = ResolverUtil.getCommonType((String[])thenTypeNames.toArray(new String[thenTypeNames.size()]));
- if (thenTypeName == null) {
- throw new QueryResolverException(ErrorMessageKeys.RESOLVER_0068, QueryPlugin.Util.getString(ErrorMessageKeys.RESOLVER_0068, "THEN/ELSE", obj)); //$NON-NLS-1$
- }
- obj.setExpression(ResolverUtil.convertExpression(obj.getExpression(), whenTypeName));
- ArrayList whens = new ArrayList(whenCount);
- ArrayList thens = new ArrayList(whenCount);
- for (int i = 0; i < whenCount; i++) {
- whens.add(ResolverUtil.convertExpression(obj.getWhenExpression(i), whenTypeName));
- thens.add(ResolverUtil.convertExpression(obj.getThenExpression(i), thenTypeName));
- }
- obj.setWhen(whens, thens);
- if (elseExpr != null) {
- obj.setElseExpression(ResolverUtil.convertExpression(elseExpr, thenTypeName));
- }
- // Set this CASE expression's type to the common THEN type, and we're done.
- obj.setType(DataTypeManager.getDataTypeClass(thenTypeName));
- }
-
- static void resolveSearchedCaseExpression(SearchedCaseExpression obj) throws QueryResolverException {
- // If already resolved, do nothing
- if (obj.getType() != null) {
- return;
- }
- final int whenCount = obj.getWhenCount();
- // 1. Call recursively to resolve any contained CASE expressions
-
- Class thenType = null;
- // Get the WHEN and THEN types, and get a candidate type for each (for the next step)
- for (int i = 0; i < whenCount; i++) {
- if (thenType == null) {
- thenType = obj.getThenExpression(i).getType();
- }
- }
-
- Expression elseExpr = obj.getElseExpression();
- if (elseExpr != null) {
- if (thenType == null) {
- thenType = elseExpr.getType();
- }
- }
- // Invariant: All the expressions contained in the obj are resolved (except References)
-
- // 2. Attempt to set the target types of all contained expressions,
- // and collect their type names for the next step
- ArrayList thenTypeNames = new ArrayList(whenCount + 1);
- Expression then = null;
- // Set the types of the WHEN and THEN parts
- for (int i = 0; i < whenCount; i++) {
- then = obj.getThenExpression(i);
- ResolverUtil.setTypeIfReference(then, thenType, obj);
- if (!thenTypeNames.contains(DataTypeManager.getDataTypeName(then.getType()))) {
- thenTypeNames.add(DataTypeManager.getDataTypeName(then.getType()));
- }
- }
- // Set the type of the else expression
- if (elseExpr != null) {
- ResolverUtil.setTypeIfReference(elseExpr, thenType, obj);
- if (!thenTypeNames.contains(DataTypeManager.getDataTypeName(elseExpr.getType()))) {
- thenTypeNames.add(DataTypeManager.getDataTypeName(elseExpr.getType()));
- }
- }
-
- // Invariants: all the expressions' types are non-null
-
- // 3. Perform implicit type conversions
- String thenTypeName = ResolverUtil.getCommonType((String[])thenTypeNames.toArray(new String[thenTypeNames.size()]));
- if (thenTypeName == null) {
- throw new QueryResolverException(ErrorMessageKeys.RESOLVER_0068, QueryPlugin.Util.getString(ErrorMessageKeys.RESOLVER_0068, "THEN/ELSE", obj)); //$NON-NLS-1$
- }
- ArrayList thens = new ArrayList(whenCount);
- for (int i = 0; i < whenCount; i++) {
- thens.add(ResolverUtil.convertExpression(obj.getThenExpression(i), thenTypeName));
- }
- obj.setWhen(obj.getWhen(), thens);
- if (elseExpr != null) {
- obj.setElseExpression(ResolverUtil.convertExpression(elseExpr, thenTypeName));
- }
- // Set this CASE expression's type to the common THEN type, and we're done.
- obj.setType(DataTypeManager.getDataTypeClass(thenTypeName));
- }
-
- /**
- * Resolve function such that all functions are resolved and type-safe.
- */
- public static void resolveFunction(Function function, QueryMetadataInterface metadata)
- throws QueryResolverException, MetaMatrixComponentException {
-
- // Check whether this function is already resolved
- if(function.getFunctionDescriptor() != null) {
- return;
- }
-
- // Look up types for all args
- boolean hasArgWithoutType = false;
- Expression[] args = function.getArgs();
- Class[] types = new Class[args.length];
- for(int i=0; i<args.length; i++) {
- types[i] = args[i].getType();
- if(types[i] == null) {
- if(!(args[i] instanceof Reference)){
- throw new QueryResolverException(ErrorMessageKeys.RESOLVER_0035, QueryPlugin.Util.getString(ErrorMessageKeys.RESOLVER_0035, new Object[] {args[i], function}));
- }
- hasArgWithoutType = true;
- }
- }
-
- FunctionLibrary library = FunctionLibraryManager.getFunctionLibrary();
-
- //special case handling for convert of an untyped reference
- if (FunctionLibrary.isConvert(function) && hasArgWithoutType) {
- Constant constant = (Constant)function.getArg(1);
- Class type = DataTypeManager.getDataTypeClass((String)constant.getValue());
-
- ResolverUtil.setTypeIfReference(function.getArg(0), type, function);
- types[0] = type;
- hasArgWithoutType = false;
- }
-
- // Attempt to get exact match of function for this signature
- FunctionDescriptor fd = findWithImplicitConversions(library, function, args, types, hasArgWithoutType);
-
- // Function did not resolve - determine reason and throw exception
- if(fd == null) {
- FunctionForm form = library.findFunctionForm(function.getName(), args.length);
- if(form == null) {
- // Unknown function form
- throw new QueryResolverException(ErrorMessageKeys.RESOLVER_0039, QueryPlugin.Util.getString(ErrorMessageKeys.RESOLVER_0039, function));
- }
- // Known function form - but without type information
- if (hasArgWithoutType) {
- throw new QueryResolverException(ErrorMessageKeys.RESOLVER_0036, QueryPlugin.Util.getString(ErrorMessageKeys.RESOLVER_0036, function));
- }
- // Known function form - unable to find implicit conversions
- throw new QueryResolverException(ErrorMessageKeys.RESOLVER_0040, QueryPlugin.Util.getString(ErrorMessageKeys.RESOLVER_0040, function));
- }
-
- if(fd.getName().equalsIgnoreCase(FunctionLibrary.CONVERT) || fd.getName().equalsIgnoreCase(FunctionLibrary.CAST)) {
- String dataType = (String) ((Constant)args[1]).getValue();
- Class dataTypeClass = DataTypeManager.getDataTypeClass(dataType);
- fd = library.findTypedConversionFunction(args[0].getType(), dataTypeClass);
-
- // Verify that the type conversion from src to type is even valid
- Class srcTypeClass = args[0].getType();
- if(srcTypeClass != null && dataTypeClass != null &&
- !srcTypeClass.equals(dataTypeClass) &&
- !DataTypeManager.isTransformable(srcTypeClass, dataTypeClass)) {
-
- throw new QueryResolverException(ErrorMessageKeys.RESOLVER_0037, QueryPlugin.Util.getString(ErrorMessageKeys.RESOLVER_0037, new Object[] {DataTypeManager.getDataTypeName(srcTypeClass), dataType}));
- }
- } else if(fd.getName().equalsIgnoreCase(FunctionLibrary.LOOKUP)) {
- ResolvedLookup lookup = resolveLookup(function, metadata);
- fd = library.copyFunctionChangeReturnType(fd, lookup.getReturnElement().getType());
- } else if(fd.getName().equalsIgnoreCase(FunctionLibrary.XPATHVALUE)) {
- // Validate the xpath value is valid
- if(args[1] != null && args[1] instanceof Constant) {
- Constant xpathConst = (Constant) args[1];
- if(xpathConst.getType().equals(DataTypeManager.DefaultDataClasses.STRING)) {
- String value = (String) xpathConst.getValue();
- if(value == null) {
- throw new QueryResolverException(QueryPlugin.Util.getString("QueryResolver.invalid_xpath", QueryPlugin.Util.getString("ResolveFunctionsVisitor.xpath_cant_be_null"))); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- try {
- XPathHelper.validateXpath(value);
- } catch(XPathException e) {
- throw new QueryResolverException(QueryPlugin.Util.getString("QueryResolver.invalid_xpath", e.getMessage())); //$NON-NLS-1$
- }
- }
- }
- }
-
- // Resolve the function
- function.setFunctionDescriptor(fd);
- function.setType(fd.getReturnType());
- }
-
public static ResolvedLookup resolveLookup(Function lookup, QueryMetadataInterface metadata) throws QueryResolverException, MetaMatrixComponentException {
Expression[] args = lookup.getArgs();
ResolvedLookup result = new ResolvedLookup();
@@ -645,49 +151,7 @@
throw new QueryResolverException(ErrorMessageKeys.RESOLVER_0063, QueryPlugin.Util.getString(ErrorMessageKeys.RESOLVER_0063));
}
- /**
- * Find possible matches based on implicit conversions of the arguments.
- * NOTE: This method has the side-effect of explicitly inserting conversions into the function arguments,
- * and thereby changing the structure of the function call.
- * @param library
- * @param function
- * @param types
- * @return
- * @since 4.3
- */
- static FunctionDescriptor findWithImplicitConversions(FunctionLibrary library, Function function, Expression[] args, Class[] types, boolean hasArgWithoutType) throws QueryResolverException {
-
- // Try to find implicit conversion path to still perform this function
- FunctionDescriptor[] conversions = library.determineNecessaryConversions(function.getName(), types, hasArgWithoutType);
-
- if(conversions == null) {
- return null;
- }
- // Insert new conversion functions as necessary, while building new signature
- Class[] newSignature = new Class[conversions.length];
- for(int i=0; i<conversions.length; i++) {
-
- Class newType = types[i];
-
- if(conversions[i] != null) {
- newType = conversions[i].getReturnType();
-
- ResolverUtil.setTypeIfReference(args[i], newType, function);
-
- //only currently typed expressions need conversions
- if (types[i] != null) {
- function.insertConversion(i, conversions[i]);
- }
- }
-
- newSignature[i] = newType;
- }
-
- // Now resolve using the new signature to get the function's descriptor
- return library.findFunction(function.getName(), newSignature);
- }
-
- private static QueryResolverException handleUnresolvedGroup(GroupSymbol symbol, String description) {
+ private static QueryResolverException handleUnresolvedGroup(GroupSymbol symbol, String description) {
UnresolvedSymbolDescription usd = new UnresolvedSymbolDescription(symbol.toString(), description);
QueryResolverException e = new QueryResolverException(usd.getDescription()+": "+usd.getSymbol()); //$NON-NLS-1$
e.setUnresolvedSymbols(Arrays.asList(usd));
Modified: trunk/engine/src/main/java/com/metamatrix/query/sql/navigator/AbstractNavigator.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/sql/navigator/AbstractNavigator.java 2009-04-21 16:32:23 UTC (rev 814)
+++ trunk/engine/src/main/java/com/metamatrix/query/sql/navigator/AbstractNavigator.java 2009-04-21 18:38:33 UTC (rev 815)
@@ -40,7 +40,7 @@
this.visitor = visitor;
}
- protected LanguageVisitor getVisitor() {
+ public LanguageVisitor getVisitor() {
return this.visitor;
}
Modified: trunk/engine/src/test/java/com/metamatrix/query/function/TestFunctionLibrary.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/function/TestFunctionLibrary.java 2009-04-21 16:32:23 UTC (rev 814)
+++ trunk/engine/src/test/java/com/metamatrix/query/function/TestFunctionLibrary.java 2009-04-21 18:38:33 UTC (rev 815)
@@ -130,7 +130,7 @@
private void helpFindConversions(String fname, Class[] types, FunctionDescriptor[] expected) {
- FunctionDescriptor[] actual = library.determineNecessaryConversions(fname, types, false);
+ FunctionDescriptor[] actual = library.determineNecessaryConversions(fname, null, types, false);
if(expected == null) {
if(actual != null) {
Modified: trunk/engine/src/test/java/com/metamatrix/query/resolver/TestFunctionResolving.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/resolver/TestFunctionResolving.java 2009-04-21 16:32:23 UTC (rev 814)
+++ trunk/engine/src/test/java/com/metamatrix/query/resolver/TestFunctionResolving.java 2009-04-21 18:38:33 UTC (rev 815)
@@ -30,7 +30,7 @@
import com.metamatrix.api.exception.query.QueryResolverException;
import com.metamatrix.common.types.DataTypeManager;
import com.metamatrix.query.parser.QueryParser;
-import com.metamatrix.query.resolver.util.ResolverVisitorUtil;
+import com.metamatrix.query.resolver.util.ResolverVisitor;
import com.metamatrix.query.sql.symbol.Constant;
import com.metamatrix.query.sql.symbol.ElementSymbol;
import com.metamatrix.query.sql.symbol.Expression;
@@ -44,7 +44,7 @@
Function function = new Function("convert", new Expression[] {new Constant(new Character('a')), new Constant(DataTypeManager.DefaultDataTypes.DATE)}); //$NON-NLS-1$
try {
- ResolverVisitorUtil.resolveFunction(function, FakeMetadataFactory.example1Cached());
+ ResolverVisitor.resolveLanguageObject(function, FakeMetadataFactory.example1Cached());
fail("excpetion expected"); //$NON-NLS-1$
} catch (QueryResolverException err) {
assertEquals("The conversion from char to date is not allowed.", err.getMessage()); //$NON-NLS-1$
@@ -53,10 +53,12 @@
@Test public void testResolvesClosestType() throws Exception {
ElementSymbol e1 = new ElementSymbol("pm1.g1.e1"); //$NON-NLS-1$
+ //dummy resolve to a byte
e1.setType(DataTypeManager.DefaultDataClasses.BYTE);
+ e1.setMetadataID(new Object());
Function function = new Function("abs", new Expression[] {e1}); //$NON-NLS-1$
- ResolverVisitorUtil.resolveFunction(function, FakeMetadataFactory.example1Cached());
+ ResolverVisitor.resolveLanguageObject(function, FakeMetadataFactory.example1Cached());
assertEquals(DataTypeManager.DefaultDataClasses.INTEGER, function.getType());
}
@@ -64,7 +66,7 @@
@Test public void testResolveConvertReference() throws Exception {
Function function = new Function("convert", new Expression[] {new Reference(0), new Constant(DataTypeManager.DefaultDataTypes.BOOLEAN)}); //$NON-NLS-1$
- ResolverVisitorUtil.resolveFunction(function, FakeMetadataFactory.example1Cached());
+ ResolverVisitor.resolveLanguageObject(function, FakeMetadataFactory.example1Cached());
assertEquals(DataTypeManager.DefaultDataClasses.BOOLEAN, function.getType());
assertEquals(DataTypeManager.DefaultDataClasses.BOOLEAN, function.getArgs()[0].getType());
@@ -74,7 +76,7 @@
Function function = new Function("LCASE", new Expression[] {new Reference(0)}); //$NON-NLS-1$
try {
- ResolverVisitorUtil.resolveFunction(function, FakeMetadataFactory.example1Cached());
+ ResolverVisitor.resolveLanguageObject(function, FakeMetadataFactory.example1Cached());
fail("excpetion expected"); //$NON-NLS-1$
} catch (QueryResolverException err) {
assertEquals("The function 'LCASE(?)' has more than one possible signature.", err.getMessage()); //$NON-NLS-1$
@@ -120,7 +122,7 @@
private Function helpResolveFunction(String sql) throws QueryParserException,
QueryResolverException, MetaMatrixComponentException {
Function func = (Function)QueryParser.getQueryParser().parseExpression(sql);
- ResolverVisitorUtil.resolveFunction(func, FakeMetadataFactory.example1Cached());
+ ResolverVisitor.resolveLanguageObject(func, FakeMetadataFactory.example1Cached());
assertEquals(DataTypeManager.DefaultDataClasses.STRING, func.getType());
return func;
}
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-21 16:32:23 UTC (rev 814)
+++ trunk/engine/src/test/java/com/metamatrix/query/resolver/TestResolver.java 2009-04-21 18:38:33 UTC (rev 815)
@@ -4653,4 +4653,8 @@
assertEquals(1, proc.getProjectedSymbols().size());
}
+ public void testSecondPassFunctionResolving() {
+ helpResolve("SELECT pm1.g1.e1 FROM pm1.g1 where lower(?) = e1 "); //$NON-NLS-1$
+ }
+
}
\ No newline at end of file
15 years, 8 months
teiid SVN: r814 - in trunk: common-core/src/test/java/com/metamatrix/api/exception and 1 other directories.
by teiid-commits@lists.jboss.org
Author: rareddy
Date: 2009-04-21 12:32:23 -0400 (Tue, 21 Apr 2009)
New Revision: 814
Modified:
trunk/client-jdbc30/pom.xml
trunk/common-core/src/test/java/com/metamatrix/api/exception/TestExceptionHolder.java
trunk/common-core/src/test/java/com/metamatrix/core/util/UnitTestUtil.java
Log:
TEIID-177: adding language processors such that same code can be compiled aginst java 1.5 and java 1.6. Also between JDBC 4.0 and JDBC 3.0
Modified: trunk/client-jdbc30/pom.xml
===================================================================
--- trunk/client-jdbc30/pom.xml 2009-04-21 14:47:32 UTC (rev 813)
+++ trunk/client-jdbc30/pom.xml 2009-04-21 16:32:23 UTC (rev 814)
@@ -99,7 +99,6 @@
<goal>run</goal>
</goals>
</execution>
- <!--
<execution>
<id>generate-1.5-test</id>
<phase>generate-sources</phase>
@@ -149,7 +148,6 @@
<goal>run</goal>
</goals>
</execution>
- -->
</executions>
</plugin>
</plugins>
@@ -162,7 +160,6 @@
<include>**/*</include>
</includes>
</resource>
- <!--
<resource>
<directory>${project.build.directory}/generated-sources/test/resources</directory>
<filtering>false</filtering>
@@ -170,7 +167,6 @@
<include>**/*</include>
</includes>
</resource>
- -->
</resources>
</build>
Modified: trunk/common-core/src/test/java/com/metamatrix/api/exception/TestExceptionHolder.java
===================================================================
--- trunk/common-core/src/test/java/com/metamatrix/api/exception/TestExceptionHolder.java 2009-04-21 14:47:32 UTC (rev 813)
+++ trunk/common-core/src/test/java/com/metamatrix/api/exception/TestExceptionHolder.java 2009-04-21 16:32:23 UTC (rev 814)
@@ -10,6 +10,8 @@
import java.sql.SQLException;
import java.util.ArrayList;
+import junit.framework.TestCase;
+
import org.junit.Test;
import com.metamatrix.api.exception.ExceptionHolder;
@@ -19,8 +21,9 @@
import com.metamatrix.core.util.ReflectionHelper;
import com.metamatrix.core.util.UnitTestUtil;
-public class TestExceptionHolder {
-
+public class TestExceptionHolder extends TestCase {
+
+ //## JDBC4.0-begin ##
@SuppressWarnings("all")
public static class BadException extends MetaMatrixProcessingException {
private Object obj;
@@ -95,4 +98,11 @@
assertTrue(e instanceof MetaMatrixRuntimeException);
assertEquals("Unknown Exception", e.getMessage()); //$NON-NLS-1$
}
+ //## JDBC4.0-end ##
+
+ /*## JDBC3.0-JDK1.5-begin ##
+ public void testPass(){
+ // since the jar files required are built with 1.6, it will always fail, so just comment the test for 1.5
+ }
+ ## JDBC3.0-JDK1.5-end ##*/
}
Modified: trunk/common-core/src/test/java/com/metamatrix/core/util/UnitTestUtil.java
===================================================================
--- trunk/common-core/src/test/java/com/metamatrix/core/util/UnitTestUtil.java 2009-04-21 14:47:32 UTC (rev 813)
+++ trunk/common-core/src/test/java/com/metamatrix/core/util/UnitTestUtil.java 2009-04-21 16:32:23 UTC (rev 814)
@@ -43,7 +43,13 @@
public static final String PATH_SEPARATOR = "/"; //$NON-NLS-1$
+ //## JDBC4.0-begin ##
private static final String DEFAULT_TESTDATA_PATH = "src/test/resources"; //$NON-NLS-1$
+ //## JDBC4.0-end ##
+
+ /*## JDBC3.0-JDK1.5-begin ##
+ private static final String DEFAULT_TESTDATA_PATH = "target/generated-sources/test/resources"; //$NON-NLS-1$
+ ## JDBC3.0-JDK1.5-end ##*/
private static final String DEFAULT_TEMP_DIR = "target/scratch"; //$NON-NLS-1$
15 years, 8 months
teiid SVN: r813 - in trunk/engine/src: main/java/com/metamatrix/query/processor/proc and 7 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2009-04-21 10:47:32 -0400 (Tue, 21 Apr 2009)
New Revision: 813
Modified:
trunk/engine/src/main/java/com/metamatrix/dqp/service/CustomizableTrackingService.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/relational/SelectNode.java
trunk/engine/src/main/java/com/metamatrix/query/resolver/util/ResolverUtil.java
trunk/engine/src/main/java/com/metamatrix/query/resolver/util/ResolverVisitorUtil.java
trunk/engine/src/main/java/com/metamatrix/query/rewriter/QueryRewriter.java
trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestOptimizer.java
trunk/engine/src/test/java/com/metamatrix/query/processor/proc/TestProcedureProcessor.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-252 generalizing resolver handling of constant type conversion so that the rewriter can filter invalid comparisons.
Modified: trunk/engine/src/main/java/com/metamatrix/dqp/service/CustomizableTrackingService.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/dqp/service/CustomizableTrackingService.java 2009-04-21 02:41:33 UTC (rev 812)
+++ trunk/engine/src/main/java/com/metamatrix/dqp/service/CustomizableTrackingService.java 2009-04-21 14:47:32 UTC (rev 813)
@@ -38,7 +38,6 @@
import com.metamatrix.common.queue.WorkerPool;
import com.metamatrix.common.queue.WorkerPoolFactory;
import com.metamatrix.common.util.LogCommonConstants;
-import com.metamatrix.common.util.PropertiesUtils;
import com.metamatrix.core.util.StringUtil;
import com.metamatrix.dqp.DQPPlugin;
import com.metamatrix.dqp.spi.CommandLoggerSPI;
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-21 02:41:33 UTC (rev 812)
+++ trunk/engine/src/main/java/com/metamatrix/query/processor/proc/ExecDynamicSqlInstruction.java 2009-04-21 14:47:32 UTC (rev 813)
@@ -149,11 +149,6 @@
public void process(ProgramEnvironment env) throws BlockedException,
MetaMatrixComponentException, MetaMatrixProcessingException {
- LogManager
- .logTrace(
- LogConstants.CTX_DQP,
- "Processing ExecDynamicSqlInstruction as part of processing the update procedure"); //$NON-NLS-1$
-
ProcedureEnvironment procEnv = (ProcedureEnvironment) env;
VariableContext localContext = procEnv.getCurrentVariableContext();
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-21 02:41:33 UTC (rev 812)
+++ trunk/engine/src/main/java/com/metamatrix/query/processor/proc/ExecSqlInstruction.java 2009-04-21 14:47:32 UTC (rev 813)
@@ -31,8 +31,6 @@
import com.metamatrix.api.exception.MetaMatrixComponentException;
import com.metamatrix.api.exception.MetaMatrixProcessingException;
import com.metamatrix.common.buffer.BlockedException;
-import com.metamatrix.common.log.LogManager;
-import com.metamatrix.dqp.util.LogConstants;
import com.metamatrix.query.processor.ProcessorPlan;
import com.metamatrix.query.processor.program.ProgramEnvironment;
import com.metamatrix.query.sql.symbol.GroupSymbol;
@@ -73,8 +71,6 @@
public void process(ProgramEnvironment env)
throws BlockedException, MetaMatrixComponentException, MetaMatrixProcessingException {
- LogManager.logTrace(LogConstants.CTX_DQP, new Object[]{"Processing ExecSqlInstruction as part of processing the update procedure"}); //$NON-NLS-1$
-
ProcedureEnvironment procEnv = (ProcedureEnvironment) env;
if(intoGroup != null && intoGroup.isTempGroupSymbol()){
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-21 02:41:33 UTC (rev 812)
+++ trunk/engine/src/main/java/com/metamatrix/query/processor/relational/SelectNode.java 2009-04-21 14:47:32 UTC (rev 813)
@@ -22,7 +22,6 @@
package com.metamatrix.query.processor.relational;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -58,6 +57,7 @@
blockedOnPrepare = false;
blockedBatch = null;
blockedRow = 0;
+ evaluator = null;
}
public void setCriteria(Criteria criteria) {
Modified: trunk/engine/src/main/java/com/metamatrix/query/resolver/util/ResolverUtil.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/resolver/util/ResolverUtil.java 2009-04-21 02:41:33 UTC (rev 812)
+++ trunk/engine/src/main/java/com/metamatrix/query/resolver/util/ResolverUtil.java 2009-04-21 14:47:32 UTC (rev 813)
@@ -175,7 +175,7 @@
}
if(canImplicitlyConvert(sourceTypeName, targetTypeName)
- || (sourceExpression instanceof Constant && canConvertConstant(sourceTypeName, targetTypeName, (Constant)sourceExpression))) {
+ || (sourceExpression instanceof Constant && convertConstant(sourceTypeName, targetTypeName, (Constant)sourceExpression) != null)) {
return getConversion(sourceExpression, sourceTypeName, targetTypeName);
}
@@ -183,29 +183,31 @@
throw new QueryResolverException(ErrorMessageKeys.RESOLVER_0041, QueryPlugin.Util.getString(ErrorMessageKeys.RESOLVER_0041, new Object[] {targetTypeName, sourceExpression, sourceTypeName}));
}
- private static boolean canConvertConstant(String sourceTypeName,
+ public static Constant convertConstant(String sourceTypeName,
String targetTypeName,
Constant constant) throws QueryResolverException {
- if (DataTypeManager.isTransformable(sourceTypeName, targetTypeName)) {
+ if (!DataTypeManager.isTransformable(sourceTypeName, targetTypeName)) {
+ return null;
+ }
- //try to get the converted constant, if this fails then it is not in a valid format
- Constant result = getProperlyTypedConstant(constant.getValue(), DataTypeManager.getDataTypeClass(targetTypeName));
-
- if (DataTypeManager.DefaultDataTypes.STRING.equals(sourceTypeName)) {
- return true;
- }
-
- //for non-strings, ensure that the conversion is consistent
- if (DataTypeManager.isTransformable(targetTypeName, sourceTypeName)) {
- Constant reverse = getProperlyTypedConstant(result.getValue(), constant.getType());
-
- if (constant.equals(reverse)) {
- return true;
- }
- }
+ //try to get the converted constant, if this fails then it is not in a valid format
+ Constant result = getProperlyTypedConstant(constant.getValue(), DataTypeManager.getDataTypeClass(targetTypeName));
+
+ if (DataTypeManager.DefaultDataTypes.STRING.equals(sourceTypeName)) {
+ return result;
}
+
+ //for non-strings, ensure that the conversion is consistent
+ if (!DataTypeManager.isTransformable(targetTypeName, sourceTypeName)) {
+ return null;
+ }
+ Constant reverse = getProperlyTypedConstant(result.getValue(), constant.getType());
+
+ if (constant.equals(reverse)) {
+ return result;
+ }
- return false;
+ return null;
}
private static Expression getConversion(Expression sourceExpression,
Modified: trunk/engine/src/main/java/com/metamatrix/query/resolver/util/ResolverVisitorUtil.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/resolver/util/ResolverVisitorUtil.java 2009-04-21 02:41:33 UTC (rev 812)
+++ trunk/engine/src/main/java/com/metamatrix/query/resolver/util/ResolverVisitorUtil.java 2009-04-21 14:47:32 UTC (rev 813)
@@ -45,7 +45,6 @@
import com.metamatrix.query.metadata.QueryMetadataInterface;
import com.metamatrix.query.metadata.StoredProcedureInfo;
import com.metamatrix.query.metadata.TempMetadataID;
-import com.metamatrix.query.sql.ReservedWords;
import com.metamatrix.query.sql.lang.BetweenCriteria;
import com.metamatrix.query.sql.lang.CompareCriteria;
import com.metamatrix.query.sql.lang.IsNullCriteria;
@@ -146,96 +145,60 @@
Expression leftExpression = ccrit.getLeftExpression();
Expression rightExpression = ccrit.getRightExpression();
- boolean leftIsAggregate = (leftExpression instanceof AggregateSymbol);
- boolean rightIsAggregate = (rightExpression instanceof AggregateSymbol);
-
// Check typing between expressions
ResolverUtil.setTypeIfReference(leftExpression, rightExpression.getType(), ccrit);
ResolverUtil.setTypeIfReference(rightExpression, leftExpression.getType(), ccrit);
- if(! leftExpression.getType().equals(rightExpression.getType()) ) {
+ if(leftExpression.getType().equals(rightExpression.getType()) ) {
+ return;
+ }
- boolean converted = false;
-
- // Try to apply an implicit conversion from one side to the other
- String leftTypeName = DataTypeManager.getDataTypeName(leftExpression.getType());
- String rightTypeName = DataTypeManager.getDataTypeName(rightExpression.getType());
-
- // Special cases when right expression is a constant
- if(rightExpression instanceof Constant) {
- // Auto-convert constant string on right to expected type on left
- try {
- ccrit.setRightExpression(ResolverUtil.convertExpression(rightExpression, rightTypeName, leftTypeName));
- converted = true;
- } catch (QueryResolverException qre) {
- //ignore
- }
- }
-
- // Special cases when left expression is a constant
- if(!converted && leftExpression instanceof Constant) {
- // Auto-convert constant string on left to expected type on right
- try {
- ccrit.setLeftExpression(ResolverUtil.convertExpression(leftExpression, leftTypeName, rightTypeName));
- converted = true;
- } catch (QueryResolverException qre) {
- //ignore
- }
+ // Try to apply an implicit conversion from one side to the other
+ String leftTypeName = DataTypeManager.getDataTypeName(leftExpression.getType());
+ String rightTypeName = DataTypeManager.getDataTypeName(rightExpression.getType());
+
+ // Special cases when right expression is a constant
+ if(rightExpression instanceof Constant) {
+ // Auto-convert constant string on right to expected type on left
+ try {
+ ccrit.setRightExpression(ResolverUtil.convertExpression(rightExpression, rightTypeName, leftTypeName));
+ return;
+ } catch (QueryResolverException qre) {
+ //ignore
}
-
- // Try to apply a conversion generically (except when aggregate involved)
- if(!converted) {
- // Try to apply conversion to left if not aggregate
- if(! leftIsAggregate && ResolverUtil.canImplicitlyConvert(leftTypeName, rightTypeName)) {
- ccrit.setLeftExpression(ResolverUtil.convertExpression(leftExpression, leftTypeName, rightTypeName) );
- converted = true;
- }
-
- // Try to apply conversion to right if left not converted and right not aggregate
- if(! converted && ! rightIsAggregate && ResolverUtil.canImplicitlyConvert(rightTypeName, leftTypeName)) {
- ccrit.setRightExpression(ResolverUtil.convertExpression(rightExpression, rightTypeName, leftTypeName) );
- converted = true;
- }
- }
-
- // Could not resolve - try last ditch effort to convert agg expression or throw exception
- if(! converted) {
- if(rightIsAggregate) {
- if(leftIsAggregate) {
- // both are aggs of differing types - can't reconcile
- throw new QueryResolverException(ErrorMessageKeys.RESOLVER_0064, QueryPlugin.Util.getString(ErrorMessageKeys.RESOLVER_0064));
- }
- AggregateSymbol aggRight = (AggregateSymbol) rightExpression;
- String aggFunc = aggRight.getAggregateFunction();
- // Convert expression inside MIN/MAX function rather than converting aggregate
- if((aggFunc.equals(ReservedWords.MIN) || aggFunc.equals(ReservedWords.MAX)) &&
- ResolverUtil.canImplicitlyConvert(rightTypeName, leftTypeName)) {
- aggRight.setExpression(ResolverUtil.convertExpression(aggRight.getExpression(), rightTypeName, leftTypeName) );
- } else {
- throw new QueryResolverException(ErrorMessageKeys.RESOLVER_0028, QueryPlugin.Util.getString(ErrorMessageKeys.RESOLVER_0028));
- }
- } else if(leftIsAggregate) {
- AggregateSymbol aggLeft = (AggregateSymbol) leftExpression;
- String aggFunc = aggLeft.getAggregateFunction();
- // Convert expression inside MIN/MAX function rather than converting aggregate
- if((aggFunc.equals(ReservedWords.MIN) || aggFunc.equals(ReservedWords.MAX)) &&
- ResolverUtil.canImplicitlyConvert(leftTypeName, rightTypeName)) {
- aggLeft.setExpression(ResolverUtil.convertExpression(aggLeft.getExpression(), leftTypeName, rightTypeName) );
- } else {
- throw new QueryResolverException(ErrorMessageKeys.RESOLVER_0028, QueryPlugin.Util.getString(ErrorMessageKeys.RESOLVER_0028));
- }
- } else {
- String commonType = ResolverUtil.getCommonType(new String[] {leftTypeName, rightTypeName});
-
- if (commonType == null) {
- // Neither are aggs, but types can't be reconciled
- throw new QueryResolverException(ErrorMessageKeys.RESOLVER_0027, QueryPlugin.Util.getString(ErrorMessageKeys.RESOLVER_0027, new Object[] { leftTypeName, rightTypeName, ccrit }));
- }
- ccrit.setLeftExpression(ResolverUtil.convertExpression(leftExpression, leftTypeName, commonType) );
- ccrit.setRightExpression(ResolverUtil.convertExpression(rightExpression, rightTypeName, commonType) );
- }
- }
+ }
+
+ // Special cases when left expression is a constant
+ if(leftExpression instanceof Constant) {
+ // Auto-convert constant string on left to expected type on right
+ try {
+ ccrit.setLeftExpression(ResolverUtil.convertExpression(leftExpression, leftTypeName, rightTypeName));
+ return;
+ } catch (QueryResolverException qre) {
+ //ignore
+ }
+ }
+
+ // Try to apply a conversion generically
+
+ if(ResolverUtil.canImplicitlyConvert(leftTypeName, rightTypeName)) {
+ ccrit.setLeftExpression(ResolverUtil.convertExpression(leftExpression, leftTypeName, rightTypeName) );
+ return;
+ }
+
+ if(ResolverUtil.canImplicitlyConvert(rightTypeName, leftTypeName)) {
+ ccrit.setRightExpression(ResolverUtil.convertExpression(rightExpression, rightTypeName, leftTypeName) );
+ return;
+ }
+
+ String commonType = ResolverUtil.getCommonType(new String[] {leftTypeName, rightTypeName});
+
+ if (commonType == null) {
+ // Neither are aggs, but types can't be reconciled
+ throw new QueryResolverException(ErrorMessageKeys.RESOLVER_0027, QueryPlugin.Util.getString(ErrorMessageKeys.RESOLVER_0027, new Object[] { leftTypeName, rightTypeName, ccrit }));
}
+ ccrit.setLeftExpression(ResolverUtil.convertExpression(leftExpression, leftTypeName, commonType) );
+ ccrit.setRightExpression(ResolverUtil.convertExpression(rightExpression, rightTypeName, commonType) );
}
static void resolveMatchCriteria(MatchCriteria mcrit)
Modified: trunk/engine/src/main/java/com/metamatrix/query/rewriter/QueryRewriter.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/rewriter/QueryRewriter.java 2009-04-21 02:41:33 UTC (rev 812)
+++ trunk/engine/src/main/java/com/metamatrix/query/rewriter/QueryRewriter.java 2009-04-21 14:47:32 UTC (rev 813)
@@ -54,7 +54,6 @@
import com.metamatrix.api.exception.query.QueryValidatorException;
import com.metamatrix.common.buffer.BlockedException;
import com.metamatrix.common.types.DataTypeManager;
-import com.metamatrix.common.types.Transform;
import com.metamatrix.common.util.TimestampWithTimezone;
import com.metamatrix.core.MetaMatrixRuntimeException;
import com.metamatrix.core.util.Assertion;
@@ -144,7 +143,6 @@
import com.metamatrix.query.sql.visitor.EvaluateExpressionVisitor;
import com.metamatrix.query.sql.visitor.ExpressionMappingVisitor;
import com.metamatrix.query.sql.visitor.PredicateCollectorVisitor;
-import com.metamatrix.query.sql.visitor.ValueIteratorProviderCollectorVisitor;
import com.metamatrix.query.util.CommandContext;
import com.metamatrix.query.util.ErrorMessageKeys;
@@ -1458,9 +1456,7 @@
* <code>typedColumn = 5 </code>
*
* Right expression has already been checked to be a Constant, left expression to be
- * a function. Function is known to be "convert" or "cast". The scope of this change
- * will be limited to the case where the left expression is attempting to convert to
- * 'string'.
+ * a function. Function is known to be "convert" or "cast".
*
* @param crit CompareCriteria
* @return same Criteria instance (possibly optimized)
@@ -1474,44 +1470,31 @@
String leftExprTypeName = DataTypeManager.getDataTypeName(leftExpr.getType());
- if (leftExpr.getType() == DataTypeManager.DefaultDataClasses.NULL || rightConstant.getType() != DataTypeManager.DefaultDataClasses.STRING) {
+ if (leftExpr.getType() == DataTypeManager.DefaultDataClasses.NULL) {
return crit;
}
- Transform transform = DataTypeManager.getTransform(leftExprTypeName, DataTypeManager.DefaultDataTypes.STRING);
-
- if (transform.isNarrowing()) {
- return crit;
+ Constant result = null;
+ try {
+ result = ResolverUtil.convertConstant(DataTypeManager.getDataTypeName(rightConstant.getType()), leftExprTypeName, rightConstant);
+ } catch(QueryResolverException e) {
+
}
-
- FunctionLibrary funcLib = FunctionLibraryManager.getFunctionLibrary();
- FunctionDescriptor descriptor = funcLib.findTypedConversionFunction(rightConstant.getType(), leftExpr.getType());
-
- if(descriptor == null){
- return crit;
- }
-
- try {
- Object result = funcLib.invokeFunction(
- descriptor, new Object[] { rightConstant.getValue(), leftExprTypeName } );
- crit.setRightExpression(new Constant(result, descriptor.getReturnType()));
- crit.setLeftExpression(leftExpr);
- } catch(InvalidFunctionException e) {
- String errorMsg = QueryExecPlugin.Util.getString("QueryRewriter.criteriaError", crit); //$NON-NLS-1$
- throw new QueryValidatorException(e, errorMsg);
- } catch(FunctionExecutionException e) {
- if (crit.getOperator() == CompareCriteria.EQ) {
+ if (result == null) {
+ if (crit.getOperator() == CompareCriteria.EQ) {
return FALSE_CRITERIA;
}
return TRUE_CRITERIA;
}
+
+ crit.setRightExpression(result);
+ crit.setLeftExpression(leftExpr);
if (leftExpr instanceof Function) {
return simplifyWithInverse(crit);
}
- // Fall through and return original criteria
return crit;
}
@@ -1541,61 +1524,49 @@
* @throws QueryValidatorException
* @since 4.2
*/
- private static SetCriteria simplifyConvertFunction(SetCriteria crit) throws QueryValidatorException {
-
-
+ private static Criteria simplifyConvertFunction(SetCriteria crit, Command procCommand, CommandContext context, QueryMetadataInterface metadata) throws QueryValidatorException {
Function leftFunction = (Function) crit.getExpression();
Expression leftExpr = leftFunction.getArgs()[0];
- Expression targetType = leftFunction.getArgs()[1];
String leftExprTypeName = DataTypeManager.getDataTypeName(leftExpr.getType());
Iterator i = crit.getValues().iterator();
Collection newValues = new ArrayList(crit.getNumberOfValues());
- boolean success = true;
- try {
- while (i.hasNext()) {
- Object next = i.next();
- if (next instanceof Constant) {
-
- Constant rightConstant = (Constant) next;
- Class rightConstantType = rightConstant.getType();
-
-
- if(targetType.getType().equals(rightConstantType) && targetType.getType().equals(DataTypeManager.DefaultDataClasses.STRING)) {
- FunctionLibrary funcLib = FunctionLibraryManager.getFunctionLibrary();
- FunctionDescriptor descriptor = funcLib.findTypedConversionFunction(rightConstantType, leftExpr.getType());
-
- if(descriptor != null){
- Object result = funcLib.invokeFunction(
- descriptor, new Object[] { rightConstant.getValue(), leftExprTypeName } );
- newValues.add(new Constant(result, descriptor.getReturnType()));
- } else {
- success = false;
- break;
- }
- } else {
- success = false;
- break;
- }
-
- } else {
- success = false;
- break;
- }
+ boolean convertedAll = true;
+ boolean removedSome = false;
+ while (i.hasNext()) {
+ Object next = i.next();
+ if (!(next instanceof Constant)) {
+ convertedAll = false;
+ continue;
}
- } catch(InvalidFunctionException e) {
- String errorMsg = QueryExecPlugin.Util.getString("QueryRewriter.criteriaError", crit); //$NON-NLS-1$
- throw new QueryValidatorException(e, errorMsg);
- } catch(FunctionExecutionException e) {
- return crit;
+
+ Constant rightConstant = (Constant) next;
+
+ Constant result = null;
+ try {
+ result = ResolverUtil.convertConstant(DataTypeManager.getDataTypeName(rightConstant.getType()), leftExprTypeName, rightConstant);
+ } catch(QueryResolverException e) {
+
+ }
+
+ if (result != null) {
+ newValues.add(result);
+ } else {
+ removedSome = true;
+ i.remove();
+ }
}
- if (success) {
- crit.setExpression(leftExpr);
- crit.setValues(newValues);
+ if (!convertedAll) {
+ if (!removedSome) {
+ return crit; //just return as is
+ }
+ return rewriteCriteria(crit, procCommand, context, metadata);
}
- return crit;
+ crit.setExpression(leftExpr);
+ crit.setValues(newValues);
+ return rewriteCriteria(crit, procCommand, context, metadata);
}
private static CompareCriteria simplifyParseFormatFunction(CompareCriteria crit) throws QueryValidatorException {
@@ -1943,9 +1914,7 @@
if (newVals.size() == 1) {
Expression value = (Expression)newVals.iterator().next();
- if (ValueIteratorProviderCollectorVisitor.getValueIteratorProviders(value).size() == 0) {
- return rewriteCriteria(new CompareCriteria(criteria.getExpression(), criteria.isNegated()?CompareCriteria.NE:CompareCriteria.EQ, value), procCommand, context, metadata);
- }
+ return rewriteCriteria(new CompareCriteria(criteria.getExpression(), criteria.isNegated()?CompareCriteria.NE:CompareCriteria.EQ, value), procCommand, context, metadata);
} else if (newVals.size() == 0) {
return FALSE_CRITERIA;
}
@@ -1954,13 +1923,7 @@
Function leftFunction = (Function)criteria.getExpression();
if(FunctionLibrary.isConvert(leftFunction)) {
- Iterator i = criteria.getValues().iterator();
- while (i.hasNext()) {
- if (!(i.next() instanceof Constant)) {
- return criteria;
- }
- }
- criteria = simplifyConvertFunction(criteria);
+ return simplifyConvertFunction(criteria, procCommand, context, metadata);
}
}
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-21 02:41:33 UTC (rev 812)
+++ trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestOptimizer.java 2009-04-21 14:47:32 UTC (rev 813)
@@ -6976,7 +6976,7 @@
FakeMetadataFacade metadata = FakeMetadataFactory.exampleBQTCached();
ProcessorPlan plan = helpPlan(
- "SELECT ClobValue from LOB.LobTbl WHERE convert(ClobValue, string) = '1'", //$NON-NLS-1$
+ "SELECT ClobValue from LOB.LobTbl WHERE convert(ClobValue, string) = ?", //$NON-NLS-1$
metadata,
null, capFinder,
new String[] {"SELECT ClobValue FROM LOB.LobTbl"}, //$NON-NLS-1$
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-21 02:41:33 UTC (rev 812)
+++ trunk/engine/src/test/java/com/metamatrix/query/processor/proc/TestProcedureProcessor.java 2009-04-21 14:47:32 UTC (rev 813)
@@ -262,9 +262,9 @@
elementSymbols,
new List[] {
- Arrays.asList( new Object[] { "First", new Integer(5), new Boolean(true), new Double(1.003)} ), //$NON-NLS-1$
- Arrays.asList( new Object[] { "Second", new Integer(15), new Boolean(true), new Double(2.003)} ), //$NON-NLS-1$
- Arrays.asList( new Object[] { "Third", new Integer(51), new Boolean(true), new Double(3.003)} ) //$NON-NLS-1$
+ Arrays.asList( new Object[] { "First", new Short((short)5), new Boolean(true), new Double(1.003)} ), //$NON-NLS-1$
+ Arrays.asList( new Object[] { "Second", new Short((short)15), new Boolean(true), new Double(2.003)} ), //$NON-NLS-1$
+ Arrays.asList( new Object[] { "Third", new Short((short)51), new Boolean(true), new Double(3.003)} ) //$NON-NLS-1$
} );
return dataMgr;
@@ -1821,7 +1821,7 @@
ProcessorPlan plan = getProcedurePlan(userUpdateStr, metadata);
// Create expected results
- List[] expected = new List[] { Arrays.asList(new Object[] { "First", new Integer(5)})}; //$NON-NLS-1$
+ List[] expected = new List[] { Arrays.asList(new Object[] { "First", new Short((short)5)})}; //$NON-NLS-1$
helpTestProcess(plan, expected, dataMgr);
}
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-21 02:41:33 UTC (rev 812)
+++ trunk/engine/src/test/java/com/metamatrix/query/resolver/TestResolver.java 2009-04-21 14:47:32 UTC (rev 813)
@@ -59,7 +59,6 @@
import com.metamatrix.query.parser.QueryParser;
import com.metamatrix.query.resolver.util.BindVariableVisitor;
import com.metamatrix.query.resolver.util.ResolverUtil;
-import com.metamatrix.query.resolver.util.ResolverVisitorUtil;
import com.metamatrix.query.sql.LanguageObject;
import com.metamatrix.query.sql.ProcedureReservedWords;
import com.metamatrix.query.sql.lang.BatchedUpdateCommand;
@@ -876,7 +875,7 @@
}
public void testHavingWithAggsOfDifferentTypes() {
- helpResolveException("SELECT * FROM pm1.g1 GROUP BY e4 HAVING MIN(e1) = MIN(e2)"); //$NON-NLS-1$
+ helpResolve("SELECT * FROM pm1.g1 GROUP BY e4 HAVING MIN(e1) = MIN(e2)"); //$NON-NLS-1$
}
public void testCaseInGroupBy() {
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-21 02:41:33 UTC (rev 812)
+++ trunk/engine/src/test/java/com/metamatrix/query/rewriter/TestQueryRewriter.java 2009-04-21 14:47:32 UTC (rev 813)
@@ -22,8 +22,6 @@
package com.metamatrix.query.rewriter;
-import java.math.BigDecimal;
-import java.math.BigInteger;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
@@ -62,7 +60,6 @@
import com.metamatrix.query.sql.symbol.Constant;
import com.metamatrix.query.sql.symbol.ElementSymbol;
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.SingleElementSymbol;
import com.metamatrix.query.sql.visitor.CorrelatedReferenceCollectorVisitor;
@@ -268,7 +265,7 @@
}
public void testRewriteCrit6() {
- helpTestRewriteCriteria("1 = convert(pm1.g1.e1,integer) + 10", "convert(pm1.g1.e1, integer) = -9"); //$NON-NLS-1$ //$NON-NLS-2$
+ helpTestRewriteCriteria("1 = convert(pm1.g1.e1,integer) + 10", "pm1.g1.e1 = '-9'"); //$NON-NLS-1$ //$NON-NLS-2$
}
public void testRewriteCrit7() {
@@ -525,7 +522,12 @@
public void testRewriteCrit_formatLong() {
helpTestRewriteCriteria("formatLong(convert(pm1.g1.e2, long), '#,##0') = '1,234,567,890,123'", //$NON-NLS-1$
- "convert(pm1.g1.e2, long) = 1234567890123" ); //$NON-NLS-1$
+ "1 = 0" ); //$NON-NLS-1$
+ }
+
+ public void testRewriteCrit_formatLong1() {
+ helpTestRewriteCriteria("formatLong(convert(pm1.g1.e2, long), '#,##0') = '1,234,567,890'", //$NON-NLS-1$
+ "pm1.g1.e2 = 1234567890" ); //$NON-NLS-1$
}
public void testRewriteCrit_formatTimestampInvert() {
@@ -542,28 +544,22 @@
helpTestRewriteCriteria(original, expected);
}
- public void testRewriteCrit_formatBigInteger() {
+ public void testRewriteCrit_formatBigInteger() throws Exception {
String original = "formatBigInteger(convert(pm1.g1.e2, biginteger), '#,##0') = '1,234,567,890'"; //$NON-NLS-1$
- String expected = "convert(pm1.g1.e2, biginteger) = 1234567890"; //$NON-NLS-1$
+ String expected = "pm1.g1.e2 = 1234567890"; //$NON-NLS-1$
FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
Criteria origCrit = parseCriteria(original, metadata);
Criteria expectedCrit = parseCriteria(expected, metadata);
- ((CompareCriteria)expectedCrit).setRightExpression(new Constant(new BigInteger("1234567890"))); //$NON-NLS-1$
// rewrite
- try {
- Criteria actual = QueryRewriter.rewriteCriteria(origCrit, null, null, null);
- assertEquals("Did not rewrite correctly: ", expectedCrit, actual); //$NON-NLS-1$
- } catch(QueryValidatorException e) {
- e.printStackTrace();
- fail("Exception during rewriting (" + e.getClass().getName() + "): " + e.getMessage()); //$NON-NLS-1$ //$NON-NLS-2$
- }
+ Criteria actual = QueryRewriter.rewriteCriteria(origCrit, null, null, null);
+ assertEquals("Did not rewrite correctly: ", expectedCrit, actual); //$NON-NLS-1$
}
public void testRewriteCrit_formatFloat() throws Exception {
- String original = "formatFloat(convert(pm1.g1.e2, float), '#,##0.###') = '1,234.123'"; //$NON-NLS-1$
- String expected = "convert(pm1.g1.e2, float) = 1234.123"; //$NON-NLS-1$
+ String original = "formatFloat(convert(pm1.g1.e4, float), '#,##0.###') = '1,234.123'"; //$NON-NLS-1$
+ String expected = "pm1.g1.e4 = 1234.123046875"; //$NON-NLS-1$
FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
Criteria origCrit = parseCriteria(original, metadata);
@@ -571,15 +567,11 @@
// rewrite
Criteria actual = QueryRewriter.rewriteCriteria(origCrit, null, null, null);
assertEquals("Did not rewrite correctly: ", expected, actual.toString()); //$NON-NLS-1$
-
- Function left = (Function)((CompareCriteria)actual).getLeftExpression();
-
- assertFalse(left.isImplicit());
}
- public void testRewriteCrit_formatDouble() {
- String original = "formatDouble(convert(pm1.g1.e2, double), '$#,##0.00') = '$1,234.50'"; //$NON-NLS-1$
- String expected = "convert(pm1.g1.e2, double) = 1234.5"; //$NON-NLS-1$
+ public void testRewriteCrit_formatDouble() throws Exception {
+ String original = "formatDouble(convert(pm1.g1.e4, double), '$#,##0.00') = '$1,234.50'"; //$NON-NLS-1$
+ String expected = "pm1.g1.e4 = '1234.5'"; //$NON-NLS-1$
FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
Criteria origCrit = parseCriteria(original, metadata);
@@ -587,32 +579,21 @@
((CompareCriteria)expectedCrit).setRightExpression(new Constant(new Double(1234.5)));
// rewrite
- try {
- Criteria actual = QueryRewriter.rewriteCriteria(origCrit, null, null, null);
- assertEquals("Did not rewrite correctly: ", expectedCrit, actual); //$NON-NLS-1$
- } catch(QueryValidatorException e) {
- e.printStackTrace();
- fail("Exception during rewriting (" + e.getClass().getName() + "): " + e.getMessage()); //$NON-NLS-1$ //$NON-NLS-2$
- }
+ Criteria actual = QueryRewriter.rewriteCriteria(origCrit, null, null, null);
+ assertEquals("Did not rewrite correctly: ", expectedCrit, actual); //$NON-NLS-1$
}
- public void testRewriteCrit_formatBigDecimal() {
- String original = "formatBigDecimal(convert(pm1.g1.e2, bigdecimal), '#,##0.###') = convert(1234.5, bigdecimal)"; //$NON-NLS-1$
- String expected = "convert(pm1.g1.e2, bigdecimal) = 1234.5"; //$NON-NLS-1$
+ public void testRewriteCrit_formatBigDecimal() throws Exception {
+ String original = "formatBigDecimal(convert(pm1.g1.e4, bigdecimal), '#,##0.###') = convert(1234.5, bigdecimal)"; //$NON-NLS-1$
+ String expected = "pm1.g1.e4 = 1234.5"; //$NON-NLS-1$
FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
Criteria origCrit = parseCriteria(original, metadata);
Criteria expectedCrit = parseCriteria(expected, metadata);
- ((CompareCriteria)expectedCrit).setRightExpression(new Constant(new BigDecimal("1234.5"))); //$NON-NLS-1$
// rewrite
- try {
- Criteria actual = QueryRewriter.rewriteCriteria(origCrit, null, null, null);
- assertEquals("Did not rewrite correctly: ", expectedCrit, actual); //$NON-NLS-1$
- } catch(QueryValidatorException e) {
- e.printStackTrace();
- fail("Exception during rewriting (" + e.getClass().getName() + "): " + e.getMessage()); //$NON-NLS-1$ //$NON-NLS-2$
- }
+ Criteria actual = QueryRewriter.rewriteCriteria(origCrit, null, null, null);
+ assertEquals("Did not rewrite correctly: ", expectedCrit, actual); //$NON-NLS-1$
}
public void testRewriteCritTimestampDiffDate1() {
@@ -1000,7 +981,7 @@
String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "SELECT e2 FROM pm1.g1 WHERE convert(sqrt(pm1.g1.e2), integer) = 10;\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "SELECT e2 FROM pm1.g1 WHERE sqrt(pm1.g1.e2) = 10.0;\n"; //$NON-NLS-1$
rewritProc = rewritProc + "END"; //$NON-NLS-1$
String procReturned = this.getReWrittenProcedure(procedure, userQuery,
@@ -1118,7 +1099,7 @@
String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
rewritProc = rewritProc + "DECLARE integer var1;\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "SELECT pm1.g1.e2 FROM pm1.g1 WHERE (CONCAT(e1, 'z') = CONCAT(CONCAT(e1, 'z'), 'y')) AND (convert(CONCAT(e1, 'k'), integer) = 1);\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "SELECT pm1.g1.e2 FROM pm1.g1 WHERE (CONCAT(e1, 'z') = CONCAT(CONCAT(e1, 'z'), 'y')) AND (CONCAT(e1, 'k') = '1');\n"; //$NON-NLS-1$
rewritProc = rewritProc + "END"; //$NON-NLS-1$
String procReturned = this.getReWrittenProcedure(procedure, userQuery,
@@ -1602,14 +1583,12 @@
helpTestRewriteCriteria("convert(pm1.g1.e1, string) = 'x'", "pm1.g1.e1 = 'x'"); //$NON-NLS-1$ //$NON-NLS-2$
}
- /** Test some other type besides 'string' has no effect */
public void testRewriteCase1954d() {
- helpTestRewriteCriteria("convert(pm1.g1.e1, timestamp) = {ts '2005-01-03 00:00:00.0'}", "convert(pm1.g1.e1, timestamp) = {ts '2005-01-03 00:00:00.0'}"); //$NON-NLS-1$ //$NON-NLS-2$
+ helpTestRewriteCriteria("convert(pm1.g1.e1, timestamp) = {ts '2005-01-03 00:00:00.0'}", "pm1.g1.e1 = '2005-01-03 00:00:00.0'"); //$NON-NLS-1$ //$NON-NLS-2$
}
- /** Test some other type besides 'string' has no effect */
public void testRewriteCase1954e() {
- helpTestRewriteCriteria("convert(pm1.g1.e4, integer) = 2", "convert(pm1.g1.e4, integer) = 2"); //$NON-NLS-1$ //$NON-NLS-2$
+ helpTestRewriteCriteria("convert(pm1.g1.e4, integer) = 2", "pm1.g1.e4 = 2.0"); //$NON-NLS-1$ //$NON-NLS-2$
}
/** Check that this fails, x is not convertable to an int */
@@ -1627,7 +1606,7 @@
}
public void testRewriteCase1954SetA() {
- helpTestRewriteCriteria("convert(pm1.g1.e2, string) in ('2', 'x')", "convert(pm1.g1.e2, string) in ('2', 'x')"); //$NON-NLS-1$ //$NON-NLS-2$
+ helpTestRewriteCriteria("convert(pm1.g1.e2, string) in ('2', 'x')", "pm1.g1.e2 = 2"); //$NON-NLS-1$ //$NON-NLS-2$
}
public void testRewriteCase1954SetB() {
15 years, 8 months