teiid SVN: r3160 - branches/7.4.x/engine/src/main/java/org/teiid/query/processor/relational.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2011-05-10 11:25:04 -0400 (Tue, 10 May 2011)
New Revision: 3160
Modified:
branches/7.4.x/engine/src/main/java/org/teiid/query/processor/relational/RelationalNodeUtil.java
Log:
changing equality test to the safer .equals
Modified: branches/7.4.x/engine/src/main/java/org/teiid/query/processor/relational/RelationalNodeUtil.java
===================================================================
--- branches/7.4.x/engine/src/main/java/org/teiid/query/processor/relational/RelationalNodeUtil.java 2011-05-10 14:54:22 UTC (rev 3159)
+++ branches/7.4.x/engine/src/main/java/org/teiid/query/processor/relational/RelationalNodeUtil.java 2011-05-10 15:25:04 UTC (rev 3160)
@@ -74,7 +74,7 @@
if (limit != null && limit.getRowLimit() instanceof Constant) {
Constant rowLimit = (Constant)limit.getRowLimit();
- if (Integer.valueOf(0) == rowLimit.getValue()) {
+ if (Integer.valueOf(0).equals(rowLimit.getValue())) {
return false;
}
}
13 years, 7 months
teiid SVN: r3159 - branches/7.4.x/runtime/src/main/java/org/teiid/deployers.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2011-05-10 10:54:22 -0400 (Tue, 10 May 2011)
New Revision: 3159
Modified:
branches/7.4.x/runtime/src/main/java/org/teiid/deployers/VDBDeployer.java
Log:
TEIID-1580 refining the fix for CME during dynamic vdb load, only need to not set status if an asynch load is happening
Modified: branches/7.4.x/runtime/src/main/java/org/teiid/deployers/VDBDeployer.java
===================================================================
--- branches/7.4.x/runtime/src/main/java/org/teiid/deployers/VDBDeployer.java 2011-05-10 14:44:57 UTC (rev 3158)
+++ branches/7.4.x/runtime/src/main/java/org/teiid/deployers/VDBDeployer.java 2011-05-10 14:54:22 UTC (rev 3159)
@@ -111,11 +111,11 @@
repo.addTranslatorMetadata(data.getName(), data);
}
createConnectorManagers(cmr, repo, deployment);
-
+ boolean asynchLoad = false;
// if store is null and vdb dynamic vdb then try to get the metadata
if (store == null && deployment.isDynamic()) {
store = new MetadataStoreGroup();
- buildDynamicMetadataStore((VFSDeploymentUnit)unit, deployment, store, cmr);
+ asynchLoad = buildDynamicMetadataStore((VFSDeploymentUnit)unit, deployment, store, cmr);
}
// allow empty vdbs for enabling the preview functionality
@@ -159,7 +159,8 @@
// Check if the VDB is fully configured.
if (!valid) {
deployment.setStatus(VDB.Status.INACTIVE);
- } else if (!deployment.isDynamic()) {
+ } else if (!asynchLoad) {
+ //if asynch this will be set by the loading thread
this.vdbRepository.finishDeployment(deployment.getName(), deployment.getVersion());
deployment.setStatus(VDB.Status.ACTIVE);
}
@@ -282,8 +283,8 @@
}
}
- private void buildDynamicMetadataStore(final VFSDeploymentUnit unit, final VDBMetaData vdb, final MetadataStoreGroup vdbStore, final ConnectorManagerRepository cmr) throws DeploymentException {
-
+ private boolean buildDynamicMetadataStore(final VFSDeploymentUnit unit, final VDBMetaData vdb, final MetadataStoreGroup vdbStore, final ConnectorManagerRepository cmr) throws DeploymentException {
+ boolean asynch = false;
// make sure we are configured correctly first
for (final ModelMetaData model:vdb.getModelMetaDatas().values()) {
if (model.getSourceNames().isEmpty()) {
@@ -302,6 +303,7 @@
}
if (!loaded) {
+ asynch = true;
threadPool.run(new Runnable() {
@Override
public void run() {
@@ -317,6 +319,7 @@
});
}
}
+ return asynch;
}
/**
13 years, 7 months
teiid SVN: r3158 - in branches/7.4.x: runtime/src/main/java/org/teiid/deployers and 1 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2011-05-10 10:44:57 -0400 (Tue, 10 May 2011)
New Revision: 3158
Modified:
branches/7.4.x/documentation/developer-guide/src/main/docbook/en-US/content/runtime-updates.xml
branches/7.4.x/runtime/src/main/java/org/teiid/deployers/CompositeVDB.java
branches/7.4.x/runtime/src/main/java/org/teiid/deployers/MetadataStoreGroup.java
branches/7.4.x/runtime/src/main/java/org/teiid/deployers/VDBDeployer.java
branches/7.4.x/runtime/src/main/java/org/teiid/deployers/VDBRepository.java
branches/7.4.x/test-integration/common/src/test/java/org/teiid/jdbc/FakeServer.java
Log:
TEIID-1580 fix for CME during dynamic vdb load
Modified: branches/7.4.x/documentation/developer-guide/src/main/docbook/en-US/content/runtime-updates.xml
===================================================================
--- branches/7.4.x/documentation/developer-guide/src/main/docbook/en-US/content/runtime-updates.xml 2011-05-09 19:00:00 UTC (rev 3157)
+++ branches/7.4.x/documentation/developer-guide/src/main/docbook/en-US/content/runtime-updates.xml 2011-05-10 14:44:57 UTC (rev 3158)
@@ -35,6 +35,7 @@
System procedures and DDL statements should be used instead since the effects will be distributed through the cluster and will not introduce inconsistencies.</para></note>
<para><code>org.teiid.metadata.AbstractMetadataRecord</code> objects passed to the <code>MetadataRepository</code> have not yet been modified.
If the <code>MetadataRepository</code> cannot persist the update, then a <code>RuntimeException</code> should be thrown to prevent the update from being applied by the runtime engine.</para>
+ <note><para>The MetadataRepository can be accessed by multiple threads both during load (if using dynamic vdbs) or at runtime with through DDL statements. Your implementation should handle any needed synchronization.</para></note>
<section>
<title>Costing Updates</title>
<para>See the Reference for the system procedures <code>SYSADMIN.setColumnStats</code> and <code>SYSADMIN.setTableStats</code>.
Modified: branches/7.4.x/runtime/src/main/java/org/teiid/deployers/CompositeVDB.java
===================================================================
--- branches/7.4.x/runtime/src/main/java/org/teiid/deployers/CompositeVDB.java 2011-05-09 19:00:00 UTC (rev 3157)
+++ branches/7.4.x/runtime/src/main/java/org/teiid/deployers/CompositeVDB.java 2011-05-10 14:44:57 UTC (rev 3158)
@@ -71,7 +71,8 @@
this.cmr = cmr;
this.additionalStores = additionalStores;
this.vdb.addAttchment(ConnectorManagerRepository.class, cmr);
- update(this.vdb, this.systemFunctions);
+ this.mergedVDB = vdb;
+ update();
}
public void addChild(CompositeVDB child) {
@@ -90,15 +91,15 @@
this.mergedVDB = null;
}
- void update(VDBMetaData vdbMetadata, FunctionTree systemFunctions) {
- TransformationMetadata metadata = buildTransformationMetaData(vdbMetadata, getVisibilityMap(), getMetadataStores(), getUDF(), systemFunctions);
- vdbMetadata.addAttchment(QueryMetadataInterface.class, metadata);
- vdbMetadata.addAttchment(TransformationMetadata.class, metadata);
+ void update() {
+ TransformationMetadata metadata = buildTransformationMetaData(mergedVDB, getVisibilityMap(), getMetadataStores(), getUDF(), systemFunctions, this.additionalStores);
+ mergedVDB.addAttchment(QueryMetadataInterface.class, metadata);
+ mergedVDB.addAttchment(TransformationMetadata.class, metadata);
TempTableStore globalTables = new TempTableStore("SYSTEM"); //$NON-NLS-1$
- vdbMetadata.addAttchment(TempTableStore.class, globalTables);
+ mergedVDB.addAttchment(TempTableStore.class, globalTables);
}
- private TransformationMetadata buildTransformationMetaData(VDBMetaData vdb, LinkedHashMap<String, Resource> visibilityMap, MetadataStoreGroup stores, UDFMetaData udf, FunctionTree systemFunctions) {
+ private static TransformationMetadata buildTransformationMetaData(VDBMetaData vdb, LinkedHashMap<String, Resource> visibilityMap, MetadataStoreGroup stores, UDFMetaData udf, FunctionTree systemFunctions, MetadataStore[] additionalStores) {
Collection <FunctionTree> udfs = new ArrayList<FunctionTree>();
if (udf != null) {
for (Map.Entry<String, Collection<FunctionMethod>> entry : udf.getFunctions().entrySet()) {
@@ -107,7 +108,7 @@
}
CompositeMetadataStore compositeStore = new CompositeMetadataStore(stores.getStores());
- for (MetadataStore s:this.additionalStores) {
+ for (MetadataStore s:additionalStores) {
compositeStore.addMetadataStore(s);
for (Schema schema:s.getSchemas().values()) {
if (!schema.getFunctions().isEmpty()) {
@@ -126,43 +127,39 @@
}
public VDBMetaData getVDB() {
- if (this.children == null || this.children.isEmpty()) {
- return vdb;
- }
if (this.mergedVDB == null) {
this.mergedVDB = buildVDB();
- update(mergedVDB, this.systemFunctions);
+ update();
}
return this.mergedVDB;
}
-
private VDBMetaData buildVDB() {
- VDBMetaData mergedVDB = new VDBMetaData();
- mergedVDB.setName(this.vdb.getName());
- mergedVDB.setVersion(this.vdb.getVersion());
- mergedVDB.setModels(this.vdb.getModels());
- mergedVDB.setDataPolicies(this.vdb.getDataPolicies());
- mergedVDB.setDescription(this.vdb.getDescription());
- mergedVDB.setStatus(this.vdb.getStatus());
- mergedVDB.setJAXBProperties(this.vdb.getJAXBProperties());
- mergedVDB.setConnectionType(this.vdb.getConnectionType());
+ VDBMetaData newMergedVDB = new VDBMetaData();
+ newMergedVDB.setName(this.vdb.getName());
+ newMergedVDB.setVersion(this.vdb.getVersion());
+ newMergedVDB.setModels(this.vdb.getModels());
+ newMergedVDB.setDataPolicies(this.vdb.getDataPolicies());
+ newMergedVDB.setDescription(this.vdb.getDescription());
+ newMergedVDB.setStatus(this.vdb.getStatus());
+ newMergedVDB.setJAXBProperties(this.vdb.getJAXBProperties());
+ newMergedVDB.setConnectionType(this.vdb.getConnectionType());
ConnectorManagerRepository mergedRepo = new ConnectorManagerRepository();
mergedRepo.getConnectorManagers().putAll(this.cmr.getConnectorManagers());
for (CompositeVDB child:this.children.values()) {
// add models
for (Model m:child.getVDB().getModels()) {
- mergedVDB.addModel((ModelMetaData)m);
+ newMergedVDB.addModel((ModelMetaData)m);
}
for (DataPolicy p:child.getVDB().getDataPolicies()) {
- mergedVDB.addDataPolicy((DataPolicyMetadata)p);
+ newMergedVDB.addDataPolicy((DataPolicyMetadata)p);
}
mergedRepo.getConnectorManagers().putAll(child.cmr.getConnectorManagers());
}
- mergedVDB.addAttchment(ConnectorManagerRepository.class, mergedRepo);
- return mergedVDB;
+ newMergedVDB.addAttchment(ConnectorManagerRepository.class, mergedRepo);
+ return newMergedVDB;
}
private UDFMetaData getUDF() {
@@ -216,7 +213,7 @@
return mergedvisibilityMap;
}
- private MetadataStoreGroup getMetadataStores() {
+ public MetadataStoreGroup getMetadataStores() {
if (this.children == null || this.children.isEmpty()) {
return this.stores;
}
@@ -226,9 +223,9 @@
mergedStores.addStores(this.stores.getStores());
}
for (CompositeVDB child:this.children.values()) {
- MetadataStoreGroup stores = child.getMetadataStores();
- if ( stores != null) {
- mergedStores.addStores(stores.getStores());
+ MetadataStoreGroup childStores = child.getMetadataStores();
+ if ( childStores != null) {
+ mergedStores.addStores(childStores.getStores());
}
}
return mergedStores;
Modified: branches/7.4.x/runtime/src/main/java/org/teiid/deployers/MetadataStoreGroup.java
===================================================================
--- branches/7.4.x/runtime/src/main/java/org/teiid/deployers/MetadataStoreGroup.java 2011-05-09 19:00:00 UTC (rev 3157)
+++ branches/7.4.x/runtime/src/main/java/org/teiid/deployers/MetadataStoreGroup.java 2011-05-10 14:44:57 UTC (rev 3158)
@@ -22,15 +22,15 @@
package org.teiid.deployers;
import java.io.Serializable;
-import java.util.ArrayList;
import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
import org.teiid.metadata.MetadataStore;
public class MetadataStoreGroup implements Serializable{
private static final long serialVersionUID = -3702321839716725121L;
- List<MetadataStore> stores = new ArrayList<MetadataStore>();
+ List<MetadataStore> stores = new CopyOnWriteArrayList<MetadataStore>();
public void addStores(List<MetadataStore> stores) {
this.stores.addAll(stores);
Modified: branches/7.4.x/runtime/src/main/java/org/teiid/deployers/VDBDeployer.java
===================================================================
--- branches/7.4.x/runtime/src/main/java/org/teiid/deployers/VDBDeployer.java 2011-05-09 19:00:00 UTC (rev 3157)
+++ branches/7.4.x/runtime/src/main/java/org/teiid/deployers/VDBDeployer.java 2011-05-10 14:44:57 UTC (rev 3158)
@@ -157,11 +157,12 @@
valid = validateSources(cmr, deployment);
// Check if the VDB is fully configured.
- if (valid) {
+ if (!valid) {
+ deployment.setStatus(VDB.Status.INACTIVE);
+ } else if (!deployment.isDynamic()) {
+ this.vdbRepository.finishDeployment(deployment.getName(), deployment.getVersion());
deployment.setStatus(VDB.Status.ACTIVE);
- } else {
- deployment.setStatus(VDB.Status.INACTIVE);
- }
+ }
}
else {
deployment.setStatus(VDB.Status.ACTIVE);
@@ -369,7 +370,7 @@
LogManager.logInfo(LogConstants.CTX_RUNTIME, RuntimePlugin.Util.getString("metadata_loaded",vdb.getName(), vdb.getVersion(), model.getName())); //$NON-NLS-1$
model.clearErrors();
if (vdb.isValid()) {
- this.vdbRepository.updateVDB(vdb.getName(), vdb.getVersion());
+ this.vdbRepository.finishDeployment(vdb.getName(), vdb.getVersion());
vdb.setStatus(VDB.Status.ACTIVE);
LogManager.logInfo(LogConstants.CTX_RUNTIME, RuntimePlugin.Util.getString("vdb_activated",vdb.getName(), vdb.getVersion())); //$NON-NLS-1$
}
Modified: branches/7.4.x/runtime/src/main/java/org/teiid/deployers/VDBRepository.java
===================================================================
--- branches/7.4.x/runtime/src/main/java/org/teiid/deployers/VDBRepository.java 2011-05-09 19:00:00 UTC (rev 3157)
+++ branches/7.4.x/runtime/src/main/java/org/teiid/deployers/VDBRepository.java 2011-05-10 14:44:57 UTC (rev 3158)
@@ -100,19 +100,17 @@
else {
cvdb = new CompositeVDB(vdb, stores, visibilityMap, udf, this.systemFunctionManager.getSystemFunctions(), cmr, this.systemStore, odbcStore);
}
- updateFromMetadataRepository(stores, cvdb);
this.vdbRepo.put(vdbId(vdb), cvdb);
notifyAdd(vdb.getName(), vdb.getVersion());
}
- private void updateFromMetadataRepository(MetadataStoreGroup stores,
- CompositeVDB cvdb) {
+ private void updateFromMetadataRepository(CompositeVDB cvdb) {
if (metadataRepository == null) {
return;
}
String vdbName = cvdb.getVDB().getName();
int vdbVersion = cvdb.getVDB().getVersion();
- LinkedList<MetadataStore> allStores = new LinkedList<MetadataStore>(stores.getStores());
+ LinkedList<MetadataStore> allStores = new LinkedList<MetadataStore>(cvdb.getMetadataStores().getStores());
allStores.addAll(Arrays.asList(cvdb.getAdditionalStores()));
metadataRepository.startLoadVdb(vdbName, vdbVersion);
for (MetadataStore metadataStore : allStores) {
@@ -316,10 +314,11 @@
}
}
- void updateVDB(String name, int version) {
+ public void finishDeployment(String name, int version) {
CompositeVDB v = this.vdbRepo.get(new VDBKey(name, version));
if (v!= null) {
- v.update(v.getVDB(), systemFunctionManager.getSystemFunctions());
+ updateFromMetadataRepository(v);
+ v.update();
}
}
Modified: branches/7.4.x/test-integration/common/src/test/java/org/teiid/jdbc/FakeServer.java
===================================================================
--- branches/7.4.x/test-integration/common/src/test/java/org/teiid/jdbc/FakeServer.java 2011-05-09 19:00:00 UTC (rev 3157)
+++ branches/7.4.x/test-integration/common/src/test/java/org/teiid/jdbc/FakeServer.java 2011-05-10 14:44:57 UTC (rev 3158)
@@ -146,6 +146,7 @@
MetadataStoreGroup stores = new MetadataStoreGroup();
stores.addStore(metadata);
this.repo.addVDB(vdbMetaData, stores, entries, null, cmr);
+ this.repo.finishDeployment(vdbName, 1);
} catch (DeploymentException e) {
throw new RuntimeException(e);
}
13 years, 7 months
teiid SVN: r3157 - trunk/build/kits/jboss-container/teiid-examples/jca.
by teiid-commits@lists.jboss.org
Author: vhalbert(a)redhat.com
Date: 2011-05-09 15:00:00 -0400 (Mon, 09 May 2011)
New Revision: 3157
Added:
trunk/build/kits/jboss-container/teiid-examples/jca/teiid-jdbc-template-ds.xml
Log:
TEIID-1581 adding a Teiid template example for defining the Teiid data source
Added: trunk/build/kits/jboss-container/teiid-examples/jca/teiid-jdbc-template-ds.xml
===================================================================
--- trunk/build/kits/jboss-container/teiid-examples/jca/teiid-jdbc-template-ds.xml (rev 0)
+++ trunk/build/kits/jboss-container/teiid-examples/jca/teiid-jdbc-template-ds.xml 2011-05-09 19:00:00 UTC (rev 3157)
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!-- ===================================================================== -->
+<!-- -->
+<!-- This is template that can be used to deploy Teiid -->
+<!-- as a datasource. -->
+<!-- ===================================================================== -->
+
+<!-- See http://www.jboss.org/community/wiki/Multiple1PC for information about local-tx-datasource -->
+<!-- ==================================================================== -->
+<!-- Datasource template for Teiid -->
+<!-- To use: -->
+<!-- - Replace (vdb) in the url with your vdb name -->
+<!-- - Place the file in the deploy directory -->
+<!-- ==================================================================== -->
+
+
+<datasources>
+ <local-tx-datasource>
+ <jndi-name>TeiidDS</jndi-name>
+ <connection-url>jdbc:teiid:(vdb)@mm://localhost:31000</connection-url>
+
+ <driver-class>org.teiid.jdbc.TeiidDriver</driver-class>
+ <user>user</user>
+ <password>user</password>
+
+ <metadata>
+ <type-mapping>jdbc</type-mapping>
+ </metadata>
+ </local-tx-datasource>
+
+</datasources>
Property changes on: trunk/build/kits/jboss-container/teiid-examples/jca/teiid-jdbc-template-ds.xml
___________________________________________________________________
Added: svn:keywords
+ Id Revision
Added: svn:eol-style
+ LF
13 years, 7 months
teiid SVN: r3156 - in branches/7.4.x: common-core/src/test/java/org/teiid/core/util and 5 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2011-05-09 13:24:36 -0400 (Mon, 09 May 2011)
New Revision: 3156
Added:
branches/7.4.x/test-integration/common/src/test/java/org/teiid/jdbc/TestLocalConnections.java
Modified:
branches/7.4.x/common-core/src/main/java/org/teiid/core/util/ReflectionHelper.java
branches/7.4.x/common-core/src/test/java/org/teiid/core/util/TestReflectionHelper.java
branches/7.4.x/engine/src/main/java/org/teiid/common/buffer/impl/BufferManagerImpl.java
branches/7.4.x/engine/src/main/java/org/teiid/dqp/internal/datamgr/ConnectorWorkItem.java
branches/7.4.x/engine/src/main/java/org/teiid/dqp/internal/process/DQPCore.java
branches/7.4.x/runtime/src/main/java/org/teiid/transport/SocketClientInstance.java
branches/7.4.x/test-integration/common/src/test/java/org/teiid/jdbc/FakeServer.java
Log:
TEIID-1579 general fix for ReflectionHelper create logic, and proper lock / queue management with synch queries.
Modified: branches/7.4.x/common-core/src/main/java/org/teiid/core/util/ReflectionHelper.java
===================================================================
--- branches/7.4.x/common-core/src/main/java/org/teiid/core/util/ReflectionHelper.java 2011-05-05 17:35:15 UTC (rev 3155)
+++ branches/7.4.x/common-core/src/main/java/org/teiid/core/util/ReflectionHelper.java 2011-05-09 17:24:36 UTC (rev 3156)
@@ -23,6 +23,7 @@
package org.teiid.core.util;
import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
@@ -175,26 +176,7 @@
}
for (Method method : methodsWithSameName) {
Class[] args = method.getParameterTypes();
- if ( args.length != argumentsClasses.size() ) {
- continue;
- }
- boolean allMatch = true; // assume all args match
- for ( int i=0; i<args.length && allMatch == true; ++i ) {
- Class<?> primitiveClazz = argumentsClassList.get(i);
- Class<?> objectClazz = argumentsClasses.get(i);
- if ( objectClazz != null ) {
- // Check for possible matches with (converted) primitive types
- // as well as the original Object type
- if ( ! args[i].equals(primitiveClazz) && ! args[i].isAssignableFrom(objectClazz) ) {
- allMatch = false; // found one that doesn't match
- }
- } else {
- // a null is assignable for everything except a primitive
- if ( args[i].isPrimitive() ) {
- allMatch = false; // found one that doesn't match
- }
- }
- }
+ boolean allMatch = argsMatch(argumentsClasses, argumentsClassList, args);
if ( allMatch ) {
if (result != null) {
throw new NoSuchMethodException(methodName + " Args: " + argumentsClasses + " has multiple possible signatures."); //$NON-NLS-1$ //$NON-NLS-2$
@@ -209,6 +191,30 @@
throw new NoSuchMethodException(methodName + " Args: " + argumentsClasses); //$NON-NLS-1$
}
+
+ private static boolean argsMatch(List<Class<?>> argumentsClasses,
+ List<Class<?>> argumentsClassList, Class[] args) {
+ if ( args.length != argumentsClasses.size() ) {
+ return false;
+ }
+ for ( int i=0; i<args.length; ++i ) {
+ Class<?> primitiveClazz = argumentsClassList.get(i);
+ Class<?> objectClazz = argumentsClasses.get(i);
+ if ( objectClazz != null ) {
+ // Check for possible matches with (converted) primitive types
+ // as well as the original Object type
+ if ( ! args[i].equals(primitiveClazz) && ! args[i].isAssignableFrom(objectClazz) ) {
+ return false; // found one that doesn't match
+ }
+ } else {
+ // a null is assignable for everything except a primitive
+ if ( args[i].isPrimitive() ) {
+ return false; // found one that doesn't match
+ }
+ }
+ }
+ return true;
+ }
/**
* Convert any argument classes to primitives.
@@ -260,10 +266,10 @@
* @param classLoader the class loader to use; may be null if the current
* class loader is to be used
* @return Object is the instance of the class
- * @throws TeiidException if an error occurrs instantiating the class
+ * @throws TeiidException if an error occurs instantiating the class
*/
- public static final Object create(String className, Collection ctorObjs,
+ public static final Object create(String className, Collection<?> ctorObjs,
final ClassLoader classLoader) throws TeiidException {
try {
int size = (ctorObjs == null ? 0 : ctorObjs.size());
@@ -272,10 +278,12 @@
int i = 0;
if (size > 0) {
- for (Iterator it=ctorObjs.iterator(); it.hasNext(); ) {
+ for (Iterator<?> it=ctorObjs.iterator(); it.hasNext(); ) {
Object obj = it.next();
- names[i] = loadClass(obj.getClass().getName(),classLoader);
- objArray[i] = obj;
+ if (obj != null) {
+ names[i] = obj.getClass();
+ objArray[i] = obj;
+ }
i++;
}
}
@@ -287,16 +295,39 @@
public static final Object create(String className, Object[] ctorObjs, Class<?>[] argTypes,
final ClassLoader classLoader) throws TeiidException {
+ Class<?> cls;
try {
- final Class<?> cls = loadClass(className,classLoader);
-
- Constructor<?> ctor = cls.getDeclaredConstructor(argTypes);
-
- return ctor.newInstance(ctorObjs);
-
+ cls = loadClass(className,classLoader);
} catch(Exception e) {
throw new TeiidException(e);
}
+ Constructor<?> ctor = null;
+ try {
+ ctor = cls.getDeclaredConstructor(argTypes);
+ } catch (NoSuchMethodException e) {
+
+ }
+
+ if (ctor == null && argTypes != null && argTypes.length > 0) {
+ List<Class<?>> argumentsClasses = Arrays.asList(argTypes);
+ List<Class<?>> argumentsClassList = convertArgumentClassesToPrimitives(argumentsClasses);
+ for (Constructor<?> possible : cls.getDeclaredConstructors()) {
+ if (argsMatch(argumentsClasses, argumentsClassList, possible.getParameterTypes())) {
+ ctor = possible;
+ break;
+ }
+ }
+ }
+
+ if (ctor == null) {
+ throw new TeiidException(className + " Args: " + Arrays.toString(argTypes)); //$NON-NLS-1$
+ }
+
+ try {
+ return ctor.newInstance(ctorObjs);
+ } catch (Exception e) {
+ throw new TeiidException(e);
+ }
}
}
Modified: branches/7.4.x/common-core/src/test/java/org/teiid/core/util/TestReflectionHelper.java
===================================================================
--- branches/7.4.x/common-core/src/test/java/org/teiid/core/util/TestReflectionHelper.java 2011-05-05 17:35:15 UTC (rev 3155)
+++ branches/7.4.x/common-core/src/test/java/org/teiid/core/util/TestReflectionHelper.java 2011-05-09 17:24:36 UTC (rev 3156)
@@ -27,6 +27,7 @@
import java.io.Serializable;
import java.lang.reflect.Method;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
import org.junit.Test;
@@ -384,6 +385,10 @@
helpAssertSameMethodSignature("Found wrong method signature", signatureExpected, signatureFound); //$NON-NLS-1$
}
+ @Test public void testCreate() throws Exception {
+ ReflectionHelper.create(SomeClass.class.getName(), Arrays.asList(true), null);
+ }
+
/**
* Test base interface
*/
@@ -419,4 +424,9 @@
void method(Serializable arg1, Number arg2);
void method(Serializable arg1, Long arg2);
}
+
+ public static class SomeClass {
+ public SomeClass(boolean primArg) {
+ }
+ }
}
Modified: branches/7.4.x/engine/src/main/java/org/teiid/common/buffer/impl/BufferManagerImpl.java
===================================================================
--- branches/7.4.x/engine/src/main/java/org/teiid/common/buffer/impl/BufferManagerImpl.java 2011-05-05 17:35:15 UTC (rev 3155)
+++ branches/7.4.x/engine/src/main/java/org/teiid/common/buffer/impl/BufferManagerImpl.java 2011-05-09 17:24:36 UTC (rev 3156)
@@ -283,7 +283,7 @@
}
}
long count = readCount.incrementAndGet();
- LogManager.logTrace(LogConstants.CTX_BUFFER_MGR, batchManager.id, id, "reading batch from disk, total reads:", count); //$NON-NLS-1$
+ LogManager.logDetail(LogConstants.CTX_BUFFER_MGR, batchManager.id, id, "reading batch from disk, total reads:", count); //$NON-NLS-1$
try {
this.batchManager.compactionLock.readLock().lock();
long[] info = batchManager.physicalMapping.get(this.id);
@@ -320,7 +320,7 @@
if (batch != null) {
if (!persistent) {
long count = writeCount.incrementAndGet();
- LogManager.logTrace(LogConstants.CTX_BUFFER_MGR, batchManager.id, id, "writing batch to disk, total writes: ", count); //$NON-NLS-1$
+ LogManager.logDetail(LogConstants.CTX_BUFFER_MGR, batchManager.id, id, "writing batch to disk, total writes: ", count); //$NON-NLS-1$
long offset = 0;
if (lobManager != null) {
for (List<?> tuple : batch.getTuples()) {
Modified: branches/7.4.x/engine/src/main/java/org/teiid/dqp/internal/datamgr/ConnectorWorkItem.java
===================================================================
--- branches/7.4.x/engine/src/main/java/org/teiid/dqp/internal/datamgr/ConnectorWorkItem.java 2011-05-05 17:35:15 UTC (rev 3155)
+++ branches/7.4.x/engine/src/main/java/org/teiid/dqp/internal/datamgr/ConnectorWorkItem.java 2011-05-09 17:24:36 UTC (rev 3156)
@@ -271,7 +271,7 @@
protected AtomicResultsMessage handleBatch() throws TranslatorException {
Assertion.assertTrue(!this.lastBatch);
- LogManager.logDetail(LogConstants.CTX_CONNECTOR, new Object[] {this.id, "Sending results from connector"}); //$NON-NLS-1$
+ LogManager.logDetail(LogConstants.CTX_CONNECTOR, new Object[] {this.id, "Getting results from connector"}); //$NON-NLS-1$
int batchSize = 0;
List<List> rows = new ArrayList<List>(batchSize/4);
@@ -320,7 +320,9 @@
}
}
LogManager.logDetail(LogConstants.CTX_CONNECTOR, new Object[] {this.id, "Obtained last batch, total row count:", rowCount}); //$NON-NLS-1$\
- }
+ } else {
+ LogManager.logDetail(LogConstants.CTX_CONNECTOR, new Object[] {this.id, "Obtained results from connector, current row count:", rowCount}); //$NON-NLS-1$
+ }
int currentRowCount = rows.size();
if ( !lastBatch && currentRowCount == 0 ) {
Modified: branches/7.4.x/engine/src/main/java/org/teiid/dqp/internal/process/DQPCore.java
===================================================================
--- branches/7.4.x/engine/src/main/java/org/teiid/dqp/internal/process/DQPCore.java 2011-05-05 17:35:15 UTC (rev 3155)
+++ branches/7.4.x/engine/src/main/java/org/teiid/dqp/internal/process/DQPCore.java 2011-05-09 17:24:36 UTC (rev 3156)
@@ -332,9 +332,10 @@
RequestWorkItem workItem = new RequestWorkItem(this, requestMsg, request, resultsFuture.getResultsReceiver(), requestID, workContext);
logMMCommand(workItem, Event.NEW, null);
addRequest(requestID, workItem, state);
+ boolean runInThread = DQPWorkContext.getWorkContext().useCallingThread() || requestMsg.isSync();
synchronized (waitingPlans) {
- if (currentlyActivePlans < maxActivePlans || (!DQPWorkContext.getWorkContext().useCallingThread() && requestMsg.isSync())) {
- startActivePlan(workItem);
+ if (runInThread || currentlyActivePlans < maxActivePlans) {
+ startActivePlan(workItem, !runInThread);
} else {
if (LogManager.isMessageToBeRecorded(LogConstants.CTX_DQP, MessageLevel.DETAIL)) {
LogManager.logDetail(LogConstants.CTX_DQP, "Queuing plan, since max plans has been reached."); //$NON-NLS-1$
@@ -342,6 +343,9 @@
waitingPlans.add(workItem);
}
}
+ if (runInThread) {
+ workItem.run();
+ }
return resultsFuture;
}
@@ -362,15 +366,12 @@
state.addRequest(requestID);
}
- private void startActivePlan(RequestWorkItem workItem) {
+ private void startActivePlan(RequestWorkItem workItem, boolean addToQueue) {
workItem.active = true;
- if (workItem.getDqpWorkContext().useCallingThread() || workItem.requestMsg.isSync()) {
- this.currentlyActivePlans++;
- workItem.run();
- } else {
+ if (addToQueue) {
this.addWork(workItem);
- this.currentlyActivePlans++;
}
+ this.currentlyActivePlans++;
}
void finishProcessing(final RequestWorkItem workItem) {
@@ -381,7 +382,7 @@
workItem.active = false;
currentlyActivePlans--;
if (!waitingPlans.isEmpty()) {
- startActivePlan(waitingPlans.remove());
+ startActivePlan(waitingPlans.remove(), true);
}
}
}
Modified: branches/7.4.x/runtime/src/main/java/org/teiid/transport/SocketClientInstance.java
===================================================================
--- branches/7.4.x/runtime/src/main/java/org/teiid/transport/SocketClientInstance.java 2011-05-05 17:35:15 UTC (rev 3155)
+++ branches/7.4.x/runtime/src/main/java/org/teiid/transport/SocketClientInstance.java 2011-05-09 17:24:36 UTC (rev 3156)
@@ -75,7 +75,7 @@
public void send(Message message, Serializable messageKey) {
if (LogManager.isMessageToBeRecorded(LogConstants.CTX_TRANSPORT, MessageLevel.DETAIL)) {
- LogManager.logDetail(LogConstants.CTX_TRANSPORT, " message: " + message + " for request ID:" + messageKey); //$NON-NLS-1$ //$NON-NLS-2$
+ LogManager.logDetail(LogConstants.CTX_TRANSPORT, " message: " + message + " for message:" + messageKey); //$NON-NLS-1$ //$NON-NLS-2$
}
message.setMessageKey(messageKey);
objectSocket.write(message);
Modified: branches/7.4.x/test-integration/common/src/test/java/org/teiid/jdbc/FakeServer.java
===================================================================
--- branches/7.4.x/test-integration/common/src/test/java/org/teiid/jdbc/FakeServer.java 2011-05-05 17:35:15 UTC (rev 3155)
+++ branches/7.4.x/test-integration/common/src/test/java/org/teiid/jdbc/FakeServer.java 2011-05-09 17:24:36 UTC (rev 3156)
@@ -102,6 +102,10 @@
registerClientService(DQP.class, dqp, null);
}
+ public void stop() {
+ this.dqp.stop();
+ }
+
public void setMetadataRepository(MetadataRepository metadataRepository) {
this.repo.setMetadataRepository(metadataRepository);
this.dqp.setMetadataRepository(metadataRepository);
Added: branches/7.4.x/test-integration/common/src/test/java/org/teiid/jdbc/TestLocalConnections.java
===================================================================
--- branches/7.4.x/test-integration/common/src/test/java/org/teiid/jdbc/TestLocalConnections.java (rev 0)
+++ branches/7.4.x/test-integration/common/src/test/java/org/teiid/jdbc/TestLocalConnections.java 2011-05-09 17:24:36 UTC (rev 3156)
@@ -0,0 +1,139 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.jdbc;
+
+import static org.junit.Assert.*;
+
+import java.lang.Thread.UncaughtExceptionHandler;
+import java.sql.Connection;
+import java.sql.Statement;
+import java.util.LinkedHashMap;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.locks.Condition;
+import java.util.concurrent.locks.ReentrantLock;
+
+import org.jboss.netty.handler.timeout.TimeoutException;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.teiid.core.types.DataTypeManager;
+import org.teiid.metadata.FunctionMethod;
+import org.teiid.metadata.FunctionParameter;
+import org.teiid.metadata.MetadataStore;
+import org.teiid.metadata.Schema;
+import org.teiid.metadata.FunctionMethod.PushDown;
+import org.teiid.query.function.metadata.FunctionCategoryConstants;
+import org.teiid.query.metadata.TransformationMetadata.Resource;
+
+@SuppressWarnings("nls")
+public class TestLocalConnections {
+
+ private final class SimpleUncaughtExceptionHandler implements
+ UncaughtExceptionHandler {
+ Throwable t;
+
+ @Override
+ public void uncaughtException(Thread arg0, Throwable arg1) {
+ t = arg1;
+ }
+ }
+
+ static ReentrantLock lock = new ReentrantLock();
+ static Condition waiting = lock.newCondition();
+ static Condition wait = lock.newCondition();
+
+ public static int blocking() throws InterruptedException {
+ lock.lock();
+ try {
+ waiting.signal();
+ if (!wait.await(2, TimeUnit.SECONDS)) {
+ throw new TimeoutException();
+ }
+ } finally {
+ lock.unlock();
+ }
+ return 1;
+ }
+
+ static FakeServer server = new FakeServer();
+
+ @BeforeClass public static void oneTimeSetup() {
+ server.setUseCallingThread(true);
+ MetadataStore ms = new MetadataStore();
+ Schema s = new Schema();
+ s.setName("test");
+ FunctionMethod function = new FunctionMethod("foo", null, FunctionCategoryConstants.MISCELLANEOUS, PushDown.CANNOT_PUSHDOWN, TestLocalConnections.class.getName(), "blocking", new FunctionParameter[0], new FunctionParameter("result", DataTypeManager.DefaultDataTypes.INTEGER), true, FunctionMethod.Determinism.NONDETERMINISTIC);
+ s.addFunction(function);
+ ms.addSchema(s);
+ server.deployVDB("test", ms, new LinkedHashMap<String, Resource>());
+ }
+
+ @AfterClass public static void oneTimeTearDown() {
+ server.stop();
+ }
+
+ @Test public void testConcurrentExection() throws Throwable {
+
+ Thread t = new Thread() {
+
+ public void run() {
+ try {
+ Connection c = server.createConnection("jdbc:teiid:test");
+
+ Statement s = c.createStatement();
+ s.execute("select foo()");
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+ };
+ SimpleUncaughtExceptionHandler handler = new SimpleUncaughtExceptionHandler();
+ t.setUncaughtExceptionHandler(handler);
+ t.start();
+
+ lock.lock();
+ try {
+ waiting.await();
+ } finally {
+ lock.unlock();
+ }
+ Connection c = server.createConnection("jdbc:teiid:test");
+ Statement s = c.createStatement();
+ s.execute("select * from tables");
+
+ lock.lock();
+ try {
+ wait.signal();
+ } finally {
+ lock.unlock();
+ }
+ t.join(2000);
+ if (t.isAlive()) {
+ fail();
+ }
+ if (handler.t != null) {
+ throw handler.t;
+ }
+ }
+
+}
Property changes on: branches/7.4.x/test-integration/common/src/test/java/org/teiid/jdbc/TestLocalConnections.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
13 years, 7 months
teiid SVN: r3155 - in branches/7.4.x/connectors/translator-jdbc/src: test/java/org/teiid/translator/jdbc/teradata and 1 other directory.
by teiid-commits@lists.jboss.org
Author: rareddy
Date: 2011-05-05 13:35:15 -0400 (Thu, 05 May 2011)
New Revision: 3155
Modified:
branches/7.4.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/teradata/TeradataExecutionFactory.java
branches/7.4.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/teradata/TeradataSQLConversionVisitor.java
branches/7.4.x/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/teradata/TestTeradataTranslator.java
Log:
TEIID-1495: Handle negation in the IN criteria, specify supported functions when they have function modifiers and some time conversion utilities are corrected.
Modified: branches/7.4.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/teradata/TeradataExecutionFactory.java
===================================================================
--- branches/7.4.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/teradata/TeradataExecutionFactory.java 2011-05-04 20:38:13 UTC (rev 3154)
+++ branches/7.4.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/teradata/TeradataExecutionFactory.java 2011-05-05 17:35:15 UTC (rev 3155)
@@ -30,12 +30,15 @@
import java.util.List;
import org.teiid.core.types.DataTypeManager;
+import org.teiid.language.Expression;
import org.teiid.language.Function;
+import org.teiid.language.Literal;
import org.teiid.metadata.FunctionMethod;
import org.teiid.metadata.FunctionParameter;
import org.teiid.translator.SourceSystemFunctions;
import org.teiid.translator.Translator;
import org.teiid.translator.TranslatorException;
+import org.teiid.translator.TypeFacility;
import org.teiid.translator.jdbc.AliasModifier;
import org.teiid.translator.jdbc.ConvertModifier;
import org.teiid.translator.jdbc.FunctionModifier;
@@ -74,14 +77,18 @@
convert.addConvert(FunctionModifier.SHORT, FunctionModifier.STRING, new ImplicitConvertModifier());
convert.addConvert(FunctionModifier.DOUBLE, FunctionModifier.STRING, new ImplicitConvertModifier());
convert.addConvert(FunctionModifier.BYTE, FunctionModifier.STRING, new ImplicitConvertModifier());
+ convert.addConvert(FunctionModifier.TIMESTAMP, FunctionModifier.TIME, new TimeModifier("TIME")); //$NON-NLS-1$
+ convert.addConvert(FunctionModifier.TIMESTAMP, FunctionModifier.DATE, new TimeModifier("DATE")); //$NON-NLS-1$
+ convert.addConvert(FunctionModifier.TIME, FunctionModifier.TIMESTAMP, new TimeModifier("TIMESTAMP")); //$NON-NLS-1$
+ convert.addConvert(FunctionModifier.DATE, FunctionModifier.TIMESTAMP, new TimeModifier("TIMESTAMP")); //$NON-NLS-1$
+
+
convert.addTypeMapping("varchar(4000)", FunctionModifier.STRING); //$NON-NLS-1$
convert.addNumericBooleanConversions();
registerFunctionModifier(SourceSystemFunctions.CONVERT, convert);
- registerFunctionModifier(SourceSystemFunctions.RAND, new AliasModifier("random")); //$NON-NLS-1$
- registerFunctionModifier(SourceSystemFunctions.NULLIF, new AliasModifier("NULLIFZERO")); //$NON-NLS-1$
- registerFunctionModifier(SourceSystemFunctions.IFNULL, new AliasModifier("ZEROIFNULL")); //$NON-NLS-1$
+ registerFunctionModifier(SourceSystemFunctions.RAND, new AliasModifier("random")); //$NON-NLS-1$
registerFunctionModifier(SourceSystemFunctions.LOG, new AliasModifier("LN")); //$NON-NLS-1$
registerFunctionModifier(SourceSystemFunctions.LCASE, new AliasModifier("LOWER")); //$NON-NLS-1$
registerFunctionModifier(SourceSystemFunctions.UCASE, new AliasModifier("UPPER")); //$NON-NLS-1$
@@ -104,6 +111,31 @@
});
registerFunctionModifier(SourceSystemFunctions.LEFT, new LeftOrRightFunctionModifier(getLanguageFactory()));
registerFunctionModifier(SourceSystemFunctions.RIGHT, new LeftOrRightFunctionModifier(getLanguageFactory()));
+ registerFunctionModifier(SourceSystemFunctions.COT, new FunctionModifier() {
+ @Override
+ public List<?> translate(Function function) {
+ function.setName(SourceSystemFunctions.TAN);
+ return Arrays.asList(getLanguageFactory().createFunction(SourceSystemFunctions.DIVIDE_OP, new Expression[] {new Literal(1, TypeFacility.RUNTIME_TYPES.INTEGER), function}, TypeFacility.RUNTIME_TYPES.DOUBLE));
+ }
+ });
+ registerFunctionModifier(SourceSystemFunctions.LTRIM, new FunctionModifier() {
+ @Override
+ public List<?> translate(Function function) {
+ return Arrays.asList("TRIM(LEADING FROM ", function.getParameters().get(0), ")"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ });
+ registerFunctionModifier(SourceSystemFunctions.RTRIM, new FunctionModifier() {
+ @Override
+ public List<?> translate(Function function) {
+ return Arrays.asList("TRIM(TRAILING FROM ", function.getParameters().get(0), ")"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ });
+ registerFunctionModifier(SourceSystemFunctions.MOD, new FunctionModifier() {
+ @Override
+ public List<?> translate(Function function) {
+ return Arrays.asList(function.getParameters().get(0), " MOD ", function.getParameters().get(1)); //$NON-NLS-1$
+ }
+ });
}
@Override
@@ -122,14 +154,37 @@
supportedFunctions.add(SourceSystemFunctions.ASIN);
supportedFunctions.add(SourceSystemFunctions.ATAN);
supportedFunctions.add(SourceSystemFunctions.ATAN2);
+ supportedFunctions.add(SourceSystemFunctions.COALESCE);
supportedFunctions.add(SourceSystemFunctions.COS);
+ supportedFunctions.add(SourceSystemFunctions.COT);
supportedFunctions.add(SourceSystemFunctions.CONVERT);
+ supportedFunctions.add(SourceSystemFunctions.CURDATE);
+ supportedFunctions.add(SourceSystemFunctions.CURTIME);
+ supportedFunctions.add(SourceSystemFunctions.DAYOFMONTH);
supportedFunctions.add(SourceSystemFunctions.EXP);
+ supportedFunctions.add(SourceSystemFunctions.HOUR);
+ supportedFunctions.add(SourceSystemFunctions.LEFT);
+ supportedFunctions.add(SourceSystemFunctions.LOCATE);
supportedFunctions.add(SourceSystemFunctions.LOG);
+ supportedFunctions.add(SourceSystemFunctions.LCASE);
+ supportedFunctions.add(SourceSystemFunctions.LTRIM);
+ supportedFunctions.add(SourceSystemFunctions.LENGTH);
+ supportedFunctions.add(SourceSystemFunctions.MINUTE);
+ supportedFunctions.add(SourceSystemFunctions.MOD);
+ supportedFunctions.add(SourceSystemFunctions.MONTH);
+ supportedFunctions.add(SourceSystemFunctions.NULLIF);
+ supportedFunctions.add(SourceSystemFunctions.RAND);
+ supportedFunctions.add(SourceSystemFunctions.RIGHT);
+ supportedFunctions.add(SourceSystemFunctions.RTRIM);
+ supportedFunctions.add(SourceSystemFunctions.SECOND);
supportedFunctions.add(SourceSystemFunctions.SIN);
supportedFunctions.add(SourceSystemFunctions.SQRT);
+ supportedFunctions.add(SourceSystemFunctions.SUBSTRING);
supportedFunctions.add(SourceSystemFunctions.TAN);
supportedFunctions.add("||"); //$NON-NLS-1$
+ supportedFunctions.add("**"); //$NON-NLS-1$
+ supportedFunctions.add(SourceSystemFunctions.UCASE);
+ supportedFunctions.add(SourceSystemFunctions.YEAR);
return supportedFunctions;
}
@@ -211,6 +266,16 @@
new FunctionParameter("String2", DataTypeManager.DefaultDataTypes.STRING, "")}, //$NON-NLS-1$ //$NON-NLS-2$
new FunctionParameter("result", DataTypeManager.DefaultDataTypes.INTEGER, "") ) ); //$NON-NLS-1$ //$NON-NLS-2$
+ pushdownFunctions.add(new FunctionMethod(TERADATA + '.' + "NULLIFZERO", "NULLIFZERO", TERADATA, //$NON-NLS-1$ //$NON-NLS-2$
+ new FunctionParameter[] {
+ new FunctionParameter("integer", DataTypeManager.DefaultDataTypes.BIG_DECIMAL, "")}, //$NON-NLS-1$ //$NON-NLS-2$
+ new FunctionParameter("result", DataTypeManager.DefaultDataTypes.BIG_DECIMAL, "") ) ); //$NON-NLS-1$ //$NON-NLS-2$
+
+ pushdownFunctions.add(new FunctionMethod(TERADATA + '.' + "ZEROIFNULL", "ZEROIFNULL", TERADATA, //$NON-NLS-1$ //$NON-NLS-2$
+ new FunctionParameter[] {
+ new FunctionParameter("integer", DataTypeManager.DefaultDataTypes.BIG_DECIMAL, "")}, //$NON-NLS-1$ //$NON-NLS-2$
+ new FunctionParameter("result", DataTypeManager.DefaultDataTypes.BIG_DECIMAL, "") ) ); //$NON-NLS-1$ //$NON-NLS-2$
+
return pushdownFunctions;
}
@@ -295,4 +360,16 @@
return Arrays.asList(function.getParameters().get(0));
}
}
+
+
+ public static class TimeModifier extends FunctionModifier {
+ private String target;
+ public TimeModifier(String target) {
+ this.target = target;
+ }
+ @Override
+ public List<?> translate(Function function) {
+ return Arrays.asList("cast("+function.getParameters().get(0), " AS "+this.target+")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+ }
}
Modified: branches/7.4.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/teradata/TeradataSQLConversionVisitor.java
===================================================================
--- branches/7.4.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/teradata/TeradataSQLConversionVisitor.java 2011-05-04 20:38:13 UTC (rev 3154)
+++ branches/7.4.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/teradata/TeradataSQLConversionVisitor.java 2011-05-05 17:35:15 UTC (rev 3155)
@@ -52,16 +52,17 @@
}
if (decompose) {
+ Comparison.Operator opCode = obj.isNegated()?Comparison.Operator.NE:Comparison.Operator.EQ;
if (exprs.size() > 1) {
- Condition left = LanguageFactory.INSTANCE.createCompareCriteria(Comparison.Operator.EQ, obj.getLeftExpression(), exprs.get(0));
+ Condition left = LanguageFactory.INSTANCE.createCompareCriteria(opCode, obj.getLeftExpression(), exprs.get(0));
for (int i = 1; i < exprs.size(); i++) {
- AndOr replace = LanguageFactory.INSTANCE.createAndOr(Operator.OR, left, LanguageFactory.INSTANCE.createCompareCriteria(Comparison.Operator.EQ, obj.getLeftExpression(), exprs.get(i)));
+ AndOr replace = LanguageFactory.INSTANCE.createAndOr(obj.isNegated()?Operator.AND:Operator.OR, left, LanguageFactory.INSTANCE.createCompareCriteria(opCode, obj.getLeftExpression(), exprs.get(i)));
left = replace;
}
super.visit((AndOr)left);
}
else {
- super.visit(LanguageFactory.INSTANCE.createCompareCriteria(Comparison.Operator.EQ, obj.getLeftExpression(), exprs.get(0)));
+ super.visit(LanguageFactory.INSTANCE.createCompareCriteria(opCode, obj.getLeftExpression(), exprs.get(0)));
}
}
else {
Modified: branches/7.4.x/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/teradata/TestTeradataTranslator.java
===================================================================
--- branches/7.4.x/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/teradata/TestTeradataTranslator.java 2011-05-04 20:38:13 UTC (rev 3154)
+++ branches/7.4.x/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/teradata/TestTeradataTranslator.java 2011-05-05 17:35:15 UTC (rev 3155)
@@ -24,6 +24,7 @@
import static org.junit.Assert.assertEquals;
import java.sql.Date;
+import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -74,6 +75,10 @@
TranslationHelper.helpTestVisitor(TranslationHelper.BQT_VDB, input, output, TRANSLATOR);
}
+ @Test public void testTimestampToTime() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Timestamp(1304604994220L), Timestamp.class), "time", "cast({ts '2011-05-05 09:16:34.22'} AS TIME)");
+ }
+
@Test public void testByteToString() throws Exception {
helpTest(LANG_FACTORY.createLiteral(new Byte((byte)1), Byte.class), "string", "1");
}
@@ -118,6 +123,17 @@
assertEquals("'1' = func() OR '1' = '3'", helpGetString(expr));
}
+ @Test public void testNegatedInDecomposeNonLiterals() throws Exception {
+ Expression left = LANG_FACTORY.createLiteral("1", String.class);
+ List<Expression> right = new ArrayList<Expression>();
+ right.add(LANG_FACTORY.createFunction("func", new Expression[] {}, Date.class));
+ right.add(LANG_FACTORY.createLiteral("3", String.class));
+
+ In expr = LANG_FACTORY.createIn(left,right, true);
+
+ assertEquals("'1' <> func() AND '1' <> '3'", helpGetString(expr));
+ }
+
@Test public void testsingleInDecomposeNonLiterals() throws Exception {
Expression left = LANG_FACTORY.createLiteral("1", String.class);
List<Expression> right = new ArrayList<Expression>();
@@ -131,12 +147,18 @@
@Test public void testNullComapreNull() throws Exception {
String input = "SELECT INTKEY, STRINGKEY, DOUBLENUM FROM bqt1.smalla WHERE NULL <> NULL";
String out = "SELECT SmallA.IntKey, SmallA.StringKey, SmallA.DoubleNum FROM SmallA WHERE 1 = 0";
- TranslationHelper.helpTestVisitor(TranslationHelper.BQT_VDB, null, input, out, new TeradataExecutionFactory());
+ TranslationHelper.helpTestVisitor(TranslationHelper.BQT_VDB, null, input, out, TRANSLATOR);
}
@Test public void testPushDownFunction() throws Exception {
String input = "SELECT teradata.HASHBAKAMP(STRINGKEY) DOUBLENUM FROM bqt1.smalla";
String out = "SELECT HASHBAKAMP(SmallA.StringKey) AS DOUBLENUM FROM SmallA";
- TranslationHelper.helpTestVisitor(TranslationHelper.BQT_VDB, null, input, out, new TeradataExecutionFactory());
+ TranslationHelper.helpTestVisitor(TranslationHelper.BQT_VDB, null, input, out, TRANSLATOR);
}
+
+ @Test public void testRightFunction() throws Exception {
+ String input = "SELECT INTKEY, FLOATNUM FROM BQT1.SmallA WHERE right(FLOATNUM, 2) <> 0 ORDER BY INTKEY";
+ String out = "SELECT SmallA.IntKey, SmallA.FloatNum FROM SmallA WHERE SUBSTR(SmallA.FloatNum, (-1 * 2)) <> '0' ORDER BY SmallA.IntKey";
+ TranslationHelper.helpTestVisitor(TranslationHelper.BQT_VDB, null, input, out, TRANSLATOR);
+ }
}
13 years, 7 months
teiid SVN: r3154 - in branches/7.4.x/engine/src: test/java/org/teiid/query/optimizer and 1 other directory.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2011-05-04 16:38:13 -0400 (Wed, 04 May 2011)
New Revision: 3154
Modified:
branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleMergeVirtual.java
branches/7.4.x/engine/src/test/java/org/teiid/query/optimizer/TestRuleMergeVirtual.java
Log:
TEIID-1577 refining the union merge fix
Modified: branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleMergeVirtual.java
===================================================================
--- branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleMergeVirtual.java 2011-05-04 20:26:28 UTC (rev 3153)
+++ branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleMergeVirtual.java 2011-05-04 20:38:13 UTC (rev 3154)
@@ -279,25 +279,21 @@
}
}
}
-
- if (parentProject.getParent() != null
- && (parentProject.getParent().getType() != NodeConstants.Types.SET_OP || parentProject.getParent().getFirstChild() == parentProject)) {
- PlanNode sort = NodeEditor.findParent(parentProject, NodeConstants.Types.SORT, NodeConstants.Types.SOURCE);
- if (sort != null) { //special handling is needed since we are retaining the child aliases
- List<SingleElementSymbol> childProject = (List<SingleElementSymbol>)NodeEditor.findNodePreOrder(frame, NodeConstants.Types.PROJECT).getProperty(NodeConstants.Info.PROJECT_COLS);
- OrderBy elements = (OrderBy)sort.getProperty(NodeConstants.Info.SORT_ORDER);
- for (OrderByItem item : elements.getOrderByItems()) {
- item.setSymbol(childProject.get(selectSymbols.indexOf(item.getSymbol())));
- }
- sort.getGroups().clear();
- sort.addGroups(GroupsUsedByElementsVisitor.getGroups(elements));
- }
- PlanNode parentSource = NodeEditor.findParent(parentProject, NodeConstants.Types.SOURCE);
+
+ correctOrderBy(frame, selectSymbols, parentProject);
+ PlanNode parentSource = NodeEditor.findParent(frame, NodeConstants.Types.SOURCE);
+ PlanNode parentSetOp = NodeEditor.findParent(parentProject, NodeConstants.Types.SET_OP, NodeConstants.Types.SOURCE);
+
+ if (parentSetOp == null || NodeEditor.findNodePreOrder(parentSetOp, NodeConstants.Types.PROJECT) == parentProject) {
if (parentSource != null) {
FrameUtil.correctSymbolMap(((SymbolMap)frame.getProperty(NodeConstants.Info.SYMBOL_MAP)).asMap(), parentSource);
}
+ if (parentSetOp != null) {
+ correctOrderBy(frame, selectSymbols, parentSetOp);
+ }
}
+ prepareFrame(frame);
//remove the parent project and the source node
NodeEditor.removeChildNode(parentProject, frame);
if (parentProject.getParent() == null) {
@@ -309,6 +305,20 @@
return root;
}
+
+ private static void correctOrderBy(PlanNode frame,
+ List<SingleElementSymbol> selectSymbols, PlanNode startNode) {
+ PlanNode sort = NodeEditor.findParent(startNode, NodeConstants.Types.SORT, NodeConstants.Types.SOURCE | NodeConstants.Types.SET_OP);
+ if (sort != null) { //special handling is needed since we are retaining the child aliases
+ List<SingleElementSymbol> childProject = (List<SingleElementSymbol>)NodeEditor.findNodePreOrder(frame, NodeConstants.Types.PROJECT).getProperty(NodeConstants.Info.PROJECT_COLS);
+ OrderBy elements = (OrderBy)sort.getProperty(NodeConstants.Info.SORT_ORDER);
+ for (OrderByItem item : elements.getOrderByItems()) {
+ item.setSymbol(childProject.get(selectSymbols.indexOf(item.getSymbol())));
+ }
+ sort.getGroups().clear();
+ sort.addGroups(GroupsUsedByElementsVisitor.getGroups(elements));
+ }
+ }
/**
* Check to ensure that we are not projecting a subquery or null dependent expressions
Modified: branches/7.4.x/engine/src/test/java/org/teiid/query/optimizer/TestRuleMergeVirtual.java
===================================================================
--- branches/7.4.x/engine/src/test/java/org/teiid/query/optimizer/TestRuleMergeVirtual.java 2011-05-04 20:26:28 UTC (rev 3153)
+++ branches/7.4.x/engine/src/test/java/org/teiid/query/optimizer/TestRuleMergeVirtual.java 2011-05-04 20:38:13 UTC (rev 3154)
@@ -289,6 +289,24 @@
TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);
}
+ @Test public void testSimpleMergeUnionSecondBranchWithOrderBy1() throws Exception {
+ FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+ BasicSourceCapabilities caps = new BasicSourceCapabilities();
+ caps.setCapabilitySupport(Capability.QUERY_UNION, true);
+ caps.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, true);
+ caps.setCapabilitySupport(Capability.ROW_LIMIT, true);
+ caps.setCapabilitySupport(Capability.QUERY_SET_ORDER_BY, true);
+ caps.setCapabilitySupport(Capability.QUERY_ORDERBY, true);
+ caps.setCapabilitySupport(Capability.QUERY_SELECT_DISTINCT, true);
+ capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+ ProcessorPlan plan = TestOptimizer.helpPlan("select '1' as x, e2 from pm1.g1 union all (select e1, e2 from (select distinct e1, 1 as e2 from pm1.g2) as x order by e1 limit 1) order by x", //$NON-NLS-1$
+ FakeMetadataFactory.example1Cached(), null, capFinder,
+ new String[] {"SELECT '1' AS c_0, pm1.g1.e2 AS c_1 FROM pm1.g1 UNION ALL (SELECT DISTINCT pm1.g2.e1 AS c_0, 1 AS c_1 FROM pm1.g2 ORDER BY c_0 LIMIT 1) ORDER BY c_0"}, ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$
+
+ TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);
+ }
+
/**
* Note that the merge is not performed since it would create an expression in the group by clause
*/
@@ -337,6 +355,21 @@
assertTrue("Alias was not accounted for in sort node", node.getElements().get(0).equals(node.getSortElements().get(0).getSymbol())); //$NON-NLS-1$
}
+ @Test public void testSortAliasWithSameNameUnion() throws Exception {
+ String sql = "select e1 from (select distinct pm1.g1.e1 as e1 from pm1.g1) x union all select e1 from pm1.g2 order by e1"; //$NON-NLS-1$
+
+ FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+ BasicSourceCapabilities caps = new BasicSourceCapabilities();
+ caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
+ capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+ RelationalPlan plan = (RelationalPlan)TestOptimizer.helpPlan(sql, FakeMetadataFactory.example1Cached(),
+ new String[] {"SELECT g_0.e1 FROM pm1.g1 AS g_0", "SELECT g_0.e1 FROM pm1.g2 AS g_0"}, capFinder, TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$
+
+ SortNode node = (SortNode)plan.getRootNode();
+ assertTrue("Alias was not accounted for in sort node", node.getElements().get(0).equals(node.getSortElements().get(0).getSymbol())); //$NON-NLS-1$
+ }
+
@Test public void testMergeImplicitGroupBy() throws Exception {
BasicSourceCapabilities caps = TestAggregatePushdown.getAggregateCapabilities();
caps.setFunctionSupport("+", true); //$NON-NLS-1$
13 years, 7 months
teiid SVN: r3153 - in branches/7.4.x/connectors/translator-jdbc/src: test/java/org/teiid/translator/jdbc/teradata and 1 other directory.
by teiid-commits@lists.jboss.org
Author: rareddy
Date: 2011-05-04 16:26:28 -0400 (Wed, 04 May 2011)
New Revision: 3153
Modified:
branches/7.4.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/teradata/TeradataExecutionFactory.java
branches/7.4.x/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/teradata/TestTeradataTranslator.java
Log:
TEIID-1495: Teradata supports implicit conversion between numeric to string
Modified: branches/7.4.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/teradata/TeradataExecutionFactory.java
===================================================================
--- branches/7.4.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/teradata/TeradataExecutionFactory.java 2011-05-04 18:22:15 UTC (rev 3152)
+++ branches/7.4.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/teradata/TeradataExecutionFactory.java 2011-05-04 20:26:28 UTC (rev 3153)
@@ -65,15 +65,15 @@
convert.addTypeMapping("double precision", FunctionModifier.DOUBLE); //$NON-NLS-1$
convert.addTypeMapping("numeric(18,0)", FunctionModifier.BIGINTEGER); //$NON-NLS-1$
convert.addTypeMapping("char(1)", FunctionModifier.CHAR); //$NON-NLS-1$
- convert.addConvert(FunctionModifier.INTEGER, FunctionModifier.STRING, new NumericToStringModifier(12));
- convert.addConvert(FunctionModifier.BIGDECIMAL, FunctionModifier.STRING, new NumericToStringModifier(38));
- convert.addConvert(FunctionModifier.BIGINTEGER, FunctionModifier.STRING, new NumericToStringModifier(38));
- convert.addConvert(FunctionModifier.FLOAT, FunctionModifier.STRING, new NumericToStringModifier(25));
- convert.addConvert(FunctionModifier.BOOLEAN, FunctionModifier.STRING, new NumericToStringModifier(1));
- convert.addConvert(FunctionModifier.LONG, FunctionModifier.STRING, new NumericToStringModifier(25));
- convert.addConvert(FunctionModifier.SHORT, FunctionModifier.STRING, new NumericToStringModifier(12));
- convert.addConvert(FunctionModifier.DOUBLE, FunctionModifier.STRING, new NumericToStringModifier(25));
- convert.addConvert(FunctionModifier.BYTE, FunctionModifier.STRING, new NumericToStringModifier(4));
+ convert.addConvert(FunctionModifier.INTEGER, FunctionModifier.STRING, new ImplicitConvertModifier());
+ convert.addConvert(FunctionModifier.BIGDECIMAL, FunctionModifier.STRING, new ImplicitConvertModifier());
+ convert.addConvert(FunctionModifier.BIGINTEGER, FunctionModifier.STRING, new ImplicitConvertModifier());
+ convert.addConvert(FunctionModifier.FLOAT, FunctionModifier.STRING, new ImplicitConvertModifier());
+ convert.addConvert(FunctionModifier.BOOLEAN, FunctionModifier.STRING, new ImplicitConvertModifier());
+ convert.addConvert(FunctionModifier.LONG, FunctionModifier.STRING, new ImplicitConvertModifier());
+ convert.addConvert(FunctionModifier.SHORT, FunctionModifier.STRING, new ImplicitConvertModifier());
+ convert.addConvert(FunctionModifier.DOUBLE, FunctionModifier.STRING, new ImplicitConvertModifier());
+ convert.addConvert(FunctionModifier.BYTE, FunctionModifier.STRING, new ImplicitConvertModifier());
convert.addTypeMapping("varchar(4000)", FunctionModifier.STRING); //$NON-NLS-1$
convert.addNumericBooleanConversions();
@@ -289,20 +289,10 @@
}
}
- public static class NumericToStringModifier extends FunctionModifier {
- private int charSize;
- private String formatCode;
- public NumericToStringModifier(int size) {
- this.charSize = size;
- StringBuilder sb = new StringBuilder();
- for(int i = 0; i < size; i++) {
- sb.append('Z');
- }
- this.formatCode = sb.toString();
- }
+ public static class ImplicitConvertModifier extends FunctionModifier {
@Override
public List<?> translate(Function function) {
- return Arrays.asList("TRIM(BOTH FROM ",function.getParameters().get(0), " (FORMAT '"+this.formatCode+"')(CHAR("+this.charSize+")))"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ return Arrays.asList(function.getParameters().get(0));
}
}
}
Modified: branches/7.4.x/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/teradata/TestTeradataTranslator.java
===================================================================
--- branches/7.4.x/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/teradata/TestTeradataTranslator.java 2011-05-04 18:22:15 UTC (rev 3152)
+++ branches/7.4.x/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/teradata/TestTeradataTranslator.java 2011-05-04 20:26:28 UTC (rev 3153)
@@ -75,11 +75,15 @@
}
@Test public void testByteToString() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Byte((byte)1), Byte.class), "string", "TRIM(BOTH FROM 1 (FORMAT 'ZZZZ')(CHAR(4)))");
+ helpTest(LANG_FACTORY.createLiteral(new Byte((byte)1), Byte.class), "string", "1");
}
+ @Test public void testByte2ToString() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral(new Byte((byte)-1), Byte.class), "string", "-1");
+ }
+
@Test public void testDoubleToString() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Double(1.0), Double.class), "string", "TRIM(BOTH FROM 1.0 (FORMAT 'ZZZZZZZZZZZZZZZZZZZZZZZZZ')(CHAR(25)))");
+ helpTest(LANG_FACTORY.createLiteral(new Double(1.0), Double.class), "string", "1.0");
}
@Test public void testInDecompose() throws Exception {
13 years, 7 months
teiid SVN: r3152 - in branches/7.4.x: engine/src/main/java/org/teiid/query/sql/visitor and 2 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2011-05-04 14:22:15 -0400 (Wed, 04 May 2011)
New Revision: 3152
Modified:
branches/7.4.x/api/src/main/java/org/teiid/language/visitor/SQLStringVisitor.java
branches/7.4.x/engine/src/main/java/org/teiid/query/sql/visitor/SQLStringVisitor.java
branches/7.4.x/engine/src/test/java/org/teiid/query/sql/visitor/TestSQLStringVisitor.java
branches/7.4.x/test-integration/common/src/test/java/org/teiid/connector/visitor/util/TestSQLStringVisitor.java
Log:
TEIID-1578 fix for properly nesting the last set op branch
Modified: branches/7.4.x/api/src/main/java/org/teiid/language/visitor/SQLStringVisitor.java
===================================================================
--- branches/7.4.x/api/src/main/java/org/teiid/language/visitor/SQLStringVisitor.java 2011-05-04 18:21:08 UTC (rev 3151)
+++ branches/7.4.x/api/src/main/java/org/teiid/language/visitor/SQLStringVisitor.java 2011-05-04 18:22:15 UTC (rev 3152)
@@ -869,9 +869,9 @@
protected void appendSetQuery(SetQuery parent, QueryExpression obj, boolean right) {
if((!(obj instanceof SetQuery) && useParensForSetQueries())
- || (right && obj instanceof SetQuery
+ || (right && ((obj instanceof SetQuery
&& ((parent.isAll() && !((SetQuery)obj).isAll())
- || parent.getOperation() != ((SetQuery)obj).getOperation()))) {
+ || parent.getOperation() != ((SetQuery)obj).getOperation())) || obj.getLimit() != null || obj.getOrderBy() != null))) {
buffer.append(Tokens.LPAREN);
append(obj);
buffer.append(Tokens.RPAREN);
Modified: branches/7.4.x/engine/src/main/java/org/teiid/query/sql/visitor/SQLStringVisitor.java
===================================================================
--- branches/7.4.x/engine/src/main/java/org/teiid/query/sql/visitor/SQLStringVisitor.java 2011-05-04 18:21:08 UTC (rev 3151)
+++ branches/7.4.x/engine/src/main/java/org/teiid/query/sql/visitor/SQLStringVisitor.java 2011-05-04 18:22:15 UTC (rev 3152)
@@ -930,8 +930,8 @@
protected void appendSetQuery( SetQuery parent,
QueryCommand obj,
boolean right ) {
- if (right && obj instanceof SetQuery
- && ((parent.isAll() && !((SetQuery)obj).isAll()) || parent.getOperation() != ((SetQuery)obj).getOperation())) {
+ if (right && ((obj instanceof SetQuery
+ && ((parent.isAll() && !((SetQuery)obj).isAll()) || parent.getOperation() != ((SetQuery)obj).getOperation())) || obj.getLimit() != null || obj.getOrderBy() != null)) {
append(Tokens.LPAREN);
visitNode(obj);
append(Tokens.RPAREN);
Modified: branches/7.4.x/engine/src/test/java/org/teiid/query/sql/visitor/TestSQLStringVisitor.java
===================================================================
--- branches/7.4.x/engine/src/test/java/org/teiid/query/sql/visitor/TestSQLStringVisitor.java 2011-05-04 18:21:08 UTC (rev 3151)
+++ branches/7.4.x/engine/src/test/java/org/teiid/query/sql/visitor/TestSQLStringVisitor.java 2011-05-04 18:22:15 UTC (rev 3152)
@@ -1875,6 +1875,12 @@
helpTest(command, "SELECT pm1.g1.e1 FROM pm1.g1 UNION SELECT e2 FROM pm1.g2 ORDER BY e1"); //$NON-NLS-1$
}
+ public void testUnionBranchOrderBy() throws Exception {
+ Command command = QueryParser.getQueryParser().parseCommand("select pm1.g1.e1 from pm1.g1 union (select e2 from pm1.g2 order by e1)"); //$NON-NLS-1$
+ QueryResolver.resolveCommand(command, FakeMetadataFactory.example1Cached());
+ helpTest(command, "SELECT pm1.g1.e1 FROM pm1.g1 UNION (SELECT e2 FROM pm1.g2 ORDER BY e1)"); //$NON-NLS-1$
+ }
+
public void testAliasedOrderBy() throws Exception {
Command command = QueryParser.getQueryParser().parseCommand("select pm1.g1.e1 as a from pm1.g1 order by a"); //$NON-NLS-1$
QueryResolver.resolveCommand(command, FakeMetadataFactory.example1Cached());
Modified: branches/7.4.x/test-integration/common/src/test/java/org/teiid/connector/visitor/util/TestSQLStringVisitor.java
===================================================================
--- branches/7.4.x/test-integration/common/src/test/java/org/teiid/connector/visitor/util/TestSQLStringVisitor.java 2011-05-04 18:21:08 UTC (rev 3151)
+++ branches/7.4.x/test-integration/common/src/test/java/org/teiid/connector/visitor/util/TestSQLStringVisitor.java 2011-05-04 18:22:15 UTC (rev 3152)
@@ -352,7 +352,7 @@
}
@Test public void testVisitIUnion1() throws Exception {
- String expected = "SELECT DISTINCT g1.e1, g1.e2, g1.e3, g1.e4 FROM g1, g2 AS myAlias, g3, g4 WHERE 100 >= 200 AND 500 < 600 GROUP BY g1.e1, g1.e2, g1.e3, g1.e4 HAVING 100 >= 200 AND 500 < 600 ORDER BY g1.e1, g1.e2 DESC, g1.e3, g1.e4 DESC UNION SELECT DISTINCT g1.e1, g1.e2, g1.e3, g1.e4 FROM g1, g2 AS myAlias, g3, g4 WHERE 100 >= 200 AND 500 < 600 GROUP BY g1.e1, g1.e2, g1.e3, g1.e4 HAVING 100 >= 200 AND 500 < 600 ORDER BY g1.e1, g1.e2 DESC, g1.e3, g1.e4 DESC ORDER BY e1, e2 DESC, e3, e4 DESC";//$NON-NLS-1$
+ String expected = "SELECT DISTINCT g1.e1, g1.e2, g1.e3, g1.e4 FROM g1, g2 AS myAlias, g3, g4 WHERE 100 >= 200 AND 500 < 600 GROUP BY g1.e1, g1.e2, g1.e3, g1.e4 HAVING 100 >= 200 AND 500 < 600 ORDER BY g1.e1, g1.e2 DESC, g1.e3, g1.e4 DESC UNION (SELECT DISTINCT g1.e1, g1.e2, g1.e3, g1.e4 FROM g1, g2 AS myAlias, g3, g4 WHERE 100 >= 200 AND 500 < 600 GROUP BY g1.e1, g1.e2, g1.e3, g1.e4 HAVING 100 >= 200 AND 500 < 600 ORDER BY g1.e1, g1.e2 DESC, g1.e3, g1.e4 DESC) ORDER BY e1, e2 DESC, e3, e4 DESC";//$NON-NLS-1$
assertEquals(expected, getString(TestSetQueryImpl.example()));
}
13 years, 7 months
teiid SVN: r3151 - in branches/7.4.x/engine/src: test/java/org/teiid/query/optimizer and 1 other directory.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2011-05-04 14:21:08 -0400 (Wed, 04 May 2011)
New Revision: 3151
Modified:
branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleMergeVirtual.java
branches/7.4.x/engine/src/test/java/org/teiid/query/optimizer/TestRuleMergeVirtual.java
Log:
TEIID-1577 fix for attempting to adjust union order by from the non-primary union branch
Modified: branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleMergeVirtual.java
===================================================================
--- branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleMergeVirtual.java 2011-05-04 15:03:22 UTC (rev 3150)
+++ branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleMergeVirtual.java 2011-05-04 18:21:08 UTC (rev 3151)
@@ -228,7 +228,7 @@
if (frame.getFirstChild().getType() == NodeConstants.Types.TUPLE_LIMIT
&& NodeEditor.findParent(parentProject,
NodeConstants.Types.SORT | NodeConstants.Types.DUP_REMOVE,
- NodeConstants.Types.SOURCE) != null) {
+ NodeConstants.Types.SOURCE | NodeConstants.Types.SET_OP) != null) {
return root;
}
@@ -280,24 +280,24 @@
}
}
- PlanNode sort = NodeEditor.findParent(parentProject, NodeConstants.Types.SORT, NodeConstants.Types.SOURCE);
- if (sort != null) { //special handling is needed since we are retaining the child aliases
- List<SingleElementSymbol> childProject = (List<SingleElementSymbol>)NodeEditor.findNodePreOrder(frame, NodeConstants.Types.PROJECT).getProperty(NodeConstants.Info.PROJECT_COLS);
- OrderBy elements = (OrderBy)sort.getProperty(NodeConstants.Info.SORT_ORDER);
- for (OrderByItem item : elements.getOrderByItems()) {
- item.setSymbol(childProject.get(selectSymbols.indexOf(item.getSymbol())));
- }
- sort.getGroups().clear();
- sort.addGroups(GroupsUsedByElementsVisitor.getGroups(elements));
+ if (parentProject.getParent() != null
+ && (parentProject.getParent().getType() != NodeConstants.Types.SET_OP || parentProject.getParent().getFirstChild() == parentProject)) {
+ PlanNode sort = NodeEditor.findParent(parentProject, NodeConstants.Types.SORT, NodeConstants.Types.SOURCE);
+ if (sort != null) { //special handling is needed since we are retaining the child aliases
+ List<SingleElementSymbol> childProject = (List<SingleElementSymbol>)NodeEditor.findNodePreOrder(frame, NodeConstants.Types.PROJECT).getProperty(NodeConstants.Info.PROJECT_COLS);
+ OrderBy elements = (OrderBy)sort.getProperty(NodeConstants.Info.SORT_ORDER);
+ for (OrderByItem item : elements.getOrderByItems()) {
+ item.setSymbol(childProject.get(selectSymbols.indexOf(item.getSymbol())));
+ }
+ sort.getGroups().clear();
+ sort.addGroups(GroupsUsedByElementsVisitor.getGroups(elements));
+ }
+ PlanNode parentSource = NodeEditor.findParent(parentProject, NodeConstants.Types.SOURCE);
+ if (parentSource != null) {
+ FrameUtil.correctSymbolMap(((SymbolMap)frame.getProperty(NodeConstants.Info.SYMBOL_MAP)).asMap(), parentSource);
+ }
}
-
- PlanNode parentSource = NodeEditor.findParent(parentProject, NodeConstants.Types.SOURCE);
-
- if (parentSource != null) {
- FrameUtil.correctSymbolMap(((SymbolMap)frame.getProperty(NodeConstants.Info.SYMBOL_MAP)).asMap(), parentSource);
- }
-
//remove the parent project and the source node
NodeEditor.removeChildNode(parentProject, frame);
if (parentProject.getParent() == null) {
Modified: branches/7.4.x/engine/src/test/java/org/teiid/query/optimizer/TestRuleMergeVirtual.java
===================================================================
--- branches/7.4.x/engine/src/test/java/org/teiid/query/optimizer/TestRuleMergeVirtual.java 2011-05-04 15:03:22 UTC (rev 3150)
+++ branches/7.4.x/engine/src/test/java/org/teiid/query/optimizer/TestRuleMergeVirtual.java 2011-05-04 18:21:08 UTC (rev 3151)
@@ -273,6 +273,22 @@
}, TestLimit.NODE_TYPES);
}
+ @Test public void testSimpleMergeUnionSecondBranchWithOrderBy() throws Exception {
+ FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+ BasicSourceCapabilities caps = new BasicSourceCapabilities();
+ caps.setCapabilitySupport(Capability.QUERY_UNION, true);
+ caps.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, true);
+ caps.setCapabilitySupport(Capability.ROW_LIMIT, true);
+ caps.setCapabilitySupport(Capability.QUERY_SET_ORDER_BY, true);
+ capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+ ProcessorPlan plan = TestOptimizer.helpPlan("select '1' as x, e2 from pm1.g1 union all select e1, e2 from (select e1, 1 as e2 from pm1.g2 limit 1) as x order by x", //$NON-NLS-1$
+ FakeMetadataFactory.example1Cached(), null, capFinder,
+ new String[] {"SELECT '1' AS c_0, pm1.g1.e2 AS c_1 FROM pm1.g1 UNION ALL (SELECT pm1.g2.e1 AS c_0, 1 AS c_1 FROM pm1.g2 LIMIT 1) ORDER BY c_0"}, ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$
+
+ TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);
+ }
+
/**
* Note that the merge is not performed since it would create an expression in the group by clause
*/
13 years, 7 months